-
Notifications
You must be signed in to change notification settings - Fork 546
/
base.py
1685 lines (1490 loc) · 61.2 KB
/
base.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
# Copyright 2015 Spotify AB. All rights reserved.
#
# The contents of this file are licensed under the Apache License, Version 2.0
# (the "License"); you may not use this file except in compliance with the
# License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License.
# Python3 support
from __future__ import print_function
from __future__ import unicode_literals
import sys
from netmiko import ConnectHandler, NetMikoTimeoutException
# local modules
import napalm.base.exceptions
import napalm.base.helpers
from napalm.base import constants as c
from napalm.base import validate
from napalm.base.exceptions import ConnectionException
class NetworkDriver(object):
def __init__(self, hostname, username, password, timeout=60, optional_args=None):
"""
This is the base class you have to inherit from when writing your own Network Driver to
manage any device. You will, in addition, have to override all the methods specified on
this class. Make sure you follow the guidelines for every method and that you return the
correct data.
:param hostname: (str) IP or FQDN of the device you want to connect to.
:param username: (str) Username you want to use
:param password: (str) Password
:param timeout: (int) Time in seconds to wait for the device to respond.
:param optional_args: (dict) Pass additional arguments to underlying driver
:return:
"""
raise NotImplementedError
def __enter__(self):
try:
self.open()
return self
except: # noqa: E722
# Swallow exception if __exit__ returns a True value
if self.__exit__(*sys.exc_info()):
pass
else:
raise
def __exit__(self, exc_type, exc_value, exc_traceback):
self.close()
if exc_type is not None and (
exc_type.__name__ not in dir(napalm.base.exceptions)
and exc_type.__name__ not in __builtins__.keys()
):
epilog = (
"NAPALM didn't catch this exception. Please, fill a bugfix on "
"https://github.com/napalm-automation/napalm/issues\n"
"Don't forget to include this traceback."
)
print(epilog)
return False
def __del__(self):
"""
This method is used to cleanup when the program is terminated suddenly.
We need to make sure the connection is closed properly and the configuration DB
is released (unlocked).
"""
try:
if self.is_alive()["is_alive"]:
self.close()
except Exception:
pass
def _netmiko_open(self, device_type, netmiko_optional_args=None):
"""Standardized method of creating a Netmiko connection using napalm attributes."""
if netmiko_optional_args is None:
netmiko_optional_args = {}
try:
self._netmiko_device = ConnectHandler(
device_type=device_type,
host=self.hostname,
username=self.username,
password=self.password,
timeout=self.timeout,
**netmiko_optional_args
)
except NetMikoTimeoutException:
raise ConnectionException("Cannot connect to {}".format(self.hostname))
# ensure in enable mode
self._netmiko_device.enable()
return self._netmiko_device
def _netmiko_close(self):
"""Standardized method of closing a Netmiko connection."""
if getattr(self, "_netmiko_device", None):
self._netmiko_device.disconnect()
self._netmiko_device = None
self.device = None
def open(self):
"""
Opens a connection to the device.
"""
raise NotImplementedError
def close(self):
"""
Closes the connection to the device.
"""
raise NotImplementedError
def is_alive(self):
"""
Returns a flag with the connection state.
Depends on the nature of API used by each driver.
The state does not reflect only on the connection status (when SSH), it must also take into
consideration other parameters, e.g.: NETCONF session might not be usable, althought the
underlying SSH session is still open etc.
"""
raise NotImplementedError
def pre_connection_tests(self):
"""
This is a helper function used by the cli tool cl_napalm_show_tech. Drivers
can override this method to do some tests, show information, enable debugging, etc.
before a connection with the device is attempted.
"""
raise NotImplementedError
def connection_tests(self):
"""
This is a helper function used by the cli tool cl_napalm_show_tech. Drivers
can override this method to do some tests, show information, enable debugging, etc.
before a connection with the device has been successful.
"""
raise NotImplementedError
def post_connection_tests(self):
"""
This is a helper function used by the cli tool cl_napalm_show_tech. Drivers
can override this method to do some tests, show information, enable debugging, etc.
after a connection with the device has been closed successfully.
"""
raise NotImplementedError
def load_template(
self, template_name, template_source=None, template_path=None, **template_vars
):
"""
Will load a templated configuration on the device.
:param cls: Instance of the driver class.
:param template_name: Identifies the template name.
:param template_source (optional): Custom config template rendered and loaded on device
:param template_path (optional): Absolute path to directory for the configuration templates
:param template_vars: Dictionary with arguments to be used when the template is rendered.
:raise DriverTemplateNotImplemented: No template defined for the device type.
:raise TemplateNotImplemented: The template specified in template_name does not exist in \
the default path or in the custom path if any specified using parameter `template_path`.
:raise TemplateRenderException: The template could not be rendered. Either the template \
source does not have the right format, either the arguments in `template_vars` are not \
properly specified.
"""
return napalm.base.helpers.load_template(
self,
template_name,
template_source=template_source,
template_path=template_path,
**template_vars
)
def load_replace_candidate(self, filename=None, config=None):
"""
Populates the candidate configuration. You can populate it from a file or from a string.
If you send both a filename and a string containing the configuration, the file takes
precedence.
If you use this method the existing configuration will be replaced entirely by the
candidate configuration once you commit the changes. This method will not change the
configuration by itself.
:param filename: Path to the file containing the desired configuration. By default is None.
:param config: String containing the desired configuration.
:raise ReplaceConfigException: If there is an error on the configuration sent.
"""
raise NotImplementedError
def load_merge_candidate(self, filename=None, config=None):
"""
Populates the candidate configuration. You can populate it from a file or from a string.
If you send both a filename and a string containing the configuration, the file takes
precedence.
If you use this method the existing configuration will be merged with the candidate
configuration once you commit the changes. This method will not change the configuration
by itself.
:param filename: Path to the file containing the desired configuration. By default is None.
:param config: String containing the desired configuration.
:raise MergeConfigException: If there is an error on the configuration sent.
"""
raise NotImplementedError
def compare_config(self):
"""
:return: A string showing the difference between the running configuration and the \
candidate configuration. The running_config is loaded automatically just before doing the \
comparison so there is no need for you to do it.
"""
raise NotImplementedError
def commit_config(self, message=""):
"""
Commits the changes requested by the method load_replace_candidate or load_merge_candidate.
"""
raise NotImplementedError
def discard_config(self):
"""
Discards the configuration loaded into the candidate.
"""
raise NotImplementedError
def rollback(self):
"""
If changes were made, revert changes to the original state.
"""
raise NotImplementedError
def get_facts(self):
"""
Returns a dictionary containing the following information:
* uptime - Uptime of the device in seconds.
* vendor - Manufacturer of the device.
* model - Device model.
* hostname - Hostname of the device
* fqdn - Fqdn of the device
* os_version - String with the OS version running on the device.
* serial_number - Serial number of the device
* interface_list - List of the interfaces of the device
Example::
{
'uptime': 151005.57332897186,
'vendor': u'Arista',
'os_version': u'4.14.3-2329074.gaatlantarel',
'serial_number': u'SN0123A34AS',
'model': u'vEOS',
'hostname': u'eos-router',
'fqdn': u'eos-router',
'interface_list': [u'Ethernet2', u'Management1', u'Ethernet1', u'Ethernet3']
}
"""
raise NotImplementedError
def get_interfaces(self):
"""
Returns a dictionary of dictionaries. The keys for the first dictionary will be the \
interfaces in the devices. The inner dictionary will containing the following data for \
each interface:
* is_up (True/False)
* is_enabled (True/False)
* description (string)
* last_flapped (float in seconds)
* speed (int in Mbit)
* MTU (in Bytes)
* mac_address (string)
Example::
{
u'Management1':
{
'is_up': False,
'is_enabled': False,
'description': '',
'last_flapped': -1.0,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:61',
},
u'Ethernet1':
{
'is_up': True,
'is_enabled': True,
'description': 'foo',
'last_flapped': 1429978575.1554043,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:62',
},
u'Ethernet2':
{
'is_up': True,
'is_enabled': True,
'description': 'bla',
'last_flapped': 1429978575.1555667,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:63',
},
u'Ethernet3':
{
'is_up': False,
'is_enabled': True,
'description': 'bar',
'last_flapped': -1.0,
'speed': 1000,
'mtu': 1500,
'mac_address': 'FA:16:3E:57:33:64',
}
}
"""
raise NotImplementedError
def get_lldp_neighbors(self):
"""
Returns a dictionary where the keys are local ports and the value is a list of \
dictionaries with the following information:
* hostname
* port
Example::
{
u'Ethernet2':
[
{
'hostname': u'junos-unittest',
'port': u'520',
}
],
u'Ethernet3':
[
{
'hostname': u'junos-unittest',
'port': u'522',
}
],
u'Ethernet1':
[
{
'hostname': u'junos-unittest',
'port': u'519',
},
{
'hostname': u'ios-xrv-unittest',
'port': u'Gi0/0/0/0',
}
],
u'Management1':
[
{
'hostname': u'junos-unittest',
'port': u'508',
}
]
}
"""
raise NotImplementedError
def get_bgp_neighbors(self):
"""
Returns a dictionary of dictionaries. The keys for the first dictionary will be the vrf
(global if no vrf). The inner dictionary will contain the following data for each vrf:
* router_id
* peers - another dictionary of dictionaries. Outer keys are the IPs of the neighbors. \
The inner keys are:
* local_as (int)
* remote_as (int)
* remote_id - peer router id
* is_up (True/False)
* is_enabled (True/False)
* description (string)
* uptime (int in seconds)
* address_family (dictionary) - A dictionary of address families available for the \
neighbor. So far it can be 'ipv4' or 'ipv6'
* received_prefixes (int)
* accepted_prefixes (int)
* sent_prefixes (int)
Note, if is_up is False and uptime has a positive value then this indicates the
uptime of the last active BGP session.
Example::
{
"global": {
"router_id": "10.0.1.1",
"peers": {
"10.0.0.2": {
"local_as": 65000,
"remote_as": 65000,
"remote_id": "10.0.1.2",
"is_up": True,
"is_enabled": True,
"description": "internal-2",
"uptime": 4838400,
"address_family": {
"ipv4": {
"sent_prefixes": 637213,
"accepted_prefixes": 3142,
"received_prefixes": 3142
},
"ipv6": {
"sent_prefixes": 36714,
"accepted_prefixes": 148,
"received_prefixes": 148
}
}
}
}
}
}
"""
raise NotImplementedError
def get_environment(self):
"""
Returns a dictionary where:
* fans is a dictionary of dictionaries where the key is the location and the values:
* status (True/False) - True if it's ok, false if it's broken
* temperature is a dict of dictionaries where the key is the location and the values:
* temperature (float) - Temperature in celsius the sensor is reporting.
* is_alert (True/False) - True if the temperature is above the alert threshold
* is_critical (True/False) - True if the temp is above the critical threshold
* power is a dictionary of dictionaries where the key is the PSU id and the values:
* status (True/False) - True if it's ok, false if it's broken
* capacity (float) - Capacity in W that the power supply can support
* output (float) - Watts drawn by the system
* cpu is a dictionary of dictionaries where the key is the ID and the values
* %usage
* memory is a dictionary with:
* available_ram (int) - Total amount of RAM installed in the device
* used_ram (int) - RAM in use in the device
"""
raise NotImplementedError
def get_interfaces_counters(self):
"""
Returns a dictionary of dictionaries where the first key is an interface name and the
inner dictionary contains the following keys:
* tx_errors (int)
* rx_errors (int)
* tx_discards (int)
* rx_discards (int)
* tx_octets (int)
* rx_octets (int)
* tx_unicast_packets (int)
* rx_unicast_packets (int)
* tx_multicast_packets (int)
* rx_multicast_packets (int)
* tx_broadcast_packets (int)
* rx_broadcast_packets (int)
Example::
{
u'Ethernet2': {
'tx_multicast_packets': 699,
'tx_discards': 0,
'tx_octets': 88577,
'tx_errors': 0,
'rx_octets': 0,
'tx_unicast_packets': 0,
'rx_errors': 0,
'tx_broadcast_packets': 0,
'rx_multicast_packets': 0,
'rx_broadcast_packets': 0,
'rx_discards': 0,
'rx_unicast_packets': 0
},
u'Management1': {
'tx_multicast_packets': 0,
'tx_discards': 0,
'tx_octets': 159159,
'tx_errors': 0,
'rx_octets': 167644,
'tx_unicast_packets': 1241,
'rx_errors': 0,
'tx_broadcast_packets': 0,
'rx_multicast_packets': 0,
'rx_broadcast_packets': 80,
'rx_discards': 0,
'rx_unicast_packets': 0
},
u'Ethernet1': {
'tx_multicast_packets': 293,
'tx_discards': 0,
'tx_octets': 38639,
'tx_errors': 0,
'rx_octets': 0,
'tx_unicast_packets': 0,
'rx_errors': 0,
'tx_broadcast_packets': 0,
'rx_multicast_packets': 0,
'rx_broadcast_packets': 0,
'rx_discards': 0,
'rx_unicast_packets': 0
}
}
"""
raise NotImplementedError
def get_lldp_neighbors_detail(self, interface=""):
"""
Returns a detailed view of the LLDP neighbors as a dictionary
containing lists of dictionaries for each interface.
Empty entries are returned as an empty string (e.g. '') or list where applicable.
Inner dictionaries contain fields:
* parent_interface (string)
* remote_port (string)
* remote_port_description (string)
* remote_chassis_id (string)
* remote_system_name (string)
* remote_system_description (string)
* remote_system_capab (list) with any of these values
* other
* repeater
* bridge
* wlan-access-point
* router
* telephone
* docsis-cable-device
* station
* remote_system_enabled_capab (list)
Example::
{
'TenGigE0/0/0/8': [
{
'parent_interface': u'Bundle-Ether8',
'remote_chassis_id': u'8c60.4f69.e96c',
'remote_system_name': u'switch',
'remote_port': u'Eth2/2/1',
'remote_port_description': u'Ethernet2/2/1',
'remote_system_description': u'''Cisco Nexus Operating System (NX-OS)
Software 7.1(0)N1(1a)
TAC support: http://www.cisco.com/tac
Copyright (c) 2002-2015, Cisco Systems, Inc. All rights reserved.''',
'remote_system_capab': ['bridge', 'repeater'],
'remote_system_enable_capab': ['bridge']
}
]
}
"""
raise NotImplementedError
def get_bgp_config(self, group="", neighbor=""):
"""
Returns a dictionary containing the BGP configuration.
Can return either the whole config, either the config only for a group or neighbor.
:param group: Returns the configuration of a specific BGP group.
:param neighbor: Returns the configuration of a specific BGP neighbor.
Main dictionary keys represent the group name and the values represent a dictionary having
the keys below. Neighbors which aren't members of a group will be stored in a key named "_":
* type (string)
* description (string)
* apply_groups (string list)
* multihop_ttl (int)
* multipath (True/False)
* local_address (string)
* local_as (int)
* remote_as (int)
* import_policy (string)
* export_policy (string)
* remove_private_as (True/False)
* prefix_limit (dictionary)
* neighbors (dictionary)
Neighbors is a dictionary of dictionaries with the following keys:
* description (string)
* import_policy (string)
* export_policy (string)
* local_address (string)
* local_as (int)
* remote_as (int)
* authentication_key (string)
* prefix_limit (dictionary)
* route_reflector_client (True/False)
* nhs (True/False)
The inner dictionary prefix_limit has the same structure for both layers::
{
[FAMILY_NAME]: {
[FAMILY_TYPE]: {
'limit': [LIMIT],
... other options
}
}
}
Example::
{
'PEERS-GROUP-NAME':{
'type' : u'external',
'description' : u'Here we should have a nice description',
'apply_groups' : [u'BGP-PREFIX-LIMIT'],
'import_policy' : u'PUBLIC-PEER-IN',
'export_policy' : u'PUBLIC-PEER-OUT',
'remove_private_as' : True,
'multipath' : True,
'multihop_ttl' : 30,
'neighbors' : {
'192.168.0.1': {
'description' : 'Facebook [CDN]',
'prefix_limit' : {
'inet': {
'unicast': {
'limit': 100,
'teardown': {
'threshold' : 95,
'timeout' : 5
}
}
}
}
'remote_as' : 32934,
'route_reflector_client': False,
'nhs' : True
},
'172.17.17.1': {
'description' : 'Twitter [CDN]',
'prefix_limit' : {
'inet': {
'unicast': {
'limit': 500,
'no-validate': 'IMPORT-FLOW-ROUTES'
}
}
}
'remote_as' : 13414
'route_reflector_client': False,
'nhs' : False
}
}
}
}
"""
raise NotImplementedError
def cli(self, commands):
"""
Will execute a list of commands and return the output in a dictionary format.
Example::
{
u'show version and haiku': u'''Hostname: re0.edge01.arn01
Model: mx480
Junos: 13.3R6.5
Help me, Obi-Wan
I just saw Episode Two
You're my only hope
''',
u'show chassis fan' : u'''
Item Status RPM Measurement
Top Rear Fan OK 3840 Spinning at intermediate-speed
Bottom Rear Fan OK 3840 Spinning at intermediate-speed
Top Middle Fan OK 3900 Spinning at intermediate-speed
Bottom Middle Fan OK 3840 Spinning at intermediate-speed
Top Front Fan OK 3810 Spinning at intermediate-speed
Bottom Front Fan OK 3840 Spinning at intermediate-speed'''
}
"""
raise NotImplementedError
def get_bgp_neighbors_detail(self, neighbor_address=""):
"""
Returns a detailed view of the BGP neighbors as a dictionary of lists.
:param neighbor_address: Retuns the statistics for a spcific BGP neighbor.
Returns a dictionary of dictionaries. The keys for the first dictionary will be the vrf
(global if no vrf).
The keys of the inner dictionary represent the AS number of the neighbors.
Leaf dictionaries contain the following fields:
* up (True/False)
* local_as (int)
* remote_as (int)
* router_id (string)
* local_address (string)
* routing_table (string)
* local_address_configured (True/False)
* local_port (int)
* remote_address (string)
* remote_port (int)
* multihop (True/False)
* multipath (True/False)
* remove_private_as (True/False)
* import_policy (string)
* export_policy (string)
* input_messages (int)
* output_messages (int)
* input_updates (int)
* output_updates (int)
* messages_queued_out (int)
* connection_state (string)
* previous_connection_state (string)
* last_event (string)
* suppress_4byte_as (True/False)
* local_as_prepend (True/False)
* holdtime (int)
* configured_holdtime (int)
* keepalive (int)
* configured_keepalive (int)
* active_prefix_count (int)
* received_prefix_count (int)
* accepted_prefix_count (int)
* suppressed_prefix_count (int)
* advertised_prefix_count (int)
* flap_count (int)
Example::
{
'global': {
8121: [
{
'up' : True,
'local_as' : 13335,
'remote_as' : 8121,
'local_address' : u'172.101.76.1',
'local_address_configured' : True,
'local_port' : 179,
'routing_table' : u'inet.0',
'remote_address' : u'192.247.78.0',
'remote_port' : 58380,
'multihop' : False,
'multipath' : True,
'remove_private_as' : True,
'import_policy' : u'4-NTT-TRANSIT-IN',
'export_policy' : u'4-NTT-TRANSIT-OUT',
'input_messages' : 123,
'output_messages' : 13,
'input_updates' : 123,
'output_updates' : 5,
'messages_queued_out' : 23,
'connection_state' : u'Established',
'previous_connection_state' : u'EstabSync',
'last_event' : u'RecvKeepAlive',
'suppress_4byte_as' : False,
'local_as_prepend' : False,
'holdtime' : 90,
'configured_holdtime' : 90,
'keepalive' : 30,
'configured_keepalive' : 30,
'active_prefix_count' : 132808,
'received_prefix_count' : 566739,
'accepted_prefix_count' : 566479,
'suppressed_prefix_count' : 0,
'advertised_prefix_count' : 0,
'flap_count' : 27
}
]
}
}
"""
raise NotImplementedError
def get_arp_table(self, vrf=""):
"""
Returns a list of dictionaries having the following set of keys:
* interface (string)
* mac (string)
* ip (string)
* age (float)
'vrf' of null-string will default to all VRFs. Specific 'vrf' will return the ARP table
entries for that VRFs (including potentially 'default' or 'global').
In all cases the same data structure is returned and no reference to the VRF that was used
is included in the output.
Example::
[
{
'interface' : 'MgmtEth0/RSP0/CPU0/0',
'mac' : '5C:5E:AB:DA:3C:F0',
'ip' : '172.17.17.1',
'age' : 1454496274.84
},
{
'interface' : 'MgmtEth0/RSP0/CPU0/0',
'mac' : '5C:5E:AB:DA:3C:FF',
'ip' : '172.17.17.2',
'age' : 1435641582.49
}
]
"""
raise NotImplementedError
def get_ntp_peers(self):
"""
Returns the NTP peers configuration as dictionary.
The keys of the dictionary represent the IP Addresses of the peers.
Inner dictionaries do not have yet any available keys.
Example::
{
'192.168.0.1': {},
'17.72.148.53': {},
'37.187.56.220': {},
'162.158.20.18': {}
}
"""
raise NotImplementedError
def get_ntp_servers(self):
"""
Returns the NTP servers configuration as dictionary.
The keys of the dictionary represent the IP Addresses of the servers.
Inner dictionaries do not have yet any available keys.
Example::
{
'192.168.0.1': {},
'17.72.148.53': {},
'37.187.56.220': {},
'162.158.20.18': {}
}
"""
raise NotImplementedError
def get_ntp_stats(self):
"""
Returns a list of NTP synchronization statistics.
* remote (string)
* referenceid (string)
* synchronized (True/False)
* stratum (int)
* type (string)
* when (string)
* hostpoll (int)
* reachability (int)
* delay (float)
* offset (float)
* jitter (float)
Example::
[
{
'remote' : u'188.114.101.4',
'referenceid' : u'188.114.100.1',
'synchronized' : True,
'stratum' : 4,
'type' : u'-',
'when' : u'107',
'hostpoll' : 256,
'reachability' : 377,
'delay' : 164.228,
'offset' : -13.866,
'jitter' : 2.695
}
]
"""
raise NotImplementedError
def get_interfaces_ip(self):
"""
Returns all configured IP addresses on all interfaces as a dictionary of dictionaries.
Keys of the main dictionary represent the name of the interface.
Values of the main dictionary represent are dictionaries that may consist of two keys
'ipv4' and 'ipv6' (one, both or none) which are themselvs dictionaries witht the IP
addresses as keys.
Each IP Address dictionary has the following keys:
* prefix_length (int)
Example::
{
u'FastEthernet8': {
u'ipv4': {
u'10.66.43.169': {
'prefix_length': 22
}
}
},
u'Loopback555': {
u'ipv4': {
u'192.168.1.1': {
'prefix_length': 24
}
},
u'ipv6': {
u'1::1': {
'prefix_length': 64
},
u'2001:DB8:1::1': {
'prefix_length': 64
},
u'2::': {
'prefix_length': 64
},
u'FE80::3': {
'prefix_length': u'N/A'
}
}
},
u'Tunnel0': {
u'ipv4': {
u'10.63.100.9': {
'prefix_length': 24
}
}
}
}
"""
raise NotImplementedError
def get_mac_address_table(self):
"""
Returns a lists of dictionaries. Each dictionary represents an entry in the MAC Address
Table, having the following keys:
* mac (string)
* interface (string)
* vlan (int)
* active (boolean)
* static (boolean)
* moves (int)
* last_move (float)
However, please note that not all vendors provide all these details.
E.g.: field last_move is not available on JUNOS devices etc.
Example::
[
{
'mac' : '00:1C:58:29:4A:71',
'interface' : 'Ethernet47',
'vlan' : 100,
'static' : False,
'active' : True,
'moves' : 1,
'last_move' : 1454417742.58
},
{
'mac' : '00:1C:58:29:4A:C1',
'interface' : 'xe-1/0/1',
'vlan' : 100,
'static' : False,
'active' : True,
'moves' : 2,
'last_move' : 1453191948.11
},
{
'mac' : '00:1C:58:29:4A:C2',
'interface' : 'ae7.900',
'vlan' : 900,