Ejemplo n.º 1
0
    def run(self):
        if not self._nm_client:
            log.debug("%s: No NetworkManager available.", self.name)
            return None

        for iface in self._onboot_ifaces:
            con_uuid = find_ifcfg_uuid_of_device(self._nm_client, iface)
            if con_uuid:
                con = self._nm_client.get_connection_by_uuid(con_uuid)
                update_connection_values(
                    con,
                    [("connection", NM.SETTING_CONNECTION_AUTOCONNECT, True)])
                commit_changes_with_autoconnection_blocked(con)
            else:
                log.warning("Configure ONBOOT: can't find ifcfg for %s", iface)
Ejemplo n.º 2
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
Ejemplo n.º 3
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)

            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
Ejemplo n.º 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_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