예제 #1
0
def setOnboot(ksdata):
    updated_devices = []
    for network_data in ksdata.network.network:

        # vlan
        if network_data.vlanid:
            physdev = get_device_name(network_data.device) or network_data.device
            devname = "%s.%s" % (physdev, network_data.vlanid)
        # bond
        elif network_data.bondslaves:
            devname = network_data.device
        # team
        elif network_data.teamslaves:
            devname = network_data.device
        # ethernet
        else:
            devname = get_device_name(network_data.device)
            if not devname:
                log.warning("Kickstart: The provided network interface %s does not exist", network_data.device)
                continue

        updated_devices.append(devname)
        try:
            nm.nm_update_settings_of_device(devname, [["connection", "autoconnect", network_data.onboot, None]])
        except (nm.SettingsNotFoundError, nm.UnknownDeviceError) as e:
            log.debug("setOnboot: %s", e)
    return updated_devices
예제 #2
0
def setOnboot(ksdata):
    updated_devices = []
    for network_data in ksdata.network.network:

        # vlan
        if network_data.vlanid:
            physdev = get_device_name(
                network_data.device) or network_data.device
            devname = "%s.%s" % (physdev, network_data.vlanid)
        # bond
        elif network_data.bondslaves:
            devname = network_data.device
        # team
        elif network_data.teamslaves:
            devname = network_data.device
        # ethernet
        else:
            devname = get_device_name(network_data.device)
            if not devname:
                log.warning(
                    "Kickstart: The provided network interface %s does not exist",
                    network_data.device)
                continue

        updated_devices.append(devname)
        try:
            nm.nm_update_settings_of_device(
                devname,
                [['connection', 'autoconnect', network_data.onboot, None]])
        except (nm.SettingsNotFoundError, nm.UnknownDeviceError) as e:
            log.debug("setOnboot: %s", e)
    return updated_devices
