Exemplo n.º 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()
Exemplo n.º 2
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()
Exemplo n.º 3
0
    def setNetworkOnbootDefault(self, ksdata):
        # if there is no device to be autoactivated after reboot
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                onboot = nm.nm_device_setting_value(devName, "connection",
                                                    "autoconnect")
            except nm.SettingsNotFoundError:
                continue
            if not onboot == False:
                return

        # set ONBOOT=yes for the device used during installation
        # (ie for majority of cases the one having the default route)
        devName = network.default_route_device()
        if not devName:
            return
        if nm.nm_device_type_is_wifi(devName):
            return
        ifcfg_path = network.find_ifcfg_file_of_device(devName,
                                                       root_path=ROOT_PATH)
        if not ifcfg_path:
            return
        ifcfg = network.IfcfgFile(ifcfg_path)
        ifcfg.read()
        ifcfg.set(('ONBOOT', 'yes'))
        ifcfg.write()
        for nd in ksdata.network.network:
            if nd.device == devName:
                nd.onboot = True
                break
Exemplo n.º 4
0
    def setNetworkOnbootDefault(self, ksdata):
        # if something's already enabled, we can just leave the config alone
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                onboot = nm.nm_device_setting_value(devName, "connection", "autoconnect")
            except nm.SettingsNotFoundError:
                continue
            if not onboot == False:
                return

        # the default otherwise: bring up the first wired netdev with link
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                link_up = nm.nm_device_carrier(devName)
            except ValueError:
                continue
            if link_up:
                ifcfg_path = network.find_ifcfg_file_of_device(devName, root_path=ROOT_PATH)
                if not ifcfg_path:
                    continue
                ifcfg = network.IfcfgFile(ifcfg_path)
                ifcfg.read()
                ifcfg.set(('ONBOOT', 'yes'))
                ifcfg.write()
                for nd in ksdata.network.network:
                    if nd.device == devName:
                        nd.onboot = True
                        break
                break
Exemplo n.º 5
0
    def setNetworkOnbootDefault(self, ksdata):
        # if something's already enabled, we can just leave the config alone
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                onboot = nm.nm_device_setting_value(devName, "connection",
                                                    "autoconnect")
            except nm.DeviceSettingsNotFoundError:
                continue
            if not onboot == False:
                return

        # the default otherwise: bring up the first wired netdev with link
        for devName in nm.nm_devices():
            if nm.nm_device_type_is_wifi(devName):
                continue
            try:
                link_up = nm.nm_device_carrier(devName)
            except ValueError:
                continue
            if link_up:
                ifcfg_path = network.find_ifcfg_file_of_device(
                    devName, root_path=ROOT_PATH)
                if not ifcfg_path:
                    continue
                ifcfg = network.IfcfgFile(ifcfg_path)
                ifcfg.read()
                ifcfg.set(('ONBOOT', 'yes'))
                ifcfg.write()
                for nd in ksdata.network.network:
                    if nd.device == devName:
                        nd.onboot = True
                        break
                break
Exemplo n.º 6
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
Exemplo n.º 7
0
def disableIPV6(rootpath):
    cfgfile = os.path.normpath(rootpath + ipv6ConfFile)
    if ('noipv6' in flags.cmdline and all(
            nm.nm_device_setting_value(dev, "ipv6", "method") == "ignore"
            for dev in nm.nm_devices() if nm.nm_device_type_is_ethernet(dev))):
        log.info('Disabling ipv6 on target system')
        with open(cfgfile, "a") as f:
            f.write("# Anaconda disabling ipv6 (noipv6 option)\n")
            f.write("net.ipv6.conf.all.disable_ipv6=1\n")
            f.write("net.ipv6.conf.default.disable_ipv6=1\n")
