-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathBwksAPIOperations.py
5411 lines (4871 loc) · 271 KB
/
BwksAPIOperations.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
# Module for accessing OCI, BroadSoft soap api for working with BroadWorks instances
import time, datetime, logging
from logging import getLogger
import requests
from requests.adapters import HTTPAdapter
import hashlib
from lxml import etree
import re
import sys
try:
import leotestcase
except:
pass
class BwksAPIOperations():
LOGNAME = "BROADWORKS OCI: "
value = ""
cookie = ""
sessionId = ""
nonce = ""
def __init__(self, url, username, password, domain, provisioning_service="/webservice/services/ProvisioningService", country_code='+1-'):
self._url = url
self._username = username
self._password = password
self._domain = domain
self._set_session_id()
self._provisioning_service = provisioning_service
self._country_code = country_code
def _set_session_id(self):
self.sessionId = str(int(round(time.time() * 1000)))
def _get_request_head(self, command):
# command and BroadsoftDocument tags should be encoded
head = """<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<processOCIMessage soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
<arg0 xsi:type="soapenc:string" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/">
<BroadsoftDocument protocol="OCI" xmlns="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<sessionId xmlns="">""" + self.sessionId + """</sessionId>
<command xsi:type="""" +command+ """" xmlns="">
"""
return head
def _get_request_tail(self,command):
# command and BroadsoftDocument tags should be encoded
tail = """</command>
</BroadsoftDocument>
</arg0>
</processOCIMessage>
</soapenv:Body>
</soapenv:Envelope>
"""
return tail
def _generate_request_body(self, command, req):
body = self._get_request_head(command) +" " + req + self._get_request_tail(command)
return body
def AuthenticationRequest(self, login):
reqst = """
<userId>""" + login + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("AuthenticationRequest", req)
logging.info(self.LOGNAME + "Send auth request to BWKS (" + self._url + self._provisioning_service + "): " + self.__pretty_text_log(request))
return request
def LoginRequest14sp4(self, login, password):
reqst = """
<userId>""" + login + """</userId>
<signedPassword>""" + password + """</signedPassword>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("LoginRequest14sp4", req)
logging.debug(self.LOGNAME + "Send request to login to BWKS: " + self.__pretty_text_log(request))
return request
def LoginRequest22(self, login, password):
reqst = """
<userId>""" + login + """</userId>
<password>""" + password + """</password>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("LoginRequest22", req)
logging.debug(self.LOGNAME + "Send request to login to BWKS: " + self.__pretty_text_log(request))
return request
def LoginRequest(self, login, password):
headers = {
'SOAPAction': 'processOCIMessage'
}
s = requests.Session()
s.mount('http://', HTTPAdapter(max_retries=30))
s.mount('https://', HTTPAdapter(max_retries=30))
logging.info(self.LOGNAME + "Send request to login to BWKS")
rauth = s.post(self._url + self._provisioning_service, data=self.AuthenticationRequest(login),
verify=False, headers=headers)
auth_cookie = rauth.cookies
logging.debug(self.LOGNAME + "Auth Response is: " + self.__pretty_text_log(rauth.text))
self.__store_nonce(self.__pretty_text(rauth.text))
passw = hashlib.md5(self.nonce + ':' + password).hexdigest()
print(passw, password)
reqst = """
<userId>""" + login + """</userId>
<signedPassword>""" + passw + """</signedPassword>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("LoginRequest14sp4", req)
logging.debug(self.LOGNAME + "Login Request is: " + self.__pretty_text_log(request))
rlogin = s.post(self._url + self._provisioning_service, data=request, verify=False,
headers=headers, cookies=auth_cookie)
logging.debug(self.LOGNAME + "Login Response is: " + self.__pretty_text_log(rlogin.text))
return self.__pretty_text(rlogin.text)
def LogoutRequest(self, user_id):
logging.info(self.LOGNAME + "Send request to BWKS to logout a user " + user_id)
reqst = """
<userId>""" + user_id + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("LogoutRequest", req)
response = self.__send_request(request)
return response
def SystemDomainAddRequest(self, domain_add):
logging.info(self.LOGNAME + "Send request to BWKS to add Domain " + domain_add)
reqst = """
<domain>""" + domain_add + """</domain>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("SystemDomainAddRequest", req)
response = self.__send_request(request)
return response
def SystemDomainDeleteRequest(self, domain):
logging.info(self.LOGNAME + "Send request to BWKS to delete System Domain " + domain)
reqst = """
<domain>""" + domain + """</domain>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("SystemDomainDeleteRequest", req)
response = self.__send_request(request)
return response
def ServiceProviderAddRequest13mp2(self, ent_id, ent_name=None):
logging.info(self.LOGNAME + "Send request to BWKS to add Enterprise " + ent_id)
if ent_name is None:
ent_name = ent_id
reqst = """
<isEnterprise>true</isEnterprise>
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<defaultDomain>""" + self._domain + """</defaultDomain>
<serviceProviderName>""" + ent_name + """</serviceProviderName>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderAddRequest13mp2", req)
response = self.__send_request(request)
return response
def SystemServiceProviderAddRequest13mp2(self, ent_id, ent_name=None, use_custom_profile='false'):
logging.info(self.LOGNAME + "Send request to BWKS to add Enterprise " + ent_id)
if ent_name is None:
ent_name = ent_id
reqst = """
<useCustomRoutingProfile>""" + use_custom_profile + """</useCustomRoutingProfile>
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<defaultDomain>""" + self._domain + """</defaultDomain>
<serviceProviderName>""" + ent_name + """</serviceProviderName>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderAddRequest13mp2", req)
response = self.__send_request(request)
return response
def ServiceProviderGetRequest(self, starts_with, ent_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Enterprise " + ent_id)
reqst = """
<searchCriteriaServiceProviderId>
<mode>""" + starts_with + """</mode>
<value>""" + ent_id + """</value>
</searchCriteriaServiceProviderId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderGetRequest", req)
response = self.__send_request(request)
return response
def ServiceProviderGetRequest13mp2(self, ent_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Enterprise " + ent_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderGetRequest13mp2", req)
response = self.__send_request(request)
return response
def ServiceProviderGetRequest17sp1(self, ent_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Enterprise " + ent_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderGetRequest17sp1", req)
response = self.__send_request(request)
return response
def ServiceProviderDomainAssignListRequest(self, ent_id, domain):
logging.info(self.LOGNAME + "Send request to BWKS to add domain to the Enterprise " + ent_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<domain>""" + domain + """</domain>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderDomainAssignListRequest", req)
response = self.__send_request(request)
return response
def GroupPasswordRulesGetRequest16(self, ent_id, group_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Password rules of group " + group_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + group_id + """</groupId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupPasswordRulesGetRequest16", req)
response = self.__send_request(request)
return response
def GroupPasswordRulesModifyRequest(self, ent_id, group_id, ppolicy_data):
logging.info(self.LOGNAME + "Send request to BWKS to modify Password rules of group " + group_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + group_id + """</groupId>
<disallowUserId>""" + ppolicy_data['disallowUserId'] + """</disallowUserId>
<disallowOldPassword>true</disallowOldPassword>
<disallowReversedOldPassword>true</disallowReversedOldPassword>
<restrictMinDigits>""" + ppolicy_data['restrictMinDigits'] + """</restrictMinDigits>
<minDigits>""" + ppolicy_data['minDigits'] + """</minDigits>
<restrictMinUpperCaseLetters>""" + ppolicy_data['restrictMinUpperCaseLetters'] +"""</restrictMinUpperCaseLetters>
<minUpperCaseLetters>""" + ppolicy_data['minUpperCaseLetters'] + """</minUpperCaseLetters>
<restrictMinLowerCaseLetters>""" + ppolicy_data['restrictMinLowerCaseLetters'] + """</restrictMinLowerCaseLetters>
<minLowerCaseLetters>""" + ppolicy_data['minLowerCaseLetters'] + """</minLowerCaseLetters>
<restrictMinNonAlphanumericCharacters>""" + ppolicy_data['restrictMinNonAlphanumericCharacters'] + """</restrictMinNonAlphanumericCharacters>
<minNonAlphanumericCharacters>""" + ppolicy_data['minNonAlphanumericCharacters'] + """</minNonAlphanumericCharacters>
<minLength>""" + ppolicy_data['minLength'] + """</minLength>
<maxFailedLoginAttempts>5</maxFailedLoginAttempts>
<passwordExpiresDays>30</passwordExpiresDays>
<sendLoginDisabledNotifyEmail>false</sendLoginDisabledNotifyEmail>
<loginDisabledNotifyEmailAddress xsi:nil="true"/>
<disallowPreviousPasswords>false</disallowPreviousPasswords>
<numberOfPreviousPasswords>2</numberOfPreviousPasswords>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupPasswordRulesModifyRequest", req)
response = self.__send_request(request)
return response
def UserTimeScheduleAddRequest(self, user_id, time_schedule):
logging.info(
self.LOGNAME + "Send request to BWKS to add Time schedule '%s' to user '%s'" % (time_schedule, user_id))
reqst = """
<userId>""" + user_id + """</userId>
<timeScheduleName>""" + time_schedule + """</timeScheduleName>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserTimeScheduleAddRequest", req)
response = self.__send_request(request)
return response
def UserTimeScheduleDeleteRequest(self, user_id, time_schedule):
logging.info(self.LOGNAME + "Send request to BWKS to delete Time schedule '%s' from user '%s'" % (
time_schedule, user_id))
reqst = """
<userId>""" + user_id + """</userId>
<timeScheduleName>""" + time_schedule + """</timeScheduleName>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserTimeScheduleDeleteRequest", req)
response = self.__send_request(request)
return response
def UserScheduleDeleteListRequest(self, user_id, schedule_name, type):
logging.info(
self.LOGNAME + "Send request to BWKS to delete schedule '%s' from user '%s'" % (schedule_name, user_id))
reqst = """
<userId>""" + user_id + """</userId>
<scheduleKey>
<scheduleName>""" + schedule_name + """</scheduleName>
<scheduleType>""" + type + """</scheduleType>
</scheduleKey>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserScheduleDeleteListRequest", req)
response = self.__send_request(request)
return response
def UserHolidayScheduleAddRequest(self, user_id, Holiday_schedule):
logging.info(
self.LOGNAME + "Send request to BWKS to add Holiday schedule '%s' to user '%s'" % (Holiday_schedule, user_id))
reqst = """
<userId>""" + user_id + """</userId>
<scheduleKey>
<scheduleName>""" + Holiday_schedule + """</scheduleName>
<scheduleType>Holiday</scheduleType>
</scheduleKey>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserScheduleAddEventRequest", req)
response = self.__send_request(request)
return response
def SystemPortalPasscodeRulesGetRequest19(self):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve System Passcode rules")
reqst = """
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("SystemPortalPasscodeRulesGetRequest19", req)
response = self.__send_request(request)
return response
def UserBroadWorksMobilityGetRequest(self, user_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Broadworks Mobility settings of user: " + user_id)
reqst = """ <userId>""" + user_id + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserBroadWorksMobilityGetRequest", req)
response = self.__send_request(request)
return response
def UserInterceptUserGetRequest16sp1(self, user_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Intercept User settings of user: " + user_id)
reqst = """ <userId>""" + user_id + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserInterceptUserGetRequest16sp1", req)
response = self.__send_request(request)
return response
def UserBroadWorksMobilityGetRequest21(self, user_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Broadworks Mobility settings of user: " + user_id)
reqst = """ <userId>""" + user_id + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserBroadWorksMobilityGetRequest21", req)
response = self.__send_request(request)
return response
def UserBroadWorksMobilityMobileIdentityDeleteRequest(self, user_id, bwks_mobility):
logging.info(self.LOGNAME + "Send request to BWKS to delete Broadworks Mobility of user: " + user_id)
reqst = """
<userId>""" + user_id + """</userId>
<mobileNumber>""" + bwks_mobility + """</mobileNumber>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserBroadWorksMobilityMobileIdentityDeleteRequest", req)
response = self.__send_request(request)
return response
def GroupCollaborateBridgeDeleteInstanceRequest(self, user_id):
logging.info(self.LOGNAME + "Send request to BWKS to delete Collaborate Bridge: " + user_id)
reqst = """
<serviceUserId>""" + user_id + """</serviceUserId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupCollaborateBridgeDeleteInstanceRequest", req)
response = self.__send_request(request)
return response
def UserBroadWorksMobilityModifyRequest21(self, user_id, dict_1={}):
logging.info(self.LOGNAME + "Send request to BWKS to modify Broadworks Mobility of user: " + user_id)
dict_2 = {}
dict_2['isActive'] = 'false'
dict_2['useMobileIdentityCallAnchoring'] = 'true'
dict_2['preventCallsToOwnMobiles'] = 'false'
dict_2['mobileIdentity'] = {}
dict_2['mobileIdentity']['mobileNumber'] = user_id
dict_2['mobileIdentity']['isPrimary'] = 'true'
dict_2['mobileIdentity']['enableAlerting'] = 'true'
#merge two dictionaries to the third which will be used in request
if dict_1:
bwks_mobility_data = dict_2.copy()
bwks_mobility_data.update(dict_1)
else: # Use default values
bwks_mobility_data = dict_2
reqst = """
<isActive>""" + bwks_mobility_data['isActive'] + """</isActive>
<useMobileIdentityCallAnchoring>""" + bwks_mobility_data['useMobileIdentityCallAnchoring'] + """</useMobileIdentityCallAnchoring>
<preventCallsToOwnMobiles>""" + bwks_mobility_data['preventCallsToOwnMobiles'] + """</preventCallsToOwnMobiles>
<mobileIdentity>
<mobileNumber>""" + bwks_mobility_data['mobileIdentity']['mobileNumber'] + """</mobileNumber>
<isPrimary>""" + bwks_mobility_data['mobileIdentity']['isPrimary'] + """</isPrimary>
<enableAlerting>""" + bwks_mobility_data['mobileIdentity']['enableAlerting'] + """</enableAlerting>
</mobileIdentity>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserBroadWorksMobilityModifyRequest21", req)
response = self.__send_request(request)
return response
def ServiceProviderPortalPasscodeRulesGetRequest19(self, ent_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Passcode rules of enterprise " + ent_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderPortalPasscodeRulesGetRequest19", req)
response = self.__send_request(request)
return response
def GroupPortalPasscodeRulesGetRequest19(self, ent_id, group_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Passcode rules of group " + group_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + group_id + """</groupId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupPortalPasscodeRulesGetRequest19", req)
response = self.__send_request(request)
return response
def ServiceProviderGetListRequest(self, withSP=True):
logging.info(self.LOGNAME + "Send request to BWKS to get all Enterprises and Service Providers")
# Ents
reqst = """
<isEnterprise>true</isEnterprise>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderGetListRequest", req)
response = self.__send_request(request)
table = self.get_xml_section_content(response, "//serviceProviderTable")
all_ents = self.get_xml_param_all_value(table, ".//row/col[1]")
if not withSP:
return all_ents
# Service providers
reqst = """
<isEnterprise>false</isEnterprise>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderGetListRequest", req)
response = self.__send_request(request)
table = self.get_xml_section_content(response, "//serviceProviderTable")
all_sps = self.get_xml_param_all_value(table, ".//row/col[1]")
return all_ents + all_sps
def SystemDomainGetListRequest(self):
logging.info(self.LOGNAME + "Send request to BWKS to get all system domains")
req = ""
request = self._generate_request_body("SystemDomainGetListRequest", req)
response = self.__send_request(request)
table = self.get_xml_section_content(response, "//command")
domains = self.get_xml_param_all_value(table, ".//domain")
return domains
def UserBusyLampFieldGetRequest(self, user):
logging.info(self.LOGNAME + "Send request to BWKS to get 'Busy Lamp Field' info about user: " + user)
reqst = """
<userId>""" + user + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserBusyLampFieldGetRequest16sp2", req)
response = self.__send_request(request)
return response
def ServiceProviderDeleteRequest(self, ent_id, try_to_delete_groups=False):
logging.info(self.LOGNAME + "Send request to BWKS to delete Enterprise " + ent_id)
if try_to_delete_groups:
logging.info(self.LOGNAME + "Try to delete all Groups from Ent first")
groups_xml = self.GroupGetListInServiceProviderRequest(ent_id)
# print groups_xml
if "groupTable" in groups_xml:
table = self.get_xml_section_content(groups_xml, "//groupTable")
groups = self.get_xml_param_all_value(table, ".//row/col[1]")
logging.debug(self.LOGNAME + "Groups are: " + str(groups))
for group in groups:
self.GroupDeleteRequest(ent_id, group)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderDeleteRequest", req)
response = self.__send_request(request)
return response
def ServiceProviderTrunkGroupGetRequest14sp1(self, ent_id):
logging.info(self.LOGNAME + "Send request to BWKS to retrieve Enterprise Trunk Group options " + ent_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderTrunkGroupGetRequest14sp1", req)
response = self.__send_request(request)
return response
def ServiceProviderAdminAddRequest14(self, ent_id, admin, adm_type, pw="leoBr00me!"):
logging.info(self.LOGNAME + "Send request to BWKS to add Enterprise admin " + admin)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<userId>""" + admin + """</userId>
<password>""" + pw + """</password>
<language>English</language>
<administratorType>""" + adm_type + """</administratorType>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderAdminAddRequest14", req)
response = self.__send_request(request)
return response
def ServiceProviderAdminGetRequest(self, admin):
logging.info(self.LOGNAME + "Send request to BWKS to get Enterprise admin " + admin)
reqst = """
<userId>""" + admin + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderAdminGetRequest", req)
response = self.__send_request(request)
return response
def ServiceProviderAdminGetRequest14(self, admin):
logging.info(self.LOGNAME + "Send request to BWKS to get Enterprise admin " + admin)
reqst = """
<userId>""" + admin + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderAdminGetRequest14", req)
response = self.__send_request(request)
return response
def GroupAdminGetRequest(self, admin):
logging.info(self.LOGNAME + "Send request to BWKS to get Group admin " + admin)
reqst = """
<userId>""" + admin + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupAdminGetRequest", req)
response = self.__send_request(request)
return response
def GroupDepartmentAdminGetRequest(self, admin):
logging.info(self.LOGNAME + "Send request to BWKS to get Group admin " + admin)
reqst = """
<userId>""" + admin + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupDepartmentAdminGetRequest", req)
response = self.__send_request(request)
return response
def ServiceProviderAdminModifyRequest(self, admin):
logging.info(self.LOGNAME + "Send request to BWKS to modify Enterprise admin " + admin.admin_id)
reqst = """
<userId>""" + admin.admin_id + """</userId>"""
if admin.admin_fname != '':
reqst += """
<firstName>""" + admin.admin_fname + """</firstName>
"""
if admin.admin_lname != '':
reqst += """
<lastName>""" + admin.admin_lname + """</lastName>
"""
reqst += """
<password>""" + admin.admin_pw + """</password>
<language>English</language>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderAdminModifyRequest", req)
response = self.__send_request(request)
return response
def SystemStateOrProvinceGetListRequest(self):
logging.info(self.LOGNAME + "Send request to BWKS to get all State/Province")
reqst = """
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("SystemStateOrProvinceGetListRequest", req)
response = self.__send_request(request)
return response
def GroupModifyRequest(self, ent_id, group_id, dict_1={}):
logging.info(self.LOGNAME + "Send request to BWKS to modify Group: '" + ent_id + ":" + group_id + "'")
# Define default values for request
dict_2 = {}
dict_2['timeZone'] = 'America/New_York'
# Let`s merge two dictionaries to the third which will be used in request
if dict_1:
user_data = dict_2.copy()
user_data.update(dict_1)
else: # Use default values
user_data = dict_2
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + group_id + """</groupId>
<timeZone>""" + user_data['timeZone'] + """</timeZone>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupModifyRequest", req)
response = self.__send_request(request)
return response
def GroupModifyCLIDNumberRequest(self, ent_id, group_id, dict_1={}):
logging.info(self.LOGNAME + "Send request to BWKS to modify Group: '" + ent_id + ":" + group_id + "'")
# Define default values for request
dict_2 = {}
dict_2['timeZone'] = 'America/New_York'
# Let`s merge two dictionaries to the third which will be used in request
if dict_1:
user_data = dict_2.copy()
user_data.update(dict_1)
else: # Use default values
user_data = dict_2
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + group_id + """</groupId>
<defaultDomain>""" + self._domain + """</defaultDomain>
<userLimit>1000</userLimit>
<groupName>""" + group_id + """</groupName>"""
if "callingLineIdPhoneNumber" in user_data:
reqst += """<callingLineIdName>""" + user_data['callingLineIdPhoneNumber'][-5:] + """CLID</callingLineIdName>""" + """
<callingLineIdPhoneNumber>""" + user_data['callingLineIdPhoneNumber'] + """</callingLineIdPhoneNumber>
<timeZone>""" + user_data['timeZone'] + """</timeZone>
<locationDialingCode xsi:nil="true"/>
<contact>
<contactName xsi:nil="true"/>
<contactNumber xsi:nil="true"/>
<contactEmail xsi:nil="true"/>
</contact>
<address>
<addressLine1 xsi:nil="true"/>
<addressLine2 xsi:nil="true"/>
<city xsi:nil="true"/>
<stateOrProvince xsi:nil="true"/>
<zipOrPostalCode xsi:nil="true"/>
<country xsi:nil="true"/>
</address>"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupModifyRequest", req)
response = self.__send_request(request)
return response
def ServiceProviderAdminDeleteRequest(self, admin):
logging.info(self.LOGNAME + "Send request to BWKS to delete Enterprise admin " + admin)
reqst = """
<userId>""" + admin + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderAdminDeleteRequest", req)
response = self.__send_request(request)
return response
def ServiceProviderTrunkGroupModifyRequest(self, ent_id, active, bursting):
logging.info(self.LOGNAME + "Send request to BWKS to set trunking call capacity for Enterprise " + ent_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<maxActiveCalls>
<quantity>""" + active + """</quantity>
</maxActiveCalls>
<burstingMaxActiveCalls>
<quantity>""" + bursting + """</quantity>
</burstingMaxActiveCalls>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderTrunkGroupModifyRequest", req)
response = self.__send_request(request)
return response
def GroupDepartmentAddRequest(self, ent_id, grp_id, name,parent={}):
logging.info(self.LOGNAME + "Send request to BWKS to add department " + name)
if parent == {}:
reqst = """<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
<departmentName>""" + name + """</departmentName>
"""
else:
reqst="""<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
<departmentName>""" + name + """</departmentName>
<parentDepartmentKey xsi:type="GroupDepartmentKey">
<serviceProviderId>""" + parent["serviceprovider_id"]+ """</serviceProviderId>
<groupId>""" + parent["group_id"] +"""</groupId>
<name>""" + parent["name"] +"""</name>
</parentDepartmentKey>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupDepartmentAddRequest", req)
response = self.__send_request(request)
return response
def GroupTrunkGroupGetInstanceListRequest14sp4(self, pattern):
request = pattern.get_all_sections()
request = request.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupTrunkGroupGetInstanceListRequest14sp4", request)
logging.debug(self.LOGNAME + "Send GroupTrunkGroupGetInstanceListRequest14sp4 to LWS: " + request)
response = self.__send_request(request)
return response
def SendRequestPattern(self, pattern, request_name):
request = pattern.get_all_sections()
request = request.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body(request_name, request)
logging.debug(self.LOGNAME + "Send " + request_name + " to Bwks: " + request)
response = self.__send_request(request)
return response
def GroupIncomingCallingPlanModifyListRequest(self, pattern):
request = pattern.get_all_sections()
request = request.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupIncomingCallingPlanModifyListRequest", request)
logging.debug(self.LOGNAME + "Send GroupIncomingCallingPlanModifyListRequest to LWS: " + request)
response = self.__send_request(request)
return response
def GroupIncomingCallingPlanGetListRequest(self, ent_id, grp_id):
reqst = """<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
"""
request = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupIncomingCallingPlanGetListRequest", request)
logging.debug(self.LOGNAME + "Send GroupIncomingCallingPlanGetListRequest to LWS: " + request)
response = self.__send_request(request)
return response
def GroupDepartmentDeleteRequest(self, ent_id, grp_id, name):
logging.info(self.LOGNAME + "Send request to BWKS to delete department " + name)
reqst = """<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
<departmentName>""" + name + """</departmentName>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupDepartmentDeleteRequest", req)
response = self.__send_request(request)
return response
def GroupDomainAssignListRequest(self, ent_id, grp_id, domain):
logging.info(self.LOGNAME + "Send request to BWKS to add domain to Group " + domain)
reqst = """<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
<domain>""" + domain + """</domain>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupDomainAssignListRequest", req)
response = self.__send_request(request)
return response
def GroupAdminAddRequest(self, ent_id, grp_id, admin_id, admin_fname, admin_lname, admin_pw):
logging.info(self.LOGNAME + "Send request to BWKS to add group admin " + admin_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
<userId>""" + admin_id + """</userId>
<firstName>""" + admin_fname + """</firstName>
<lastName>""" + admin_lname + """</lastName>
<password>""" + admin_pw + """</password>
<language>English</language>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupAdminAddRequest", req)
response = self.__send_request(request)
return response
def GroupAdminAddRequest_dict(self, ent_id, grp_id, admin, reset_pw=True):
logging.info(self.LOGNAME + "Send request to BWKS to add group admin " + admin["admin_id"])
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
<userId>""" + admin["admin_id"] + '@' + admin["domain"] + """</userId>"""
if 'fname' in admin:
reqst += "<firstName>" + admin["fname"] + "</firstName>"
if 'lname' in admin:
reqst += "<lastName>" + admin["lname"] + "</lastName>"
reqst += """<password>""" + admin["password"] + """</password>
<language>""" + admin["language"] + """</language>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupAdminAddRequest", req)
response = self.__send_request(request)
if reset_pw:
self.PasswordModifyRequest_dict(admin, admin["password"])
return response
def GroupAdminGetListRequest(self, ent_id, grp_id):
logging.info(self.LOGNAME + "Send request to BWKS to get group admins from Group " + grp_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupAdminGetListRequest", req)
response = self.__send_request(request)
return response
def ServiceProviderAdminGetListRequest14(self, ent_id):
logging.info(self.LOGNAME + "Send request to BWKS to get group admins from Ent " + ent_id)
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("ServiceProviderAdminGetListRequest14", req)
response = self.__send_request(request)
return response
def GroupCallCenterGetSupervisorListRequest(self, cc_id):
logging.info(self.LOGNAME + "Send request to BWKS to get list of supervisors for Call Center: " + cc_id)
reqst = """
<serviceUserId>""" + cc_id + """</serviceUserId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupCallCenterGetSupervisorListRequest16", req)
response = self.__send_request(request)
return response
def GroupDepartmentAdminAddRequest(self, ent_id, grp_id, admin, dep_name, reset_pw=True):
logging.info(self.LOGNAME + "Send request to BWKS to add department admin " + admin.admin_id)
reqst = """<departmentKey>
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
<name>""" + dep_name + """</name>
</departmentKey>
<userId>""" + admin.admin_id + """</userId>
<password>""" + admin.admin_pw + """</password>
<language>English</language>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupDepartmentAdminAddRequest", req)
response = self.__send_request(request)
if reset_pw:
self.PasswordModifyRequest(admin, admin.admin_pw)
return response
def SystemAdminAddRequest(self, admin, admin_type, reset_pw=True,
readonly="false"): # admin type = "System" or "Provisioning", readonly = "true" or "false"
logging.info(self.LOGNAME + "Send request to BWKS to add " + admin_type + " admin " + admin.admin_id)
reqst = """
<userId>""" + admin.admin_id + """</userId>
<password>""" + admin.admin_pw + """</password>
<language>English</language>
<adminType>""" + admin_type + """</adminType>
<readOnly>""" + readonly + """</readOnly>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("SystemAdminAddRequest", req)
response = self.__send_request(request)
if reset_pw:
self.PasswordModifyRequest(admin, admin.admin_pw)
return response
def SystemAdminDeleteRequest(self, admin):
logging.info(self.LOGNAME + "Send request to BWKS to delete System/Provisioning admin " + admin.admin_id)
reqst = """
<userId>""" + admin.admin_id + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("SystemAdminDeleteRequest", req)
response = self.__send_request(request)
return response
def ll(self, ent_id):
logging.info(self.LOGNAME + "Send request to BWKS to display User PreAlerting Announcements")
reqst = """
<userId>""" + user_id + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("UserPreAlertingAnnouncementGetRequest20", req)
response = self.__send_request(request)
return response
def SystemAdminDeleteRequestSimple(self, admin):
logging.info(self.LOGNAME + "Send request to BWKS to delete System/Provisioning admin " + admin)
reqst = """
<userId>""" + admin + """</userId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("SystemAdminDeleteRequest", req)
response = self.__send_request(request)
return response
def SystemAdminGetListRequest(self):
logging.info(self.LOGNAME + "Send request to BWKS to get list of all System/Provisioning admins")
reqst = """ """
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("SystemAdminGetListRequest", req)
response = self.__send_request(request)
table = self.get_xml_section_content(response, "//systemAdminTable")
all_admins = self.get_xml_param_all_value(table, ".//row/col[1]")
return all_admins
def PasswordModifyRequest(self, admin, new_pass):
logging.info(self.LOGNAME + "Send request to BWKS to change password for " + admin.admin_id)
reqst = """
<userId>""" + admin.admin_id + """</userId>
<oldPassword>""" + admin.admin_pw + """</oldPassword>
<newPassword>""" + new_pass + """</newPassword>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("PasswordModifyRequest", req)
response = self.__send_request(request)
return response
def PasswordModifyRequest_dict(self, admin, new_pass):
logging.info(self.LOGNAME + "Send request to BWKS to change password for " + admin["admin_id"])
reqst = """
<userId>""" + admin["admin_id"] + """</userId>
<oldPassword>""" + admin["password"] + """</oldPassword>
<newPassword>""" + new_pass + """</newPassword>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("PasswordModifyRequest", req)
response = self.__send_request(request)
return response
def userPasswordModifyRequest(self, user_id, new_pass):
logging.info(self.LOGNAME + "Send request to BWKS to change password for " + user_id)
reqst = """
<userId>""" + user_id + """</userId>
<newPassword>""" + new_pass + """</newPassword>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("PasswordModifyRequest", req)
response = self.__send_request(request)
return response
def EnterprisePreAlertingAnnounRequest(self, ent_id):
logging.info(self.LOGNAME + "Send request to BWKS to display enterprise PreAlerting Announcements")
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("EnterprisePreAlertingAnnouncementGetRequest", req)
response = self.__send_request(request)
return response
def GroupPreAlertingAnnounRequest(self, ent_id, grp_id):
logging.info(self.LOGNAME + "Send request to BWKS to display enterprise PreAlerting Announcements")
reqst = """
<serviceProviderId>""" + ent_id + """</serviceProviderId>
<groupId>""" + grp_id + """</groupId>
"""
req = reqst.replace("<", "<").replace(">", ">").replace("\"", """)
request = self._generate_request_body("GroupPreAlertingAnnouncementGetRequest", req)
response = self.__send_request(request)
return response
def GroupAdminDeleteRequest(self, admin, type_admin='group'):
if type_admin == 'group':
logging.info(self.LOGNAME + "Send request to BWKS to delete group admin " + admin)