Exemple #1
0
    def _set_onboot_to_yes(self, root, connection_uuids):
        """Set onboot value of config (ifcfg) files on target system.

        :param root: path to the root of the target system
        :type root: str
        :param connection_uuids: uuids of config files to be set
        :type connection_uuids: list(str)
        """
        for uuid in connection_uuids:
            update_onboot_value(uuid, True, root)
Exemple #2
0
    def _set_onboot_to_yes(self, root, connection_uuids):
        """Set onboot value of config (ifcfg) files on target system.

        :param root: path to the root of the target system
        :type root: str
        :param connection_uuids: uuids of config files to be set
        :type connection_uuids: list(str)
        """
        for uuid in connection_uuids:
            update_onboot_value(uuid, True, root)
Exemple #3
0
    def set_connection_onboot_value(self, uuid, onboot):
        """Sets ONBOOT value of connection given by uuid.

        The value is stored in ifcfg file because setting the value in
        NetworkManager connection ('autoconnect') to True could cause
        activating of the connection.

        :param uuid: UUID of the connection to be set
        :param onboot: value of ONBOOT for the connection
        """
        return update_onboot_value(uuid, onboot)
Exemple #4
0
    def set_connection_onboot_value(self, uuid, onboot):
        """Sets ONBOOT value of connection given by uuid.

        The value is stored in ifcfg file because setting the value in
        NetworkManager connection ('autoconnect') to True could cause
        activating of the connection.

        :param uuid: UUID of the connection to be set
        :param onboot: value of ONBOOT for the connection
        """
        return update_onboot_value(uuid, onboot)
Exemple #5
0
    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
Exemple #6
0
    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