Exemplo n.º 1
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.º 2
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.º 3
0
    def setNetworkOnbootDefault(self, ksdata):
        # if something's already enabled, we can just leave the config alone
        for devName in nm.nm_devices():
            if not nm.nm_device_type_is_wifi(devName) and \
               network.get_ifcfg_value(devName, "ONBOOT", ROOT_PATH) == "yes":
                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 as e:
                continue
            if link_up:
                dev = network.NetworkDevice(ROOT_PATH + network.netscriptsDir, devName)
                dev.loadIfcfgFile()
                dev.set(('ONBOOT', 'yes'))
                dev.writeIfcfgFile()
                for nd in ksdata.network.network:
                    if nd.device == dev.iface:
                        nd.onboot = True
                        break
                break
Exemplo n.º 4
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.º 5
0
def find_ifcfg_file_of_device(devname, root_path=""):
    ifcfg_path = None

    if devname not in nm.nm_devices():
        return None

    if nm.nm_device_type_is_wifi(devname):
        ssid = nm.nm_device_active_ssid(devname)
        if ssid:
            ifcfg_path = find_ifcfg_file([("ESSID", ssid)])
    elif nm.nm_device_type_is_bond(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_team(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_vlan(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_ethernet(devname):
        try:
            hwaddr = nm.nm_device_hwaddress(devname)
        except nm.PropertyNotFoundError:
            hwaddr = None
        if hwaddr:
            hwaddr_check = lambda mac: mac.upper() == hwaddr.upper()
            nonempty = lambda x: x
            # slave configration created in GUI takes precedence
            ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check), ("MASTER", nonempty)], root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check), ("TEAM_MASTER", nonempty)], root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check)], root_path)
        if not ifcfg_path:
            ifcfg_path = find_ifcfg_file([("DEVICE", devname)], root_path)

    return ifcfg_path
Exemplo n.º 6
0
def ksdata_from_ifcfg(devname):

    if nm.nm_device_is_slave(devname):
        return None

    ifcfg_path = None

    # Find ifcfg file for the device.
    # If the device is active, use uuid of its active connection.
    uuid = nm.nm_device_active_con_uuid(devname)
    if uuid:
        ifcfg_path = find_ifcfg_file([("UUID", uuid)])
    else:
        # If not, look it up by other values depending on its type
        if nm.nm_device_type_is_ethernet(devname):
            ifcfg_path = find_ifcfg_file_of_device(devname)
        elif nm.nm_device_type_is_wifi(devname):
            ssid = nm.nm_device_active_ssid(devname)
            if ssid:
                ifcfg_path = find_ifcfg_file([("ESSID", ssid)])
        elif nm.nm_device_type_is_bond(devname):
            ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
        elif nm.nm_device_type_is_vlan(devname):
            ifcfg_path = find_ifcfg_file([("DEVICE", devname)])

    if not ifcfg_path:
        return None

    ifcfg = IfcfgFile(ifcfg_path)
    ifcfg.read()
    nd = ifcfg_to_ksdata(ifcfg, devname)

    if not nd:
        return None

    if nm.nm_device_type_is_ethernet(devname):
        nd.device = devname
    elif nm.nm_device_type_is_wifi(devname):
        nm.device = ""
    elif nm.nm_device_type_is_bond(devname):
        nd.device = devname
    elif nm.nm_device_type_is_vlan(devname):
        nd.device = devname.split(".")[0]

    return nd
Exemplo n.º 7
0
def ksdata_from_ifcfg(devname, uuid=None):

    if devname not in nm.nm_devices():
        return None

    if nm.nm_device_is_slave(devname):
        return None
    if nm.nm_device_type_is_wifi(devname):
        # wifi from kickstart is not supported yet
        return None

    if not uuid:
        # Find ifcfg file for the device.
        # If the device is active, use uuid of its active connection.
        uuid = nm.nm_device_active_con_uuid(devname)

    if uuid:
        ifcfg_path = find_ifcfg_file([("UUID", uuid)])
    else:
        # look it up by other values depending on its type
        ifcfg_path = find_ifcfg_file_of_device(devname)

    if not ifcfg_path:
        return None

    ifcfg = IfcfgFile(ifcfg_path)
    ifcfg.read()
    nd = ifcfg_to_ksdata(ifcfg, devname)

    if not nd:
        return None

    if nm.nm_device_type_is_ethernet(devname):
        nd.device = devname
    elif nm.nm_device_type_is_wifi(devname):
        nm.device = ""
    elif nm.nm_device_type_is_bond(devname):
        nd.device = devname
    elif nm.nm_device_type_is_team(devname):
        nd.device = devname
    elif nm.nm_device_type_is_vlan(devname):
        if devname != default_ks_vlan_interface_name(nd.device, nd.vlanid):
            nd.interfacename = devname

    return nd
