-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbpsRest.py
More file actions
executable file
·825 lines (731 loc) · 38 KB
/
bpsRest.py
File metadata and controls
executable file
·825 lines (731 loc) · 38 KB
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
import requests
import json
import time
import os
import sys
from os.path import basename
from os.path import join
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.poolmanager import PoolManager
import ssl
requests.packages.urllib3.disable_warnings()
class TlsAdapter(HTTPAdapter):
def init_poolmanager(self, connections, maxsize, block=False):
self.poolmanager = PoolManager(num_pools=connections, maxsize=maxsize, block=block,ssl_version=ssl.PROTOCOL_TLSv1_1)
class BPS:
def pretty_print_requests(self, req):
request = req.request
print('\n\n{}\n{}\n{}\n\n{}'.format(
'-----------REQUEST START-----------',
request.method + ' ' + request.url,
'\n'.join('{}: {}'.format(k, v) for k, v in request.headers.items()),
request.body,
))
print '-----------REQUEST END-----------'
print '\n\n-----------RESPONSE START-----------'
print req.status_code
print '\n'
print req.headers.get('content-type')
print req.content
print '-----------RESPONSE END-----------'
print '\n\n'
def __init__(self, ipstr, username, password):
self.ipstr = ipstr
self.username = username
self.password = password
self.session = requests.Session()
self.session.mount('https://', TlsAdapter())
#Login
def login(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/auth/session'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'username':self.username, 'password':self.password})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print 'Login successful. Welcome ' + self.username
else:
print r.status_code
print r.content
sys.exit(0)
#Logout
def logout(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/auth/session'
r = self.session.delete(service, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 204):
print 'User logout successful'
#Port state
def portsState(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ports/'
r = self.session.get(service, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print r.json().get('portReservationState')
#Port state printed in json format
def portsStateJson(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ports?prettyprint=true'
r = self.session.get(service, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print r.json().get('portReservationState')
#Port reserve
def reservePorts(self, slot, portList, group, force, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ports/operations/reserve'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'slot':slot, 'portList':portList, 'group':group, 'force':force})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print 'Port reservation successful.'
print r.content
#Port Unreserved
def unreservePorts(self, slot, portList, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ports/operations/unreserve'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'slot':slot, 'portList':portList})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print 'Port unreservation successful'
print r.content
#View the running tests
def runningTestInfo(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests'
jheaders = {'content-type': 'application/json'}
r = self.session.get(service, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print r.json().get('runningTestInfo')
def formattedRunningTestInfo(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/getFormattedRunningTestInfo'
jheaders = {'content-type': 'application/json'}
r = self.session.post(service, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
result = r.json().get('result')
return result
#Run Test
def runTest(self, modelname, group, neighborhood = None, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/start'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'modelname':modelname, 'group':group, 'neighborhood':neighborhood})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print 'Test started successfully with testid: [' + json.loads(r.text).get('testid')+ '].'
runid = json.loads(r.text).get('testid')
return runid
else:
print r.status_code
print 'Some error occurred while starting the test.'
print r.json().get('error')
return -1
#Stop Test
#Setting testid by default to None in order to keep backwards compatibility
def stopTest(self, testid = None, enableRequestPrints = False):
print 'Currently running tests:'
self.runningTestInfo()
if testid is None:
testid = raw_input('Enter the complete testid to cancel the running test: ')
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/stop'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'testid':testid})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print 'Test: [' + testid + '] has been successfully stopped.'
else:
print 'Some error occurred while cancelling the running test: [' + testid + ']'
#Get Run time stats
def getRTS(self, runid, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/getRTS'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'runid':runid})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print "RTS Values: ", r.json().get('rts')
return json.loads(r.text).get('progress')
def getRealTimeStatistics(self, runid, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/getRealTimeStatistics'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'runid':runid})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
return r.json().get('rts')
def getRealTimeStatByName(self, runid, statname, enableRequestPrints = False):
response = self.getRealTimeStatistics(runid)
if response != None:
values = json.loads(response).get('values')
if values != None:
statValue = values.get(statname)
return statValue
def getTestProgress(self, runid, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/getRTS'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'runid':runid})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
return json.loads(r.text).get('progress')
def getTestResult(self, runid, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/result'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'runid':runid})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
result = json.loads(r.text).get('result');
print result
return result
def getTestFailureDescription(self, runid, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/failuredescription'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'runid':runid})
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
result = json.loads(r.text).get('result');
print result
return result
# Network Neighbourhood
def retrieveNetwork(self, NN_name=None, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/network/operations/retrieve'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'name':NN_name})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For retrieve Network %s" %r
print "For retrieve Network json object %s" %(r.json())
def viewNetwork(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/network'
jheaders = {'content-type': 'application/json'}
r = self.session.get(service)
if(enableRequestPrints):
self.pretty_print_requests(r)
print r.status_code
print "For view Network %s" %r
print "For view Network json object %s" %(r.json())
def modifyNetwork(self, componentId, elementId, Value, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/network/operations/modify'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'componentId':componentId, 'elementId':elementId, 'value':Value})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For modify Network %s" %r
print "For modify Network json object %s" %(r.json())
def createModifyBatchArg(self, componentId, elementId, Value):
batchArg = {}
batchArg['componentId'] = componentId
batchArg['elementId'] = elementId
batchArg['value'] = Value
return batchArg
def modifyBatchNetwork(self, modifyBatchArgs, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/network/operations/modifyBatch'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'networkArgs':modifyBatchArgs})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For modify batch Network %s" %r
print "For modify batch Network json object %s" %(r.json())
def saveNetwork(self, name_, force, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/network/operations/saveas'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'name':name_, 'force': force})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For save Network %s" %r
print "For save Network json object %s" %(r.json())
# Component modification
def setNormalTest(self, NN_name=None, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/workingmodel'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'template':NN_name})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For set working model %s" %r
def viewNormalTest(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/workingmodel/settings'
jheaders = {'content-type': 'application/json'}
#jdata = json.dumps({'name':NN_name})
#print jdata
r = self.session.get(service)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For view working model %s" %r
def uploadCapture(self, filePath, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/upload/capture'
fileName = basename(filePath)
files = {'file': (fileName, open(filePath, 'rb'), 'multipart/form-data')}
r = self.session.post(service, files=files, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
if(r.status_code == 200):
print 'The Capture was uploaded and saved with name: [' + json.loads(r.text).get('result') + ']'
return json.loads(r.text).get('result')
else:
print "Failed to load Capture"
print "For Upload Capture json object %s" %(r.json())
return
def modifyNormalTest(self, componentId, elementId, Value, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/workingmodel'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'newParams':{'componentId':componentId, 'elementId':elementId, 'value':Value}})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For modify working model %s" %r
if(r.status_code != 204):
print "For modify working model json object %s" %(r.json())
def modifyNormalTest2(self, componentId, elementId, paramId, Value, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/workingmodel'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'newParams':{'componentId':componentId, 'elementId':elementId, 'paramId':paramId, 'value':Value}})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For modify working model %s" %r
if(r.status_code != 204):
print "For modify working model json object %s" %(r.json())
def saveNormalTest(self, name_, force, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/workingmodel/operations/save'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'name':name_, 'force': force})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For save working model %s" %r
print "For save working model json object %s" %(r.json())
# sessionsender Lab
def setSessionSender(self, template, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/sessionlabtest/'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'template':template})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For set template status code -- %s" %r.status_code
if r.status_code != 204:
print "For set template json object %s" %(r.json())
def viewSessionSender(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/sessionlabtest/'
jheaders = {'content-type': 'application/json'}
r = self.session.get(service)
if(enableRequestPrints):
self.pretty_print_requests(r)
print r.status_code
print "For view template json object %s" %(r.json())
def modifySessionSender(self, elementId, Value, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/sessionlabtest/'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'sessionlabParams':{'elementId':elementId, 'value':Value}})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print r.status_code
if r.status_code != 204:
print "For modify template json object %s" %(r.json())
def saveSessionSender(self, name_, force, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/sessionlabtest/operations/saveas'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'name':name_, 'force':force})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print r.status_code
print "For save template json object %s" %(r.json())
#Lawful test
def setLawful(self, template, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/lawfulinterceptlabtest/'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'template':template})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For set template %s" %r
if r.status_code != 204:
print "For set template json object %s" %(r.json())
def viewLawful(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/lawfulinterceptlabtest/'
jheaders = {'content-type': 'application/json'}
r = self.session.get(service)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For view template %s" %r
print "For view template json object %s" %(r.json())
def modifyLawful(self, elementId, Value, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/lawfulinterceptlabtest/'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'lawfulInterceptlabParams':{'elementId':elementId, 'value':Value}})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For modify template %s" %r
if r.status_code != 204:
print "For modify template json object %s" %(r.json())
def saveLawful(self, name_, force, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/lawfulinterceptlabtest/operations/saveas'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'name':name_, 'force':force})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For save template %s" %r
#RFC2544 test
def setRfc(self, template, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/rfc2544test/'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'template':template})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For set template %s" %r
def viewRfc(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/rfc2544test/'
jheaders = {'content-type': 'application/json'}
r = self.session.get(service)
print "For view template %s" %r
def modifyRfc(self, elementId, Value, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/rfc2544test/'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'rfc2544Params':{'elementId':elementId, 'value':Value}})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For modify template %s" %r
if r.status_code != 204:
print "For modify template json object %s" %(r.json())
def saveRfc(self, name, force, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/rfc2544test/operations/saveas'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'name':name, 'force':force})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For save template %s" %r
print "For save template json object %s" %(r.json())
#Multicast Lab test
def setMulticast(self, template, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/multicasttest/'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'template':template})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For set template %s" %r
def viewMulticast(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/multicasttest/'
jheaders = {'content-type': 'application/json'}
r = self.session.get(service)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For view template %s" %r
def modifyMulticast(self, elementId, paramId, Value, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/multicasttest/'
jheaders = {'content-type': 'application/json'}
source = ['10.1.1.3']
jdata = json.dumps({'multicastNewParams':{'elementId':elementId, 'paramId':paramId, 'value':Value, "sourceIp":source}})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For modify template %s" %r
if r.status_code != 204:
print "For modify template json object %s" %(r.json())
def addSource(self, type_, ipAddress, multicastAddress, Rate, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/multicasttest/operations/add'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'type':type_, 'ipAddress':ipAddress, 'multicastAddress':multicastAddress, 'rate':Rate})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For Add source %s" %r
print "For Add source json object %s" %(r.json())
def deleteSource(self, elementId, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/multicasttest/operations/delete'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'elementId':elementId})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For Delete source %s" %r
print "For Delete source json object %s" %(r.json())
def addSubscriber(self, type_, maxSubscribers, groupAddress, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/multicasttest/operations/add'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'type':type_, 'maxSubscribers':maxSubscribers, 'groupAddress':groupAddress})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For Add Subscriber %s" %r
print "For Add Subscriber json object %s" %(r.json())
def deleteSubscriber(self, elementId, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/multicasttest/operations/delete'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'elementId':elementId})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For Delete Subscriber %s" %r
print "For Delete Subscriber json object %s" %(r.json())
def saveMulticast(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/multicasttest/operations/save'
jheaders = {'content-type': 'application/json'}
r = self.session.post(service, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For save template %s" %r
def saveasMulticast(self, name, force, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/multicasttest/operations/saveas'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'name':name, 'force':force})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For save template %s" %r
print "For save template json object %s" %(r.json())
#LTE lab test
def setLte(self, template, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ltelabtest/'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'template':template})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For set template %s" %r
def viewLte(self, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ltelabtest/'
jheaders = {'content-type': 'application/json'}
r = self.session.get(service)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For view template %s" %r
def modifyLte(self, elementId, Value, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ltelabtest/'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'lteLabParams':{'elementId':elementId, 'value':Value}})
print jdata
r = self.session.patch(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For modify template %s" %r
if r.status_code != 204:
print "For modify template json object %s" %(r.json())
def addMmeLte(self, mme_ip, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ltelabtest/operations/addmme'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'mme_ip':mme_ip})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For Add MME %s" %r
print "For Add MME json object %s" %(r.json())
def modifyMmeLte(self, oldMme, newMme, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ltelabtest/operations/modifymme'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'oldMme':oldMme, 'newMme':newMme})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For modify MME %s" %r
print "For modify MME json object %s" %(r.json())
def deleteMmeLte(self, mme_ip, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ltelabtest/operations/removemme'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'mme_ip':mme_ip})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For Delete MME %s" %r
print "For Delete MME json object %s" %(r.json())
def saveLte(self, name, force, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/ltelabtest/operations/saveas'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'name':name, 'force':force})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For save template %s" %r
print "For save template json object %s" %(r.json())
#Importing bpt
def uploadBPT(self, filePath, force, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/upload'
fileName = basename(filePath)
files = {'file': (fileName, open(filePath, 'rb'), 'application/xml')}
jdata = {'force':force}
print jdata
r = self.session.post(service, files=files, data=jdata, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "For upload template status code %s" %r.status_code
if(r.status_code == 200):
print 'The bpt was uploaded and saved with name: [' + json.loads(r.text).get('result') + ']'
return json.loads(r.text).get('result')
else:
print "Failed to load BPT"
print "For upload template json object %s" %(r.json())
return
#Export Report
def exportTestReport(self, testId, reportName, location, enableRequestPrints = False):
reportFormat = reportName.split('.')[1].lower()
service = 'https://' + self.ipstr + '/api/v1/bps/export/report/' + testId + '/' + reportFormat
print 'Please wait while your report is being downloaded. You will be informed once the download is complete'
r = self.session.get(service, verify=False, stream=True)
if(enableRequestPrints):
self.pretty_print_requests(r)
if not os.path.isdir(location):
os.makedirs(location)
with open(join(location,reportName), 'wb') as fd:
for chunk in r.iter_content(chunk_size=1024):
fd.write(chunk)
fd.close()
r.close()
if(r.status_code == 200):
print 'Your report for the testid: [' + testId + '] has been successfully downloaded'
#Export BPT
def exportTestBPT(self, bptName, testId=None, testName=None, location='.//', enableRequestPrints = False):
bptName = bptName + '.bpt'
if (testId is not None) and (testName is None):
service = 'https://' + self.ipstr + '/api/v1/bps/export/bpt/testid/' + testId
print 'Please wait while your bpt is being downloaded. You will be informed once the download is complete'
r = self.session.get(service, verify=False, stream=True)
if(enableRequestPrints):
self.pretty_print_requests(r)
with open(join(location,bptName), 'wb') as fd:
for chunk in r.iter_content(chunk_size=1024):
fd.write(chunk)
fd.close()
r.close()
if(r.status_code == 200):
print 'Your bpt having the testid: [' + testId + '] has been successfully downloaded'
elif (testId is None) and (testName is not None):
service = 'https://' + self.ipstr + '/api/v1/bps/export/bpt/testname/' + testName
print 'Please wait while your bpt is being downloaded. You will be informed once the download is complete'
r = self.session.get(service, verify=False, stream=True)
if(enableRequestPrints):
self.pretty_print_requests(r)
with open(join(location,bptName), 'wb') as fd:
for chunk in r.iter_content(chunk_size=1024):
fd.write(chunk)
fd.close()
r.close()
if(r.status_code == 200):
print 'Your bpt for the test: [' + testName + '] has been successfully downloaded'
else :
print 'Wrong usage. You can only use of the two methods to export the test model.'
def exportTestsCsv(self, csvName, location='.//', enableRequestPrints = False):
csvName = csvName + '.csv'
service = 'https://' + self.ipstr + '/api/v1/bps/export/tests'
print 'Please wait while your csv is being downloaded. You will be informed once the download is complete'
r = self.session.get(service, verify=False, stream=True)
if(enableRequestPrints):
self.pretty_print_requests(r)
with open(join(location,csvName), 'wb') as fd:
for chunk in r.iter_content(chunk_size=1024):
fd.write(chunk)
fd.close()
r.close()
if(r.status_code == 200):
print 'Your csv having the test details has been successfully downloaded'
#Aggregate stats
def aggStats(self, testid, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/getAggregateStats'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'testid':testid})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "Aggregate statistics ****** %s" %r.json()
return r.json()
#Component Level stats
def compStats(self, testid, componentId, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/getComponentStats'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'testid':testid, 'componentId':componentId})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "Component statistics ****** %s" %r.json()
return r.json()
#Protocol Level stats
def protoStats(self, testid, componentId, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/getProtocolStats'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'testid':testid, 'componentId':componentId})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "Protocol statistics ****** %s" %r.json()
#Get all components
def testComponents(self, modelName, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/getTestComponents'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'modelName':modelName})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "Component Names ****** %s" %r.json()
return r.json()
def compName(self, modelName, enableRequestPrints = False):
service = 'https://' + self.ipstr + '/api/v1/bps/tests/operations/getComponents'
jheaders = {'content-type': 'application/json'}
jdata = json.dumps({'modelName':modelName})
print jdata
r = self.session.post(service, data=jdata, headers=jheaders, verify=False)
if(enableRequestPrints):
self.pretty_print_requests(r)
print "Component Names ****** %s" %r.json()