def _update_connection(self, con, iface): log.debug( "%s: updating id and binding (interface-name) of connection %s for %s", self.name, con.get_uuid(), iface) s_con = con.get_setting_connection() s_con.set_property(NM.SETTING_CONNECTION_ID, iface) s_con.set_property(NM.SETTING_CONNECTION_INTERFACE_NAME, iface) s_wired = con.get_setting_wired() if s_wired: # By default connections are bound to interface name s_wired.set_property(NM.SETTING_WIRED_MAC_ADDRESS, None) bound_mac = bound_hwaddr_of_device(self._nm_client, iface, self._ifname_option_values) if bound_mac: s_wired.set_property(NM.SETTING_WIRED_MAC_ADDRESS, bound_mac) log.debug( "%s: iface %s bound to mac address %s by ifname boot option", self.name, iface, bound_mac) log.debug("%s: updating addr-gen-mode of connection %s for %s", self.name, con.get_uuid(), iface) s_ipv6 = con.get_setting_ip6_config() # For example slave connections do not have ipv6 setting present if s_ipv6: s_ipv6.set_property(NM.SETTING_IP6_CONFIG_ADDR_GEN_MODE, NM.SettingIP6ConfigAddrGenMode.EUI64)
def run(self): """Run dumping of missing ifcfg files. :returns: names of devices for which ifcfg file was created :rtype: list(str) """ new_ifcfgs = [] if not self._nm_client: log.debug("%s: No NetworkManager available.", self.name) return new_ifcfgs for device in self._nm_client.get_devices(): if device.get_device_type() not in supported_wired_device_types: continue iface = device.get_iface() if get_ifcfg_file_of_device(self._nm_client, iface): continue cons = device.get_available_connections() n_cons = len(cons) device_is_slave = any(con.get_setting_connection().get_master() for con in cons) if n_cons == 0: log.debug("%s: creating default connection for %s", self.name, iface) add_connection_from_ksdata(self._nm_client, self._default_network_data, iface, activate=False, ifname_option_values=self._ifname_option_values) elif n_cons == 1: if device_is_slave: log.debug("%s: not creating default connection for slave device %s", self.name, iface) continue con = cons[0] log.debug("%s: dumping default autoconnection %s for %s", self.name, con.get_uuid(), iface) s_con = con.get_setting_connection() s_con.set_property(NM.SETTING_CONNECTION_ID, iface) s_con.set_property(NM.SETTING_CONNECTION_INTERFACE_NAME, iface) if not bound_hwaddr_of_device(self._nm_client, iface, self._ifname_option_values): s_wired = con.get_setting_wired() s_wired.set_property(NM.SETTING_WIRED_MAC_ADDRESS, None) else: log.debug("%s: iface %s bound to mac address by ifname boot option", self.name, iface) con.commit_changes(True, None) elif n_cons > 1: if not device_is_slave: log.warning("%s: %d non-slave connections found for device %s", self.name, n_cons, iface) continue new_ifcfgs.append(iface) return new_ifcfgs
def _update_connection(self, con, iface): log.debug("%s: updating id and binding (interface-name) of connection %s for %s", self.name, con.get_uuid(), iface) s_con = con.get_setting_connection() s_con.set_property(NM.SETTING_CONNECTION_ID, iface) s_con.set_property(NM.SETTING_CONNECTION_INTERFACE_NAME, iface) s_wired = con.get_setting_wired() # By default connections are bound to interface name s_wired.set_property(NM.SETTING_WIRED_MAC_ADDRESS, None) bound_mac = bound_hwaddr_of_device(self._nm_client, iface, self._ifname_option_values) if bound_mac: s_wired.set_property(NM.SETTING_WIRED_MAC_ADDRESS, bound_mac) log.debug("%s: iface %s bound to mac address %s by ifname boot option", self.name, iface, bound_mac)
def dump_missing_ifcfg_files(self): """Dump missing default ifcfg file for wired devices. Make sure each supported wired device has ifcfg file. For default auto connections created by NM upon start (which happens in case of missing ifcfg file, eg the file was not created in initramfs) rename the in-memory connection using device name and dump it into ifcfg file. If default auto connections are turned off by NM configuration (based on policy, eg on RHEL or server), the connection will be created by Anaconda and dumped into ifcfg file. The connection id (and consequently ifcfg file name) is set to device name. """ if not self.nm_available: return [] new_ifcfgs = [] for device in self.nm_client.get_devices(): if device.get_device_type() not in supported_wired_device_types: continue iface = device.get_iface() if get_ifcfg_file_of_device(self.nm_client, iface): continue cons = device.get_available_connections() n_cons = len(cons) device_is_slave = any(con.get_setting_connection().get_master() for con in cons) if n_cons == 0: data = self.get_kickstart_handler() default_data = data.NetworkData(onboot=False, ipv6="auto") log.debug( "dump missing ifcfgs: creating default connection for %s", iface) add_connection_from_ksdata(self.nm_client, default_data, iface) elif n_cons == 1: if device_is_slave: log.debug( "dump missing ifcfgs: not creating default connection for slave device %s", iface) continue con = cons[0] log.debug( "dump missing ifcfgs: dumping default autoconnection %s for %s", con.get_uuid(), iface) s_con = con.get_setting_connection() s_con.set_property(NM.SETTING_CONNECTION_ID, iface) s_con.set_property(NM.SETTING_CONNECTION_INTERFACE_NAME, iface) if not bound_hwaddr_of_device(self.nm_client, iface, self.ifname_option_values): s_wired = con.get_setting_wired() s_wired.set_property(NM.SETTING_WIRED_MAC_ADDRESS, None) else: log.debug( "dump missing ifcfgs: iface %s bound to mac address by ifname boot option" ) con.commit_changes(True, None) elif n_cons > 1: if not device_is_slave: log.warning( "dump missing ifcfgs: %d non-slave connections found for device %s", n_cons, iface) continue new_ifcfgs.append(iface) return new_ifcfgs
def run(self): """Run dumping of missing ifcfg files. :returns: names of devices for which ifcfg file was created :rtype: list(str) """ new_ifcfgs = [] if not self._nm_client: log.debug("%s: No NetworkManager available.", self.name) return new_ifcfgs for device in self._nm_client.get_devices(): if device.get_device_type() not in supported_wired_device_types: continue iface = device.get_iface() if get_ifcfg_file_of_device(self._nm_client, iface): continue cons = device.get_available_connections() n_cons = len(cons) device_is_slave = any(con.get_setting_connection().get_master() for con in cons) if n_cons == 0: log.debug("%s: creating default connection for %s", self.name, iface) add_connection_from_ksdata( self._nm_client, self._default_network_data, iface, activate=False, ifname_option_values=self._ifname_option_values) elif n_cons == 1: if device_is_slave: log.debug( "%s: not creating default connection for slave device %s", self.name, iface) continue con = cons[0] log.debug("%s: dumping default autoconnection %s for %s", self.name, con.get_uuid(), iface) s_con = con.get_setting_connection() s_con.set_property(NM.SETTING_CONNECTION_ID, iface) s_con.set_property(NM.SETTING_CONNECTION_INTERFACE_NAME, iface) if not bound_hwaddr_of_device(self._nm_client, iface, self._ifname_option_values): s_wired = con.get_setting_wired() s_wired.set_property(NM.SETTING_WIRED_MAC_ADDRESS, None) else: log.debug( "%s: iface %s bound to mac address by ifname boot option", self.name, iface) con.commit_changes(True, None) elif n_cons > 1: if not device_is_slave: log.warning( "%s: %d non-slave connections found for device %s", self.name, n_cons, iface) continue new_ifcfgs.append(iface) return new_ifcfgs