Exemplo n.º 8
0
def ksdata_from_ifcfg(devname):

    if nm.nm_device_is_slave(devname):
        return None

    ifcfg_path = None

    # Find ifcfg file for the device.
    # If the device is active, use uuid of its active connection.
    uuid = nm.nm_device_active_con_uuid(devname)
    if uuid:
        ifcfg_path = find_ifcfg_file([("UUID", uuid)])
    else:
        # If not, look it up by other values depending on its type
        if nm.nm_device_type_is_ethernet(devname):
            ifcfg_path = find_ifcfg_file_of_device(devname)
        elif nm.nm_device_type_is_wifi(devname):
            ssid = nm.nm_device_active_ssid(devname)
            if ssid:
                ifcfg_path = find_ifcfg_file([("ESSID", ssid)])
        elif nm.nm_device_type_is_bond(devname):
            ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
        elif nm.nm_device_type_is_vlan(devname):
            ifcfg_path = find_ifcfg_file([("DEVICE", devname)])

    if not ifcfg_path:
        return None

    ifcfg = IfcfgFile(ifcfg_path)
    ifcfg.read()
    nd = ifcfg_to_ksdata(ifcfg, devname)

    if not nd:
        return None

    if nm.nm_device_type_is_ethernet(devname):
        nd.device = devname
    elif nm.nm_device_type_is_wifi(devname):
        nm.device = ""
    elif nm.nm_device_type_is_bond(devname):
        nd.device = devname
    elif nm.nm_device_type_is_vlan(devname):
        nd.device = devname.split(".")[0]

    return nd
Exemplo n.º 9
0
def ksdata_from_ifcfg(devname, uuid=None):

    if nm.nm_device_is_slave(devname):
        return None
    if nm.nm_device_type_is_wifi(devname):
        # wifi from kickstart is not supported yet
        return None

    if not uuid:
        # Find ifcfg file for the device.
        # If the device is active, use uuid of its active connection.
        uuid = nm.nm_device_active_con_uuid(devname)

    if uuid:
        ifcfg_path = find_ifcfg_file([("UUID", uuid)])
    else:
        # look it up by other values depending on its type
        ifcfg_path = find_ifcfg_file_of_device(devname)

    if not ifcfg_path:
        return None

    ifcfg = IfcfgFile(ifcfg_path)
    ifcfg.read()
    nd = ifcfg_to_ksdata(ifcfg, devname)

    if not nd:
        return None

    if nm.nm_device_type_is_ethernet(devname):
        nd.device = devname
    elif nm.nm_device_type_is_wifi(devname):
        nm.device = ""
    elif nm.nm_device_type_is_bond(devname):
        nd.device = devname
    elif nm.nm_device_type_is_team(devname):
        nd.device = devname
    elif nm.nm_device_type_is_vlan(devname):
        if devname != default_ks_vlan_interface_name(nd.device, nd.vlanid):
            nd.interfacename = devname

    return nd
Exemplo n.º 10
0
 def setNetworkOnbootDefault(self, ksdata):
     if ksdata.method.method not in ("url", "nfs"):
         return
     if network.has_some_wired_autoconnect_device():
         return
     dev = network.default_route_device()
     if not dev:
         return
     if nm.nm_device_type_is_wifi(dev):
         return
     network.update_onboot_value(dev, "yes", ksdata)
Exemplo n.º 11
0
 def setNetworkOnbootDefault(self, ksdata):
     if any(nd.onboot for nd in ksdata.network.network if nd.device):
         return
     # choose the device used during installation
     # (ie for majority of cases the one having the default route)
     dev = network.default_route_device() or network.default_route_device(family="inet6")
     if not dev:
         return
     # ignore wireless (its ifcfgs would need to be handled differently)
     if nm.nm_device_type_is_wifi(dev):
         return
     network.update_onboot_value(dev, True, ksdata=ksdata)
