diff options
author | Christian Poessinger <christian@poessinger.com> | 2020-12-14 19:23:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-14 19:23:50 +0100 |
commit | a6b35825a78b5fe8c3a91bc4cf6abf0f50a08738 (patch) | |
tree | 25b11a3ccb981b6595b457fe35c7a917aa97258d /python/vyos/configdict.py | |
parent | 36eb1b34e9b9b048bf91a3236849f27d44287931 (diff) | |
parent | 57392bec3d1f0d919bfdcdbb057d524df0c0fae1 (diff) | |
download | vyos-1x-a6b35825a78b5fe8c3a91bc4cf6abf0f50a08738.tar.gz vyos-1x-a6b35825a78b5fe8c3a91bc4cf6abf0f50a08738.zip |
Merge pull request #644 from jack9603301/T3089
interfaces: mirror: T3089: Fix the dependency problem between interfaces
Diffstat (limited to 'python/vyos/configdict.py')
-rw-r--r-- | python/vyos/configdict.py | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py index 99c1ae2e4..b299f4a18 100644 --- a/python/vyos/configdict.py +++ b/python/vyos/configdict.py @@ -221,6 +221,44 @@ def is_member(conf, interface, intftype=None): old_level = conf.set_level(old_level) return ret_val +def is_monitor_intf(conf,interface,direction=None): + """ + Check whether the passed interface is the mirror monitoring interface of + other interfaces of the specified type. + direction is optional, if not passed it will search all known direction + (currently ingress and egress) + + Returns: + None -> Interface is not a monitor interface + Array() -> This interface is a monitor interface of interfaces + """ + + directions = ['ingress', 'egress'] + if direction not in directions + [None]: + raise ValueError(f'unknown interface mirror direction "{direction}"') + + direction = directions if direction == None else [direction] + + ret_val = [] + old_level = conf.get_level() + conf.set_level([]) + base = ['interfaces'] + + for dire in direction: + for iftype in conf.list_nodes(base): + iftype_base = base + [iftype] + for intf in conf.list_nodes(iftype_base): + mirror = iftype_base + [intf, 'mirror', dire, interface] + if conf.exists(mirror): + ret_val.append({intf : dire}) + + old_level = conf.set_level(old_level) + if len(ret_val) == 0: + return None + else: + return ret_val + + def has_vlan_subinterface_configured(conf, intf): """ Checks if interface has an VLAN subinterface configured. @@ -334,6 +372,10 @@ def get_interface_dict(config, base, ifname=''): # Check if we are a member of a bridge device bridge = is_member(config, ifname, 'bridge') if bridge: dict.update({'is_bridge_member' : bridge}) + + # Check if it is a monitor interface + mirror = is_monitor_intf(config, ifname) + if mirror: dict.update({'is_monitor_intf' : mirror}) # Check if we are a member of a bond device bond = is_member(config, ifname, 'bonding') |