Exemple #1
0
    def _configure_network_interface(self, data):
        devname = data
        ndata = network.ksdata_from_ifcfg(devname)
        if not ndata:
            # There is no ifcfg file for the device.
            # Make sure there is just one connection for the device.
            try:
                nm.nm_device_setting_value(devname, "connection", "uuid")
            except nm.SettingsNotFoundError:
                log.debug("can't find any connection for %s", devname)
                return
            except nm.MultipleSettingsFoundError:
                log.debug("multiple non-ifcfg connections found for %s",
                          devname)
                return

            log.debug("dumping ifcfg file for in-memory connection %s",
                      devname)
            nm.nm_update_settings_of_device(
                devname, [['connection', 'id', devname, None]])
            ndata = network.ksdata_from_ifcfg(devname)

        new_spoke = ConfigureNetworkSpoke(self.data, self.storage,
                                          self.payload, self.instclass, ndata)
        ScreenHandler.push_screen_modal(new_spoke)
        self.redraw()

        if ndata.ip == "dhcp":
            ndata.bootProto = "dhcp"
            ndata.ip = ""
        else:
            ndata.bootProto = "static"
            if not ndata.netmask:
                self.errors.append(
                    _("Configuration not saved: netmask missing in static configuration"
                      ))
                return

        if ndata.ipv6 == "ignore":
            ndata.noipv6 = True
            ndata.ipv6 = ""
        else:
            ndata.noipv6 = False

        uuid = network.update_settings_with_ksdata(devname, ndata)
        network.update_onboot_value(devname,
                                    ndata.onboot,
                                    ksdata=None,
                                    root_path="")
        network.logIfcfgFiles("settings of %s updated in tui" % devname)

        if new_spoke.apply_configuration:
            self._apply = True
            try:
                nm.nm_activate_device_connection(devname, uuid)
            except (nm.UnmanagedDeviceError, nm.UnknownConnectionError):
                self.errors.append(
                    _("Can't apply configuration, device activation failed."))

        self.apply()
Exemple #2
0
def apply_kickstart(ksdata):
    applied_devices = []

    for i, network_data in enumerate(ksdata.network.network):

        # TODO: wireless not supported yet
        if network_data.essid:
            continue

        dev_name = get_device_name(network_data)
        if not dev_name:
            log.warning("network: apply kickstart: --device %s does not exist", network_data.device)
            continue

        ifcfg_path = find_ifcfg_file_of_device(dev_name)
        if ifcfg_path:
            with open(ifcfg_path, 'r') as f:
                # If we have kickstart ifcfg from initramfs
                if "Generated by parse-kickstart" in f.read():
                    # and we should activate the device
                    if i == 0 or network_data.activate:
                        ifcfg = IfcfgFile(ifcfg_path)
                        ifcfg.read()
                        con_uuid = ifcfg.get("UUID")
                        # and the ifcfg had not been already applied to device by NM
                        if con_uuid != nm.nm_device_active_con_uuid(dev_name):
                            # apply it overriding configuration generated by NM
                            # taking over connection activated in initramfs
                            log.debug("network: kickstart - reactivating device %s with %s", dev_name, con_uuid)
                            try:
                                nm.nm_activate_device_connection(dev_name, con_uuid)
                            except nm.UnknownConnectionError:
                                log.warning("network: kickstart - can't activate connection %s on %s",
                                            con_uuid, dev_name)
                    continue

        # If we don't have kickstart ifcfg from initramfs the command was added
        # in %pre section after switch root, so apply it now
        applied_devices.append(dev_name)
        if ifcfg_path:
            # if the device was already configured in initramfs update the settings
            log.debug("network: pre kickstart - updating settings of device %s", dev_name)
            con_uuid = update_settings_with_ksdata(dev_name, network_data)
            added_connections = [(con_uuid, dev_name)]
        else:
            log.debug("network: pre kickstart - adding connection for %s", dev_name)
            # Virtual devices (eg vlan, bond) return dev_name == None
            added_connections = add_connection_for_ksdata(network_data, dev_name)

        if network_data.activate:
            for con_uuid, dev_name in added_connections:
                try:
                    nm.nm_activate_device_connection(dev_name, con_uuid)
                except nm.UnknownConnectionError:
                    log.warning("network: pre kickstart: can't activate connection %s on %s",
                               con_uuid, dev_name)
    return applied_devices