Exemplo n.º 8
0
def disableIPV6(rootpath):
    cfgfile = os.path.normpath(rootpath + ipv6ConfFile)
    if ('noipv6' in flags.cmdline
        and all(nm.nm_device_setting_value(dev, "ipv6", "method") == "ignore"
                for dev in nm.nm_devices() if nm.nm_device_type_is_ethernet(dev))):
        log.info('Disabling ipv6 on target system')
        with open(cfgfile, "a") as f:
            f.write("# Anaconda disabling ipv6 (noipv6 option)\n")
            f.write("net.ipv6.conf.all.disable_ipv6=1\n")
            f.write("net.ipv6.conf.default.disable_ipv6=1\n")
Exemplo n.º 9
0
    def initialize(self):
        for name in nm_devices():
            if nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)

        EditTUISpoke.initialize(self)
        if not self.data.network.seen:
            self._update_network_data()
Exemplo n.º 10
0
    def initialize(self):
        for name in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm.nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)

        EditTUISpoke.initialize(self)
        if not self.data.network.seen:
            self._update_network_data()
Exemplo n.º 11
0
def dumpMissingDefaultIfcfgs():
    """
    Dump missing default ifcfg file for wired devices.
    For default auto connections created by NM upon start - which happens
    in case of missing ifcfg file - rename the connection using device name
    and dump its ifcfg file. (For server, default auto connections will
    be turned off in NetworkManager.conf.)
    The connection id (and consequently ifcfg file) is set to device name.
    Returns list of devices for which ifcfg file was dumped.

    """
    rv = []

    for devname in nm.nm_devices():
        # for each ethernet device
        # FIXME add more types (infiniband, bond...?)
        if not nm.nm_device_type_is_ethernet(devname):
            continue

        # check that device has connection without ifcfg file
        try:
            nm.nm_device_setting_value(devname, "connection", "uuid")
        except nm.SettingsNotFoundError:
            continue
        if find_ifcfg_file_of_device(devname):
            continue

        try:
            nm.nm_update_settings_of_device(
                devname, [['connection', 'id', devname, None]])
            log.debug(
                "network: dumping ifcfg file for default autoconnection on %s",
                devname)
            nm.nm_update_settings_of_device(
                devname, [['connection', 'autoconnect', False, None]])
            log.debug("network: setting autoconnect of %s to False", devname)
        except nm.SettingsNotFoundError:
            log.debug("network: no ifcfg file for %s", devname)
        rv.append(devname)

    return rv
Exemplo n.º 12
0
    def _load_new_devices(self):
        devices = nm.nm_devices()
        intf_dumped = network.dumpMissingDefaultIfcfgs()
        if intf_dumped:
            log.debug("Dumped interfaces: %s", intf_dumped)

        for name in devices:
            if name in self.supported_devices:
                continue
            if nm.nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm.nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)
Exemplo n.º 13
0
    def _load_new_devices(self):
        devices = nm.nm_devices()
        intf_dumped = network.dumpMissingDefaultIfcfgs()
        if intf_dumped:
            log.debug("Dumped interfaces: %s", intf_dumped)

        for name in devices:
            if name in self.supported_devices:
                continue
            if nm.nm_device_type_is_ethernet(name):
                # ignore slaves
                if nm.nm_device_setting_value(name, "connection", "slave-type"):
                    continue
                self.supported_devices.append(name)
Exemplo n.º 14
0
def dumpMissingDefaultIfcfgs():
    """
    Dump missing default ifcfg file for wired devices.
    For default auto connections created by NM upon start - which happens
    in case of missing ifcfg file - rename the connection using device name
    and dump its ifcfg file. (For server, default auto connections will
    be turned off in NetworkManager.conf.)
    The connection id (and consequently ifcfg file) is set to device name.
    Returns list of devices for which ifcfg file was dumped.

    """
    rv = []

    for devname in nm.nm_devices():
        # for each ethernet device
        # FIXME add more types (infiniband, bond...?)
        if not nm.nm_device_type_is_ethernet(devname):
            continue

        # check that device has connection without ifcfg file
        try:
            nm.nm_device_setting_value(devname, "connection", "uuid")
        except nm.SettingsNotFoundError:
            continue
        if find_ifcfg_file_of_device(devname):
            continue

        try:
            nm.nm_update_settings_of_device(devname, [['connection', 'id', devname, None]])
            log.debug("network: dumping ifcfg file for default autoconnection on %s", devname)
            nm.nm_update_settings_of_device(devname, [['connection', 'autoconnect', False, None]])
            log.debug("network: setting autoconnect of %s to False" , devname)
        except nm.SettingsNotFoundError:
            log.debug("network: no ifcfg file for %s", devname)
        rv.append(devname)

    return rv
