-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRuckusLibrary.py
1794 lines (1633 loc) · 86.7 KB
/
RuckusLibrary.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Written by David Johnson
# Implemented by Kai McGregor for use in Kai-ACK
# 1.7634, double ap functionality, double not on controller fix
'''
PURPOSE
This file contains functions for communicating with a Ruckus SmartZone
controller.
It also contains functionality to work with Kai-ACK.
'''
# ------------------------------------------------------------------------------
'''
FUNCTIONALITY
MikroTiks tell the AP to connect to a controller through Option 43, which has a
control IP of the first controller in a cluster.
The control IP is usually associated with the first management IP in that
cluster.
'''
# ------------------------------------------------------------------------------
'''
OBJECTS
--NO KAI-ACK--
If you want to use RuckusLibrary separate of Kai-ACK, you must create an
object using the controllerInputObject class.
Once that's done, create a Session like so:
with requests.session() as sessionID:
Then place your code to login within your session. Like so:
with requests.session() as sessionID:
for ip in userInputObject.controllerCluster:
loginAttempt = RuckusLibrary.loginRuckus(sessionID, userInputObject, ip)
if loginAttempt == 200:
sessionIP = ip
break
time.sleep(1)
**************YOUR FUNCTIONS GO HERE**************
RuckusLibrary.logoutRuckus(sessionID, sessionIP)
Some functions may require previous info to get retrieved. It's good measure
to create an object using the initializeZoneInfo class if you're doing
anything AP/zone related.
--WITH KAI-ACK--
RuckusLibrary is used alongside Kai-ACK.
The programKaiACK class is used to program both single and double APs.
Kai-ACK displays messages to the user through a library called Publisher.
When 'panel' object is being passed in - Publisher messages are being used.
'''
# ------------------------------------------------------------------------------
# Python/3rd Party Libraries
import requests
import time
import json
import socket
import urllib3
# UI Libraries
import googlesheets
import traceback # helps identify errors
from pubsub import pub as Publisher # used to post messages in UI
import wx # used for login error message
# urllib3.disable_warnings(urllib3.exceptions.NewConnectionError, urllib3.exceptions.MaxRetryError)
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# controller API communicates through HTTP requests. It requires each command
# to have certain info sent with it to properly understand what's being sent
# These headers are used in every command except the Login
universalHeaders = {
'Content-Type': 'application/json;charset=UTF-8'
}
# These cookies are used in every command except the Login
universalCookies = {
'Cookie': 'JSESSIONID={JSESSIONID}'
}
# --------------------------------CLASSES---------------------------------------
class initializeZoneInfo: # retrieves static zone information
def __init__(self, userInputObject):
self.userInputObject = userInputObject
# --------------------------------------------
self.apZoneName = userInputObject.apZoneName
self.apGroupList = ''
self.apGroupID = ''
self.apZoneList = ''
self.apZoneID = ''
self.sessionIP = '' # zone info class uses sessionIP inside its functions
self.validSession = False # used in each function to check if session is good
def retrieveZoneInfo(self):
sessionID = requests.session() # ID used to store session cookies # ID used to store session cookies
print('\n*****************************Retrieving AP lists...*****************************')
loginAttempt = loginRuckus(sessionID, self, self.userInputObject)
if loginAttempt == 200: # login successful
zoneList = retrieveZoneList(sessionID, self, self.userInputObject)
if zoneList == 200:
retrieveAPGroupList(sessionID, self, self.userInputObject)
logoutRuckus(sessionID, self.sessionIP)
self.sessionIP = None
print('******************************AP Lists retrieved.*******************************\n')
return 200
elif zoneList == 404: # zone not found with name given
return 404 # zone name incorrect
elif loginAttempt == 202: # login username/password incorrect
print('Controller username or password is incorrect.')
return loginAttempt
else: # login not successful
print(loginAttempt)
return loginAttempt
return False # all ips failed on login
class initializeWLANInfo: # retrieves IDs for WLAN groups
def __init__(self):
self.wlanGroupID = ''
self.wlanGroupName = ''
self.wlanGroupGuestID = ''
self.wlanGroupGuestName = ''
class initializeAP:
def __init__(self):
self.apMAC = ''
self.apSN = ''
self.apSSID = ''
self.apIP = ''
self.apModel = ''
wlanInfo = initializeWLANInfo()
self.wlanInfo = wlanInfo
class programKaiACK: # skeleton class that calls objects for programming APs
def __init__(self, userInputObject):
# STORES USER INPUTS & OBJECTS
self.userInputObject = userInputObject # used in zoneInfo & prog APs
# -------------------------------------
self.zoneInfoObject = None
def kaiACKRetrieveZoneInfo(self):
# ZONE INFO
self.zoneInfoObject = initializeZoneInfo(self.userInputObject) # initializes zoneInfo object
zoneInfoStatus = self.zoneInfoObject.retrieveZoneInfo() # populates zoneInfo object with IDs
return zoneInfoStatus # will return True or False
def kaiACKProgramSingleAP(self, panel):
print('\n*****************************Programming single AP.*****************************')
apWLANInfoObj = initializeWLANInfo() # used to store WLAN group IDs
apInfoObj = initializeAP() # creates temp object that uses panel attributes
apInfoObj.apSSID = panel.ssid
apInfoObj.apMAC = panel.apMAC
apInfoObj.apIP = '10.10.10.254'
panel.apSN = '' # panel obj takes SN at end of process
self.zoneInfoObject.validSession = False # used in each function to check if session is good
# checks for required info from AP Info object
if self.zoneInfoObject.apZoneID == None:
print("Couldn't find AP Zone. Please relaunch and enter a valid zone.")
Publisher.sendMessage('status', ssid=panel.ssid, message="Couldn't find AP Zone. Please relaunch and enter a valid zone.", group = 1)
return panel
sessionID = requests.session() # ID used to store session cookies
# -------------------------RETRIEVES DATA---------------------------
# operates if required AP Lists info is retrieved successfully
# or doesn't recieve the info it needs from a previous command
while True: # MASTER BLOCK, REDOES SESSIONS IF INVALID MIDWAY
# LOGIN BLOCK
printLoginPublisher = True
while self.zoneInfoObject.validSession is False: # loops until session is established
# selects controller ip to use for programming process
loginAttempt = loginRuckus(sessionID, self.zoneInfoObject, self.userInputObject)
if loginAttempt == 200:
Publisher.sendMessage('status', ssid=panel.ssid, message='Ruckus Controller logged in.', group = 1)
break
elif printLoginPublisher is True:
Publisher.sendMessage('status', ssid=panel.ssid, message='Controller login error. Retrying...', group = 1)
printLoginPublisher = False # stops login publisher messages
if self.zoneInfoObject.validSession is True: # ends LOGIN BLOCK
break # continues to next loop
# PROGRAMMING BLOCK
while self.zoneInfoObject.validSession is True:
retrieveWLANGroupList(sessionID, self.zoneInfoObject, self.userInputObject, apInfoObj)
if 'Guest'.lower() in apInfoObj.wlanInfo.wlanGroupName:
print("Guest WLAN used. Couldn't find unit specific WLAN for AP.")
if apInfoObj.wlanInfo.wlanGroupID != '':
Publisher.sendMessage('status', ssid=panel.ssid, message='WLAN IDs retrieved.', group = 1)
else: # wlanGroupIDs weren't found
Publisher.sendMessage('status', ssid=panel.ssid, message='No WLAN IDs retrieved.', group = 1)
return False
# -------------------------CHANGES DATA-----------------------
showZoneStatus = True # variable that sets publisher messages to only print once
# CHANGE ZONE
while self.zoneInfoObject.validSession is True:
changeAPZoneResponse = changeAPZone(sessionID, self.zoneInfoObject, self.userInputObject, apInfoObj)
if changeAPZoneResponse == 204:
Publisher.sendMessage('status', ssid=panel.ssid, message='AP zone changed.', group = 1)
break
elif changeAPZoneResponse == 403:
if showZoneStatus == True:
Publisher.sendMessage('status', ssid=panel.ssid, message='Controller not accepting commands. Make sure AP is on the controller...', group = 1)
showZoneStatus = False
time.sleep(10)
else:
if showZoneStatus == True:
Publisher.sendMessage('status', ssid=panel.ssid, message='AP zone changed failed, Retrying...', group = 1)
showZoneStatus = False
time.sleep(10)
# CHANGE CONFIG
changeAPConfigResponse = changeAPConfig(sessionID, self.zoneInfoObject, self.userInputObject, apInfoObj)
if changeAPConfigResponse is 204:
Publisher.sendMessage('status', ssid=panel.ssid, message='AP configured.', group = 1)
elif changeAPConfigResponse == 211:
Publisher.sendMessage('status', ssid=panel.ssid, message='Changing AP config failed. AP Not found on controller...', group = 1)
else:
Publisher.sendMessage('status', ssid=panel.ssid, message='AP configuration failed, Retrying...', group = 1)
# QC BLOCK
# --------------------checkAPConfig return---------------------
# [returnStatus, apName, zoneID, apGroupID, wlanGroup24ID, wlanGroup50ID, ipType, modelSpecific]
# --------------------incorrect setting format----------------
# apName = [retrieveAPConfig['name'], False]
# returnStatus should return True, and everything else false
# ex. qcAP[ap][y]
# x refers to returnStatus, and y refers to the setting. y has 2 indexes (name and boolean)
qcAP = checkAPConfig(sessionID, False, self.zoneInfoObject, self.userInputObject, apInfoObj)
if qcAP[0] == True: # ends program single AP
print('AP settings correct.')
logoutRuckus(sessionID, self.zoneInfoObject.sessionIP)
panel.apSN = apInfoObj.apSN
print('******************************Programmed single AP.*****************************\n')
return panel # ends program single AP
elif qcAP[0] == False: # returnStatus is false
print('Detected AP error. Performing quality control.')
if qcAP[1][1] is False: # apName
print('AP Name incorrect: ' + str(qcAP[1][0]))
if qcAP[2][1] is False: # zoneID
print('Zone incorrect: ' + str(qcAP[2][0]))
if qcAP[3][1] is False: # apGroupID
print('AP Group incorrect: ' + str(qcAP[3][0]))
if qcAP[4][1] is False: # wlanGroup24ID
print('2.4Ghz WLAN incorrect: ' + str(qcAP[4][0]))
if qcAP[5][1] is False: # wlanGroup50ID
print('5.0Ghz WLAN incorrect: ' + str(qcAP[5][0]))
if qcAP[6][1] is False: # ipType
print('IP Type incorrect: ' + str(qcAP[6][0]))
break # breaks programming block
def programDoubleAP(self, ssidList, apMACList, doubleAPList):
# this is one of the messier functions. wasn't really thought out beforehand,
# but it's functional. at some point we'll rewrite it
self.zoneInfoObject.validSession = False # used in each function to check if session is good
sessionID = requests.session() # ID used to store session cookies
print('\n****************************Programming Double APs...***************************')
if self.zoneInfoObject.apZoneID == None:
print("Couldn't find AP Zone. Please relaunch and enter a valid zone.")
Publisher.sendMessage('status', ssid='Double APs', message="Couldn't find AP Zone. Please relaunch and enter a valid zone.")
return False
# LOGIN BLOCK
printLoginPublisher = True
while self.zoneInfoObject.validSession is False: # loops until session is established
# selects controller ip to use for programming process
loginAttempt = loginRuckus(sessionID, self, self.userInputObject)
if loginAttempt == 200:
Publisher.sendMessage('status', ssid='Double APs', message='Ruckus Controller logged in.')
break
elif printLoginPublisher is True:
Publisher.sendMessage('status', ssid='Double APs', message='Controller login error. Retrying...')
printLoginPublisher = False # stops login publisher messages
# PROGRAMMING BLOCK
# AP Hierarchy:
# Primary AP - Original AP attached to panel
# Parent AP - AP which child AP is attached to
# Child AP - AP which is attached to either primary/parent APs
# Double AP List works like this:
# ap[SSID, MAC, IP]
# ap[0] - SSID
# ap[1] - MAC
# ap[2] - IP
ap = 0 # indexing through doubleAPList
while ap < len(doubleAPList):
# FIRST SECONDARY AP IN SPREADHSEET
# CHANGES MODEL SPECIFIC FOR MAIN PANEL
if doubleAPList[ap][2] == '10.10.10.253':
ssid = 0 # refers to index of ssidList
while ssid < len(ssidList):
if doubleAPList[ap][0] == ssidList[ssid]:
# panel = googlesheets.panel(ssidList[ssid-1], '', '', '', '')
primaryAP = initializeAP()
primaryAP.apSSID = ssidList[ssid-1]
primaryAP.apMAC = apMACList[ssid-1]
print('Now modifying: ' + primaryAP.apSSID)
# print(doubleAPList[ap][0])
break
ssid += 1
wlanGroupList = retrieveWLANGroupList(sessionID, self.zoneInfoObject, self.userInputObject, primaryAP)
# changes config then QCs
while True: # loops for model specific of first child AP to operate until correct
changeAPSpecific(sessionID, self.zoneInfoObject, self.userInputObject, primaryAP)
qcAP = checkAPConfig(sessionID, True, self.zoneInfoObject, self.userInputObject, primaryAP)
# ------------------------------QC----------------------
# --------------------checkAPConfig return---------------------
# [returnStatus, apName, zoneID, apGroupID, wlanGroup24ID, wlanGroup50ID, ipType, modelSpecific]
# --------------------incorrect setting format----------------
# apName = [retrieveAPConfig['name'], False]
# returnStatus should return True, and everything else false
# ex. qcAP[ap][y]
# x refers to returnStatus, and y refers to the setting. y has 2 indexes (name and boolean)
if qcAP[0] is True:
Publisher.sendMessage('status', ssid='Double APs', message=primaryAP.apSSID + ' model specific option enabled')
print('AP settings correct.')
break
elif qcAP[0] == False: # returnStatus is false
print('Detected AP error. Performing quality control.')
if qcAP[7][1] is False: # modelSpecific
print('Model specific incorrect: ' + str(qcAP[7][0]))
# -------------------------------------------------------------------------------------------------------
# # NO SECONDARY AP IN SPEADSHEET
# if primaryAP.wlanInfo.wlanGroupName is '':
# Publisher.sendMessage('status', ssid='Double APs', message=primaryAP.apSSID + ' skipped')
# continue
# -------------------------------------------------------------------------------------------------------
# CHANGES CONFIGURATION FOR CHILD APS
# doubleAPPanel = googlesheets.panel(doubleAPList[ap][0], '', '', '', '') # creates panel object to store ssid + mac
childAP = initializeAP()
childAP.apSSID = doubleAPList[ap][0] # sets ap ssid
childAP.apMAC = doubleAPList[ap][1] # sets ap mac
childAP.apIP = doubleAPList[ap][2] # sets static ip
childAP.wlanInfo = primaryAP.wlanInfo # uses parent AP wlan info
print('\nNow modifying: ' + childAP.apSSID)
# doubleAPPanel.apMAC = doubleAPList[ap][1] # sets ap mac
# doubleAPPanel.ip = doubleAPList[ap][2] # sets static ip
while True:
showAPStatus = True
while True: # loop is for zone change
changeAPZoneResponse = changeAPZone(sessionID, self.zoneInfoObject, self.userInputObject, childAP)
try:
if changeAPZoneResponse == 204:
break
elif (changeAPZoneResponse == 403) and (showAPStatus is True): # breaks the code in case the second AP MAC is wrong
Publisher.sendMessage('status', ssid='Double APs', message=childAP.apSSID + ' not registered on controller. Waiting until AP is added.')
showAPStatus = False
else:
print('changeAPZoneResponse: ' + str(changeAPZoneResponse))
time.sleep(10)
except TypeError: # response was None
pass
changeChildAP = changeAPConfig(sessionID, self.zoneInfoObject, self.userInputObject, childAP)
qcAP = checkAPConfig(sessionID, True, self.zoneInfoObject, self.userInputObject, childAP)
if qcAP[0] is True: # returnStatus is True
print('AP settings correct.')
break
elif qcAP[0] is False: # returnStatus is False
print('Detected AP error. Performing quality control.')
if qcAP[1][1] is False: # apName
print('AP Name incorrect: ' + str(qcAP[1][0]))
if qcAP[2][1] is False: # zoneID
print('Zone incorrect: ' + str(qcAP[2][0]))
if qcAP[3][1] is False: # apGroupID
print('AP Group incorrect: ' + str(qcAP[3][0]))
if qcAP[4][1] is False: # wlanGroup24ID
print('2.4Ghz WLAN incorrect: ' + str(qcAP[4][0]))
if qcAP[5][1] is False: # wlanGroup50ID
print('5.0Ghz WLAN incorrect: ' + str(qcAP[5][0]))
if qcAP[6][1] is False: # ipType
print('IP Type incorrect: ' + str(qcAP[6][0]))
break
# -------------------------------------------------------------------------------------------------------------
# MODEL SPECIFIC FOR PARENT APS (More than 2 on a panel)
# Modifies Parents for Child APs
try:
apIPSuffix = int(doubleAPList[ap][2][len(doubleAPList[ap][2])-3:len(doubleAPList[ap][2])]) # first ap suffixes
postAPIPSuffix = int(doubleAPList[ap+1][2][len(doubleAPList[ap+1][2])-3:len(doubleAPList[ap+1][2])]) # second ap suffixes
if apIPSuffix > postAPIPSuffix:
parentAP = initializeAP()
parentAP.apSSID = doubleAPList[ap][0]
parentAP.apMAC = doubleAPList[ap][1]
# panel = googlesheets.panel(doubleAPList[ap][0], '', '', '', '')
# panel.apMAC = doubleAPList[ap][1]
# changes config then QCs
while True: # loops for model specific of first child AP to operate until correct
changeAPSpecific(sessionID, self.zoneInfoObject, self.userInputObject, parentAP)
qcAP = checkAPConfig(sessionID, True, self.zoneInfoObject, self.userInputObject, parentAP)
if qcAP[0] == False: # returnStatus is false
print('Detected AP error. Performing quality control.')
if qcAP[7][1] is False: # apName
print('AP Name incorrect: ' + str(qcAP[7][0]))
else:
Publisher.sendMessage('status', ssid='Double APs', message=parentAP.apSSID + ' model specific option enabled')
print('AP settings correct.')
break
except IndexError:
print('AP list finished configuring.')
pass
# apConfig = retrieveAPConfig(sessionID, self.zoneInfoObject, self.userInputObject, ???which ap here?????)
while True:
try:
# doubleAPList[ap][2] = apConfig['serial'] # overrites previous ip
doubleAPList[ap][2] = childAP.apSN
break
except KeyError:
Publisher.sendMessage('status', ssid='Double APs', message="Couldn't retrieve " + childAP.apSSID + "'s serial. Make sure MAC is in spreadsheet.")
time.sleep(5)
pass
# Publisher.sendMessage('status', ssid='Double APs', message=childAP.apSSID + ' SN stored')
Publisher.sendMessage('status', ssid='Double APs', message=childAP.apSSID + ' configured')
ap += 1
logoutRuckus(sessionID, self.zoneInfoObject.sessionIP)
print('*****************************Programmed Double APs.*****************************\n')
return doubleAPList
class controllerInputObject:
def __init__(self, username, password, controllerCluster, controllerPort, apZoneName):
self.loginUsername = username
self.loginPassword = password
self.controllerCluster = controllerCluster
self.controllerPort = controllerPort
self.apZoneName = apZoneName
# -----------------------FUNCTION TEMPLATE----------------------------
# def templateFunction(sessionID, controllerCluster):
# serverResponse = checkController.checkController(controllerCluster, sessionID)
# loginAttempts = 1 # initializes counter used to count up if a controller ip is unresponsive
# # ----------------FUNCTION PURPOSE-------------------
# # body
# print('Test function operating...')
# body = {
# "value": value,
# }
#
# try:
# while serverResponse is False:
# time.sleep(1)
# serverResponse = checkController.checkController(controllerCluster, sessionID)
# # runs until a valid response is returned from the controller
# returnVal = sessionID.responsetype('https://' + serverResponse + ':8443/wsg/api/public/v6_1/', headers=universalHeaders, cookies=universalCookies, data=json.dumps(body), verify=False)
# if returnVal.status_code == 200 or 204: # checks HTTP response code
# print('Successful.')
# return value
# if returnVal.status_code == 403: # checks HTTP response code
# print('Failure.')
# return value
# if returnVal.status_code == 404: # checks HTTP response code
# print('Command not found.')
# return value
# if returnVal.status_code == 422: # checks HTTP response code
# print('Semantic error.')
# return value
# if loginAttempts >= 4:
# print('Failed to perform test function.')
# print(returnVal)
# return value
# else:
# loginAttempts += 1
# print('Test function failed. Retrying...')
# time.sleep(1)
# except (socket.gaierror, requests.exceptions.ConnectionError):
# time.sleep(1)
# -----------------------PROGRAMMING FUNCTIONS BELOW----------------
def loginRuckus(sessionID, zoneInfoObj, userInputObject):
printPublisherAmount = True # used in a loop, allows publisher messages
# ---------------------CONTROLLER LOGIN-------------------------------
print('Logging into Ruckus controller...')
# login specific header that sets cookies
loginInitializeCookies = {
'Set-Cookie:"JSESSIONID': '{JSESSIONID}"',
'Path': '/wsg'
}
# login specific parameters
loginRequestParameters = (
('username', userInputObject.loginUsername),
('password', userInputObject.loginPassword),
('apiVersions', '"v6_1"'),
('timeZoneUtcOffset', '"-04:00"'),
)
# body for login request
loginRequestBody = {
'username': userInputObject.loginUsername,
'password': userInputObject.loginPassword,
'apiVersions': [
'v6_1'
],
'timeZoneUtvOffset': '-04:00'
}
# ----------------------------------------------
for ip in userInputObject.controllerCluster:
try:
# sends login request
loginRequest = sessionID.post('https://' + ip + ':8443/wsg/api/public/v6_1/session', params=loginRequestParameters, cookies=loginInitializeCookies, data=json.dumps(loginRequestBody), verify=False)
if loginRequest.status_code == 200: # checks HTTP response code
zoneInfoObj.sessionIP = ip
zoneInfoObj.validSession = True
print('Logged into Ruckus controller.')
return 200
elif loginRequest.status_code == 401:
print('Controller username or password is incorrect.')
print(json.dumps(loginRequest.json(), indent=4))
return 202
else:
time.sleep(1)
# logins to all IPs weren't successful
print(json.dumps(loginRequest.json(), indent=4))
return loginRequest.status_code
except (socket.gaierror, requests.exceptions.ConnectionError, UnboundLocalError):
print("Login attempt failed, didn't receive connection to controller...")
time.sleep(5)
def logoutRuckus(sessionID, ip):
while True:
try:
logoutRequest = sessionID.delete('https://' + ip + ':8443/wsg/api/public/v6_1/session', headers=universalHeaders, cookies=universalCookies, verify=False)
break
except requests.exceptions.ConnectionError:
time.sleep(.2)
print('Logged out of Ruckus Controller.')
return logoutRequest
def retrieveSessionInfo(sessionID, ip):
retrieveSessionInfo = sessionID.get('https://' + ip + ':8443/wsg/api/public/v6_1/session', headers=universalHeaders, cookies=universalCookies, verify=False)
return retrieveSessionInfo.json()
def retrieveZoneList(sessionID, zoneInfoObject, userInputObject):
# -----------------GETS AVAILABLE ZONE LISTs---------------
# parameters
zoneListParameters = (
('listSize', '999'),
)
print('Retrieving zone list...')
while True:
try:
if zoneInfoObject.validSession is False:
newSessionID = requests.session()
loginAttempt = loginRuckus(newSessionID, zoneInfoObject, userInputObject)
if loginAttempt == 200:
sessionID = newSessionID
apZoneList = sessionID.get('https://' + zoneInfoObject.sessionIP + ':8443/wsg/api/public/v6_1/rkszones', headers=universalHeaders, cookies=universalCookies, params=zoneListParameters, verify=False)
if apZoneList.status_code == 200: # checks HTTP response code
print('Zone list retrieved.')
apZoneList = apZoneList.json()
for zones in apZoneList['list']: # 'zones' is a variable that iterates through list
if zones['name'] == zoneInfoObject.apZoneName:
print('Zone ID retrieved.')
zoneInfoObject.apZoneID = zones['id']
zoneInfoObject.apZoneList = retrieveZoneList
return 200
if zoneInfoObject.apZoneID == '':
print('Zone not found. Please check zone spelling.')
return 404
else: # runs if none of the clusters respond
print(apZoneList.status_code)
print(json.dumps(apZoneList, indent=4))
return apZoneList.status_code
except (socket.gaierror, requests.exceptions.ConnectionError):
print('Error connecting to controller. Check your internet connection.')
time.sleep(1)
zoneInfoObject.validSession = False
except (TypeError):
print('Zone list returned NoneType.')
pass
def retrieveAPGroupList(sessionID, zoneInfoObject, userInputObject):
# -----------------GETS AVAILABLE ZONE LISTs---------------
# parameters
zoneListParameters = (
('listSize', '999'),
)
print('Retrieving AP group list...')
while True:
try:
if zoneInfoObject.validSession is False:
newSessionID = requests.session()
loginAttempt = loginRuckus(newSessionID, zoneInfoObject, userInputObject)
if loginAttempt == 200:
sessionID = newSessionID
retrieveAPGroupList = sessionID.get('https://' + zoneInfoObject.sessionIP + ':8443/wsg/api/public/v6_1/rkszones/' + zoneInfoObject.apZoneID + '/apgroups', headers=universalHeaders, cookies=universalCookies, params=zoneListParameters, verify=False)
if retrieveAPGroupList.status_code == 200: # checks HTTP response code
print('AP group list retrieved.')
zoneInfoObject.apGroupList = retrieveAPGroupList.json()
zoneInfoObject.apGroupID = zoneInfoObject.apGroupList['list'][0]['id']
return True
elif retrieveAPGroupList.status_code == 211:
print('AP zone not found.')
return retrieveAPGroupList.status_code
else:
print('AP group list retrieval failed.')
print(retrieveAPGroupList.status_code)
print(retrieveAPGroupList.json())
return retrieveAPGroupList.status_code
except (socket.gaierror, requests.exceptions.ConnectionError):
print('Error connecting to controller. Check your internet connection.')
time.sleep(1)
zoneInfoObject.validSession = False
def retrieveAPConfig(sessionID, zoneInfoObject, userInputObject, apInfoObj):
# ----------------------RETRIEVE AP CONFIGURATION---------------------------
while True:
try:
if zoneInfoObject.validSession is False:
newSessionID = requests.session()
loginAttempt = loginRuckus(newSessionID, zoneInfoObject, userInputObject)
if loginAttempt == 200:
sessionID = newSessionID
# runs until a valid response is returned from the controller
# gets ap configuration response
retrieveAPConfig = sessionID.get('https://' + zoneInfoObject.sessionIP + ':8443/wsg/api/public/v6_1/aps/' + apInfoObj.apMAC, headers=universalHeaders, cookies=universalCookies, verify=False)
print('Retrieving AP Configuration...')
if retrieveAPConfig.status_code == 200: # checks HTTP response code
print('AP configuration retrieval successful.')
return retrieveAPConfig.json()
if retrieveAPConfig.status_code == 211:
print('AP not detected on controller cluster.')
return retrieveAPConfig.status_code
if retrieveAPConfig.status_code == 403:
print('Access was denied requesting AP configuration.')
return retrieveAPConfig.status_code
if retrieveAPConfig.status_code == 404:
print("Can't read AP MAC.")
return retrieveAPConfig.status_code
else:
print(retrieveAPConfig.status_code)
print(json.dumps(retrieveAPConfig.json(), indent=4))
return retrieveAPConfig.status_code
except (socket.gaierror, requests.exceptions.ConnectionError):
print('Error connecting to controller. Check your internet connection.')
time.sleep(1)
zoneInfoObject.validSession = False
def retrieveWLANGroupList (sessionID, zoneInfoObject, userInputObject, apInfoObj):
# ----------------RETRIEVE WLAN GROUP LIST-------------------
print('Retrieving WLAN Group list...')
# parameters
wlanListParameters = (
('listSize', '99999'),
)
while True:
try:
if zoneInfoObject.validSession is False:
newSessionID = requests.session()
loginAttempt = loginRuckus(newSessionID, zoneInfoObject, userInputObject)
if loginAttempt == 200:
sessionID = newSessionID
# runs until a valid response is returned from the controller
wlanGroupList = sessionID.get('https://' + zoneInfoObject.sessionIP + ':8443/wsg/api/public/v6_1/rkszones/' + zoneInfoObject.apZoneID + '/wlangroups', headers=universalHeaders, cookies=universalCookies, params=wlanListParameters, verify=False)
if wlanGroupList.status_code == 200: # checks HTTP response code
wlanGroupList = wlanGroupList.json()
print('WLAN Group list retrieved.')
for wlanGroup in wlanGroupList['list']: # 'zones' is a variable that iterates through list
# Sets Guest WLAN group as the default
if 'guest' in wlanGroup['name'].lower():
apInfoObj.wlanInfo.wlanGroupID = wlanGroup['id']
apInfoObj.wlanInfo.wlanGroupName = wlanGroup['name']
apInfoObj.wlanInfo.wlanGroupGuestID = wlanGroup['id']
apInfoObj.wlanInfo.wlanGroupGuestName = wlanGroup['name']
break
else:
'No guest WLAN Group found.'
# --------------SSID WLAN Group CHOSEN---------------
for wlans in wlanGroupList['list']:
if wlans['name'] == apInfoObj.apSSID:
print('WLAN for AP found.')
apInfoObj.wlanInfo.wlanGroupID = wlans['id']
apInfoObj.wlanInfo.wlanGroupName = wlans['name']
break
return 200
else:
print('WLAN Group list retrieval failed.')
print(wlanGroupList.status_code)
print(json.dumps(wlanGroupList.json(), indent=4))
except (socket.gaierror, requests.exceptions.ConnectionError):
print('Error connecting to controller. Check your internet connection.')
time.sleep(1)
zoneInfoObject.validSession = False
def retrieveWLANGroupConfig (apIDs, apLists, wlanGroupList, sessionID, controllerCluster, panel):
# ----------------RETRIEVE WLAN GROUP CONFIGURATION-------------------
print('Retrieving WLAN group configuration...')
# this block of code runs through the list of wlan groups and gets our
# wlangroup id that is needed
# --------------GUEST WLAN CHOSEN---------------
# WLAN defaults to guest if the SSID isn't found
for wlans in wlanGroupList['list']: # 'zones' is a variable that iterates through list
if 'guest' in wlans['name'].lower():
apIDs.wlanGroupID = str(wlans['id'])
apIDs.wlanGroupName = str(wlans['name'])
break
else:
'No guest WLAN Group found.'
# --------------SSID WLAN CHOSEN---------------
for wlans in wlanGroupList['list']:
if wlans['name'] == panel.ssid:
apIDs.wlanGroupID = str(wlans['id'])
apIDs.wlanGroupName = str(wlans['name'])
break
# runs until a valid response is returned from the controller
try:
retrieveWLANGroupConfig = sessionID.get('https://' + serverResponse + ':8443/wsg/api/public/v6_1/rkszones/' + apLists.apZoneID + '/wlangroups/' + apIDs.wlanGroupID, headers=universalHeaders, cookies=universalCookies, verify=False)
if retrieveWLANGroupConfig.status_code == 200: # checks HTTP response code
print('WLAN group configuration retrieved.')
return retrieveWLANGroupConfig.json()
else:
print('WLAN group configuration retrieval failed. Retrying...')
time.sleep(1)
except (socket.gaierror, requests.exceptions.ConnectionError):
print('Error connecting to controller. Check your internet connection.')
time.sleep(1)
def changeAPZone(sessionID, zoneInfoObject, userInputObject, apInfoObj):
# ----------------CHANGE BASIC AP CONFIGURATION-------------------
print('Changing AP zone...')
# body for request is converted into json through json.dump
# body used to change the ap zone
sendAPConfig = {
"zoneId": zoneInfoObject.apZoneID,
"apGroupId": zoneInfoObject.apGroupID,
"network": {
"ipType": "Dynamic" # APs set to static before cannot be moved without primary and secondary DNS so it is set to dynamic
}
}
while True:
try:
if zoneInfoObject.validSession is False:
newSessionID = requests.session()
loginAttempt = loginRuckus(newSessionID, zoneInfoObject, userInputObject)
if loginAttempt == 200:
sessionID = newSessionID
# runs until a valid response is returned from the controller
changeAPZone = sessionID.patch('https://' + zoneInfoObject.sessionIP + ':8443/wsg/api/public/v6_1/aps/' + apInfoObj.apMAC, headers=universalHeaders, cookies=universalCookies, data=json.dumps(sendAPConfig), verify=False)
if changeAPZone.status_code == 204: # checks HTTP response code
print('AP zone changed.')
return changeAPZone.status_code
elif changeAPZone.status_code == 403: # checks HTTP response code
print("Controller error. 'Change Zone' command sent incorrect syntax.")
print(json.dumps(changeAPZone.json(), indent=4))
return changeAPZone.status_code
elif changeAPZone.status_code == 422: # checks HTTP response code
print('AP already in a zone.')
print(json.dumps(changeAPZone.json(), indent=4))
return changeAPZone.status_code
else:
print('Changing AP zone failed. Retrying...')
print(changeAPZone.status_code)
print(json.dumps(changeAPZone.json(), indent=4))
time.sleep(1)
return changeAPZone.status_code
except (socket.gaierror, requests.exceptions.ConnectionError):
print('Error connecting to controller. Check your internet connection.')
time.sleep(1)
zoneInfoObject.validSession = False
def changeAPConfig(sessionID, zoneInfoObject, userInputObject, apInfoObj):
# ----------------CHANGE BASIC CONFIGURATION-------------------
# body for request is converted into json through json.dump
# controller doesn't accept blank dns entries currently
# body
print('Changing AP configuration...')
sendAPConfig = {
"name": apInfoObj.apSSID,
"description": apInfoObj.apSSID,
"wlanGroup24": {
"id": apInfoObj.wlanInfo.wlanGroupID,
"name": apInfoObj.wlanInfo.wlanGroupName
},
"wlanGroup50": {
"id": apInfoObj.wlanInfo.wlanGroupID,
"name": apInfoObj.wlanInfo.wlanGroupName
},
"network": {
"ipType": "Static",
"ip": apInfoObj.apIP,
"netmask": "255.255.255.0",
"gateway": "10.10.10.1",
"primaryDns": "10.10.10.1",
"secondaryDns": "10.10.10.1"
},
}
while True:
try:
if zoneInfoObject.validSession is False:
newSessionID = requests.session()
loginAttempt = loginRuckus(newSessionID, zoneInfoObject, userInputObject)
if loginAttempt == 200:
sessionID = newSessionID
# runs until a valid response is returned from the controller
changeAPConfig = sessionID.patch('https://' + zoneInfoObject.sessionIP + ':8443/wsg/api/public/v6_1/aps/' + apInfoObj.apMAC, headers=universalHeaders, cookies=universalCookies, data=json.dumps(sendAPConfig), verify=False)
if changeAPConfig.status_code == 204: # checks HTTP response code
print('AP configuration changed.')
return 204
elif changeAPConfig.status_code == 211:
print('AP not on controller.')
return 211
else:
print('Changing AP configuration failed. Retrying...')
(changeAPConfig.status_code)
print(json.dumps(changeAPConfig.json(), indent=4))
time.sleep(1)
return changeAPConfig.status_code
except (socket.gaierror, requests.exceptions.ConnectionError):
time.sleep(1)
zoneInfoObject.validSession = False
def checkAPConfig(sessionID, poeSpecific, zoneInfoObject, userInputObject, apInfoObj):
returnStatus = True
apName = ['', True]
zoneID = ['', True]
apGroupID = ['', True]
wlanGroup24ID = ['', True]
wlanGroup50ID = ['', True]
ipType = ['', True]
modelSpecific = ['', True]
# ----------------RETRIEVE AP CONFIGURATION-------------------
#Publisher.sendMessage('status', ssid=self.panel.ssid, message='Retrieving AP configuration...')
print('Checking AP Configuration.')
while True:
try:
if zoneInfoObject.validSession is False:
newSessionID = requests.session()
loginAttempt = loginRuckus(newSessionID, zoneInfoObject, userInputObject)
if loginAttempt == 200:
sessionID = newSessionID
# gets ap configuration response
retrieveAPConfig = sessionID.get('https://' + zoneInfoObject.sessionIP + ':8443/wsg/api/public/v6_0/aps/' + apInfoObj.apMAC, headers=universalHeaders, cookies=universalCookies, verify=False)
if retrieveAPConfig.status_code == 200:
retrieveAPConfig = retrieveAPConfig.json() # converts config to json
apInfoObj.apSN = retrieveAPConfig['serial']
# only checks certain values, if these are present then the others are aswell
# these values return to the programSingleAP function
# if a setting isn't correct, an array is created, holding the
# incorrect setting and a False value to be checked in programSingleAP
try:
if poeSpecific == True:
if retrieveAPConfig['specific'] is None:
modelSpecific = ['None', False]
returnStatus = False
if apInfoObj.apModel == "R610" and retrieveAPConfig['specific']['poeModeSetting'] != '_802_3at':
modelSpecific = [retrieveAPConfig['specific']['poeModeSetting'], False]
returnStatus = False
#needs to check for R510's eventually
else:
if retrieveAPConfig['name'] != apInfoObj.apSSID:
apName = [retrieveAPConfig['name'], False]
returnStatus = False
if retrieveAPConfig['zoneId'] != zoneInfoObject.apZoneID:
zoneID = [retrieveAPConfig['name'], False]
returnStatus = False
if retrieveAPConfig['apGroupId'] != zoneInfoObject.apGroupID:
apGroupID = [retrieveAPConfig['apGroupId'], False]
returnStatus = False
if retrieveAPConfig['wlanGroup24'] is None:
wlanGroup24ID = ['No WLAN Assigned', False]
returnStatus = False
elif retrieveAPConfig['wlanGroup24']['name'] != apInfoObj.apSSID and 'guest' not in retrieveAPConfig['wlanGroup24']['name'].lower():
wlanGroup50ID = [retrieveAPConfig['wlanGroup24']['name'], False]
returnStatus = False
if retrieveAPConfig['wlanGroup50'] is None:
wlanGroup50ID = ['No WLAN Assigned', False]
returnStatus = False
elif retrieveAPConfig['wlanGroup50']['name'] != apInfoObj.apSSID and 'guest' not in retrieveAPConfig['wlanGroup50']['name'].lower():
wlanGroup50ID = [retrieveAPConfig['wlanGroup50']['name'], False]
returnStatus = False
if retrieveAPConfig['network']['ipType'] != 'Static': # aps are always static
ipType = [retrieveAPConfig['network']['ipType'], False]
returnStatus = False
except (TypeError, AttributeError): # one of the values was a None type
returnStatus = False
else:
print(retrieveAPConfig.status_code)
print(json.dumps(retrieveAPConfig.json(), indent=4))
return retrieveAPConfig.status_code
except (socket.gaierror, requests.exceptions.ConnectionError):
print('Hiccup occurred at AP QC start. Retrying...')
time.sleep(1)
zoneInfoObject.validSession = False
return [returnStatus, apName, zoneID, apGroupID, wlanGroup24ID, wlanGroup50ID, ipType, modelSpecific]
def retrieveZoneAPModel(apConfig, apLists, sessionID, controllerCluster, panel):
serverResponse = checkController.checkController(controllerCluster, sessionID)
apModel = str(apConfig['model'])
loginAttempts = 1 # initializes counter used to count up if a controller ip is unresponsive
# ----------------RETRIEVE AP MODEL-------------------
try:
while serverResponse is False:
time.sleep(1)
serverResponse = checkController.checkController(controllerCluster, sessionID)
# runs until a valid response is returned from the controller
# gets ap configuration response
retrieveAPModel = sessionID.get('https://' + serverResponse + ':8443/wsg/api/public/v6_1/rkszones/' + apLists.apZoneID + '/apmodel/' + apModel, headers=universalHeaders, cookies=universalCookies, verify=False)
if retrieveAPModel.status_code == 200: # checks HTTP response code
print('Zone AP Model retrieved.')
return retrieveAPModel.json()
if loginAttempts >= 4:
#Publisher.sendMessage('status', ssid=self.panel.ssid, message='AP configuration retrieval failed.')
print(retrieveAPModel.text)
return retrieveAPModel
else:
loginAttempts += 1
#Publisher.sendMessage('status', ssid=self.panel.ssid, message='AP configuration retrieval failed. Retrying...')
time.sleep(1)
except (socket.gaierror, requests.exceptions.ConnectionError):
#Publisher.sendMessage('status', ssid=self.panel.ssid, message='Error connecting to controller. Check your internet connection.')
time.sleep(1)
def changeAPSpecific(sessionID, zoneInfoObject, userInputObject, parentAP):
# ----------------CHANGE BASIC AP CONFIGURATION-------------------
# body for request is converted into json through json.dump
# controller doesn't accept blank dns entries currently
print('--------Changing parent AP model specific options...--------')
# portID retrieves ID of LAN port for master AP to use
try:
apConfig = retrieveAPConfig(sessionID, zoneInfoObject, userInputObject, parentAP)
apModel = apConfig['model'] # front end stores serial variable
parentAP.apModel = apConfig['model'] # front end stores serial variable
except KeyError:
print('Model not found in AP Config')
'''
Key:
portIDs[0] - Access port
portIDs[1] - Trunk port
'''
portIDs = retrievePortID(sessionID, zoneInfoObject, userInputObject)
if apModel == "R610":
# body
sendAPConfig = {
"lldp": {
"enabled": True,
"advertiseIntervalInSec": 30,
"holdTimeInSec": 120,
"managementIPTLVEnabled": True