Exemple #3
0
    def input(self, args, key):
        """ Handle the input. """
        try:
            num = int(key)
        except ValueError:
            return key

        if num == 1:
            # set hostname
            self.app.switch_screen_modal(
                self.hostname_dialog,
                Entry(_("Hostname"), "hostname", re.compile(".*$"), True))
            self.apply()
            return INPUT_PROCESSED
        elif 2 <= num <= len(self.supported_devices) + 1:
            # configure device
            devname = self.supported_devices[num - 2]
            ndata = network.ksdata_from_ifcfg(devname)
            newspoke = ConfigureNetworkSpoke(self.app, self.data, self.storage,
                                             self.payload, self.instclass,
                                             ndata)
            self.app.switch_screen_modal(newspoke)

            if ndata.ip == "dhcp":
                ndata.bootProto = "dhcp"
                ndata.ip = ""
            else:
                ndata.bootProto = "static"
                if not ndata.gateway or not ndata.netmask:
                    self.errors.append(
                        _("Configuration not saved: gateway or netmask missing in static configuration"
                          ))
                    return INPUT_PROCESSED

            if ndata.ipv6 == "ignore":
                ndata.noipv6 = True
                ndata.ipv6 = ""
            else:
                ndata.noipv6 = False

            network.update_settings_with_ksdata(devname, ndata)

            if ndata._apply:
                uuid = nm.nm_device_setting_value(devname, "connection",
                                                  "uuid")
                try:
                    nm.nm_activate_device_connection(devname, uuid)
                except (nm.UnmanagedDeviceError, nm.UnknownConnectionError):
                    self.errors.append(
                        _("Can't apply configuration, device activation failed."
                          ))

            self.apply()
            return INPUT_PROCESSED
        else:
            return key
Exemple #4
0
    def _configure_network_interface(self, data):
        devname = data
        ndata = network.ksdata_from_ifcfg(devname)
        if not ndata:
            # There is no ifcfg file for the device.
            # Make sure there is just one connection for the device.
            try:
                nm.nm_device_setting_value(devname, "connection", "uuid")
            except nm.SettingsNotFoundError:
                log.debug("can't find any connection for %s", devname)
                return
            except nm.MultipleSettingsFoundError:
                log.debug("multiple non-ifcfg connections found for %s", devname)
                return

            log.debug("dumping ifcfg file for in-memory connection %s", devname)
            nm.nm_update_settings_of_device(devname, [['connection', 'id', devname, None]])
            ndata = network.ksdata_from_ifcfg(devname)

        new_spoke = ConfigureNetworkSpoke(self.data, self.storage,
                                          self.payload, self.instclass, ndata)
        ScreenHandler.push_screen_modal(new_spoke)
        self.redraw()

        if ndata.ip == "dhcp":
            ndata.bootProto = "dhcp"
            ndata.ip = ""
        else:
            ndata.bootProto = "static"
            if not ndata.netmask:
                self.errors.append(_("Configuration not saved: netmask missing in static configuration"))
                return

        if ndata.ipv6 == "ignore":
            ndata.noipv6 = True
            ndata.ipv6 = ""
        else:
            ndata.noipv6 = False

        uuid = network.update_settings_with_ksdata(devname, ndata)
        network.update_onboot_value(devname, ndata.onboot, ksdata=None, root_path="")
        network.logIfcfgFiles("settings of %s updated in tui" % devname)

        if ndata._apply:
            self._apply = True
            try:
                nm.nm_activate_device_connection(devname, uuid)
            except (nm.UnmanagedDeviceError, nm.UnknownConnectionError):
                self.errors.append(_("Can't apply configuration, device activation failed."))

        self.apply()
