-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathksvisionlib.py
More file actions
5226 lines (4516 loc) · 246 KB
/
ksvisionlib.py
File metadata and controls
5226 lines (4516 loc) · 246 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
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
1#################################################################################
#
# File: ksvisionlib.py
# Date: May 9, 2019
# Author: Fred Mota (fred.mota@keysight.com)
#
# Description:
# The intent of this file is to provide a Python package that will facilitate
# the access to Keysight Network Packet Broker (NPB) devices using the RESTful
# Web API interface.
#
# References:
# - Using certificates in urllib3
# http://stackoverflow.com/questions/23954120/using-certificates-in-urllib3
#
# History:
# February 8, 2019:
# - Initial version.
# - In sync with the Network Visibility Software 5.0.0,
# December 2018 - Web API version 5.0.0
# - In sync with the "Ixia GSC 7400 Series Web API User Guide,"
# GSC 1.5.0, October 2018
#
# March 25, 2019:
# - Added the getPortGroupProperties method.
#
# April 15, 2019:
# - Added getters and setters for: debud and request_timeout
# - Check the return code after sending a request and raise an alarm if
# necessary.
#
# December 15, 2019:
# - Added getFilterProperties
#
# December 22, 2019:
# - Replaced % string formatting with prefered format function.
# - Renamed method getAeEventsSummaryReportAction to getAeEventsSummaryReport
#
# - Added Vision NPB v5.0.2 Changes:
# - Added method getAeEventsReportHistory
#
# - Added Vision NPB v5.1.0 Changes:
# - Added method getEventsSummaryReport
# - Added method getChannelLatencyStats
# - Added method getAllEodReportsInfo
# - Added method getCteNeighbors
# - Added method installNetservice
# - Added method removeNetservice
# - Added method removePortModuleConfiguration
# - Added method validateAuthCalls
# - Added method forcePowerPortModule
# - Added all the methods for GTP FD resources
# - Added all the methods for Netservice Instances
#
# - Added Vision NPB v5.2.0 Changes:
# - Added method markEodReportAsGolden
# - Added method optimizeRoutes
# - Added method getAllIfcRoutes
# - Added method getIfcRoute
# - Added method searchIfcRoute
#
# December 24, 2019:
# - Added Vision NPB v5.3.0 Changes:
# - Added method sendSyntheticPackets
# - Added method restoreFirewall
# - Added all the methods for CTE Monitors
# - Added all the methods for CTE Netflow Resources
#
# April 30, 2020:
# - Added method exportOfflineLicenseActivationRequest
# - Added Vision NPB v5.4.0 Changes:
# - Added method getLfdLocalPorts
# - Added method getLfdPeerPorts
# - Added method getChannelBurstStats
# - Renamed method optimizeRoutes to optimizeCteRoutes
# - Added method resetCteEventRateLimiterStatus
# - Added all the methods for Kubernetes Nodes
# - Added all the methods for IFC Capture Resources
# - Added GSC v1.5.3 Changes:
# - Added method getNumberSessions
#
# July 22, 2020:
# - Fixed error in __str__
# - Added Vision NPB v5.5.0 Changes:
# - Added method getMemoryMetersPreview
# - Added method autoDetectChannels
# - Added method getAvailableFilterCriteria
# - Added method getEarlyClassificationCriteria
#
# October 8, 2020:
# - Added Vision NPB v5.6.0 Changes:
# - Added method changeOfflinePortSpeed
# - Added method deployNetServiceInstance
# - Added method installMakoOs
# - Added method removePlugin
# - Added method clearCteAeChannelStatsHistory
# - Fixed getAllNetserviceInstancesType, changed PUT to GET
# - Fixed restartNetserviceInstance, changed PUT to POST
#
# November 18, 2020:
# - Renamed createBypass to createInlineBypassConnector
# - Renamed getBypass to getInlineBypassConnector
# - Renamed getAllBypasses to getAllInlineBypasseConnectors
# - Renamed searchBypass to searchInlineBypassConnectors
# - Renamed modifyBypass to modifyInlineBypassConnector
# - Added deleteInlineBypassConnector
# - Renamed createInline to createInlineServiceChain
# - Renamed deleteInline to deleteInlineServiceChain
# - Renamed getInline to getInlineServiceChain
# - Renamed getAllInlines to getAllInlineServiceChains
# - Renamed searchInline to searchInlineServiceChains
# - Renamed modifyInline to modifyInlineServiceChain
# - Added all the methods for Inline Tool Connectors
# - Added all the methods for Inline Tool Resources
#
# November 21, 2020:
# - Added Vision NPB v5.6.1 Changes:
# - Added method updateSingleIpAddress
#
# December 18, 2020:
# - Added Vision NPB v5.7.0 Changes:
# - Added all the methods for Aggregator Resources
# - Added all the methods for GSC Resources
# - Added method resumeItrTraffic
# - Added method backupGscConfig
# - Added method restoreGscConfig
# - Added method discoverCteConnections
# - Added method updateCteUpdateSingleIpAddress
# - Added timeout and reties to the VisionWebApi __init__ function
# - Added the retries decorators
#
# January 23, 2021
# - Added method modifyCtePort
# - Added method createCtePortGroup
# - Added method deleteCtePortGroup
# - Added method disableCtePortGroup
# - Added method enableCtePortGroup
# - Added method modifyCtePortGroup
#
# February 15, 2021
# - Added API versioning support
#
# March 11, 2021:
# - Added Vision NPB v5.7.1 Changes:
# - Added method clearPort
# - Added method createPort
# - Added method deletePort
# - Added method getPortTransceiverInfo
#
# April 22, 2021
# - Added all the methods for Boards
#
# April 30, 2021
# - Modified all the methods that had an ID parameter to convert it to a string
# - Added all the methods for Netservice Settings
# - Added all the methods for Netservices
# - Added Vision NPB v5.8.0 Changes:
# - Added method getNetserviceLicensedFeatures
# - In SIP Correlator Resources, changed "White List" to "Allow List"
#
# May 3, 2021
# - Fixed/renamed duplicated searchCtePortGroup to searchCtePorts
# - Renamed searchCapture to searchCaptures
# - Renamed searchAggregator to searchAggregators
# - Renamed searchAtip to searchAtips
# - Renamed searchAnalysisEngine to searchAnalysisEngines
# - Renamed saveCteBufferCapture to saveCteBufferCaptures
# - Renamed searchCteCapture to searchCteCaptures
# - Renamed searchCteConnection to searchCteConnections
# - Renamed searchCteFilter to searchCteFilters
# - Renamed searchCteMember to searchCteMembers
# - Renamed searchCteMonitor to searchCteMonitors
# - Renamed searchCteNetflowResource to searchCteNetflowResources
# - Renamed searchCtePortGroup to searchCtePortGroups
# - Renamed searchIfcRoute to searchIfcRoutes
# - Renamed searchCte to searchCtes
# - Renamed searchIcon to searchIcons
# - Renamed searchGscResource to searchGscResources
# - Renamed searchGtpFdResource to searchGtpFdResources
# - Renamed searchHeartbeat to searchHeartbeats
# - Renamed searchLineBoard to searchLineBoards
# - Renamed searchBoard to searchBoards
# - Renamed searchNetserviceInstance to searchNetserviceInstances
# - Renamed searchRtp to searchRtps
# - Renamed searchSip to searchSips
# - Renamed searchAfm to searchAfms
# - Renamed searchSubscriberByFTeid to searchSubscribersByFTeid
# - Renamed searchSubscriberByImsi to searchSubscribersByImsi
#
# June 11, 2021
# - Added Vision NPB v5.8.1 Changes:
# - Added method clearCtePort
#
# June 28, 2021
# - Added the GSC filters configuration methods
# - Added the GSC IMSI lists methods
#
# August 4, 2021
# - Added Vision NPB v5.9.0 Changes:
# - Added the IFC Dual Home Tools methods
# - Added the getTradeVisionEvents method
# - Added the getTradeVisionEventsValuesRanges method
# - Fixed the installCteDtsp method
# - Added the IFC custom icons methods
#
# November 8, 2021
# - No changes for v5.9.1 and v5.10.0
#
# January 24, 2022
# - No changes for v5.10.1
# - Added the getLogs method
#
# July 13, 2022
# - No changes for v5.11.0 and v5.11.1
#
# COPYRIGHT 2019-2022 Keysight Technologies.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights to
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
# of the Software, and to permit persons to whom the Software is furnished to do
# so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
#
################################################################################
import urllib3
import base64
import json
import time
import os
import sys
class KeysightNpbExceptions(Exception):
"""Base class for exceptions in this module."""
pass
class ConnectionError(KeysightNpbExceptions):
"""Exception raised for maximum retries connection errors."""
pass
class AuthenticationError(KeysightNpbExceptions):
"""Exception raised for authentication errors."""
pass
class webAPIError(KeysightNpbExceptions):
"""Exception raised for API errors."""
def __init__(self, code):
super(webAPIError, self).__init__()
self.code = code
def __str__(self):
return "Return code = {0}".format(self.code)
class webAPIClientError(webAPIError):
"""Exception raised for API client errors."""
pass
class webAPIServerError(webAPIError):
"""Exception raised for API server errors."""
pass
class UnknownError(KeysightNpbExceptions):
"""Exception raised for unknown errors."""
pass
class VisionWebApi(object):
def __init__(self, host, username, password, port=8000, debug=False, log_file=None, timeout=30, retries=2, version=None):
#urllib3.disable_warnings()
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
self.host = host
self.port = port
self.user = username
self.password = password
self.__debug = debug
self.auth_b64 = ''
self.password_headers = ''
self.token_headers = ''
self.version = version
self.connection = ''
self.log_file = log_file
self.__request_timeout = timeout
self.__request_retries = retries
self.auth_b64 = base64.b64encode(bytearray(username + ":" + password, 'ascii')).decode('ascii')
self.password_headers = { 'Authorization' : 'Basic ' + self.auth_b64, 'Content-type' : 'application/json' }
#self.connection = urllib3.connectionpool.HTTPSConnectionPool(host, port=port, ssl_version='TLSv1_2')
self.connection = urllib3.connectionpool.HTTPSConnectionPool(host, port=port, cert_reqs='CERT_NONE', ca_certs=None, timeout=self.__request_timeout, retries=self.__request_retries)
try:
response = self.connection.urlopen('GET', '/api/auth', headers=self.password_headers)
except urllib3.exceptions.MaxRetryError:
raise ConnectionError
except:
raise UnknownError
if self.__debug:
self._log ("Status={:d}\n".format(response.status))
self._log ("Reason={:s}\n".format(response.reason))
self._log ("Headers={:}\n".format(response.headers))
self._log ("Data={:}\n".format(response.data))
try:
self.token = response.headers['x-auth-token']
except:
raise AuthenticationError
self.token_headers = { 'Authentication' : self.token, 'Content-type' : 'application/json' }
if self.version:
self.token_headers.update({'Version': self.version})
def __str__(self):
return "VisionWebApi(host='{:s}', port={:d}, user='{:s}', password='{:s}', auth64='{:s}', password_hdrs='{:s}', token_hdrs='{:s}', connection='{:s}', debug={:s}, log_file={:s}, timeout={:d}, retries={:d}, version={:s})".format(self.host, self.port, self.user, self.password, self.auth_b64, str(self.password_headers), str(self.token_headers), str(self.connection), str(self.__debug), str(self.log_file), self.__request_timeout, self.__request_retries, str(self.version))
def __repr__(self):
return str(self)
def _log(self, message):
handle = open(self.log_file, 'a') if self.log_file else sys.stdout
handle.write(message)
if handle is not sys.stdout:
handle.close()
def _sendRequest(self, httpMethod, url, args=None, decode=True):
""" Send the request to the Web API server."""
response = None
if self.__debug:
self._log ("Sending a message to the server with parameters:\n")
self._log (" httpMethod={:s}\n".format(httpMethod))
self._log (" url={:s}\n".format(url))
self._log (" args={:s}\n".format(str(args)))
args = json.dumps(args)
response = self.connection.urlopen(httpMethod, url, body=args, headers=self.token_headers)
if self.__debug:
self._log ("Response:\n")
self._log (" Status={:d}\n".format(response.status))
self._log (" Reason={:s}\n".format(response.reason))
self._log (" Headers={:}\n".format(response.headers))
self._log (" Data={:}\n".format(response.data))
self._log (" decode={:}\n".format(decode))
if (response.status >= 400) and (response.status <= 499):
raise webAPIClientError(response.status)
elif (response.status >= 500) and (response.status <= 599):
raise webAPIServerError(response.status)
elif (response.status != 200) and (response.status != 204):
raise webAPIError(response.status)
data = response.data
if decode:
#data = json.loads(data.decode('ascii'))
data = json.loads(data.decode('iso-8859-1'))
return data
@property
def debug(self):
""" Get the debug flag """
return self.__debug
@debug.setter
def debug(self, flag):
""" Set the debug flag """
self.__debug = flag
@property
def request_timeout(self):
""" Get the request timeout """
return self.__request_timeout
@request_timeout.setter
def request_timeout(self, timeout):
""" Set the request timeout """
self.__request_timeout = timeout
self.connection.timeout = urllib3.Timeout(connect=timeout, read=timeout)
@property
def request_retries(self):
""" Get the request retries """
return self.__request_retries
@request_retries.setter
def request_retries(self, retries):
""" Set the request retries """
self.__request_retries = retries
self.connection.retries = urllib3.Retry(connect=retries, read=retries)
def authenticate(self):
""" authenticate :
Athenticate with the NTO using username and password.
Sample usage:
>>> nto.authenticate()
"""
response = self.connection.urlopen('GET', '/api/auth', headers=self.password_headers)
if self.__debug:
self._log ("Status={:d}\n".format(response.status))
self._log ("Reason={:s}\n".format(response.reason))
self._log ("Headers={:s}\n".format(response.headers))
self._log ("Data={:s}\n".format(response.data))
self.token_headers = { 'Authentication' : response.headers['x-auth-token'], 'Content-type' : 'application/json' }
###################################################
# Actions
###################################################
def addAggregationSwitch(self):
""" addAggregationSwitch :
Adds a new Aggregation Switch to a Switch Cluster.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/add_aggregation_switch', None)
def autoDetectChannels(self, args):
""" autoDetectChannels :
Allows Auto Detection of Channels per Analysis Engine.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/auto_detect_channels', args)
def certificateManagement(self, args):
""" certificateManagement :
Allows Syslog and TLS/HTTPS certificates to be uploaded and deleted. Basic
information can also be viewed for certificates installed on the system.
Sample usage:
>>> nto.certificateManagement({'action': 'VIEW', 'certificate_use': 'DEFAULT_TLS_HTTPS'})
{u'authentication': [{u'valid_from': u'May 28, 2015 10:06:25 AM GMT', u'sha1_fingerprint': u'D3:75:74:30:D7:D8:50:FE:73:2F:10:E3:62:59:1B:EF:83:24:44:58', u'signature_algorithm': u'SHA256WITHRSA', u'valid_to': u'May 25, 2025 10:06:25 AM GMT', u'version': u'3', u'signature': u'12:B5:F1:75:7B:26:86:B2:C7:CE:A8:CE:74:CC:E8:82:8A:A3:45:45:AB:D3:DF:35:96:6A:50:61:F7:70:32:51:0A:03:5E:D1:14:1E:19:8E:ED:1A:E0:71:6E:CD:79:3C:67:70:F1:66:73:6C:1E:4F:97:97:94:79:25:D9:16:9C:B5:C7:E1:84:2A:A4:D6:FE:74:E7:E1:B5:B7:E0:32:0F:12:EA:A0:9C:62:75:D8:70:63:1B:C2:04:67:B9:33:5B:FE:9F:73:20:8B:AF:92:EA:6E:1A:61:B7:79:2A:AF:9E:50:EF:7D:7D:CE:DD:55:BD:20:E3:D7:C3:49:EB:A1:7D:B7:C8:89:43:19:13:59:4D:B6:2F:B9:22:8C:06:5C:4D:BB:8C:03:5B:45:B2:6D:DC:B5:4A:80:9A:14:32:2B:44:9D:CF:83:D8:E8:81:B8:77:94:2D:71:D0:54:ED:47:53:45:06:28:39:86:7D:EF:9D:3D:DC:BD:06:E0:BC:EF:62:AA:85:02:20:D7:E6:61:4E:12:81:04:9E:42:AA:40:18:4F:1B:3D:41:62:9B:E4:36:A9:F8:39:5F:60:2B:C1:83:5D:CF:FE:9F:3B:C0:FD:62:A7:D6:47:9E:C4:73:02:CA:C6:86:F5:7B:52:5B:E8:58:3B:23:57:3F:EE:2C:09:E2', u'serial_number': u'1165506059 (4578360b)', u'md5_fingerprint': u'57:7E:03:2E:2B:67:AA:E7:75:44:AA:21:5C:8F:BE:A1', u'subject': u'CN=Ixia, OU=Ixia, O=Ixia, L=Calabasas, ST=California, C=US', u'issuer': u'CN=Ixia, OU=Ixia, O=Ixia, L=Calabasas, ST=California, C=US'}]}
"""
if 'action' in args:
if (args['action'] == 'VIEW') or (args['action'] == 'DELETE'):
return self._sendRequest('POST', '/api/actions/certificates', args)
elif args['action'] == 'UPLOAD':
# TLS/HTTPS
authentication = None
if 'authentication' in args:
authentication = args['authentication']
del args['authentication']
# Syslog - Client
client = None
if 'client' in args:
client = args['client']
del args['client']
# Syslog - Trsuted Root
trusted_root = None
if 'trusted_root' in args:
trusted_root = args['trusted_root']
del args['trusted_root']
boundary = "-----WebKitFormBoundary" + str(int(time.time())) + str(os.getpid())
buffer = bytearray()
# Set param
buffer.extend(b'--' + bytearray(boundary, 'ascii') + b'\r\n')
buffer.extend(b'Content-Disposition: form-data; name="param"\r\n')
buffer.extend(b'Content-Type: application/json\r\n')
buffer.extend(b'\r\n')
buffer.extend(bytearray(json.dumps(args), 'ascii'))
buffer.extend(b'\r\n')
buffer.extend(b'--' + bytearray(boundary, 'ascii') + b'\r\n')
# Set creative contents part.
if authentication:
buffer.extend(b'Content-Disposition: form-data; name="authentication"; filename=' + bytearray(authentication, 'ascii') + b'\r\n')
buffer.extend(b'Content-Type: application/octet-stream\r\n')
buffer.extend(b'\r\n')
# TODO: catch errors with opening file.
buffer.extend(open(authentication, 'rb').read())
buffer.extend(b'\r\n')
buffer.extend(b'--' + bytearray(boundary, 'ascii') + b'--\r\n')
if client:
buffer.extend(b'Content-Disposition: form-data; name="client"; filename=' + bytearray(client, 'ascii') + b'\r\n')
buffer.extend(b'Content-Type: application/octet-stream\r\n')
buffer.extend(b'\r\n')
# TODO: catch errors with opening file.
buffer.extend(open(client, 'rb').read())
buffer.extend(b'\r\n')
buffer.extend(b'--' + bytearray(boundary, 'ascii') + b'--\r\n')
if trusted_root:
buffer.extend(b'Content-Disposition: form-data; name="trusted_root"; filename=' + bytearray(trusted_root, 'ascii') + b'\r\n')
buffer.extend(b'Content-Type: application/octet-stream\r\n')
buffer.extend(b'\r\n')
# TODO: catch errors with opening file.
buffer.extend(open(trusted_root, 'rb').read())
buffer.extend(b'\r\n')
buffer.extend(b'--' + bytearray(boundary, 'ascii') + b'--\r\n')
buffer.extend(b'\r\n')
hdrs = { 'Authentication' : self.token, 'Content-type' : 'multipart/form-data; boundary=' + boundary }
response = self.connection.urlopen('POST', '/api/actions/certificates', body=buffer, headers=hdrs)
#self._log (response.status, response.reason)
data = response.data
return data
def changeRole(self):
""" changeRole :
This command changes role between supervisor and independent.
Sample usage:
>>> nto.changeRole()
"""
args = {}
return self._sendRequest('POST', '/api/actions/change_role', args)
def changeFilterPriority(self, args):
""" changeFilterPriority :
Allows changing the priority of connections between ports and port
groups to out of band (i.e., non-inline) dynamic filters. To update
the priority of inline filters, update the inline_service_chain_priority_list
of the corresponding inline Bypass connector.
This should only be used when the filter build mode is PRIORITY
(see system memory_allocation property, filter_build_settings).
This method is allowed only on the following models: Vision One, E40, E100
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/change_filter_priority', args)
def changePortSpeed(self, args):
""" changePortSpeed :
Changes the speed configuration of port.
Sample usage:
>>> nto.changePortSpeed({'port_list': [64], 'qsfp28_port_mode': 'MODE_QSFP'})
'{}'
"""
return self._sendRequest('POST', '/api/actions/change_speed_configuration', args, False)
def changeOfflinePortSpeed(self, args):
""" changeOfflinePortSpeed :
This action will change the speed configuration of an offline port.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/change_offline_speed_configuration', args, False)
def clearAeChannelStatsHistory(self, args):
""" clearAeChannelStatsHistory :
Clears the Burst and/or Latency & Jitter Stats History Files from the Disk per AE.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/clear_ae_channel_statistics_history', args)
def clearAggregationSwitch(self):
""" clearAggregationSwitch :
Clears the configuration of an aggregation switch.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/clear_aggregation_switch', None)
def changeQsfp28PortMode(self, args):
""" changeQsfp28PortMode :
Changes the QSFP mode of a QSFP28 port.
* This method was deprecated in v4.8.0, and replaced with change_speed_configuration.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/change_qsfp28_port_mode', args, False)
def changeSpeedConfiguration(self, args):
""" changeSpeedConfiguration :
Changes the speed configuration of port..
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/change_speed_configuration', args, False)
def changePortAggregationMode(self, args):
""" changePortAggregationMode :
* This method was deleted in v4.7.5.
Agregates four 10G ports into one 40G port and backward.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/change_port_aggregation_mode', args, False)
def clearConfig(self):
""" clearConfig :
Clear the configuration by deleting all filters, regular users, groups,
filter templates, filter template collections, port groups, and custom
icons and by setting all ports to default values.
Sample usage:
>>> nto.clearConfig()
{u'message': u'Configuration cleared.'}
"""
args = {}
return self._sendRequest('POST', '/api/actions/clear_config', args)
def clearFiltersAndPorts(self):
""" clearFiltersAndPorts :
This command deletes all filters and port groups and sets all ports to
default values.
Sample usage:
>>> nto.clearFiltersAndPorts()
{u'message': u'Filters and ports cleared.'}
"""
args = {}
return self._sendRequest('POST', '/api/actions/clear_filters_and_ports', args)
def clearSystem(self):
""" clearSystem :
This command clears the system and restores it to a default state, including
resetting the admin account to default values. The license currently
installed will not be removed.
Sample usage:
>>> nto.clearSystem()
{u'message': u'System restored to default state.'}
"""
args = {}
return self._sendRequest('POST', '/api/actions/clear_system', args)
def deployNetServiceInstance(self, args):
""" deployNetServiceInstance :
This command will deploy a netservice instance based on a default name.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/deploy_net_service_instance', args, False)
def drainNetServiceInstance(self, args):
""" drainNetServiceInstance :
This command will drain a netservice instance based on a default name.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/drain_net_service_instance', args, False)
def enableFipsServerEncryption(self):
""" enableFipsServerEncryption :
This commands causes FIPS encryption to be enabled on the server.
Sample usage:
*** TO BE TESTED ***
>>> nto.enableFipsServerEncryption()
"""
args = {}
return self._sendRequest('POST', '/api/actions/enable_fips_server_encryption', args)
def exportConfig(self, args):
""" exportConfig :
Return configuration settings from an NTO to a file.
Sample usage:
nto.exportConfig({'boundary' : 'INCLUDE', 'description' : 'SNMP Config', 'export_type' : 'CUSTOM', 'file_name' : '/Users/fmota/Desktop/snmp+user.ata', 'user': None, 'system' : 'snmp_config'})
"""
file_name = ''
if 'file_name' in args:
file_name = args['file_name']
file = self._sendRequest('POST', '/api/actions/export', args, False)
f = open(file_name, 'wb')
f.write(file)
f.close()
def exportOfflineLicenseActivationRequest(self, args):
""" exportOfflineLicenseActivationRequest :
Export the request file for FNOOD offline license activation for the current system.
Sample usage:
*** TO BE TESTED ***
"""
file_name = ''
if 'file_name' in args:
file_name = args['file_name']
file = self._sendRequest('POST', '/api/actions/export_offline_license_request_file', args, False)
f = open(file_name, 'wb')
f.write(file)
f.close()
def exportKeyGenLicense(self, args):
""" exportKeyGenLicense :
Export the KeyGen license details to a json file that can be used
on the migration portal to obtain a new style license for an NTO
or an union.
Sample usage:
>>> nto.exportKeyGenLicense({'file_name': 'mylicense'})
"""
file_name = ''
if 'file_name' in args:
file_name = args['file_name']
file = self._sendRequest('POST', '/api/actions/export_keygen_license_to_json', args, False)
f = open(file_name, 'wb')
f.write(file)
f.close()
def fipsServerEncryptionStatus(self):
""" fipsServerEncryptionStatus :
This commands causes FIPS encryption to be enabled on the server.
Sample usage:
*** TO BE TESTED ***
>>> nto.fipsServerEncryptionStatus()
"""
args = {}
return self._sendRequest('POST', '/api/actions/fips_server_encryption_status', args)
def factoryReset(self):
""" factoryReset :
This command clears the system and restores it to a factory default
state, including resetting the admin account to default values. The
license currently installed will also be removed.
Sample usage:
>>> nto.factoryReset()
"""
args = {}
return self._sendRequest('POST', '/api/actions/factory_reset', args)
def forcePowerPortModule(self, args):
""" forcePowerPortModule :
This command will power on/off the port module in the given module location.
This method is allowed only on the following models: 8000.
Sample usage:
"""
args = {}
return self._sendRequest('POST', '/api/actions/force_power_port_module', args, False)
def generateCsr(self, args):
""" generateCsr :
Allows Syslog and TLS/HTTPS certificates to be uploaded and deleted. Basic
information can also be viewed for certificates installed on the system.
Sample usage:
>>> nto.generateCsr({'csr_use' : 'SYSLOG', 'tls_cert_request_info' : {'city' : 'Austin', 'common_name' : 'Test API', 'country' : 'US', 'organization' : 'Ixia', 'organization_unit' : 'NVS', 'state' : 'TX', 'subject_alt_name' : 'Anue'}})
{u'csr': u'-----BEGIN CERTIFICATE REQUEST-----MIIC5zCCAc8CAQAwWzELMAkGA1UECBMCVFgxDzANBgNVBAcTBkF1c3RpbjELMAkGA1UEBhMCVVMxDDAKBgNVBAsTA05WUzENMAsGA1UEChMESXhpYTERMA8GA1UEAxMIVGVzdCBBUEkwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC4RNOnSPTRamGkAwj/otEgzAFYIEXlpsO4OS16P49l3c0n5ShDs0uo2pd4a0Qe4Wvh/KX4L1oZbxS/2YNJgNlLiRkHo5K62ZYYskfNGXPBYfkkRDLk76SrhgHyoGSEy8h6OdeE2QpfgsD/XLQVoFQ3dVemSwo76bE3Vap333fJmvtNJNgItkKqKBW3zF1doSWJwEHDwwhG9/KSfFBHf/qE51LRj2iybZQE4ijZGHv0I7CtSF20166sH75EhsoK8/vs1RT6LpyuEM9JKoRzmvE1ufk3nHtlvF3UniUluUCubXfldaEROIeBvYfoWZGGuyzAN01ZbxZ+/K2ENokpVKPbAgMBAAGgRzBFBgkqhkiG9w0BCQ4xODA2MA8GA1UdEQQIMAaCBEFudWUwDgYDVR0PAQH/BAQDAgUgMBMGA1UdJQQMMAoGCCsGAQUFBwMCMA0GCSqGSIb3DQEBCwUAA4IBAQAfVnwTv1t56YWU2W5+Fjlc9nuTL7eAoKqkioTJ1CuAINLybbHYUVXVfpBahfjj7g6ZmiWZ383SK7ImuPfHE7kt/eRDna+/+HUQ22799HQmyLcxCkYZVSH8gWkTNbUIhgh4AFMwt83zWu324P+qNkh5u0sckPTfNzry3Mxz2QzmM5sP+oU8/RCt04iYzz5KSu+tzHWJ9FOGLQqQ73Ausz0smTDFBlVLs8VCifHVc2QmSbIofHVPUOUEjWo+FFb6WK6/7NjgE4DM9rVDV7eW9WXZgos6WnXRVMIpedeibh31iM/sc63F0tQHXt696kfO19LBc6FLMKLCvVtkGfSnq5u9-----END CERTIFICATE REQUEST-----'}
"""
return self._sendRequest('POST', '/api/actions/generate_csr', args)
def getAllEodReportsInfo(self, args):
""" getAllEodReportsInfo :
Returns the list of all Eod events summary Report for all AEs in a TradeVision.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_ae_events_report_info', args)
def getAvailableFilterCriteria(self, args):
""" getAvailableFilterCriteria :
Return a list of filter criteria which can be used given an already
present set of filter criteria.
Sample usage:
>>> nto.getAvailableFilterCriteria({'filter_object_type': 'FILTER'})
[]
"""
return self._sendRequest('POST', '/api/actions/get_available_filter_criteria', args)
def getChannelBurstStats(self, args):
""" getChannelBurstStats :
This command is used to get the Channel Burst statisics for a given channel id and VLAN Match type per Analysis Engine.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_channel_burst_stats', args)
def getChannelLatencyStats(self, args):
""" getChannelLatencyStats :
This command is used to get the latency/jitter statisics for a given channel id and VLAN Match type per Analysis Engine.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_channel_latency_stats', args)
def getDtspChannelInfo(self, args):
""" getDtspChannelInfo :
This command is used to get the channel info based on a given list of channel IP:Port.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_dtsp_channel_info', args)
def getEventsSummaryReport(self):
""" getEventsSummaryReport :
Return a End-Of-Day report by name or a comparison report between two different End-Of-Day reports.
If report name is specified, event summary report is returned.
If two report names are specified, a new report is generated holding the differences between the two EOD reports.
Sample usage:
"""
args = {}
return self._sendRequest('POST', '/api/actions/get_ae_events_report_action', args)
def getAeEventsReportHistory(self):
""" getAeEventsReportHistory :
Return either a list of the latest 8 End-Of-Day reports run on the system or a comparison between
two different End-Of-Day reports. If no report dates are specified, the latest 8 End-Of-Day reports
are returned (the maximum number of EOD reports retained by the system). If two dates are specified
(representing the end date of two different EOD reports), a new report is generated holding the
differences between the two EOD reports. Note that the end dates must be from any of the latest 8
EOD reports run.
Sample usage:
"""
args = {}
return self._sendRequest('POST', '/api/actions/get_ae_events_report_history_action', args)
def getAeEventsSummaryReport(self):
""" getAeEventsSummaryReport :
Return events summary report for all the AEs in a TradeVision.
Sample usage:
"""
args = {}
return self._sendRequest('POST', '/api/actions/get_ae_events_summary_report_action', args)
def getLoginInfo(self):
""" getLoginInfo :
Returns last login session details plus hardware info and sensor readings for the device
Sample usage:
>>> nto.getLoginInfo()
{
"hardware_info": {
"cpld_rev": null,
"fpga_rev": null,
"mac_address": "001B6E08D47F",
"mac_address2": "001b6e08d47f",
"max_cool_temperature": 49,
"max_hot_temperature": 81,
"max_ok_temperature": 57,
"module_list": [ ... ],
"primary_mgmt_port": "eth0",
"secondary_mgmt_port": null,
"snmp_engine_id": "0x80007f6c03001B6E08D47F",
"system_id": "E40-00001456",
"top_assembly_number": "Vision E40"
},
"has_license_file": true,
"is_password_expired": false,
"password_change_required": false,
"prev_login_info": {
"client_ip_address": "156.140.231.30",
"failures_count": 0,
"is_sysadm_modified": false,
"timestamp": 1536342551729
}
}
"""
args = {}
return self._sendRequest('POST', '/api/actions/get_login_info', args)
def getFabricPorts(self, args):
""" getFabricPorts :
Return fabric ports information for one or more members. This
information can be used as input to the update_fabric_ports action.
Sample usage:
>>> nto.getFabricPorts()
"""
return self._sendRequest('POST', '/api/actions/get_fabric_ports', args)
def getHaCliConfig(self):
""" getHaCliConfig :
Returns the HA config needed by CLI.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_ha_config_for_cli')
def getMemoryMeters(self):
""" getMemoryMeters :
Return the filter memory meters showing memory allocation and percentage used.
Sample usage:
>>> nto.getMemoryMeters()
[{u'unit_name': u'LC1', u'memory_meters': [{u'custom_memory_slice_count': 0, u'meters': [{u'alloc_pcnt': 89, u'avail_pcnt': 100, u'meter_name': u'FILTER_ETHERTYPE_VLAN_L3_L4'}, {u'alloc_pcnt': 89, u'avail_pcnt': 100, u'meter_name': u'FILTER_L2_L3_L4'}], u'memory_type': u'DYNAMIC_FILTER_NON_IP'}, {u'custom_memory_slice_count': 0, u'meters': [{u'alloc_pcnt': 50, u'avail_pcnt': 100, u'meter_name': u'DYNAMIC_SIP_IPV4'}, {u'alloc_pcnt': 50, u'avail_pcnt': 100, u'meter_name': u'DYNAMIC_DIP'}], u'memory_type': u'DYNAMIC_FILTER_IP'}, {u'custom_memory_slice_count': 0, u'meters': [{u'alloc_pcnt': 100, u'avail_pcnt': 100, u'meter_name': u'NETWORK_PORT_L2_L3_IPV4'}], u'memory_type': u'NETWORK_PORT_FILTER'}, {u'custom_memory_slice_count': 0, u'meters': [{u'alloc_pcnt': 100, u'avail_pcnt': 100, u'meter_name': u'TOOL_PORT_L2_L3_IPV4'}], u'memory_type': u'TOOL_PORT_FILTER'}]}, ...
"""
args = {}
return self._sendRequest('POST', '/api/actions/get_memory_meters', args)
def getMemoryMetersPreview(self, args):
""" getMemoryMetersPreview :
Accepts a memory allocation configuration and return what the filter memory meters would be for that allocation.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_memory_meters_preview', args)
def getTransceiverInfo(self):
""" getTransceiverInfo :
Return the transceiver information.
Sample usage:
>>> nto.getTransceiverInfo()
[{'lanes': 1, 'port_default_name': 'P01', 'port_id': '16', 'port_name': 'P01', 'transceiver_info': [{'cable': 'N/A', 'compliance': '100G AOC or 25GAUI C2M AOC', 'connector': 'No separable connector', 'diag_calibration': 'Not Applicable', 'identifier': 'QSFP28', 'length_comment': 'OM4 50um', 'length_mode': 'Unspecified', 'max_length': '6 meters', 'present': 'true', 'rx_input_power1': '1.3392', 'rx_input_power1_dbm': '1.27', 'rx_input_power2': '1.3545', 'rx_input_power2_dbm': '1.32', 'rx_input_power3': '1.3764', 'rx_input_power3_dbm': '1.39', 'rx_input_power4': '1.352', 'rx_input_power4_dbm': '1.31', 'rx_input_power_high_alert_threshold': '3.4673', 'rx_input_power_high_alert_threshold_dbm': '5.40', 'rx_input_power_high_warning_threshold': '1.7378', 'rx_input_power_high_warning_threshold_dbm': '2.40', 'rx_input_power_low_alert_threshold': '0.0467', 'rx_input_power_low_alert_threshold_dbm': '-13.31', 'rx_input_power_low_warning_threshold': '0.0933', 'rx_input_power_low_warning_threshold_dbm': '-10.30', 'rx_input_power_status1': 'Normal', 'rx_input_power_status2': 'Normal', 'rx_input_power_status3': 'Normal', 'rx_input_power_status4': 'Normal', 'temperature': '35', 'temperature_high_alert_threshold': '80', 'temperature_high_warning_threshold': '70', 'temperature_low_alert_threshold': '-10', 'temperature_low_warning_threshold': '0', 'temperature_status': 'Normal', 'tx_bias1': '6.75', 'tx_bias2': '6.75', 'tx_bias3': '6.75', 'tx_bias4': '6.75', 'tx_bias_high_alert_threshold': '8.5', 'tx_bias_high_warning_threshold': '8.0', 'tx_bias_low_alert_threshold': '5.492', 'tx_bias_low_warning_threshold': '6.0', 'tx_bias_status1': 'Normal', 'tx_bias_status2': 'Normal', 'tx_bias_status3': 'Normal', 'tx_bias_status4': 'Normal', 'tx_output_power1': '1.6412', 'tx_output_power1_dbm': '2.15', 'tx_output_power2': '1.6222', 'tx_output_power2_dbm': '2.10', 'tx_output_power3': '1.5521', 'tx_output_power3_dbm': '1.91', 'tx_output_power4': '1.5447', 'tx_output_power4_dbm': '1.89', 'tx_output_power_high_alert_threshold': '3.4673', 'tx_output_power_high_alert_threshold_dbm': '5.40', 'tx_output_power_high_warning_threshold': '1.7378', 'tx_output_power_high_warning_threshold_dbm': '2.40', 'tx_output_power_low_alert_threshold': '0.0724', 'tx_output_power_low_alert_threshold_dbm': '-11.40', 'tx_output_power_low_warning_threshold': '0.1445', 'tx_output_power_low_warning_threshold_dbm': '-8.40', 'tx_output_power_status1': 'Normal', 'tx_output_power_status2': 'Normal', 'tx_output_power_status3': 'Normal', 'tx_output_power_status4': 'Normal', 'vendor_date_code': '05-07-2018', 'vendor_lot_code': ' ', 'vendor_name': 'Mellanox', 'vendor_oui': '0002c9', 'vendor_part_number': 'MFA1A00-C003', 'vendor_rev': 'B1', 'vendor_serial_number': 'MT1823FT00529', 'voltage': '3.2691', 'voltage_high_alert_threshold': '3.5', 'voltage_high_warning_threshold': '3.465', 'voltage_low_alert_threshold': '3.1', 'voltage_low_warning_threshold': '3.135', 'voltage_status': 'Normal', 'wavelength': '8500'}]},
<snip>
"""
args = {}
return self._sendRequest('POST', '/api/actions/get_transceiver_info', args)
def getTradeVisionEvents(self):
""" getTradeVisionEvents :
This command is used to get TradeVision-only events from the server database.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_tv_events')
def getTradeVisionEventsValuesRanges(self):
""" getTradeVisionEventsValuesRanges :
This command is used to get TradeVision events from the server database.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_tv_events_value_range')
def getNeighbors(self, args):
""" getNeighbors :
Get neighbors of a list of ports given as parameter. If the list given is empty or is not given at all, it will return
all neighbors for all ports that are valid for LLDP and have valid neighbors registrations.
This method is allowed only on the following models: E40, TradeVision
Sample usage:
>>> nto.getNeighbors({'port_id_list': [8]})
{u'P49': [{u'system_name': u'Ixia Vision One (Neo10 project)', u'port_description': u'', u'system_description': u'', u'expired': False, u'age': 1, u'chassis_id': u'00:1b:6e:04:8d:44', u'custom_tlvs': [], u'ttl': 120, u'port_id': u'P50', u'system_capabilities': u'', u'management_addresses': [], u'last_seen': 1577241420}]}
"""
return self._sendRequest('POST', '/api/actions/get_neighbors', args)['message']
def getLfdLocalPorts(self):
""" getLfdLocalPorts :
Get a list of local ports valid for LFD.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_local_ports_valid_for_lfd', {})
def getLfdPeerPorts(self):
""" getLfdPeerPorts :
Get a list of peer ports valid for LFD.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_peer_ports_valid_for_lfd', {})
def getEarlyClassificationCriteria(self):
""" getEarlyClassificationCriteria :
Get a list of valid early classification criteria for Intersection filtering.
This method is allowed only on the following models: 7816, 8000, E100.
Sample usage:
"""
return self._sendRequest('POST', '/api/actions/get_early_classification_criteria', {})
def getAllNeighbors(self, port_id_list=[]):
""" getAllNeighbors :
Fetch a list containing summaries for all the neigbors the system learned by snooping on LLDP messages.
Sample usage:
>>> nto.getAllNeighbors()
{u'P50': [{u'system_name': u'Ixia Vision One (Neo10 project)', u'port_description': u'', u'system_description': u'', u'expired': False, u'age': 1, u'chassis_id': u'00:1b:6e:04:8d:44', u'custom_tlvs': [], u'ttl': 120, u'port_id': u'P49', u'system_capabilities': u'', u'management_addresses': [], u'last_seen': 1577241872}], u'P49': [{u'system_name': u'Ixia Vision One (Neo10 project)', u'port_description': u'', u'system_description': u'', u'expired': False, u'age': 3, u'chassis_id': u'00:1b:6e:04:8d:44', u'custom_tlvs': [], u'ttl': 120, u'port_id': u'P50', u'system_capabilities': u'', u'management_addresses': [], u'last_seen': 1577241870}]}
"""
# TODO TEST we got HTTP/200 with JSON back
# TODO TEST we got 'message' key back
return self._sendRequest('POST', '/api/actions/get_neighbors', {'port_id_list': port_id_list})['message']
def getObjectType(self, args):
""" getObjectType :
Return the object type for an internal id.
Sample usage:
>>> nto.getObjectType({'id':238})
{u'object_type': u'PORT'}
"""
return self._sendRequest('POST', '/api/actions/get_object_type', args)
def getProperties(self, args):
""" getProperties :
Return a list of the properties that are available for a particular type of object.
Sample usage:
>>> nto.getProperties({'object_type' : 'monitor'})
{u'properties': [u'actions', u'created', u'description', u'history', u'id', u'mod_count', u'name', u'trigger']}
"""
return self._sendRequest('POST', '/api/actions/get_props', args)
def getPropertyValues(self, args):
""" getPropertyValues :
Return a list of the properties that are available for a particular type of object.
Sample usage:
>>> nto.getPropertyValues({'object_type': 'port', 'prop_name': 'force_link_up'})
{u'value': [u'DISABLED', u'ENABLED', u'MIXED', u'NOT_SUPPORTED']}
"""
return self._sendRequest('POST', '/api/actions/get_values', args)
def importConfig(self, args):
""" importConfig :
Copy configuration settings from a file to an NTO.
Sample usage:
>>> nto.importConfig({'boundary': 'INCLUDE', 'import_type': 'CUSTOM', 'file_name': '/Users/fmota/Desktop/snmp+user.ata', 'system' : 'snmp_config'})
'{"message": "Configuration imported from /Users/fmota/Desktop/snmp+user.ata."}'
"""
file_name = ''
if 'file_name' in args:
file_name = args['file_name']
del args['file_name']
boundary = "-----WebKitFormBoundary" + str(int(time.time())) + str(os.getpid())
buffer = bytearray()
# Set param
buffer.extend(b'--' + bytearray(boundary, 'ascii') + b'\r\n')
buffer.extend(b'Content-Disposition: form-data; name="param"\r\n')
buffer.extend(b'Content-Type: application/json\r\n')
buffer.extend(b'\r\n')