diff --git a/debian/control b/debian/control index 189a959b0e..8fc5a2bb04 100644 --- a/debian/control +++ b/debian/control @@ -54,7 +54,6 @@ Depends: at, rsync, vyatta-bash, - vyatta-biosdevname, vyatta-cfg, vyos-http-api-tools, vyos-utils, diff --git a/src/helpers/vyos_net_name b/src/helpers/vyos_net_name index f5de182c66..3b20375fac 100755 --- a/src/helpers/vyos_net_name +++ b/src/helpers/vyos_net_name @@ -20,6 +20,7 @@ import time import logging import logging.handlers import tempfile + from pathlib import Path from sys import argv @@ -30,18 +31,17 @@ from vyos.utils.boot import boot_configuration_complete from vyos.utils.locking import Lock from vyos.migrate import ConfigMigrate + # Define variables vyos_udev_dir = directories['vyos_udev_dir'] config_path = '/opt/vyatta/etc/config/config.boot' - def is_available(intfs: dict, intf_name: str) -> bool: """Check if interface name is already assigned""" if intf_name in list(intfs.values()): return False return True - def find_available(intfs: dict, prefix: str) -> str: """Find lowest indexed iterface name that is not assigned""" index_list = [ @@ -55,7 +55,6 @@ def find_available(intfs: dict, prefix: str) -> str: return f'{prefix}{len(index_list)}' - def mod_ifname(ifname: str) -> str: """Check interface with names eX and return ifname on the next format eth{ifindex} - 2""" if re.match('^e[0-9]+$', ifname): @@ -68,33 +67,6 @@ def mod_ifname(ifname: str) -> str: return ifname - -def get_biosdevname(ifname: str) -> str: - """Use legacy vyatta-biosdevname to query for name - - This is carried over for compatability only, and will likely be dropped - going forward. - XXX: This throws an error, and likely has for a long time, unnoticed - since vyatta_net_name redirected stderr to /dev/null. - """ - intf = mod_ifname(ifname) - - if 'eth' not in intf: - return intf - if os.path.isdir('/proc/xen'): - return intf - - time.sleep(1) - - try: - biosname = cmd(f'/sbin/biosdevname --policy all_ethN -i {ifname}') - except Exception as e: - logger.error(f'biosdevname error: {e}') - biosname = '' - - return intf if biosname == '' else biosname - - def leave_rescan_hint(intf_name: str, hwid: str): """Write interface information reported by udev @@ -116,7 +88,6 @@ def leave_rescan_hint(intf_name: str, hwid: str): except OSError as e: logger.critical(f'OSError {e}') - def get_configfile_interfaces() -> dict: """Read existing interfaces from config file""" interfaces: dict = {} @@ -136,7 +107,7 @@ def get_configfile_interfaces() -> dict: config = ConfigTree(config_file) except Exception: try: - logger.debug('updating component version string syntax') + logger.debug('Updating component version string syntax') # this will update the component version string syntax, # required for updates 1.2 --> 1.3/1.4 with tempfile.NamedTemporaryFile() as fp: @@ -161,12 +132,12 @@ def get_configfile_interfaces() -> dict: for intf in eth_intfs: path = base + [intf, 'hw-id'] if not config.exists(path): - logger.warning(f"no 'hw-id' entry for {intf}") + logger.warning(f"No 'hw-id' entry for {intf}") continue hwid = config.return_value(path) if hwid in list(interfaces): logger.warning( - f'multiple entries for {hwid}: {interfaces[hwid]}, {intf}' + f'Multiple entries for {hwid}: {interfaces[hwid]}, {intf}' ) continue interfaces[hwid] = intf @@ -177,21 +148,20 @@ def get_configfile_interfaces() -> dict: for intf in wlan_intfs: path = base + [intf, 'hw-id'] if not config.exists(path): - logger.warning(f"no 'hw-id' entry for {intf}") + logger.warning(f"No 'hw-id' entry for {intf}") continue hwid = config.return_value(path) if hwid in list(interfaces): logger.warning( - f'multiple entries for {hwid}: {interfaces[hwid]}, {intf}' + f'Multiple entries for {hwid}: {interfaces[hwid]}, {intf}' ) continue interfaces[hwid] = intf - logger.debug(f'config file entries: {interfaces}') + logger.debug(f'Config file entries: {interfaces}') return interfaces - def add_assigned_interfaces(intfs: dict): """Add interfaces found by previous invocation of udev rule""" if not os.path.isdir(vyos_udev_dir): @@ -207,38 +177,31 @@ def add_assigned_interfaces(intfs: dict): continue intfs[hwid] = intf - -def on_boot_event(intf_name: str, hwid: str, predefined: str = '') -> str: +def on_boot_event(intf_name: str, hwid: str, newname: str) -> str: """Called on boot by vyos-router: 'coldplug' in vyatta_net_name""" - logger.info(f'lookup {intf_name}, {hwid}') + logger.info(f'Looking up {intf_name}, {hwid}') interfaces = get_configfile_interfaces() - logger.debug(f'config file interfaces are {interfaces}') + logger.debug(f'Config file interfaces are {interfaces}') if hwid in list(interfaces): - logger.info(f"use mapping from config file: '{hwid}' -> '{interfaces[hwid]}'") + logger.info(f"Using the mapping from the config file: '{hwid}' -> '{interfaces[hwid]}'") return interfaces[hwid] add_assigned_interfaces(interfaces) - logger.debug(f'adding assigned interfaces: {interfaces}') + logger.debug(f'Adding assigned interfaces: {interfaces}') - if predefined: - newname = predefined - logger.info(f"predefined interface name for '{intf_name}' is '{newname}'") - else: - newname = get_biosdevname(intf_name) - logger.info(f"biosdevname returned '{newname}' for '{intf_name}'") + logger.info(f"Predefined interface name for '{intf_name}' is '{newname}'") if not is_available(interfaces, newname): prefix = re.sub(r'\d+$', '', newname) newname = find_available(interfaces, prefix) - logger.info(f"new name for '{intf_name}' is '{newname}'") + logger.info(f"The new name for '{intf_name}' is '{newname}'") leave_rescan_hint(newname, hwid) return newname - def hotplug_event(): # Not yet implemented, since interface-rescan will only be run on boot. pass @@ -257,20 +220,22 @@ if __name__ == '__main__': logger.debug(f'Started with arguments: {argv}') if len(argv) > 3: + intf_name = argv[1] + hwid = argv[2] predef_name = argv[3] else: - predef_name = '' + raise RuntimeError('vyos_net_name helper called without required arguments') lock = Lock('vyos_net_name') # Wait 60 seconds for other running scripts to finish lock.acquire(60) if not boot_configuration_complete(): - res = on_boot_event(argv[1], argv[2], predefined=predef_name) - logger.debug(f'on boot, returned name is {res}') + res = on_boot_event(intf_name, hwid, predef_name) + logger.debug(f'Processed an on-boot event for {intf_name}, assigned name is {res}') print(res) else: - logger.debug('boot configuration complete') + logger.debug(f'Called outside of boot-time configuration, exiting') lock.release() logger.debug('Finished')