def install_network_with_task(self, sysroot, onboot_ifaces, overwrite): """Install network with an installation task. :param sysroot: a path to the root of the installed system :param onboot_ifaces: list of network interfaces which should have ONBOOT=yes :param overwrite: overwrite existing configuration :return: a DBus path of an installation task """ disable_ipv6 = self.disable_ipv6 and devices_ignore_ipv6( self.nm_client, supported_wired_device_types) network_ifaces = [ device.get_iface() for device in self.nm_client.get_devices() ] onboot_ifaces_by_policy = [] if self._should_apply_onboot_policy() and \ not self._has_any_onboot_yes_device(self._device_configurations): onboot_ifaces_by_policy = self._get_onboot_ifaces_by_policy( conf.network.default_on_boot) all_onboot_ifaces = list(set(onboot_ifaces + onboot_ifaces_by_policy)) self._onboot_yes_ifaces = all_onboot_ifaces onboot_yes_uuids = [ find_ifcfg_uuid_of_device(self.nm_client, iface) or "" for iface in all_onboot_ifaces ] log.debug("ONBOOT will be set to yes for %s (fcoe) %s (policy)", onboot_ifaces, onboot_ifaces_by_policy) task = NetworkInstallationTask(sysroot, self.hostname, disable_ipv6, overwrite, onboot_yes_uuids, network_ifaces) task.succeeded_signal.connect( lambda: self.log_task_result(task, root_path=sysroot)) path = self.publish_task(NETWORK.namespace, task) return path
def install_network_with_task(self, sysroot, onboot_ifaces, overwrite): """Install network with an installation task. :param sysroot: a path to the root of the installed system :param onboot_ifaces: list of network interfaces which should have ONBOOT=yes :param overwrite: overwrite existing configuration :return: a DBus path of an installation task """ disable_ipv6 = self.disable_ipv6 and devices_ignore_ipv6(self.nm_client, supported_wired_device_types) network_ifaces = [device.get_iface() for device in self.nm_client.get_devices()] onboot_ifaces_by_policy = [] if self._should_apply_onboot_policy() and \ not self._has_any_onboot_yes_device(self._device_configurations): onboot_ifaces_by_policy = self._get_onboot_ifaces_by_policy(conf.network.default_on_boot) all_onboot_ifaces = list(set(onboot_ifaces + onboot_ifaces_by_policy)) self._onboot_yes_ifaces = all_onboot_ifaces onboot_yes_uuids = [find_ifcfg_uuid_of_device(self.nm_client, iface) or "" for iface in all_onboot_ifaces] log.debug("ONBOOT will be set to yes for %s (fcoe) %s (policy)", onboot_ifaces, onboot_ifaces_by_policy) task = NetworkInstallationTask(sysroot, self.hostname, disable_ipv6, overwrite, onboot_yes_uuids, network_ifaces, self.ifname_option_values) task.succeeded_signal.connect(lambda: self.log_task_result(task, root_path=sysroot)) path = self.publish_task(NETWORK.namespace, task) return path
def _find_connection_uuid_of_device(self, device): """Find uuid of connection that should be bound to the device. Assumes existence of no more than one ifcfg file per non-slave physical device. :param device: NetworkManager device object :type device: NMDevice :returns: uuid of NetworkManager connection :rtype: str """ uuid = None iface = device.get_iface() # For virtual device only the active connection could be the connection if device.get_device_type() in virtual_device_types: ac = device.get_active_connection() if ac: uuid = ac.get_connection().get_uuid() else: log.debug("no active connection for virtual device %s", iface) # For physical device we need to pick the right connection in some # cases. else: cons = device.get_available_connections() ifcfg_uuid = None if not cons: log.debug("no available connection for physical device %s", iface) elif len(cons) > 1: # This can happen when activating device in initramfs and # reconfiguring it via kickstart without activation. log.debug("physical device %s has multiple connections: %s", iface, [c.get_uuid() for c in cons]) hwaddr = device.get_hw_address() ifcfg_uuid = find_ifcfg_uuid_of_device(self.nm_client, iface, hwaddr=hwaddr) for c in cons: # Ignore slave connections if c.get_setting_connection() and c.get_setting_connection( ).get_slave_type(): continue candidate_uuid = c.get_uuid() # In case of multiple connections choose the ifcfg connection if not ifcfg_uuid or candidate_uuid == ifcfg_uuid: uuid = candidate_uuid return uuid
def run(self): if not self._nm_client: log.debug("%s: No NetworkManager available.", self.name) return None for iface in self._onboot_ifaces: con_uuid = find_ifcfg_uuid_of_device(self._nm_client, iface) if con_uuid: con = self._nm_client.get_connection_by_uuid(con_uuid) update_connection_values( con, [("connection", NM.SETTING_CONNECTION_AUTOCONNECT, True)]) commit_changes_with_autoconnection_blocked(con) else: log.warning("Configure ONBOOT: can't find ifcfg for %s", iface)
def run(self): """Run the ONBOOT values updating. :return: names of devices for which ONBOOT was updated :rtype: list(str) """ updated_devices = [] if not self._nm_client: log.debug("%s: No NetworkManager available.", self.name) return updated_devices if not self._network_data: log.debug("%s: No kickstart data.", self.name) return updated_devices for network_data in self._network_data: device_name = get_device_name_from_network_data( self._nm_client, network_data, self._supported_devices, self._bootif) if not device_name: log.warning("%s: --device %s does not exist.", self.name, network_data.device) devices_to_update = [device_name] master = device_name # When defining both bond/team and vlan in one command we need more care # network --onboot yes --device bond0 --bootproto static --bondslaves ens9,ens10 # --bondopts mode=active-backup,miimon=100,primary=ens9,fail_over_mac=2 # --ip 192.168.111.1 --netmask 255.255.255.0 --gateway 192.168.111.222 --noipv6 # --vlanid 222 --no-activate if network_data.vlanid and (network_data.bondslaves or network_data.teamslaves): master = network_data.device devices_to_update.append(master) for devname in devices_to_update: if network_data.onboot: # We need to handle "no" -> "yes" change by changing ifcfg file instead of the NM connection # so the device does not get autoactivated (BZ #1261864) uuid = find_ifcfg_uuid_of_device(self._nm_client, devname) or "" if not update_onboot_value( uuid, network_data.onboot, root_path=""): continue else: n_cons = update_iface_setting_values( self._nm_client, devname, [("connection", NM.SETTING_CONNECTION_AUTOCONNECT, network_data.onboot)]) if n_cons != 1: log.debug("%s: %d connections found for %s", self.name, n_cons, devname) if n_cons > 1: # In case of multiple connections for a device, update ifcfg directly uuid = find_ifcfg_uuid_of_device( self._nm_client, devname) or "" if not update_onboot_value( uuid, network_data.onboot, root_path=""): continue updated_devices.append(devname) # Handle slaves if there are any if network_data.bondslaves or network_data.teamslaves or network_data.bridgeslaves: # Master can be identified by devname or uuid, try to find master uuid uuid = None device = self._nm_client.get_device_by_iface(master) if device: cons = device.get_available_connections() n_cons = len(cons) if n_cons == 1: uuid = cons[0].get_uuid() else: log.debug("%s: %d connections found for %s", self.name, n_cons, master) updated_slaves = update_slaves_onboot_value( self._nm_client, master, network_data.onboot, uuid=uuid) updated_devices.extend(updated_slaves) return updated_devices
def run(self): """Run the ONBOOT values updating. :return: names of devices for which ONBOOT was updated :rtype: list(str) """ updated_devices = [] if not self._nm_client: log.debug("%s: No NetworkManager available.", self.name) return updated_devices if not self._network_data: log.debug("%s: No kickstart data.", self.name) return updated_devices for network_data in self._network_data: device_name = get_device_name_from_network_data( self._nm_client, network_data, self._supported_devices, self._bootif) if not device_name: log.warning("%s: --device %s does not exist.", self.name, network_data.device) devices_to_update = [device_name] master = device_name # When defining both bond/team and vlan in one command we need more care # network --onboot yes --device bond0 --bootproto static --bondslaves ens9,ens10 # --bondopts mode=active-backup,miimon=100,primary=ens9,fail_over_mac=2 # --ip 192.168.111.1 --netmask 255.255.255.0 --gateway 192.168.111.222 --noipv6 # --vlanid 222 --no-activate if network_data.vlanid and (network_data.bondslaves or network_data.teamslaves): master = network_data.device devices_to_update.append(master) cons_to_update = [] for devname in devices_to_update: cons = get_connections_available_for_iface( self._nm_client, devname) n_cons = len(cons) con = None if n_cons == 1: cons_to_update.append((devname, cons[0])) else: log.debug("%s: %d connections found for %s", self.name, n_cons, devname) if n_cons > 1: ifcfg_uuid = find_ifcfg_uuid_of_device( self._nm_client, devname) or "" con = self._nm_client.get_connection_by_uuid( ifcfg_uuid) if con: cons_to_update.append((devname, con)) # Handle slaves if there are any if network_data.bondslaves or network_data.teamslaves or network_data.bridgeslaves: # Master can be identified by devname or uuid, try to find master uuid master_uuid = None device = self._nm_client.get_device_by_iface(master) if device: cons = device.get_available_connections() n_cons = len(cons) if n_cons == 1: master_uuid = cons[0].get_uuid() else: log.debug("%s: %d connections found for %s", self.name, n_cons, master) for name, con_uuid in get_master_slaves_from_ifcfgs( self._nm_client, master, uuid=master_uuid): con = self._nm_client.get_connection_by_uuid(con_uuid) cons_to_update.append((name, con)) for devname, con in cons_to_update: log.debug( "updating ONBOOT values of connection %s for device %s", con.get_uuid(), devname) update_connection_values( con, [("connection", NM.SETTING_CONNECTION_AUTOCONNECT, network_data.onboot)]) commit_changes_with_autoconnection_blocked(con) updated_devices.append(devname) return updated_devices
def run(self): """Run the ONBOOT values updating. :return: names of devices for which ONBOOT was updated :rtype: list(str) """ updated_devices = [] if not self._nm_client: log.debug("%s: No NetworkManager available.", self.name) return updated_devices if not self._network_data: log.debug("%s: No kickstart data.", self.name) return updated_devices for network_data in self._network_data: device_name = get_device_name_from_network_data(self._nm_client, network_data, self._supported_devices, self._bootif) if not device_name: log.warning("%s: --device %s does not exist.", self.name, network_data.device) devices_to_update = [device_name] master = device_name # When defining both bond/team and vlan in one command we need more care # network --onboot yes --device bond0 --bootproto static --bondslaves ens9,ens10 # --bondopts mode=active-backup,miimon=100,primary=ens9,fail_over_mac=2 # --ip 192.168.111.1 --netmask 255.255.255.0 --gateway 192.168.111.222 --noipv6 # --vlanid 222 --no-activate if network_data.vlanid and (network_data.bondslaves or network_data.teamslaves): master = network_data.device devices_to_update.append(master) for devname in devices_to_update: if network_data.onboot: # We need to handle "no" -> "yes" change by changing ifcfg file instead of the NM connection # so the device does not get autoactivated (BZ #1261864) uuid = find_ifcfg_uuid_of_device(self._nm_client, devname) or "" if not update_onboot_value(uuid, network_data.onboot, root_path=""): continue else: n_cons = update_iface_setting_values(self._nm_client, devname, [("connection", NM.SETTING_CONNECTION_AUTOCONNECT, network_data.onboot)]) if n_cons != 1: log.debug("%s: %d connections found for %s", self.name, n_cons, devname) if n_cons > 1: # In case of multiple connections for a device, update ifcfg directly uuid = find_ifcfg_uuid_of_device(self._nm_client, devname) or "" if not update_onboot_value(uuid, network_data.onboot, root_path=""): continue updated_devices.append(devname) # Handle slaves if there are any if network_data.bondslaves or network_data.teamslaves or network_data.bridgeslaves: # Master can be identified by devname or uuid, try to find master uuid uuid = None device = self._nm_client.get_device_by_iface(master) if device: cons = device.get_available_connections() n_cons = len(cons) if n_cons == 1: uuid = cons[0].get_uuid() else: log.debug("%s: %d connections found for %s", self.name, n_cons, master) updated_slaves = update_slaves_onboot_value(self._nm_client, master, network_data.onboot, uuid=uuid) updated_devices.extend(updated_slaves) return updated_devices