Exemplo n.º 15
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
Exemplo n.º 16
0
    def _load_new_devices(self):
        devices = nm.nm_devices()
        intf_dumped = network.dumpMissingDefaultIfcfgs()
        if intf_dumped:
            log.debug("dumped interfaces: %s", intf_dumped)

        for name in devices:
            if name in self.supported_devices:
                continue
            if network.is_ibft_configured_device(name):
                continue
            if network.device_type_is_supported_wired(name):
                # ignore slaves
                try:
                    if nm.nm_device_setting_value(name, "connection", "slave-type"):
                        continue
                except nm.MultipleSettingsFoundError as e:
                    log.debug("%s during initialization", e)
                self.supported_devices.append(name)
Exemplo n.º 17
0
    def _load_new_devices(self):
        devices = nm.nm_devices()
        intf_dumped = network.dumpMissingDefaultIfcfgs()
        if intf_dumped:
            log.debug("dumped interfaces: %s", intf_dumped)

        for name in devices:
            if name in self.supported_devices:
                continue
            if network.is_ibft_configured_device(name):
                continue
            if network.device_type_is_supported_wired(name):
                # ignore slaves
                try:
                    if nm.nm_device_setting_value(name, "connection", "slave-type"):
                        continue
                except nm.MultipleSettingsFoundError as e:
                    log.debug("%s during initialization", e)
                self.supported_devices.append(name)
Exemplo n.º 18
0
def dumpMissingDefaultIfcfgs():
    """
    Dump missing default ifcfg file for wired devices.
    Returns list of devices for which ifcfg file was dumped.
    """
    rv = []

    for devname in nm.nm_devices():
        if not nm.nm_device_type_is_ethernet(devname):
            continue

        try:
            con_uuid = nm.nm_device_setting_value(devname, "connection",
                                                  "uuid")
        except nm.SettingsNotFoundError:
            if find_ifcfg_file_of_device(devname):
                continue
            from pyanaconda.kickstart import AnacondaKSHandler
            handler = AnacondaKSHandler()
            network_data = handler.NetworkData(onboot=False, ipv6="auto")
            add_connection_for_ksdata(network_data, devname)
            rv.append(devname)

    return rv