Exemple #5
0
    def input(self, args, key):
        """ Handle the input. """
        try:
            num = int(key)
        except ValueError:
            return key

        if num == 1:
            # set hostname
            self.app.switch_screen_modal(self.hostname_dialog, Entry(_("Host Name"),
                                "hostname", re.compile(".*$"), True))
            self.apply()
            return INPUT_PROCESSED
        elif 2 <= num <= len(self.supported_devices) + 1:
            # configure device
            devname = self.supported_devices[num-2]
            ndata = network.ksdata_from_ifcfg(devname)
            newspoke = ConfigureNetworkSpoke(self.app, self.data, self.storage,
                                    self.payload, self.instclass, ndata)
            self.app.switch_screen_modal(newspoke)

            if ndata.ip == "dhcp":
                ndata.bootProto = "dhcp"
                ndata.ip = ""
            else:
                ndata.bootProto = "static"
                if not ndata.gateway or not ndata.netmask:
                    self.errors.append(_("Configuration not saved: gateway or netmask missing in static configuration"))
                    return INPUT_PROCESSED

            if ndata.ipv6 == "ignore":
                ndata.noipv6 = True
                ndata.ipv6 = ""
            else:
                ndata.noipv6 = False

            network.update_settings_with_ksdata(devname, ndata)

            if ndata._apply:
                uuid = nm.nm_device_setting_value(devname, "connection", "uuid")
                try:
                    nm.nm_activate_device_connection(devname, uuid)
                except (nm.UnmanagedDeviceError, nm.UnknownConnectionError):
                    self.errors.append(_("Can't apply configuration, device activation failed."))

            self.apply()
            return INPUT_PROCESSED
        else:
            return key
def apply_kickstart_from_pre_section(ksdata):
    applied_devices = []

    for network_data in ksdata.network.network:

        # TODO: wireless not supported yet
        if network_data.essid:
            continue

        # get device name for device specified by MAC, link, bootif, etc...
        dev_name = ks_spec_to_device_name(network_data.device)
        if not dev_name:
            log.error(
                "Kickstart: The provided network interface %s does not exist",
                network_data.device)
            continue

        if network_data.vlanid:
            dev_name = "%s.%s" % (dev_name, network_data.vlanid)

        ifcfg_path = find_ifcfg_file_of_device(dev_name)
        # if the device was already configured in intramfs by kickstart ignore it
        if ifcfg_path:
            with open(ifcfg_path, 'r') as f:
                if "Generated by parse-kickstart" in f.read():
                    continue

        applied_devices.append(dev_name)
        if ifcfg_path:
            # if the device was already configured in initramfs update the settings
            log.debug(
                "network: pre kickstart - updating settings of device %s",
                dev_name)
            con_uuid = update_settings_with_ksdata(dev_name, network_data)
            added_connections = [(con_uuid, dev_name)]
        else:
            log.debug("network: pre kickstart - adding connection for %s",
                      dev_name)
            # Virtual devices (eg vlan, bond) return dev_name == None
            added_connections = add_connection_for_ksdata(
                network_data, dev_name)

        if network_data.activate:
            for con_uuid, dev_name in added_connections:
                nm.nm_activate_device_connection(dev_name, con_uuid)

    return applied_devices
