diff options
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/ifconfig/bond.py | 38 | ||||
| -rw-r--r-- | python/vyos/system/compat.py | 10 | ||||
| -rw-r--r-- | python/vyos/utils/assertion.py | 4 | 
3 files changed, 40 insertions, 12 deletions
| diff --git a/python/vyos/ifconfig/bond.py b/python/vyos/ifconfig/bond.py index c6d0f1cff..b8ea90049 100644 --- a/python/vyos/ifconfig/bond.py +++ b/python/vyos/ifconfig/bond.py @@ -18,6 +18,7 @@ import os  from vyos.ifconfig.interface import Interface  from vyos.utils.dict import dict_search  from vyos.utils.assertion import assert_list +from vyos.utils.assertion import assert_mac  from vyos.utils.assertion import assert_positive  @Interface.register @@ -54,6 +55,10 @@ class BondIf(Interface):              'validate': lambda v: assert_list(v, ['slow', 'fast']),              'location': '/sys/class/net/{ifname}/bonding/lacp_rate',          }, +        'bond_system_mac': { +            'validate': lambda v: assert_mac(v, test_all_zero=False), +            'location': '/sys/class/net/{ifname}/bonding/ad_actor_system', +        },          'bond_miimon': {              'validate': assert_positive,              'location': '/sys/class/net/{ifname}/bonding/miimon' @@ -385,6 +390,24 @@ class BondIf(Interface):          """          return self.set_interface('bond_mode', mode) +    def set_system_mac(self, mac): +        """ +        In an AD system, this specifies the mac-address for the actor in +	    protocol packet exchanges (LACPDUs). The value cannot be NULL or +	    multicast. It is preferred to have the local-admin bit set for this +	    mac but driver does not enforce it. If the value is not given then +	    system defaults to using the masters' mac address as actors' system +	    address. + +	    This parameter has effect only in 802.3ad mode and is available through +	    SysFs interface. + +        Example: +        >>> from vyos.ifconfig import BondIf +        >>> BondIf('bond0').set_system_mac('00:50:ab:cd:ef:01') +        """ +        return self.set_interface('bond_system_mac', mac) +      def update(self, config):          """ General helper function which works on a dictionary retrived by          get_config_dict(). It's main intention is to consolidate the scattered @@ -426,14 +449,13 @@ class BondIf(Interface):                      Interface(interface).set_admin_state('up')              # Bonding policy/mode - default value, always present -            mode = config.get('mode') -            self.set_mode(mode) +            self.set_mode(config['mode'])              # LACPDU transmission rate - default value -            if mode == '802.3ad': +            if config['mode'] == '802.3ad':                  self.set_lacp_rate(config.get('lacp_rate')) -            if mode not in ['802.3ad', 'balance-tlb', 'balance-alb']: +            if config['mode'] not in ['802.3ad', 'balance-tlb', 'balance-alb']:                  tmp = dict_search('arp_monitor.interval', config)                  value = tmp if (tmp != None) else '0'                  self.set_arp_interval(value) @@ -468,6 +490,14 @@ class BondIf(Interface):                  Interface(interface).flush_addrs()                  self.add_port(interface) +        # Add system mac address for 802.3ad - default address is all zero +        # mode is always present (defaultValue) +        if config['mode'] == '802.3ad': +            mac = '00:00:00:00:00:00' +            if 'system_mac' in config: +                mac = config['system_mac'] +            self.set_system_mac(mac) +          # Primary device interface - must be set after 'mode'          value = config.get('primary')          if value: self.set_primary(value) diff --git a/python/vyos/system/compat.py b/python/vyos/system/compat.py index 1b487c1d2..d35bddea2 100644 --- a/python/vyos/system/compat.py +++ b/python/vyos/system/compat.py @@ -220,14 +220,8 @@ def get_default(data: dict, root_dir: str = '') -> Union[int, None]:      sublist = list(filter(lambda x: (x.get('version') == image_name and                                       x.get('console_type') == console_type and -                                     x.get('console_num') == console_num and                                       x.get('bootmode') == 'normal'),                            menu_entries)) -    # legacy images added with legacy tools omitted 'ttyUSB'; if entry not -    # available, default to initial entry of version -    if not sublist: -        sublist = list(filter(lambda x: x.get('version') == image_name, -                              menu_entries))      if sublist:          return menu_entries.index(sublist[0]) @@ -253,6 +247,10 @@ def update_version_list(root_dir: str = '') -> list[dict]:      menu_entries = parse_menuentries(grub_cfg_main)      menu_versions = find_versions(menu_entries) +    # remove deprecated console-type ttyUSB +    menu_entries = list(filter(lambda x: x.get('console_type') != 'ttyUSB', +                               menu_entries)) +      # get list of versions added/removed by image-tools      current_versions = grub.version_list(root_dir) diff --git a/python/vyos/utils/assertion.py b/python/vyos/utils/assertion.py index 1aaa54dff..c7fa220c3 100644 --- a/python/vyos/utils/assertion.py +++ b/python/vyos/utils/assertion.py @@ -53,7 +53,7 @@ def assert_mtu(mtu, ifname):      if (max_mtu and cur_mtu > max_mtu) or cur_mtu > 65536:          raise ValueError(f'MTU is too small for interface "{ifname}": {mtu} > {max_mtu}') -def assert_mac(m): +def assert_mac(m, test_all_zero=True):      split = m.split(':')      size = len(split) @@ -74,7 +74,7 @@ def assert_mac(m):          raise ValueError(f'{m} is a multicast MAC address')      # overall mac address is not allowed to be 00:00:00:00:00:00 -    if sum(octets) == 0: +    if test_all_zero and sum(octets) == 0:          raise ValueError('00:00:00:00:00:00 is not a valid MAC address')      if octets[:5] == (0, 0, 94, 0, 1): | 