Exemplo n.º 19
0
def status_message():
    """ A short string describing which devices are connected. """

    msg = _("Unknown")

    state = nm.nm_state()
    if state == NetworkManager.State.CONNECTING:
        msg = _("Connecting...")
    elif state == NetworkManager.State.DISCONNECTING:
        msg = _("Disconnecting...")
    else:
        active_devs = nm.nm_activated_devices()
        if active_devs:

            slaves = {}
            ssids = {}

            # first find slaves and wireless aps
            for devname in active_devs:
                slaves[devname] = nm.nm_device_slaves(devname) or []
                if nm.nm_device_type_is_wifi(devname):
                    ssids[devname] = nm.nm_device_active_ssid(devname) or ""

            all_slaves = set(itertools.chain.from_iterable(slaves.values()))
            nonslaves = [dev for dev in active_devs if dev not in all_slaves]

            if len(nonslaves) == 1:
                devname = nonslaves[0]
                if nm.nm_device_type_is_ethernet(devname):
                    msg = _("Wired (%(interface_name)s) connected") % {"interface_name": devname}
                elif nm.nm_device_type_is_wifi(devname):
                    msg = _("Wireless connected to %(access_point)s") % {"access_point": ssids[devname]}
                elif nm.nm_device_type_is_bond(devname):
                    msg = _("Bond %(interface_name)s (%(list_of_slaves)s) connected") % {
                        "interface_name": devname,
                        "list_of_slaves": ",".join(slaves[devname]),
                    }
                elif nm.nm_device_type_is_team(devname):
                    msg = _("Team%(interface_name)s (%(list_of_slaves)s) connected") % {
                        "interface_name": devname,
                        "list_of_slaves": ",".join(slaves[devname]),
                    }
                elif nm.nm_device_type_is_vlan(devname):
                    parent = nm.nm_device_setting_value(devname, "vlan", "parent")
                    vlanid = nm.nm_device_setting_value(devname, "vlan", "id")
                    msg = _("Vlan %(interface_name)s (%(parent_device)s, ID %(vlanid)s) connected") % {
                        "interface_name": devname,
                        "parent_device": parent,
                        "vlanid": vlanid,
                    }
            elif len(nonslaves) > 1:
                devlist = []
                for devname in nonslaves:
                    if nm.nm_device_type_is_ethernet(devname):
                        devlist.append("%s" % devname)
                    elif nm.nm_device_type_is_wifi(devname):
                        devlist.append("%s" % ssids[devname])
                    elif nm.nm_device_type_is_bond(devname):
                        devlist.append("%s (%s)" % (devname, ",".join(slaves[devname])))
                    elif nm.nm_device_type_is_team(devname):
                        devlist.append("%s (%s)" % (devname, ",".join(slaves[devname])))
                    elif nm.nm_device_type_is_vlan(devname):
                        devlist.append("%s" % devname)
                msg = _("Connected: %(list_of_interface_names)s") % {"list_of_interface_names": ", ".join(devlist)}
        else:
            msg = _("Not connected")

    if not nm.nm_devices():
        msg = _("No network devices available")

    return msg
Exemplo n.º 20
0
def status_message():
    """ A short string describing which devices are connected. """

    msg = _("Unknown")

    state = nm.nm_state()
    if state == NetworkManager.State.CONNECTING:
        msg = _("Connecting...")
    elif state == NetworkManager.State.DISCONNECTING:
        msg = _("Disconnecting...")
    else:
        active_devs = nm.nm_activated_devices()
        if active_devs:

            slaves = {}
            ssids = {}

            # first find slaves and wireless aps
            for devname in active_devs:
                slaves[devname] = nm.nm_device_slaves(devname) or []
                if nm.nm_device_type_is_wifi(devname):
                    ssids[devname] = nm.nm_device_active_ssid(devname) or ""

            all_slaves = set(itertools.chain.from_iterable(slaves.values()))
            nonslaves = [dev for dev in active_devs if dev not in all_slaves]

            if len(nonslaves) == 1:
                devname = nonslaves[0]
                if nm.nm_device_type_is_ethernet(devname):
                    msg = _("Wired (%(interface_name)s) connected") \
                          % {"interface_name": devname}
                elif nm.nm_device_type_is_wifi(devname):
                    msg = _("Wireless connected to %(access_point)s") \
                          % {"access_point" : ssids[devname]}
                elif nm.nm_device_type_is_bond(devname):
                    msg = _("Bond %(interface_name)s (%(list_of_slaves)s) connected") \
                          % {"interface_name": devname, \
                             "list_of_slaves": ",".join(slaves[devname])}
                elif nm.nm_device_type_is_team(devname):
                    msg = _("Team%(interface_name)s (%(list_of_slaves)s) connected") \
                          % {"interface_name": devname, \
                             "list_of_slaves": ",".join(slaves[devname])}
                elif nm.nm_device_type_is_vlan(devname):
                    parent = nm.nm_device_setting_value(
                        devname, "vlan", "parent")
                    vlanid = nm.nm_device_setting_value(devname, "vlan", "id")
                    msg = _("Vlan %(interface_name)s (%(parent_device)s, ID %(vlanid)s) connected") \
                          % {"interface_name": devname, "parent_device": parent, "vlanid": vlanid}
            elif len(nonslaves) > 1:
                devlist = []
                for devname in nonslaves:
                    if nm.nm_device_type_is_ethernet(devname):
                        devlist.append("%s" % devname)
                    elif nm.nm_device_type_is_wifi(devname):
                        devlist.append("%s" % ssids[devname])
                    elif nm.nm_device_type_is_bond(devname):
                        devlist.append("%s (%s)" %
                                       (devname, ",".join(slaves[devname])))
                    elif nm.nm_device_type_is_team(devname):
                        devlist.append("%s (%s)" %
                                       (devname, ",".join(slaves[devname])))
                    elif nm.nm_device_type_is_vlan(devname):
                        devlist.append("%s" % devname)
                msg = _("Connected: %(list_of_interface_names)s") \
                      % {"list_of_interface_names": ", ".join(devlist)}
        else:
            msg = _("Not connected")

    if not nm.nm_devices():
        msg = _("No network devices available")

    return msg
