Example #1
0
    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
Example #2
0
    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
Example #3
0
    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]
                self._update_connection(con, iface)
                log.debug("%s: dumping connection %s to ifcfg file for %s",
                          self.name, con.get_uuid(), iface)
                con.commit_changes(True, None)
            elif n_cons > 1:
                if not device_is_slave:
                    log.debug(
                        "%s: %d non-slave connections found for device %s",
                        self.name, n_cons, iface)
                    con = self._select_persistent_connection_for_device(
                        device, cons)
                    if not con:
                        log.warning(
                            "%s: none of the connections %s can be dumped as persistent",
                            self.name, [con.get_uuid() for con in cons])
                        continue
                    self._update_connection(con, iface)
                    log.debug(
                        "%s: dumping selected connection %s to ifcfg file for %s",
                        self.name, con.get_uuid(), iface)
                    con.commit_changes(True, None)

            new_ifcfgs.append(iface)

        return new_ifcfgs
Example #4
0
    def run(self):
        """Run dumping of missing config files.

        :returns: names of devices for which config file was created
        :rtype: list(str)
        """
        new_configs = []

        if not self._nm_client:
            log.debug("%s: No NetworkManager available.", self.name)
            return new_configs

        dumped_device_types = supported_wired_device_types + virtual_device_types
        for device in self._nm_client.get_devices():
            if device.get_device_type() not in dumped_device_types:
                continue

            iface = device.get_iface()
            if get_config_file_connection_of_device(self._nm_client, iface):
                continue

            cons = device.get_available_connections()
            log.debug("%s: %s connections found for device %s", self.name,
                      [con.get_uuid() for con in cons], iface)
            n_cons = len(cons)
            con = None

            device_is_slave = any(con.get_setting_connection().get_master()
                                  for con in cons)
            if device_is_slave:
                # We have to dump persistent ifcfg files for slaves created in initramfs
                if n_cons == 1 and self._is_initramfs_connection(
                        cons[0], iface):
                    log.debug(
                        "%s: device %s has an initramfs slave connection",
                        self.name, iface)
                    con = self._select_persistent_connection_for_device(
                        device, cons, allow_slaves=True)
                else:
                    log.debug(
                        "%s: creating default connection for slave device %s",
                        self.name, iface)

            if not con:
                con = self._select_persistent_connection_for_device(
                    device, cons)

            # Devices activated in initramfs should have ONBOOT=yes
            has_initramfs_con = any(
                self._is_initramfs_connection(con, iface) for con in cons)
            if has_initramfs_con:
                log.debug("%s: device %s has initramfs connection", self.name,
                          iface)

            if con:
                self._update_connection(con, iface)
                if has_initramfs_con:
                    update_connection_values(con, [
                        ("connection", NM.SETTING_CONNECTION_AUTOCONNECT, True)
                    ])
                log.debug("%s: dumping connection %s to config file for %s",
                          self.name, con.get_uuid(), iface)
                con.commit_changes(True, None)
            else:
                log.debug(
                    "%s: none of the connections can be dumped as persistent",
                    self.name)
                if n_cons > 1 and not device_is_slave:
                    log.warning(
                        "%s: unexpected number of connections, not dumping any",
                        self.name)
                    continue
                # TODO: Try to clone the persistent connection for the device
                # from the connection which should be a generic (not bound
                # to iface) connection created by NM in initramfs
                log.debug("%s: creating default connection for %s", self.name,
                          iface)
                network_data = copy.deepcopy(self._default_network_data)
                if has_initramfs_con:
                    network_data.onboot = True
                add_connection_from_ksdata(
                    self._nm_client,
                    network_data,
                    iface,
                    activate=False,
                    ifname_option_values=self._ifname_option_values)

            new_configs.append(iface)

        return new_configs
Example #5
0
    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
Example #6
0
    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
Example #7
0
    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
Example #8
0
    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
Example #9
0
    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
Example #10
0
    def run(self):
        """Run dumping of missing config files.

        :returns: names of devices for which config file was created
        :rtype: list(str)
        """
        new_configs = []

        if not self._nm_client:
            log.debug("%s: No NetworkManager available.", self.name)
            return new_configs

        dumped_device_types = supported_wired_device_types + virtual_device_types
        for device in self._nm_client.get_devices():
            if device.get_device_type() not in dumped_device_types:
                continue

            iface = device.get_iface()
            if get_config_file_connection_of_device(self._nm_client, iface):
                continue

            cons = device.get_available_connections()
            log.debug("%s: %s connections found for device %s", self.name,
                      [con.get_uuid() for con in cons], iface)
            n_cons = len(cons)
            con = None

            device_is_port = any(con.get_setting_connection().get_master() for con in cons)
            if device_is_port:
                # We have to dump persistent ifcfg files for ports created in initramfs
                if n_cons == 1 and self._is_initramfs_connection(cons[0], iface):
                    log.debug("%s: device %s has an initramfs port connection",
                              self.name, iface)
                    con = self._select_persistent_connection_for_device(
                        device, cons, allow_ports=True)
                else:
                    log.debug("%s: creating default connection for port device %s",
                              self.name, iface)

            if not con:
                con = self._select_persistent_connection_for_device(device, cons)

            has_initramfs_con = any(self._is_initramfs_connection(con, iface) for con in cons)
            if has_initramfs_con:
                log.debug("%s: device %s has initramfs connection", self.name, iface)
                if not con and n_cons == 1:
                    # Try to clone the persistent connection for the device
                    # from the connection which should be a generic (not bound
                    # to iface) connection created by NM in initramfs
                    con = clone_connection_sync(self._nm_client, cons[0], con_id=iface)

            if con:
                self._update_connection(con, iface)
                # Update some values of connection generated in initramfs so it
                # can be used as persistent configuration.
                if has_initramfs_con:
                    update_connection_values(
                        con,
                        [
                            # Make sure ONBOOT is yes
                            (NM.SETTING_CONNECTION_SETTING_NAME,
                             NM.SETTING_CONNECTION_AUTOCONNECT,
                             True),
                            # Update cloned generic connection from initramfs
                            (NM.SETTING_CONNECTION_SETTING_NAME,
                             NM.SETTING_CONNECTION_MULTI_CONNECT,
                             0),
                            # Update cloned generic connection from initramfs
                            (NM.SETTING_CONNECTION_SETTING_NAME,
                             NM.SETTING_CONNECTION_WAIT_DEVICE_TIMEOUT,
                             -1)
                        ]
                    )
                log.debug("%s: dumping connection %s to config file for %s",
                          self.name, con.get_uuid(), iface)
                commit_changes_with_autoconnection_blocked(con)
            else:
                log.debug("%s: none of the connections can be dumped as persistent",
                          self.name)
                if n_cons > 1 and not device_is_port:
                    log.warning("%s: unexpected number of connections, not dumping any",
                                self.name)
                    continue
                log.debug("%s: creating default connection for %s", self.name, iface)
                network_data = copy.deepcopy(self._default_network_data)
                if has_initramfs_con:
                    network_data.onboot = True
                add_connection_from_ksdata(
                    self._nm_client,
                    network_data,
                    iface,
                    activate=False,
                    ifname_option_values=self._ifname_option_values
                )

            new_configs.append(iface)

        return new_configs