Exemplo n.º 12
0
 def setNetworkOnbootDefault(self, ksdata):
     if any(nd.onboot for nd in ksdata.network.network if nd.device):
         return
     # choose the device used during installation
     # (ie for majority of cases the one having the default route)
     dev = network.default_route_device() or network.default_route_device(family="inet6")
     if not dev:
         return
     # ignore wireless (its ifcfgs would need to be handled differently)
     if nm.nm_device_type_is_wifi(dev):
         return
     network.update_onboot_value(dev, True, ksdata=ksdata)
Exemplo n.º 13
0
 def setNetworkOnbootDefault(self, ksdata):
     if network.has_some_wired_autoconnect_device():
         return
     # choose the device used during installation
     # (ie for majority of cases the one having the default route)
     dev = network.default_route_device() \
           or network.default_route_device(family="inet6")
     if not dev:
         return
     # ignore wireless (its ifcfgs would need to be handled differently)
     if nm.nm_device_type_is_wifi(dev):
         return
     network.update_onboot_value(dev, "yes", ksdata)
Exemplo n.º 14
0
 def setNetworkOnbootDefault(self, ksdata):
     if network.has_some_wired_autoconnect_device():
         return
     # choose the device used during installation
     # (ie for majority of cases the one having the default route)
     dev = network.default_route_device() \
           or network.default_route_device(family="inet6")
     if not dev:
         return
     # ignore wireless (its ifcfgs would need to be handled differently)
     if nm.nm_device_type_is_wifi(dev):
         return
     network.update_onboot_value(dev, "yes", ksdata)
Exemplo n.º 15
0
 def setNetworkOnbootDefault(self, ksdata):
     if network.has_some_wired_autoconnect_device():
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, "yes", ksdata)
             break
Exemplo n.º 16
0
 def setNetworkOnbootDefault(self, ksdata):
     if any(nd.onboot for nd in ksdata.network.network if nd.device):
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, True, ksdata=ksdata)
             break
Exemplo n.º 17
0
 def setNetworkOnbootDefault(self, ksdata):
     if any(nd.onboot for nd in ksdata.network.network if nd.device):
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, True, ksdata=ksdata)
             break
Exemplo n.º 18
0
 def setNetworkOnbootDefault(self, ksdata):
     if network.has_some_wired_autoconnect_device():
         return
     # choose first wired device having link
     for dev in nm.nm_devices():
         if nm.nm_device_type_is_wifi(dev):
             continue
         try:
             link_up = nm.nm_device_carrier(dev)
         except (nm.UnknownDeviceError, nm.PropertyNotFoundError):
             continue
         if link_up:
             network.update_onboot_value(dev, "yes", ksdata)
             break
Exemplo n.º 19
0
def find_ifcfg_file_of_device(devname, root_path=""):
    ifcfg_path = None

    if devname not in nm.nm_devices():
        return None

    if nm.nm_device_type_is_wifi(devname):
        ssid = nm.nm_device_active_ssid(devname)
        if ssid:
            ifcfg_path = find_ifcfg_file([("ESSID", ssid)])
    elif nm.nm_device_type_is_bond(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_team(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_vlan(devname):
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)])
    elif nm.nm_device_type_is_ethernet(devname):
        try:
            hwaddr = nm.nm_device_hwaddress(devname)
        except nm.PropertyNotFoundError:
            hwaddr = None
        if hwaddr:
            hwaddr_check = lambda mac: mac.upper() == hwaddr.upper()
            nonempty = lambda x: x
            # slave configration created in GUI takes precedence
            ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check),
                                          ("MASTER", nonempty)], root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check),
                                              ("TEAM_MASTER", nonempty)],
                                             root_path)
            if not ifcfg_path:
                ifcfg_path = find_ifcfg_file([("HWADDR", hwaddr_check)],
                                             root_path)
        if not ifcfg_path:
            ifcfg_path = find_ifcfg_file([("DEVICE", devname)], root_path)

    return ifcfg_path
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 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