예제 #3
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()
예제 #4
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 True if any ifcfg file was dumped.

    """
    rv = False

    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

        # if there is no ifcfg file for the device
        device_cfg = NetworkDevice(netscriptsDir, devname)
        if os.access(device_cfg.path, os.R_OK):
            continue

        try:
            nm.nm_update_settings_of_device(devname, 'connection', 'id', devname)
            log.debug("network: dumping ifcfg file for default autoconnection on %s" % devname)
            nm.nm_update_settings_of_device(devname, 'connection', 'autoconnect', False)
            log.debug("network: setting autoconnect of %s to False" % devname)
        except nm.DeviceSettingsNotFoundError as e:
            log.debug("network: no ifcfg file for %s" % devname)
        rv = True

    return rv
예제 #5
0
파일: network.py 프로젝트: mykntom/anaconda
def update_settings_with_ksdata(devname, networkdata):

    new_values = []

    # ipv4 settings
    method4 = "auto"
    if networkdata.bootProto == "static":
        method4 = "manual"
    new_values.append(["ipv4", "method", method4, "s"])

    if method4 == "manual":
        addr4 = nm.nm_ipv4_to_dbus_int(networkdata.ip)
        gateway4 = nm.nm_ipv4_to_dbus_int(networkdata.gateway)
        prefix4 = netmask2prefix(networkdata.netmask)
        new_values.append(
            ["ipv4", "addresses", [[addr4, prefix4, gateway4]], "aau"])

    # ipv6 settings
    if networkdata.noipv6:
        method6 = "ignore"
    else:
        if networkdata.ipv6 == "auto":
            method6 = "auto"
        elif networkdata.ipv6 == "dhcp":
            method6 = "dhcp"
        else:
            method6 = "manual"
    new_values.append(["ipv6", "method", method6, "s"])

    if method6 == "manual":
        addr6, _slash, prefix6 = networkdata.ipv6.partition("/")
        if prefix6:
            prefix6 = int(prefix6)
        else:
            prefix6 = 64
        addr6 = nm.nm_ipv6_to_dbus_ay(addr6)
        if networkdata.ipv6gateway:
            gateway6 = nm.nm_ipv6_to_dbus_ay(networkdata.ipv6gateway)
        else:
            gateway6 = [0] * 16
        new_values.append(
            ["ipv6", "addresses", [(addr6, prefix6, gateway6)], "a(ayuay)"])

    # nameservers
    nss4 = []
    nss6 = []
    if networkdata.nameserver:
        for ns in networkdata.nameserver.split(","):
            if ":" in ns:
                nss6.append(nm.nm_ipv6_to_dbus_ay(ns))
            else:
                nss4.append(nm.nm_ipv4_to_dbus_int(ns))
    new_values.append(["ipv4", "dns", nss4, "au"])
    new_values.append(["ipv6", "dns", nss6, "aay"])

    # onboot
    new_values.append(['connection', 'autoconnect', networkdata.onboot, None])

    nm.nm_update_settings_of_device(devname, new_values)
예제 #6
0
파일: network.py 프로젝트: Sabayon/anaconda
def update_settings_with_ksdata(devname, networkdata):

    new_values = []

    # ipv4 settings
    method4 = "auto"
    if networkdata.bootProto == "static":
        method4 = "manual"
    new_values.append(["ipv4", "method", method4, "s"])

    if method4 == "manual":
        addr4 = nm.nm_ipv4_to_dbus_int(networkdata.ip)
        gateway4 = nm.nm_ipv4_to_dbus_int(networkdata.gateway)
        prefix4 = netmask2prefix(networkdata.netmask)
        new_values.append(["ipv4", "addresses", [[addr4, prefix4, gateway4]], "aau"])

    # ipv6 settings
    if networkdata.noipv6:
        method6 = "ignore"
    else:
        if networkdata.ipv6 == "auto":
            method6 = "auto"
        elif networkdata.ipv6 == "dhcp":
            method6 = "dhcp"
        else:
            method6 = "manual"
    new_values.append(["ipv6", "method", method6, "s"])

    if method6 == "manual":
        addr6, _slash, prefix6 = networkdata.ipv6.partition("/")
        if prefix6:
            prefix6 = int(prefix6)
        else:
            prefix6 = 64
        addr6 = nm.nm_ipv6_to_dbus_ay(addr6)
        if networkdata.ipv6gateway:
            gateway6 = nm.nm_ipv6_to_dbus_ay(networkdata.ipv6gateway)
        else:
            gateway6 = [0] * 16
        new_values.append(["ipv6", "addresses", [(addr6, prefix6, gateway6)], "a(ayuay)"])

    # nameservers
    nss4 = []
    nss6 = []
    if networkdata.nameserver:
        for ns in networkdata.nameserver.split(","):
            if ":" in ns:
                nss6.append(nm.nm_ipv6_to_dbus_ay(ns))
            else:
                nss4.append(nm.nm_ipv4_to_dbus_int(ns))
    new_values.append(["ipv4", "dns", nss4, "au"])
    new_values.append(["ipv6", "dns", nss6, "aay"])

    # onboot
    new_values.append(['connection', 'autoconnect', networkdata.onboot, None])

    nm.nm_update_settings_of_device(devname, new_values)
예제 #7
0
파일: network.py 프로젝트: Sabayon/anaconda
def setOnboot(ksdata):
    for network_data in ksdata.network.network:

        devname = get_device_name(network_data.device)
        if not devname:
            log.error("Kickstart: The provided network interface %s does not exist", network_data.device)
            continue

        try:
            nm.nm_update_settings_of_device(devname, [['connection', 'autoconnect', network_data.onboot, None]])
            ifcfglog.debug("setting autoconnect (ONBOOT) of %s to %s" , devname, network_data.onboot)
        except nm.DeviceSettingsNotFoundError as e:
            log.debug("setOnboot: %s", e)
예제 #8
0
파일: network.py 프로젝트: jaymzh/anaconda
    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()
예제 #9
0
def setOnboot(ksdata):
    updated_devices = []
    for network_data in ksdata.network.network:

        devname = get_device_name(network_data)
        if not devname:
            log.warning("network: set ONBOOT: --device %s does not exist", network_data.device)
            continue

        updated_devices.append(devname)
        try:
            nm.nm_update_settings_of_device(devname, [['connection', 'autoconnect', network_data.onboot, None]])
        except (nm.SettingsNotFoundError, nm.UnknownDeviceError) as e:
            log.debug("setOnboot: %s", e)
    return updated_devices
예제 #10
0
파일: network.py 프로젝트: mykntom/anaconda
def setOnboot(ksdata):
    for network_data in ksdata.network.network:

        devname = get_device_name(network_data.device)
        if not devname:
            log.error(
                "Kickstart: The provided network interface %s does not exist",
                network_data.device)
            continue

        try:
            nm.nm_update_settings_of_device(
                devname,
                [['connection', 'autoconnect', network_data.onboot, None]])
            ifcfglog.debug("setting autoconnect (ONBOOT) of %s to %s", devname,
                           network_data.onboot)
        except nm.DeviceSettingsNotFoundError as e:
            log.debug("setOnboot: %s", e)
예제 #11
0
def setOnboot(ksdata):
    updated_devices = []
    for network_data in ksdata.network.network:

        devname = get_device_name(network_data)
        if not devname:
            log.warning("network: set ONBOOT: --device %s does not exist",
                        network_data.device)
            continue

        updated_devices.append(devname)
        try:
            nm.nm_update_settings_of_device(
                devname,
                [['connection', 'autoconnect', network_data.onboot, None]])
        except (nm.SettingsNotFoundError, nm.UnknownDeviceError) as e:
            log.debug("setOnboot: %s", e)
    return updated_devices
예제 #12
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:
            con_uuid = 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
예제 #13
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:
            con_uuid = 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
예제 #14
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)
            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.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
예제 #15
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
예제 #16
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:
                # There is no ifcfg file for the device.
                # Make sure there is just one connection for the device.
                try:
                    uuid = nm.nm_device_setting_value(devname, "connection", "uuid")
                except nm.SettingsNotFoundError:
                    log.debug("can't find any connection for %s", devname)
                    return INPUT_PROCESSED
                except nm.MultipleSettingsFoundError:
                    log.debug("multiple non-ifcfg connections found for %s, using %s", devname, uuid)
                    return INPUT_PROCESSED

                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)

            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

            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()
            return INPUT_PROCESSED
        else:
            return key
예제 #17
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
예제 #18
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