Exemple #7
0
def apply_kickstart_from_pre_section(ksdata):
    applied_devices = []

    for network_data in ksdata.network.network:

        # TODO: wireless not supported yet
        if network_data.essid:
            continue

        dev_name = get_device_name(network_data)
        if not dev_name:
            log.warning("network: pre kickstart: --device %s does not exist",
                        network_data.device)
            continue

        ifcfg_path = find_ifcfg_file_of_device(dev_name)
        # if the device was already configured in intramfs by kickstart ignore it
        if ifcfg_path:
            with open(ifcfg_path, 'r') as f:
                if "Generated by parse-kickstart" in f.read():
                    continue

        applied_devices.append(dev_name)
        if ifcfg_path:
            # if the device was already configured in initramfs update the settings
            log.debug(
                "network: pre kickstart - updating settings of device %s",
                dev_name)
            con_uuid = update_settings_with_ksdata(dev_name, network_data)
            added_connections = [(con_uuid, dev_name)]
        else:
            log.debug("network: pre kickstart - adding connection for %s",
                      dev_name)
            # Virtual devices (eg vlan, bond) return dev_name == None
            added_connections = add_connection_for_ksdata(
                network_data, dev_name)

        if network_data.activate:
            for con_uuid, dev_name in added_connections:
                try:
                    nm.nm_activate_device_connection(dev_name, con_uuid)
                except nm.UnknownConnectionError:
                    log.warning(
                        "network: pre kickstart: can't activate connection %s on %s",
                        con_uuid, dev_name)
    return applied_devices
Exemple #8
0
def apply_kickstart_from_pre_section(ksdata):
    applied_devices = []

    for network_data in ksdata.network.network:

        # TODO: wireless not supported yet
        if network_data.essid:
            continue

        # get device name for device specified by MAC, link, bootif, etc...
        dev_name = ks_spec_to_device_name(network_data.device)
        if (not dev_name
            or (dev_name not in nm.nm_devices()
                and not network_data.vlanid
                and not network_data.bondslaves)):
            log.error("network: pre kickstart: --device %s does not exist", network_data.device)
            continue

        if network_data.vlanid:
            dev_name = "%s.%s" % (dev_name, network_data.vlanid)

        ifcfg_path = find_ifcfg_file_of_device(dev_name)
        # if the device was already configured in intramfs by kickstart ignore it
        if ifcfg_path:
            with open(ifcfg_path, 'r') as f:
                if "Generated by parse-kickstart" in f.read():
                    continue

        applied_devices.append(dev_name)
        if ifcfg_path:
            # if the device was already configured in initramfs update the settings
            log.debug("network: pre kickstart - updating settings of device %s", dev_name)
            con_uuid = update_settings_with_ksdata(dev_name, network_data)
            added_connections = [(con_uuid, dev_name)]
        else:
            log.debug("network: pre kickstart - adding connection for %s", dev_name)
            # Virtual devices (eg vlan, bond) return dev_name == None
            added_connections = add_connection_for_ksdata(network_data, dev_name)

        if network_data.activate:
            for con_uuid, dev_name in added_connections:
                nm.nm_activate_device_connection(dev_name, con_uuid)

    return applied_devices
Exemple #9
0
def apply_kickstart_from_pre_section(ksdata):
    applied_devices = []

    for network_data in ksdata.network.network:

        # TODO: wireless not supported yet
        if network_data.essid:
            continue

        dev_name = get_device_name(network_data)
        if not dev_name:
            log.warning("network: pre kickstart: --device %s does not exist", network_data.device)
            continue

        ifcfg_path = find_ifcfg_file_of_device(dev_name)
        # if the device was already configured in intramfs by kickstart ignore it
        if ifcfg_path:
            with open(ifcfg_path, 'r') as f:
                if "Generated by parse-kickstart" in f.read():
                    continue

        applied_devices.append(dev_name)
        if ifcfg_path:
            # if the device was already configured in initramfs update the settings
            log.debug("network: pre kickstart - updating settings of device %s", dev_name)
            con_uuid = update_settings_with_ksdata(dev_name, network_data)
            added_connections = [(con_uuid, dev_name)]
        else:
            log.debug("network: pre kickstart - adding connection for %s", dev_name)
            # Virtual devices (eg vlan, bond) return dev_name == None
            added_connections = add_connection_for_ksdata(network_data, dev_name)

        if network_data.activate:
            for con_uuid, dev_name in added_connections:
                try:
                    nm.nm_activate_device_connection(dev_name, con_uuid)
                except nm.UnknownConnectionError:
                    log.warning("network: pre kickstart: can't activate connection %s on %s",
                               con_uuid, dev_name)
    return applied_devices
