diff options
author | Christian Poessinger <christian@poessinger.com> | 2021-06-21 17:02:30 +0200 |
---|---|---|
committer | Christian Poessinger <christian@poessinger.com> | 2021-06-21 17:03:45 +0200 |
commit | e42a5fd5f6c0580e11ec5ae1e98c8a5907103f0a (patch) | |
tree | b45c7e6d956ae0b80b3656a343071120052a9a04 | |
parent | fa09a06efbeb905622fa9e1ac8598e50e683710d (diff) | |
download | vyos-1x-e42a5fd5f6c0580e11ec5ae1e98c8a5907103f0a.tar.gz vyos-1x-e42a5fd5f6c0580e11ec5ae1e98c8a5907103f0a.zip |
Python: T3641: adjust to changes in latest vesion of netifaces library
-rw-r--r-- | python/vyos/ifconfig/interface.py | 18 | ||||
-rw-r--r-- | python/vyos/validate.py | 6 |
2 files changed, 11 insertions, 13 deletions
diff --git a/python/vyos/ifconfig/interface.py b/python/vyos/ifconfig/interface.py index 6a66d958f..08b7af90b 100644 --- a/python/vyos/ifconfig/interface.py +++ b/python/vyos/ifconfig/interface.py @@ -779,9 +779,7 @@ class Interface(Control): # Note that currently expanded netmasks are not supported. That means # 2001:db00::0/24 is a valid argument while 2001:db00::0/ffff:ff00:: not. # see https://docs.python.org/3/library/ipaddress.html - bits = bin( - int(v6_addr['netmask'].replace(':', ''), 16)).count('1') - prefix = '/' + str(bits) + prefix = '/' + v6_addr['netmask'].split('/')[-1] # we alsoneed to remove the interface suffix on link local # addresses @@ -1345,14 +1343,14 @@ class Interface(Control): # create/update 802.1q VLAN interfaces for vif_id, vif_config in config.get('vif', {}).items(): - + vif_ifname = f'{ifname}.{vif_id}' vif_config['ifname'] = vif_ifname - + tmp = deepcopy(VLANIf.get_config()) tmp['source_interface'] = ifname tmp['vlan_id'] = vif_id - + # We need to ensure that the string format is consistent, and we need to exclude redundant spaces. sep = ' ' if 'egress_qos' in vif_config: @@ -1360,14 +1358,14 @@ class Interface(Control): egress_qos_array = vif_config['egress_qos'].split() # The split array is spliced according to the fixed format tmp['egress_qos'] = sep.join(egress_qos_array) - + if 'ingress_qos' in vif_config: # Unwrap strings into arrays ingress_qos_array = vif_config['ingress_qos'].split() # The split array is spliced according to the fixed format tmp['ingress_qos'] = sep.join(ingress_qos_array) - - # Since setting the QoS control parameters in the later stage will + + # Since setting the QoS control parameters in the later stage will # not completely delete the old settings, # we still need to delete the VLAN encapsulation interface in order to # ensure that the changed settings are effective. @@ -1382,7 +1380,7 @@ class Interface(Control): if qos_str != tmp['ingress_qos']: if self.exists(vif_ifname): VLANIf(vif_ifname).remove() - + qos_str = '' tmp2 = dict_search('linkinfo.info_data.egress_qos', cur_cfg) if 'egress_qos' in tmp and tmp2: diff --git a/python/vyos/validate.py b/python/vyos/validate.py index 23e88b5ac..0dad2a6cb 100644 --- a/python/vyos/validate.py +++ b/python/vyos/validate.py @@ -49,7 +49,7 @@ def is_intf_addr_assigned(intf, addr): return _is_intf_addr_assigned(intf, ip, mask) return _is_intf_addr_assigned(intf, addr) -def _is_intf_addr_assigned(intf, address, netmask=''): +def _is_intf_addr_assigned(intf, address, netmask=None): """ Verify if the given IPv4/IPv6 address is assigned to specific interface. It can check both a single IP address (e.g. 192.0.2.1 or a assigned CIDR @@ -85,14 +85,14 @@ def _is_intf_addr_assigned(intf, address, netmask=''): continue # we do not have a netmask to compare against, they are the same - if netmask == '': + if not netmask: return True prefixlen = '' if is_ipv4(ip_addr): prefixlen = sum([bin(int(_)).count('1') for _ in ip['netmask'].split('.')]) else: - prefixlen = sum([bin(int(_,16)).count('1') for _ in ip['netmask'].split(':') if _]) + prefixlen = sum([bin(int(_,16)).count('1') for _ in ip['netmask'].split('/')[0].split(':') if _]) if str(prefixlen) == netmask: return True |