Exemplo n.º 21
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
Exemplo n.º 22
0
def update_settings_with_ksdata(devname, networkdata):
    new_values = _get_ip_setting_values_from_ksdata(networkdata)
    new_values.append(['connection', 'autoconnect', networkdata.onboot, None])
    uuid = nm.nm_device_setting_value(devname, "connection", "uuid")
    nm.nm_update_settings_of_device(devname, new_values)
    return uuid
Exemplo n.º 23
0
def ifcfg_to_ksdata(ifcfg, devname):

    from pyanaconda.kickstart import AnacondaKSHandler

    handler = AnacondaKSHandler()
    kwargs = {}

    # no network command for bond slaves
    if ifcfg.get("MASTER"):
        return None
    # no network command for team slaves
    if ifcfg.get("TEAM_MASTER"):
        return None

    # ipv4 and ipv6
    if ifcfg.get("ONBOOT") and ifcfg.get("ONBOOT") == "no":
        kwargs["onboot"] = False
    if ifcfg.get("MTU") and ifcfg.get("MTU") != "0":
        kwargs["mtu"] = ifcfg.get("MTU")
    # ipv4
    if not ifcfg.get("BOOTPROTO"):
        kwargs["noipv4"] = True
    else:
        if iutil.lowerASCII(ifcfg.get("BOOTPROTO")) == "dhcp":
            kwargs["bootProto"] = "dhcp"
            if ifcfg.get("DHCPCLASS"):
                kwargs["dhcpclass"] = ifcfg.get("DHCPCLASS")
        elif ifcfg.get("IPADDR"):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get("IPADDR")
            netmask = ifcfg.get("NETMASK")
            prefix = ifcfg.get("PREFIX")
            if not netmask and prefix:
                netmask = prefix2netmask(int(prefix))
            if netmask:
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get("GATEWAY"):
                kwargs["gateway"] = ifcfg.get("GATEWAY")
        elif ifcfg.get("IPADDR0"):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get("IPADDR0")
            prefix = ifcfg.get("PREFIX0")
            if prefix:
                netmask = prefix2netmask(int(prefix))
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get("GATEWAY0"):
                kwargs["gateway"] = ifcfg.get("GATEWAY0")

    # ipv6
    if not ifcfg.get("IPV6INIT") or ifcfg.get("IPV6INIT") == "no":
        kwargs["noipv6"] = True
    else:
        if ifcfg.get("IPV6_AUTOCONF") in ("yes", ""):
            kwargs["ipv6"] = "auto"
        else:
            if ifcfg.get("IPV6ADDR"):
                kwargs["ipv6"] = ifcfg.get("IPV6ADDR")
                if ifcfg.get("IPV6_DEFAULTGW") and ifcfg.get("IPV6_DEFAULTGW") != "::":
                    kwargs["ipv6gateway"] = ifcfg.get("IPV6_DEFAULTGW")
            if ifcfg.get("DHCPV6C") == "yes":
                kwargs["ipv6"] = "dhcp"

    # ipv4 and ipv6
    dnsline = ""
    for key in ifcfg.info.keys():
        if iutil.upperASCII(key).startswith("DNS"):
            if dnsline == "":
                dnsline = ifcfg.get(key)
            else:
                dnsline += "," + ifcfg.get(key)
    if dnsline:
        kwargs["nameserver"] = dnsline

    if ifcfg.get("ETHTOOL_OPTS"):
        kwargs["ethtool"] = ifcfg.get("ETHTOOL_OPTS")

    if ifcfg.get("ESSID"):
        kwargs["essid"] = ifcfg.get("ESSID")

    # hostname
    if ifcfg.get("DHCP_HOSTNAME"):
        kwargs["hostname"] = ifcfg.get("DHCP_HOSTNAME")

    # bonding
    # FIXME: dracut has only BOND_OPTS
    if ifcfg.get("BONDING_MASTER") == "yes" or ifcfg.get("TYPE") == "Bond":
        slaves = get_bond_slaves_from_ifcfgs([devname, ifcfg.get("UUID")])
        if slaves:
            kwargs["bondslaves"] = ",".join(slaves)
        bondopts = ifcfg.get("BONDING_OPTS")
        if bondopts:
            sep = ","
            if sep in bondopts:
                sep = ";"
            kwargs["bondopts"] = sep.join(bondopts.split())

    # vlan
    if ifcfg.get("VLAN") == "yes" or ifcfg.get("TYPE") == "Vlan":
        kwargs["device"] = ifcfg.get("PHYSDEV")
        kwargs["vlanid"] = ifcfg.get("VLAN_ID")

    # pylint: disable-msg=E1101
    nd = handler.NetworkData(**kwargs)

    # teaming
    if ifcfg.get("TYPE") == "Team" or ifcfg.get("DEVICETYPE") == "Team":
        slaves = get_team_slaves([devname, ifcfg.get("UUID")])
        for dev, cfg in slaves:
            nd.teamslaves.append((dev, cfg))

        teamconfig = nm.nm_device_setting_value(devname, "team", "config")
        if teamconfig:
            nd.teamconfig = teamconfig

    return nd