Exemple #10
0
    def input(self, args, key):
        """ Handle the input. """
        try:
            num = int(key)
        except ValueError:
            return super(NetworkSpoke, self).input(args, key)

        if num == 1:
            # set hostname
            self.app.switch_screen_modal(self.hostname_dialog, Entry(_("Host Name"),
                                "hostname", re.compile(".*$"), True))
            self.apply()
            return INPUT_PROCESSED
        elif 2 <= num <= len(self.supported_devices) + 1:
            # configure device
            devname = self.supported_devices[num-2]
            ndata = network.ksdata_from_ifcfg(devname)
            if not ndata:
                try:
                    nm.nm_device_setting_value(devname, "connection", "uuid")
                except nm.SettingsNotFoundError:
                    pass
                else:
                    log.debug("network: dumping ifcfg file for in-memory connection %s", devname)
                    nm.nm_update_settings_of_device(devname, [['connection', 'id', devname, None]])
                    ndata = network.ksdata_from_ifcfg(devname)

            if not ndata:
                log.debug("network: can't find any connection for %s", devname)
                self.errors.append(_("Configuration of device not found"))
                return INPUT_PROCESSED

            newspoke = ConfigureNetworkSpoke(self.app, self.data, self.storage,
                                    self.payload, self.instclass, ndata)
            self.app.switch_screen_modal(newspoke)

            if ndata.ip == "dhcp":
                ndata.bootProto = "dhcp"
                ndata.ip = ""
            else:
                ndata.bootProto = "static"
                if not ndata.netmask:
                    self.errors.append(_("Configuration not saved: netmask missing in static configuration"))
                    return INPUT_PROCESSED

            if ndata.ipv6 == "ignore":
                ndata.noipv6 = True
                ndata.ipv6 = ""
            else:
                ndata.noipv6 = False

            network.update_settings_with_ksdata(devname, ndata)
            network.update_onboot_value(devname, ndata.onboot, ksdata=None, root_path="")

            if ndata._apply:
                self._apply = True
                uuid = nm.nm_device_setting_value(devname, "connection", "uuid")
                try:
                    nm.nm_activate_device_connection(devname, uuid)
                except (nm.UnmanagedDeviceError, nm.UnknownConnectionError):
                    self.errors.append(_("Can't apply configuration, device activation failed."))

            self.apply()
            return INPUT_PROCESSED
        else:
            return key
