def _update_network_data_with_onboot(self, network_data, ifaces): if not ifaces: return for nd in network_data: supported_devices = [dev_info.device_name for dev_info in self.get_supported_devices()] device_name = get_device_name_from_network_data(self.nm_client, nd, supported_devices, self.bootif) if device_name in ifaces: log.debug("Updating network data onboot value: %s -> %s", nd.onboot, True) nd.onboot = True
def _update_network_data_with_onboot(self, network_data, ifaces): if not ifaces: return for nd in network_data: supported_devices = self.get_supported_devices() device_name = get_device_name_from_network_data( self.nm_client, nd, supported_devices, self._bootif) if device_name in ifaces: log.debug("Updating network data onboot value: %s -> %s", nd.onboot, True) nd.onboot = True
def run(self): """Run the kickstart application. :returns: names of devices to which kickstart was applied :rtype: list(str) """ applied_devices = [] if not self._network_data: log.debug("%s: No kickstart data.", self.name) return applied_devices if not self._nm_client: log.debug("%s: No NetworkManager available.", self.name) return applied_devices for network_data in self._network_data: # Wireless is not supported if network_data.essid: log.info( "%s: Wireless devices configuration is not supported.", self.name) continue 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 not found", self.name, network_data.device) continue ifcfg_file = get_ifcfg_file_of_device(self._nm_client, device_name) if ifcfg_file and ifcfg_file.is_from_kickstart: if network_data.activate: if ensure_active_connection_for_device( self._nm_client, ifcfg_file.uuid, device_name): applied_devices.append(device_name) continue # If there is no kickstart ifcfg from initramfs the command was added # in %pre section after switch root, so apply it now applied_devices.append(device_name) if ifcfg_file: # if the device was already configured in initramfs update the settings con_uuid = ifcfg_file.uuid log.debug( "%s: pre kickstart - updating settings %s of device %s", self.name, con_uuid, device_name) connection = self._nm_client.get_connection_by_uuid(con_uuid) update_connection_from_ksdata(self._nm_client, connection, network_data, device_name=device_name) if network_data.activate: device = self._nm_client.get_device_by_iface(device_name) self._nm_client.activate_connection_async( connection, device, None, None) log.debug( "%s: pre kickstart - activating connection %s with device %s", self.name, con_uuid, device_name) else: log.debug("%s: pre kickstart - adding connection for %s", self.name, device_name) add_connection_from_ksdata( self._nm_client, network_data, device_name, activate=network_data.activate, ifname_option_values=self._ifname_option_values) return applied_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
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: config_uuid = get_config_file_connection_of_device( self._nm_client, devname) con = self._nm_client.get_connection_by_uuid( config_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) if not master_uuid: master_uuid = get_config_file_connection_of_device( self._nm_client, master) master_specs = [master, master_uuid ] if master_uuid else [master] for name, _iface, uuid in get_slaves_from_connections( self._nm_client, ["bond", "bridge", "team"], master_specs): con = self._nm_client.get_connection_by_uuid(uuid) cons_to_update.append((name, con)) for con_name, con in cons_to_update: log.debug( "updating ONBOOT values of connection %s for device %s", con.get_uuid(), con_name) update_connection_values( con, [("connection", NM.SETTING_CONNECTION_AUTOCONNECT, network_data.onboot)]) commit_changes_with_autoconnection_blocked(con) updated_devices.append(con_name) return updated_devices
def apply_kickstart(self): """Apply kickstart configuration which has not already been applied. * Activate configurations created in initramfs if --activate is True. * Create configurations for %pre kickstart commands and activate eventually. :returns: list of devices to which kickstart configuration was applied """ applied_devices = [] if not self._original_network_data: log.debug("No kickstart data to apply.") return [] for network_data in self._original_network_data: # Wireless is not supported if network_data.essid: log.info("Wireless devices configuration is not supported.") continue supported_devices = self.get_supported_devices() device_name = get_device_name_from_network_data( self.nm_client, network_data, supported_devices, self._bootif) if not device_name: log.warning("apply kickstart: --device %s not found", network_data.device) continue ifcfg_file = get_ifcfg_file_of_device(self.nm_client, device_name) if ifcfg_file and ifcfg_file.is_from_kickstart: if network_data.activate: if ensure_active_connection_for_device( self.nm_client, ifcfg_file.uuid, device_name): applied_devices.append(device_name) continue # If there is no kickstart ifcfg from initramfs the command was added # in %pre section after switch root, so apply it now applied_devices.append(device_name) if ifcfg_file: # if the device was already configured in initramfs update the settings con_uuid = ifcfg_file.uuid log.debug("pre kickstart - updating settings %s of device %s", con_uuid, device_name) connection = self.nm_client.get_connection_by_uuid(con_uuid) update_connection_from_ksdata(self.nm_client, connection, network_data, device_name=device_name) if network_data.activate: device = self.nm_client.get_device_by_iface(device_name) self.nm_client.activate_connection_async( connection, device, None, None) log.debug( "pre kickstart - activating connection %s with device %s", con_uuid, device_name) else: log.debug("pre kickstart - adding connection for %s", device_name) add_connection_from_ksdata(self.nm_client, network_data, device_name, activate=network_data.activate) return applied_devices
def run(self): """Run the kickstart application. :returns: names of devices to which kickstart was applied :rtype: list(str) """ applied_devices = [] if not self._network_data: log.debug("%s: No kickstart data.", self.name) return applied_devices if not self._nm_client: log.debug("%s: No NetworkManager available.", self.name) return applied_devices for network_data in self._network_data: # Wireless is not supported if network_data.essid: log.info( "%s: Wireless devices configuration is not supported.", self.name) continue 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 not found", self.name, network_data.device) continue applied_devices.append(device_name) connection = self._find_initramfs_connection_of_iface(device_name) if connection: # if the device was already configured in initramfs update the settings log.debug("%s: updating connection %s of device %s", self.name, connection.get_uuid(), device_name) update_connection_from_ksdata( self._nm_client, connection, network_data, device_name, ifname_option_values=self._ifname_option_values) if network_data.activate: device = self._nm_client.get_device_by_iface(device_name) self._nm_client.activate_connection_async( connection, device, None, None) log.debug( "%s: activating updated connection %s with device %s", self.name, connection.get_uuid(), device_name) else: log.debug("%s: adding connection for %s", self.name, device_name) add_connection_from_ksdata( self._nm_client, network_data, device_name, activate=network_data.activate, ifname_option_values=self._ifname_option_values) return applied_devices
def run(self): """Run the kickstart application. :returns: names of devices to which kickstart was applied :rtype: list(str) """ applied_devices = [] if not self._network_data: log.debug("%s: No kickstart data.", self.name) return applied_devices if not self._nm_client: log.debug("%s: No NetworkManager available.", self.name) return applied_devices for network_data in self._network_data: # Wireless is not supported if network_data.essid: log.info("%s: Wireless devices configuration is not supported.", self.name) continue 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 not found", self.name, network_data.device) continue ifcfg_file = get_ifcfg_file_of_device(self._nm_client, device_name) if ifcfg_file and ifcfg_file.is_from_kickstart: if network_data.activate: if ensure_active_connection_for_device(self._nm_client, ifcfg_file.uuid, device_name): applied_devices.append(device_name) continue # If there is no kickstart ifcfg from initramfs the command was added # in %pre section after switch root, so apply it now applied_devices.append(device_name) if ifcfg_file: # if the device was already configured in initramfs update the settings con_uuid = ifcfg_file.uuid log.debug("%s: pre kickstart - updating settings %s of device %s", self.name, con_uuid, device_name) connection = self._nm_client.get_connection_by_uuid(con_uuid) update_connection_from_ksdata(self._nm_client, connection, network_data, device_name=device_name) if network_data.activate: device = self._nm_client.get_device_by_iface(device_name) self._nm_client.activate_connection_async(connection, device, None, None) log.debug("%s: pre kickstart - activating connection %s with device %s", self.name, con_uuid, device_name) else: log.debug("%s: pre kickstart - adding connection for %s", self.name, device_name) add_connection_from_ksdata(self._nm_client, network_data, device_name, activate=network_data.activate, ifname_option_values=self._ifname_option_values) return applied_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