Exemplo n.º 24
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
Exemplo n.º 25
0
def ifcfg_to_ksdata(ifcfg, devname):

    from pyanaconda.kickstart import AnacondaKSHandler
    handler = AnacondaKSHandler()
    kwargs = {}

    # no network command for bond slaves
    if ifcfg.get("MASTER"):
        return None
    # no network command for team slaves
    if ifcfg.get("TEAM_MASTER"):
        return None

    # ipv4 and ipv6
    if ifcfg.get("ONBOOT") and ifcfg.get("ONBOOT") == "no":
        kwargs["onboot"] = False
    if ifcfg.get('MTU') and ifcfg.get('MTU') != "0":
        kwargs["mtu"] = ifcfg.get('MTU')
    # ipv4
    if not ifcfg.get('BOOTPROTO'):
        kwargs["noipv4"] = True
    else:
        if iutil.lowerASCII(ifcfg.get('BOOTPROTO')) == 'dhcp':
            kwargs["bootProto"] = "dhcp"
            if ifcfg.get('DHCPCLASS'):
                kwargs["dhcpclass"] = ifcfg.get('DHCPCLASS')
        elif ifcfg.get('IPADDR'):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get('IPADDR')
            netmask = ifcfg.get('NETMASK')
            prefix = ifcfg.get('PREFIX')
            if not netmask and prefix:
                netmask = prefix2netmask(int(prefix))
            if netmask:
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get('GATEWAY'):
                kwargs["gateway"] = ifcfg.get('GATEWAY')
        elif ifcfg.get('IPADDR0'):
            kwargs["bootProto"] = "static"
            kwargs["ip"] = ifcfg.get('IPADDR0')
            prefix = ifcfg.get('PREFIX0')
            if prefix:
                netmask = prefix2netmask(int(prefix))
                kwargs["netmask"] = netmask
            # note that --gateway is common for ipv4 and ipv6
            if ifcfg.get('GATEWAY0'):
                kwargs["gateway"] = ifcfg.get('GATEWAY0')

    # ipv6
    if (not ifcfg.get('IPV6INIT') or ifcfg.get('IPV6INIT') == "no"):
        kwargs["noipv6"] = True
    else:
        if ifcfg.get('IPV6_AUTOCONF') in ("yes", ""):
            kwargs["ipv6"] = "auto"
        else:
            if ifcfg.get('IPV6ADDR'):
                kwargs["ipv6"] = ifcfg.get('IPV6ADDR')
                if ifcfg.get('IPV6_DEFAULTGW') \
                   and ifcfg.get('IPV6_DEFAULTGW') != "::":
                    kwargs["ipv6gateway"] = ifcfg.get('IPV6_DEFAULTGW')
            if ifcfg.get('DHCPV6C') == "yes":
                kwargs["ipv6"] = "dhcp"

    # ipv4 and ipv6
    dnsline = ''
    for key in ifcfg.info.keys():
        if iutil.upperASCII(key).startswith('DNS'):
            if dnsline == '':
                dnsline = ifcfg.get(key)
            else:
                dnsline += "," + ifcfg.get(key)
    if dnsline:
        kwargs["nameserver"] = dnsline

    if ifcfg.get("ETHTOOL_OPTS"):
        kwargs["ethtool"] = ifcfg.get("ETHTOOL_OPTS")

    if ifcfg.get("ESSID"):
        kwargs["essid"] = ifcfg.get("ESSID")

    # hostname
    if ifcfg.get("DHCP_HOSTNAME"):
        kwargs["hostname"] = ifcfg.get("DHCP_HOSTNAME")

    # bonding
    # FIXME: dracut has only BOND_OPTS
    if ifcfg.get("BONDING_MASTER") == "yes" or ifcfg.get("TYPE") == "Bond":
        slaves = get_bond_slaves_from_ifcfgs([devname, ifcfg.get("UUID")])
        if slaves:
            kwargs["bondslaves"] = ",".join(slaves)
        bondopts = ifcfg.get("BONDING_OPTS")
        if bondopts:
            sep = ","
            if sep in bondopts:
                sep = ";"
            kwargs["bondopts"] = sep.join(bondopts.split())

    # vlan
    if ifcfg.get("VLAN") == "yes" or ifcfg.get("TYPE") == "Vlan":
        kwargs["device"] = ifcfg.get("PHYSDEV")
        kwargs["vlanid"] = ifcfg.get("VLAN_ID")

    # pylint: disable-msg=E1101
    nd = handler.NetworkData(**kwargs)

    # teaming
    if ifcfg.get("TYPE") == "Team" or ifcfg.get("DEVICETYPE") == "Team":
        slaves = get_team_slaves([devname, ifcfg.get("UUID")])
        for dev, cfg in slaves:
            nd.teamslaves.append((dev, cfg))

        teamconfig = nm.nm_device_setting_value(devname, "team", "config")
        if teamconfig:
            nd.teamconfig = teamconfig

    return nd
Exemplo n.º 26
0
def update_settings_with_ksdata(devname, networkdata):
    new_values = _get_ip_setting_values_from_ksdata(networkdata)
    new_values.append(["connection", "autoconnect", networkdata.onboot, None])
    uuid = nm.nm_device_setting_value(devname, "connection", "uuid")
    nm.nm_update_settings_of_device(devname, new_values)
    return uuid