-
Notifications
You must be signed in to change notification settings - Fork 69
/
interfaces.py
946 lines (728 loc) · 32.1 KB
/
interfaces.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
#
# Copyright (c) 2014, Arista Networks, Inc.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are
# met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# Neither the name of Arista Networks nor the names of its
# contributors may be used to endorse or promote products derived from
# this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARISTA NETWORKS
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
# BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
# WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
# OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
# IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
#
"""Module for working with interfaces in EOS
This module provides an API for pragmatically working with EOS interface
configurations. Interfaces include any data or management plane interface
available in EOS.
Parameters:
name (string): The name of the interface the configuration should be
applied to. The interface name is the full interface identifier.
shutdown (boolean): True if the interface is administratively disabled,
and False if the interface is administratively enable. This value
does not validate the interfaces operational state.
description (string): The interface description string. This value is
an arbitrary operator defined value.
sflow (boolean): True if sFlow is enabled on the interface otherwise
False
flowcontrol_send (string): The flowcontrol send configuration value for
the interface. Valid values are on or off
flowcontrol_receive (string): The flowcontrol receive configuration value
for the interface. Valid values are on or off
"""
import re
from pyeapi.api import EntityCollection
from pyeapi.utils import ProxyCall
MIN_LINKS_RE = re.compile(r'(?<=\s{3}min-links\s)(?P<value>.+)$', re.M)
DEFAULT_LACP_MODE = 'on'
VALID_INTERFACES = frozenset([
'Ethernet',
'Management',
'Loopback',
'Port-Channel',
'Vlan',
'Vxlan',
])
def isvalidinterface(value):
match = re.match(r'([EPVLM][a-z-C]+)', value)
return match and match.group() in VALID_INTERFACES
class Interfaces(EntityCollection):
def __init__(self, node, *args, **kwargs):
super(Interfaces, self).__init__(node, *args, **kwargs)
self._instances = dict()
def get(self, name):
return self.get_instance(name)[name]
def getall(self):
"""Returns all interfaces in a dict object.
Returns:
A Python dictionary object containing all interface
configuration indexed by interface name::
{
"Ethernet1": {...},
"Ethernet2": {...}
}
"""
commands = list()
commands.append('show interfaces')
try:
result = self.node.enable(commands)
interfaces = result[0]['result']['interfaces']
except:
return None
response = dict()
for name in interfaces:
interface = self.get(str(name))
if interface:
response[name] = interface
return response
def __getattr__(self, name):
return ProxyCall(self.marshall, name)
def get_instance(self, interface):
cls = INTERFACE_CLASS_MAP.get(interface[0:2]) or BaseInterface
if cls in self._instances:
instance = self._instances[cls]
else:
instance = cls(self.node)
self._instances[cls] = instance
return instance
def marshall(self, name, *args, **kwargs):
interface = args[0]
if not isvalidinterface(interface):
raise ValueError('invalid interface {}'.format(interface))
instance = self.get_instance(interface)
if not hasattr(instance, name):
raise AttributeError("'%s' object has no attribute '%s'" %
(instance, name))
method = getattr(instance, name)
return method(*args, **kwargs)
class BaseInterface(EntityCollection):
def __str__(self):
return 'Interface'
def get(self, name):
"""Returns a generic interface as a set of key/value pairs
This class is should normally serve as a base class for building more
specific interface resources. The attributes of this resource are
common to all interfaces regardless of type in EOS.
The generic interface resource returns the following:
* name (str): The name of the interface
* type (str): Always returns 'generic'
* shutdown (bool): True if the interface is shutdown
* description (str): The interface description value
Args:
name (str): The interface identifier to retrieve from the
running-configuration
Returns:
A Python dictionary object of key/value pairs that represents
the interface configuration. If the specified interface
does not exist, then None is returned
"""
commands = list()
commands.append('show interfaces %s' % name)
try:
result = self.node.enable(commands)
config = result[0]['result']['interfaces'].get(name)
except:
return None
resource = dict(name=name, type='generic')
resource.update(self._parse_shutdown(config))
resource.update(self._parse_description(config))
return resource
def _parse_shutdown(self, config):
"""Scans the specified config block and returns the shutdown value
Args:
config (str): The interface config block to scan
Returns:
dict: Returns a dict object with the shutdown value retrieved
from the config block. The returned dict object is intended
to be merged into the interface resource dict
"""
value = config['interfaceStatus'] == 'disabled'
return dict(shutdown=value)
def _parse_description(self, config):
"""Scans the specified config block and returns the description value
Args:
config (str): The interface config block to scan
Returns:
dict: Returns a dict object with the description value retrieved
from the config block. If the description value is not
configured, None is returned as the value. The returned dict
is intended to be merged into the interface resource dict.
"""
value = config.get('description')
value = value if value else None
return dict(description=value)
def create(self, name):
"""Creates a new interface on the node
Note:
This method will attempt to create the interface regardless
if the interface exists or not. If the interface already exists
then this method will still return True
Args:
name (string): The full name of the interface.
Returns:
True if the interface could be created otherwise False (see Note)
"""
return self.configure('interface %s' % name)
def delete(self, name):
"""Deletes the interface from the node
Note:
This method will attempt to delete the interface from the nodes
operational config. If the interface does not exist then this
method will not perform any changes but still return True
Args:
name (string): The full name of the interface
Returns:
True if the interface could be deleted otherwise False (see Node)
"""
return self.configure('no interface %s' % name)
def default(self, name):
"""Defaults an interface in the running configuration
Args:
name (string): The full name of the interface
Returns:
True if the command operation succeeds otherwise False
"""
return self.configure('default interface %s' % name)
def set_description(self, name, value=None, default=False):
"""Configures the interface description
EosVersion:
4.13.7M
Args:
name (string): The interface identifier. It must be a full
interface name (ie Ethernet, not Et)
value (string): The value to set the description to.
default (boolean): Specifies to default the interface description
Returns:
True if the operation succeeds otherwise False
"""
string = 'description'
commands = self.command_builder(string, value=value, default=default)
return self.configure_interface(name, commands)
def set_shutdown(self, name, value=None, default=False):
"""Configures the interface shutdown state
Args:
name (string): The interface identifier. It must be a full
interface name (ie Ethernet, not Et)
value (boolean): True if the interface should be in shutdown state
otherwise False
default (boolean): Specifies to default the interface description
Returns:
True if the operation succeeds otherwise False is returned
"""
if value not in [True, False, None]:
raise ValueError('invalid value for shutdown')
commands = ['interface %s' % name]
if default:
commands.append('default shutdown')
elif value:
commands.append('shutdown')
else:
commands.append('no shutdown')
return self.configure(commands)
class EthernetInterface(BaseInterface):
def __str__(self):
return 'EthernetInterface'
def get(self, name):
"""Returns an interface as a set of key/value pairs
Args:
name (string): the interface identifier to retrieve the from
the configuration
Returns:
A Python dictionary object of key/value pairs that represent
the current configuration for the specified node. If the
specified interface name does not exist, then None is returned::
{
"name": <string>,
"type": "ethernet",
"sflow": [true, false],
"flowcontrol_send": [on, off],
"flowcontrol_receive": [on, off]
}
"""
commands = list()
commands.append('show interfaces %s' % name)
commands.append('show sflow interfaces')
commands.append('show flowcontrol')
try:
result = self.node.enable(commands)
config = result[0]['result']['interfaces'].get(name)
sflow_config = result[1]['result']['interfaces'].get(name)
flow_config = result[2]
except:
return None
resource = super(EthernetInterface, self).get(name)
resource.update(dict(name=name, type='ethernet'))
resource.update(self._parse_sflow(sflow_config))
resource.update(self._parse_flowcontrol(name, flow_config))
return resource
def _parse_sflow(self, config):
"""Scans the specified config block and returns the sflow value
Args:
config (str): The interface config block to scan
Returns:
dict: Returns a dict object with the sflow value retrieved
from the config block. The returned dict object is intended
to be merged into the interface resource dict
"""
value = config is not None
return dict(sflow=value)
def _parse_flowcontrol(self, name, config):
"""Scans the config block and returns the flowcontrol send value
Args:
config (str): The interface config block to scan
Returns:
dict: Returns a dict object with the flowcontrol send value
retrieved from the config block. The returned dict object
is intended to be merged into the interface resource dict
"""
if config['encoding'] == 'json':
config = config['result']['interfaceFlowControls'].get(name)
send = config['txAdminState']
receive = config['rxAdminState']
elif config['encoding'] == 'text':
text = config['result']['output']
abbr = re.search(r'\D+(\d\S*)', name)
if abbr:
abbr = name[0:2] + abbr.group(1)
flowcontrol = re.search(r'^%s\s+(\w+)\s+\w+\s+(\w+)' % abbr, text,
re.M)
if flowcontrol:
send = flowcontrol.group(1)
receive = flowcontrol.group(2)
return dict(flowcontrol_send=send, flowcontrol_receive=receive)
def create(self, name):
"""Creating Ethernet interfaces is currently not supported
Args:
name (string): The interface name
Raises:
NotImplementedError: creating Ethernet interfaces is not supported
"""
raise NotImplementedError('creating Ethernet interfaces is '
'not supported')
def delete(self, name):
"""Deleting Ethernet interfaces is currently not supported
Args:
name (string): The interface name
Raises:
NotImplementedError: Deleting Ethernet interfaces is not supported
"""
raise NotImplementedError('deleting Ethernet interfaces is '
'not supported')
def set_flowcontrol_send(self, name, value=None, default=False):
"""Configures the interface flowcontrol send value
Args:
name (string): The interface identifier. It must be a full
interface name (ie Ethernet, not Et)
direction (string): one of either 'send' or 'receive'
value (boolean): True if the interface should be in shutdown state
otherwise False
default (boolean): Specifies to default the interface description
Returns:
True if the operation succeeds otherwise False is returned
"""
return self.set_flowcontrol(name, 'send', value, default)
def set_flowcontrol_receive(self, name, value=None, default=False):
"""Configures the interface flowcontrol receive value
Args:
name (string): The interface identifier. It must be a full
interface name (ie Ethernet, not Et)
value (boolean): True if the interface should be in shutdown state
otherwise False
default (boolean): Specifies to default the interface description
Returns:
True if the operation succeeds otherwise False is returned
"""
return self.set_flowcontrol(name, 'receive', value, default)
def set_flowcontrol(self, name, direction, value=None, default=False):
"""Configures the interface flowcontrol value
Args:
name (string): The interface identifier. It must be a full
interface name (ie Ethernet, not Et)
direction (string): one of either 'send' or 'receive'
value (boolean): True if the interface should be in shutdown state
otherwise False
default (boolean): Specifies to default the interface description
Returns:
True if the operation succeeds otherwise False is returned
"""
if value is not None:
if value not in ['on', 'off']:
raise ValueError('invalid flowcontrol value')
if direction not in ['send', 'receive']:
raise ValueError('invalid direction specified')
commands = ['interface %s' % name]
if default:
commands.append('default flowcontrol %s' % direction)
elif value:
commands.append('flowcontrol %s %s' % (direction, value))
else:
commands.append('no flowcontrol %s' % direction)
return self.configure(commands)
def set_sflow(self, name, value=None, default=False):
"""Configures the sFlow state on the interface
Args:
name (string): The interface identifier. It must be a full
interface name (ie Ethernet, not Et)
value (boolean): True if sFlow should be enabled otherwise False
default (boolean): Specifies the default value for sFlow
Returns:
True if the operation succeeds otherwise False is returned
"""
if value not in [True, False, None]:
raise ValueError
commands = ['interface %s' % name]
if default:
commands.append('default sflow')
elif value:
commands.append('sflow enable')
else:
commands.append('no sflow enable')
return self.configure(commands)
class PortchannelInterface(BaseInterface):
def __str__(self):
return 'PortchannelInterface'
def get(self, name):
"""Returns a Port-Channel interface as a set of key/value pairs
Args:
name (str): The interface identifier to retrieve from the
running-configuration
Returns:
A Python dictionary object of key/value pairs that represents
the interface configuration. If the specified interface
does not exist, then None is returned::
{
"name": <string>,
"type": "portchannel",
"members": <arrary of interface names>,
"minimum_links: <integer>,
"lacp_mode": [on, active, passive]
}
"""
config = self.get_block('^interface %s' % name)
if not config:
return None
response = super(PortchannelInterface, self).get(name)
response.update(dict(name=name, type='portchannel'))
response['members'] = self.get_members(name)
response['lacp_mode'] = self.get_lacp_mode(name)
response.update(self._parse_minimum_links(config))
return response
def _parse_minimum_links(self, config):
value = 0
match = re.search(r'port-channel min-links (\d+)', config)
if match:
value = int(match.group(1))
return dict(minimum_links=value)
def get_lacp_mode(self, name):
"""Returns the LACP mode for the specified Port-Channel interface
Args:
name(str): The Port-Channel interface name to return the LACP
mode for from the configuration
Returns:
The configured LACP mode for the interface. Valid mode values
are 'on', 'passive', 'active'
"""
members = self.get_members(name)
if not members:
return DEFAULT_LACP_MODE
cmd = 'show running-config interfaces %s' % str(members[0])
config = self.node.enable(cmd, encoding='text')[0]['result']['output']
match = re.search(r'channel-group\s\d+\smode\s(?P<value>.+)',
config)
value = None
if match:
value = str(match.group('value'))
return value
def get_members(self, name):
"""Returns the member interfaces for the specified Port-Channel
Args:
name(str): The Port-channel interface name to return the member
interfaces for
Returns:
A list of physical interface names that belong to the specified
interface
"""
grpid = re.search(r'(\d+)', name).group()
command = 'show port-channel %s all-ports' % grpid
config = self.node.enable(command, 'text')
members = re.findall(r'\b(?!Peer)Ethernet[\d/]*\b',
config[0]['result']['output'])
return members
def set_members(self, name, members, mode=None):
"""Configures the array of member interfaces for the Port-Channel
Args:
name(str): The Port-Channel interface name to configure the member
interfaces
members(list): The list of Ethernet interfaces that should be
member interfaces
mode(str): The LACP mode to configure the member interfaces to.
Valid values are 'on, 'passive', 'active'. When there are
existing channel-group members and their lacp mode differs
from this attribute, all of those members will be removed and
then re-added using the specified lacp mode. If this attribute
is omitted, the existing lacp mode will be used for new
member additions.
Returns:
True if the operation succeeds otherwise False
"""
commands = list()
grpid = re.search(r'(\d+)', name).group()
current_members = self.get_members(name)
lacp_mode = self.get_lacp_mode(name)
if mode and mode != lacp_mode:
lacp_mode = mode
self.set_lacp_mode(grpid, lacp_mode)
# remove members from the current port-channel interface
for member in set(current_members).difference(members):
commands.append('interface %s' % member)
commands.append('no channel-group %s' % grpid)
# add new member interfaces to the port-channel interface
for member in set(members).difference(current_members):
commands.append('interface %s' % member)
commands.append('channel-group %s mode %s' % (grpid, lacp_mode))
return self.configure(commands) if commands else True
def set_lacp_mode(self, name, mode):
"""Configures the LACP mode of the member interfaces
Args:
name(str): The Port-Channel interface name to configure the
LACP mode
mode(str): The LACP mode to configure the member interfaces to.
Valid values are 'on, 'passive', 'active'
Returns:
True if the operation succeeds otherwise False
"""
if mode not in ['on', 'passive', 'active']:
return False
grpid = re.search(r'(\d+)', name).group()
remove_commands = list()
add_commands = list()
for member in self.get_members(name):
remove_commands.append('interface %s' % member)
remove_commands.append('no channel-group %s' % grpid)
add_commands.append('interface %s' % member)
add_commands.append('channel-group %s mode %s' % (grpid, mode))
return self.configure(remove_commands + add_commands)
def set_minimum_links(self, name, value=None, default=False):
"""Configures the Port-Channel min-links value
Args:
name(str): The Port-Channel interface name
value(str): The value to configure the min-links
default (bool): Specifies to default the interface description
Returns:
True if the operation succeeds otherwise False is returned
"""
commands = ['interface %s' % name]
if default:
commands.append('default port-channel min-links')
elif value is not None:
commands.append('port-channel min-links %s' % value)
else:
commands.append('no port-channel min-links')
return self.configure(commands)
class VxlanInterface(BaseInterface):
DEFAULT_SRC_INTF = ''
DEFAULT_MCAST_GRP = ''
def __str__(self):
return 'VxlanInterface'
def get(self, name):
"""Returns a Vxlan interface as a set of key/value pairs
The Vxlan interface resource returns the following:
* name (str): The name of the interface
* type (str): Always returns 'vxlan'
* source_interface (str): The vxlan source-interface value
* multicast_group (str): The vxlan multicast-group value
* udp_port (int): The vxlan udp-port value
* vlans (dict): The vlan to vni mappings
* flood_list (list): The list of global VTEP flood list
Args:
name (str): The interface identifier to retrieve from the
running-configuration
Returns:
A Python dictionary object of key/value pairs that represents
the interface configuration. If the specified interface
does not exist, then None is returned
"""
commands = list()
commands.append('show running-config interfaces %s' % name)
try:
result = self.node.enable(commands, encoding='text')
config = result[0]['result']['output']
except:
return None
if not config:
return None
response = super(VxlanInterface, self).get(name)
response.update(dict(name=name, type='vxlan'))
response.update(self._parse_source_interface(config))
response.update(self._parse_multicast_group(config))
response.update(self._parse_udp_port(config))
response.update(self._parse_vlans(config))
response.update(self._parse_flood_list(config))
return response
def _parse_source_interface(self, config):
""" Parses the conf block and returns the vxlan source-interface value
Parses the provided configuration block and returns the value of
vxlan source-interface. If the value is not configured, this method
will return DEFAULT_SRC_INTF instead.
Args:
config (str): The Vxlan config block to scan
Return:
dict: A dict object intended to be merged into the resource dict
"""
match = re.search(r'vxlan source-interface ([^\s]+)', config)
value = match.group(1) if match else self.DEFAULT_SRC_INTF
return dict(source_interface=value)
def _parse_multicast_group(self, config):
match = re.search(r'vxlan multicast-group ([^\s]+)', config)
value = match.group(1) if match else self.DEFAULT_MCAST_GRP
return dict(multicast_group=value)
def _parse_udp_port(self, config):
match = re.search(r'vxlan udp-port (\d+)', config)
value = int(match.group(1))
return dict(udp_port=value)
def _parse_vlans(self, config):
vlans = frozenset(re.findall(r'vxlan vlan (\d+)', config))
values = dict()
for vid in vlans:
values[vid] = dict()
regexp = r'vxlan vlan {} vni (\d+)'.format(vid)
match = re.search(regexp, config)
values[vid]['vni'] = match.group(1) if match else None
regexp = r'vxlan vlan {} flood vtep (.*)$'.format(vid)
matches = re.search(regexp, config, re.M)
flood_list = matches.group(1).split(' ') if matches else []
values[vid]['flood_list'] = flood_list
return dict(vlans=values)
def _parse_flood_list(self, config):
match = re.search(r'vxlan flood vtep (.+)$', config, re.M)
values = list()
if match:
values = match.group(1).split(' ')
return dict(flood_list=values)
def set_source_interface(self, name, value=None, default=False):
"""Configures the Vxlan source-interface value
EosVersion:
4.13.7M
Args:
name(str): The interface identifier to configure, defaults to
Vxlan1
value(str): The value to configure the source-interface to
default(bool): Configures the source-interface value to default
Returns:
True if the operation succeeds otherwise False
"""
string = 'vxlan source-interface'
cmds = self.command_builder(string, value=value, default=default)
return self.configure_interface(name, cmds)
def set_multicast_group(self, name, value=None, default=False):
"""Configures the Vxlan multicast-group value
EosVersion:
4.13.7M
Args:
name(str): The interface identifier to configure, defaults to
Vxlan1
value(str): The value to configure the multicast-group to
default(bool): Configures the mulitcat-group value to default
Returns:
True if the operation succeeds otherwise False
"""
string = 'vxlan multicast-group'
cmds = self.command_builder(string, value=value, default=default)
return self.configure_interface(name, cmds)
def set_udp_port(self, name, value=None, default=False):
"""Configures vxlan udp-port value
EosVersion:
4.13.7M
Args:
name(str): The name of the interface to configure
value(str): The value to set udp-port to
default(bool): Configure using the default keyword
Returns:
True if the operation succeeds otherwise False
"""
string = 'vxlan udp-port'
cmds = self.command_builder(string, value=value, default=default)
return self.configure_interface(name, cmds)
def add_vtep(self, name, vtep, vlan=None):
"""Adds a new VTEP endpoint to the global or local flood list
EosVersion:
4.13.7M
Args:
name (str): The name of the interface to configure
vtep (str): The IP address of the remote VTEP endpoint to add
vlan (str): The VLAN ID associated with this VTEP. If the VLAN
keyword is used, then the VTEP is configured as a local flood
endpoing
Returns:
True if the command completes successfully
"""
if not vlan:
cmd = 'vxlan flood vtep add {}'.format(vtep)
else:
cmd = 'vxlan vlan {} flood vtep add {}'.format(vlan, vtep)
return self.configure_interface(name, cmd)
def remove_vtep(self, name, vtep, vlan=None):
"""Removes a VTEP endpoint from the global or local flood list
EosVersion:
4.13.7M
Args:
name (str): The name of the interface to configure
vtep (str): The IP address of the remote VTEP endpoint to add
vlan (str): The VLAN ID associated with this VTEP. If the VLAN
keyword is used, then the VTEP is configured as a local flood
endpoing
Returns:
True if the command completes successfully
"""
if not vlan:
cmd = 'vxlan flood vtep remove {}'.format(vtep)
else:
cmd = 'vxlan vlan {} flood vtep remove {}'.format(vlan, vtep)
return self.configure_interface(name, cmd)
def update_vlan(self, name, vid, vni):
"""Adds a new vlan to vni mapping for the interface
EosVersion:
4.13.7M
Args:
vlan (str, int): The vlan id to map to the vni
vni (str, int): The vni value to use
Returns:
True if the command completes successfully
"""
cmd = 'vxlan vlan %s vni %s' % (vid, vni)
return self.configure_interface(name, cmd)
def remove_vlan(self, name, vid):
"""Removes a vlan to vni mapping for the interface
EosVersion:
4.13.7M
Args:
vlan (str, int): The vlan id to map to the vni
Returns:
True if the command completes successfully
"""
return self.configure_interface(name, 'no vxlan vlan %s vni' % vid)
INTERFACE_CLASS_MAP = {
'Et': EthernetInterface,
'Po': PortchannelInterface,
'Vx': VxlanInterface
}
def instance(api):
return Interfaces(api)