Exemple #11
0
    def input(self, args, key):
        """ Handle the input. """
        try:
            num = int(key)
        except ValueError:
            return super(NetworkSpoke, self).input(args, key)

        if num == 1:
            # set hostname
            self.app.switch_screen_modal(
                self.hostname_dialog,
                Entry(_("Host Name"), "hostname", re.compile(".*$"), True))
            self.apply()
            return INPUT_PROCESSED
        elif 2 <= num <= len(self.supported_devices) + 1:
            # configure device
            devname = self.supported_devices[num - 2]
            ndata = network.ksdata_from_ifcfg(devname)
            if not ndata:
                try:
                    nm.nm_device_setting_value(devname, "connection", "uuid")
                except nm.SettingsNotFoundError:
                    pass
                else:
                    log.debug(
                        "network: dumping ifcfg file for in-memory connection %s",
                        devname)
                    nm.nm_update_settings_of_device(
                        devname, [['connection', 'id', devname, None]])
                    ndata = network.ksdata_from_ifcfg(devname)

            if not ndata:
                log.debug("network: can't find any connection for %s", devname)
                self.errors.append(_("Configuration of device not found"))
                return INPUT_PROCESSED

            newspoke = ConfigureNetworkSpoke(self.app, self.data, self.storage,
                                             self.payload, self.instclass,
                                             ndata)
            self.app.switch_screen_modal(newspoke)

            if ndata.ip == "dhcp":
                ndata.bootProto = "dhcp"
                ndata.ip = ""
            else:
                ndata.bootProto = "static"
                if not ndata.netmask:
                    self.errors.append(
                        _("Configuration not saved: netmask missing in static configuration"
                          ))
                    return INPUT_PROCESSED

            if ndata.ipv6 == "ignore":
                ndata.noipv6 = True
                ndata.ipv6 = ""
            else:
                ndata.noipv6 = False

            network.update_settings_with_ksdata(devname, ndata)
            network.update_onboot_value(devname,
                                        ndata.onboot,
                                        ksdata=None,
                                        root_path="")

            if ndata._apply:
                self._apply = True
                uuid = nm.nm_device_setting_value(devname, "connection",
                                                  "uuid")
                try:
                    nm.nm_activate_device_connection(devname, uuid)
                except (nm.UnmanagedDeviceError, nm.UnknownConnectionError):
                    self.errors.append(
                        _("Can't apply configuration, device activation failed."
                          ))

            self.apply()
            return INPUT_PROCESSED
        else:
            return key
Exemple #12
0
def apply_kickstart(ksdata):
    applied_devices = []

    for i, network_data in enumerate(ksdata.network.network):

        # TODO: wireless not supported yet
        if network_data.essid:
            continue

        dev_name = get_device_name(network_data)
        if not dev_name:
            log.warning(
                "network: apply kickstart: --device %s does not exist" %
                network_data.device)
            continue

        ifcfg_path = find_ifcfg_file_of_device(dev_name)
        if ifcfg_path:
            with open(ifcfg_path, 'r') as f:
                # If we have kickstart ifcfg from initramfs
                if "Generated by parse-kickstart" in f.read():
                    # and we should activate the device
                    if i == 0 or network_data.activate:
                        ifcfg = IfcfgFile(ifcfg_path)
                        ifcfg.read()
                        con_uuid = ifcfg.get("UUID")
                        # and the ifcfg had not been already applied to device by NM
                        if con_uuid != nm.nm_device_active_con_uuid(dev_name):
                            # apply it overriding configuration generated by NM
                            # taking over connection activated in initramfs
                            log.debug(
                                "network: kickstart - reactivating device %s with %s"
                                % (dev_name, con_uuid))
                            try:
                                nm.nm_activate_device_connection(
                                    dev_name, con_uuid)
                            except nm.UnknownConnectionError:
                                log.warning(
                                    "network: pre kickstart: can't activate connection %s on %s"
                                    % (con_uuid, dev_name))
                    continue

        # If we don't have kickstart ifcfg from initramfs the command was added
        # in %pre section after switch root, so apply it now
        applied_devices.append(dev_name)
        if ifcfg_path:
            # if the device was already configured in initramfs update the settings
            log.debug(
                "network: pre kickstart - updating settings of device %s" %
                dev_name)
            con_uuid = update_settings_with_ksdata(dev_name, network_data)
            added_connections = [(con_uuid, dev_name)]
        else:
            log.debug("network: pre kickstart - adding connection for %s" %
                      dev_name)
            # Virtual devices (eg vlan, bond) return dev_name == None
            added_connections = add_connection_for_ksdata(
                network_data, dev_name)

        if network_data.activate:
            for con_uuid, dev_name in added_connections:
                try:
                    nm.nm_activate_device_connection(dev_name, con_uuid)
                except nm.UnknownConnectionError:
                    log.warning(
                        "network: pre kickstart: can't activate connection %s on %s"
                        % (con_uuid, dev_name))
    return applied_devices