Пример #1
0
    def run(self):
        """Run the connections consolidation.

        :returns: names of devices of which the connections have been consolidated
        :rtype: list(str)
        """
        consolidated_devices = []

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

        for device in self._nm_client.get_devices():
            cons = device.get_available_connections()
            number_of_connections = len(cons)
            iface = device.get_iface()

            if number_of_connections < 2:
                continue

            # Ignore devices which are slaves
            if any(con.get_setting_connection().get_master() for con in cons):
                log.debug("%s: %d for %s - it is OK, device is a slave",
                          self.name, number_of_connections, iface)
                continue

            # Ignore devices with iBFT connections
            if self._device_has_ibft_connection(device):
                log.debug("%s: %d for %s - it is OK, device was configured from iBFT",
                          self.name, number_of_connections, iface)
                continue

            config_uuid = get_config_file_connection_of_device(self._nm_client, iface)
            if config_uuid:
                # There is a connection from kickstart generated in intramfs,
                # the device will be handled when applying kickstart
                continue

            log.debug("%s: %d for %s - no config file found",
                      self.name, number_of_connections, iface)
            con_for_iface = self._select_persistent_connection_for_iface(iface, cons)
            if not con_for_iface:
                log.debug("%s: %d for %s - no suitable connection for the interface found",
                          self.name, number_of_connections, iface)
                continue

            log.debug("%s: %d for %s - ensure connection with config is active",
                      self.name, number_of_connections, iface)

            ensure_active_connection_for_device(
                self._nm_client,
                con_for_iface.get_uuid(),
                iface,
                only_replace=True
            )

            consolidated_devices.append(iface)

        return consolidated_devices
Пример #2
0
    def run(self):
        """Run the connections consolidation.

        :returns: names of devices of which the connections have been consolidated
        :rtype: list(str)
        """
        consolidated_devices = []

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

        for device in self._nm_client.get_devices():
            cons = device.get_available_connections()
            number_of_connections = len(cons)
            iface = device.get_iface()

            if number_of_connections < 2:
                continue

            # Ignore devices which are slaves
            if any(con.get_setting_connection().get_master() for con in cons):
                log.debug("%s: %d for %s - it is OK, device is a slave",
                          self.name, number_of_connections, iface)
                continue

            ifcfg_file = get_ifcfg_file_of_device(self._nm_client, iface)
            if not ifcfg_file:
                log.debug("%s: %d for %s - no ifcfg file found", self.name,
                          number_of_connections, iface)
                con_for_iface = self._select_persistent_connection_for_iface(
                    iface, cons)
                if not con_for_iface:
                    log.debug(
                        "%s: %d for %s - no suitable connection for the interface found",
                        self.name, number_of_connections, iface)
                    continue
            else:
                # Handle only ifcfgs created from boot options in initramfs
                # (Kickstart based ifcfgs are handled when applying kickstart)
                if ifcfg_file.is_from_kickstart:
                    continue
                con_for_iface = ifcfg_file.uuid

            log.debug("%s: %d for %s - ensure active ifcfg connection",
                      self.name, number_of_connections, iface)

            ensure_active_connection_for_device(self._nm_client,
                                                con_for_iface.get_uuid(),
                                                iface,
                                                only_replace=True)

            consolidated_devices.append(iface)

        return consolidated_devices
Пример #3
0
    def consolidate_initramfs_connections(self):
        """Ensure devices configured in initramfs have no more than one NM connection.

        In case of multiple connections for device having ifcfg configuration from
        boot options, the connection should correspond to the ifcfg file.
        NetworkManager can be generating additional in-memory connection in case it
        fails to match device configuration to the ifcfg (#1433891).  By
        reactivating the device with ifcfg connection the generated in-memory
        connection will be deleted by NM.

        Don't enforce on slave devices for which having multiple connections can be
        valid (slave connection, regular device connection).
        """
        consolidated_devices = []

        for device in self.nm_client.get_devices():
            cons = device.get_available_connections()
            number_of_connections = len(cons)
            iface = device.get_iface()

            if number_of_connections < 2:
                continue

            # Ignore devices which are slaves
            if any(con.get_setting_connection().get_master() for con in cons):
                log.debug(
                    "consolidate %d initramfs connections for %s: it is OK, device is a slave",
                    number_of_connections, iface)
                continue

            ifcfg_file = get_ifcfg_file_of_device(self.nm_client, iface)
            if not ifcfg_file:
                log.error(
                    "consolidate %d initramfs connections for %s: no ifcfg file",
                    number_of_connections, iface)
                continue
            else:
                # Handle only ifcfgs created from boot options in initramfs
                # (Kickstart based ifcfgs are handled when applying kickstart)
                if ifcfg_file.is_from_kickstart:
                    continue

            log.debug(
                "consolidate %d initramfs connections for %s: ensure active ifcfg connection",
                number_of_connections, iface)

            ensure_active_connection_for_device(self.nm_client,
                                                ifcfg_file.uuid,
                                                iface,
                                                only_replace=True)

            consolidated_devices.append(iface)

        return consolidated_devices
Пример #4
0
    def run(self):
        """Run the connections consolidation.

        :returns: names of devices of which the connections have been consolidated
        :rtype: list(str)
        """
        consolidated_devices = []

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

        for device in self._nm_client.get_devices():
            cons = device.get_available_connections()
            number_of_connections = len(cons)
            iface = device.get_iface()

            if number_of_connections < 2:
                continue

            # Ignore devices which are slaves
            if any(con.get_setting_connection().get_master() for con in cons):
                log.debug("%s: %d for %s - it is OK, device is a slave",
                          self.name, number_of_connections, iface)
                continue

            ifcfg_file = get_ifcfg_file_of_device(self._nm_client, iface)
            if not ifcfg_file:
                log.error("%s: %d for %s - no ifcfg file found",
                          self.name, number_of_connections, iface)
                continue
            else:
                # Handle only ifcfgs created from boot options in initramfs
                # (Kickstart based ifcfgs are handled when applying kickstart)
                if ifcfg_file.is_from_kickstart:
                    continue

            log.debug("%s: %d for %s - ensure active ifcfg connection",
                      self.name, number_of_connections, iface)

            ensure_active_connection_for_device(self._nm_client, ifcfg_file.uuid, iface, only_replace=True)

            consolidated_devices.append(iface)

        return consolidated_devices
Пример #5
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
Пример #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
Пример #7
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