示例#1
0
    def refresh(self):
        """
        The refresh method that is called every time the spoke is displayed.
        It should update the UI elements according to the contents of
        self.data.

        :see: pyanaconda.ui.common.UIObject.refresh

        """
        ## Every time we enter, make a list of all the devices that
        # are not the public interface (user might have changed this)
        pubif = network.default_route_device()
        allifs = filter(lambda x: nm.nm_device_type_is_ethernet(x),\
                nm.nm_devices())
        privates = filter(lambda x: x != pubif,allifs)
        idx = self.ifaceCombo.get_active()
        self.deviceStore.clear()
        for x in privates:
            entry=[None,None,None,None]
            entry[DEVICEIDX] = x
            entry[TYPEIDX] = "ethernet"
            entry[MACIDX] = nm.nm_device_perm_hwaddress(x)
            entry[LABELIDX] = "%s;%s" % (x,entry[MACIDX])
            self.deviceStore.append(entry)
        if len(privates) == 0:
            entry=[None,None,None,None]
            entry[DEVICEIDX] = "%s:0" % pubif
            entry[LABELIDX] = "%s;virtual interface" % entry[DEVICEIDX] 
            entry[TYPEIDX] = "virtual"
            entry[MACIDX] = ""
            self.deviceStore.append(entry)

        # Set the active entry, even if we reodered 
        self.ifaceCombo.set_active(idx)
示例#2
0
def get_device_name(devspec):

    devices = nm.nm_devices()
    devname = None

    if not devspec:
        if "ksdevice" in flags.cmdline:
            msg = "ksdevice boot parameter"
            devname = ks_spec_to_device_name(flags.cmdline["ksdevice"])
        elif nm.nm_is_connected():
            # device activated in stage 1 by network kickstart command
            msg = "first active device"
            try:
                devname = nm.nm_activated_devices()[0]
            except IndexError:
                log.debug("get_device_name: NM is connected but no activated devices found")
        else:
            msg = "first device found"
            devname = min(devices)
        log.info("unspecified network --device in kickstart, using %s (%s)",
                 devname, msg)
    else:
        if iutil.lowerASCII(devspec) == "ibft":
            devname = ""
        if iutil.lowerASCII(devspec) == "link":
            for dev in sorted(devices):
                try:
                    link_up = nm.nm_device_carrier(dev)
                except ValueError as e:
                    log.debug("get_device_name: %s", e)
                    continue
                if link_up:
                    devname = dev
                    break
            else:
                log.error("Kickstart: No network device with link found")
        elif iutil.lowerASCII(devspec) == "bootif":
            if "BOOTIF" in flags.cmdline:
                # MAC address like 01-aa-bb-cc-dd-ee-ff
                devname = flags.cmdline["BOOTIF"][3:]
                devname = devname.replace("-",":")
            else:
                log.error("Using --device=bootif without BOOTIF= boot option supplied")
        else: devname = devspec

    if devname and devname not in devices:
        for d in devices:
            try:
                hwaddr = nm.nm_device_perm_hwaddress(d)
            except ValueError as e:
                log.debug("get_device_name: %s", e)
                continue
            if hwaddr.lower() == devname.lower():
                devname = d
                break
        else:
            return ""

    return devname
示例#3
0
def ks_spec_to_device_name(ksspec=""):

    if not ksspec:
        ksspec = flags.cmdline.get('ksdevice', "")
    ksdevice = ksspec

    bootif_mac = ''
    if ksdevice == 'bootif' and "BOOTIF" in flags.cmdline:
        bootif_mac = flags.cmdline["BOOTIF"][3:].replace("-", ":").upper()
    for dev in sorted(nm.nm_devices()):
        # "eth0"
        if ksdevice == dev:
            break
        # "link"
        elif ksdevice == 'link':
            try:
                link_up = nm.nm_device_carrier(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if link_up:
                ksdevice = dev
                break
        # "XX:XX:XX:XX:XX:XX" (mac address)
        elif ':' in ksdevice:
            try:
                hwaddr = nm.nm_device_perm_hwaddress(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if ksdevice.lower() == hwaddr.lower():
                ksdevice = dev
                break
        # "bootif" and BOOTIF==XX:XX:XX:XX:XX:XX
        elif ksdevice == 'bootif':
            try:
                hwaddr = nm.nm_device_perm_hwaddress(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if bootif_mac.lower() == hwaddr.lower():
                ksdevice = dev
                break

    return ksdevice
示例#4
0
def ks_spec_to_device_name(ksspec=""):

    ksdevice = ksspec

    bootif_mac = ''
    if ksdevice == 'bootif' and "BOOTIF" in flags.cmdline:
        bootif_mac = flags.cmdline["BOOTIF"][3:].replace("-", ":").upper()
    for dev in sorted(nm.nm_devices()):
        # "eth0"
        if ksdevice == dev:
            break
        # "link"
        elif ksdevice == 'link':
            try:
                link_up = nm.nm_device_carrier(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if link_up:
                ksdevice = dev
                break
        # "XX:XX:XX:XX:XX:XX" (mac address)
        elif ':' in ksdevice:
            try:
                hwaddr = nm.nm_device_perm_hwaddress(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if ksdevice.lower() == hwaddr.lower():
                ksdevice = dev
                break
        # "bootif" and BOOTIF==XX:XX:XX:XX:XX:XX
        elif ksdevice == 'bootif':
            try:
                hwaddr = nm.nm_device_perm_hwaddress(dev)
            except ValueError as e:
                log.debug("ks_spec_to_device_name: %s", e)
                continue
            if bootif_mac.lower() == hwaddr.lower():
                ksdevice = dev
                break

    return ksdevice
示例#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_perm_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
示例#6
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_perm_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
示例#7
0
def add_connection_for_ksdata(networkdata, devname):

    added_connections = []
    con_uuid = str(uuid4())
    values = _get_ip_setting_values_from_ksdata(networkdata)
    # HACK preventing NM to autoactivate the connection
    #values.append(['connection', 'autoconnect', networkdata.onboot, 'b'])
    values.append(['connection', 'autoconnect', False, 'b'])
    values.append(['connection', 'uuid', con_uuid, 's'])

    # type "bond"
    if networkdata.bondslaves:
        # bond connection is autoactivated
        values.append(['connection', 'type', 'bond', 's'])
        values.append(['connection', 'id', devname, 's'])
        values.append(['bond', 'interface-name', devname, 's'])
        options = bond_options_ksdata_to_dbus(networkdata.bondopts)
        values.append(['bond', 'options', options, 'a{ss}'])
        for _i, slave in enumerate(networkdata.bondslaves.split(","), 1):

            #slave_name = "%s slave %d" % (devname, i)
            slave_name = slave

            svalues = []
            suuid =  str(uuid4())
            svalues.append(['connection', 'uuid', suuid, 's'])
            svalues.append(['connection', 'id', slave_name, 's'])
            svalues.append(['connection', 'slave-type', 'bond', 's'])
            svalues.append(['connection', 'master', devname, 's'])
            svalues.append(['connection', 'type', '802-3-ethernet', 's'])
            mac = nm.nm_device_perm_hwaddress(slave)
            mac = [int(b, 16) for b in mac.split(":")]
            svalues.append(['802-3-ethernet', 'mac-address', mac, 'ay'])

            # disconnect slaves
            if networkdata.activate:
                nm.nm_disconnect_device(slave)
            # remove ifcfg file
            ifcfg_path = find_ifcfg_file_of_device(slave)
            if ifcfg_path and os.access(ifcfg_path, os.R_OK):
                os.unlink(ifcfg_path)

            nm.nm_add_connection(svalues)
            added_connections.append((suuid, slave))
        dev_spec = None
    # type "team"
    elif networkdata.teamslaves:
        values.append(['connection', 'type', 'team', 's'])
        values.append(['connection', 'id', devname, 's'])
        values.append(['team', 'interface-name', devname, 's'])
        values.append(['team', 'config', networkdata.teamconfig, 's'])
        for _i, (slave, cfg) in enumerate(networkdata.teamslaves):

            # assume ethernet, TODO: infiniband, wifi, vlan
            #slave_name = "%s slave %d" % (devname, i)
            slave_name = slave

            svalues = []
            suuid =  str(uuid4())
            svalues.append(['connection', 'uuid', suuid, 's'])
            svalues.append(['connection', 'id', slave_name, 's'])
            svalues.append(['connection', 'slave-type', 'team', 's'])
            svalues.append(['connection', 'master', devname, 's'])
            svalues.append(['connection', 'type', '802-3-ethernet', 's'])
            mac = nm.nm_device_perm_hwaddress(slave)
            mac = [int(b, 16) for b in mac.split(":")]
            svalues.append(['802-3-ethernet', 'mac-address', mac, 'ay'])
            svalues.append(['team-port', 'config', cfg, 's'])

            # disconnect slaves
            if networkdata.activate:
                nm.nm_disconnect_device(slave)
            # remove ifcfg file
            ifcfg_path = find_ifcfg_file_of_device(slave)
            if ifcfg_path and os.access(ifcfg_path, os.R_OK):
                os.unlink(ifcfg_path)

            nm.nm_add_connection(svalues)
            added_connections.append((suuid, slave))
        dev_spec = None
    # type "vlan"
    elif networkdata.vlanid:
        parent, _sep, _vlanid = devname.partition(".")
        values.append(['vlan', 'parent', parent, 's'])
        values.append(['connection', 'type', 'vlan', 's'])
        values.append(['connection', 'id', devname, 's'])
        values.append(['vlan', 'interface-name', devname, 's'])
        values.append(['vlan', 'id', int(networkdata.vlanid), 'u'])
        dev_spec = None
    # type "802-3-ethernet"
    else:
        values.append(['connection', 'type', '802-3-ethernet', 's'])
        values.append(['connection', 'id', devname, 's'])
        mac = nm.nm_device_perm_hwaddress(devname)
        mac = [int(b, 16) for b in mac.split(":")]
        values.append(['802-3-ethernet', 'mac-address', mac, 'ay'])
        dev_spec = devname

    nm.nm_add_connection(values)
    added_connections.insert(0, (con_uuid, dev_spec))
    return added_connections
示例#8
0
def add_connection_for_ksdata(networkdata, devname):

    added_connections = []
    con_uuid = str(uuid4())
    values = _get_ip_setting_values_from_ksdata(networkdata)
    # HACK preventing NM to autoactivate the connection
    #values.append(['connection', 'autoconnect', networkdata.onboot, 'b'])
    values.append(['connection', 'autoconnect', False, 'b'])
    values.append(['connection', 'uuid', con_uuid, 's'])

    # type "bond"
    if networkdata.bondslaves:
        # bond connection is autoactivated
        values.append(['connection', 'type', 'bond', 's'])
        values.append(['connection', 'id', devname, 's'])
        values.append(['bond', 'interface-name', devname, 's'])
        options = bond_options_ksdata_to_dbus(networkdata.bondopts)
        values.append(['bond', 'options', options, 'a{ss}'])
        for _i, slave in enumerate(networkdata.bondslaves.split(","), 1):

            #slave_name = "%s slave %d" % (devname, i)
            slave_name = slave

            svalues = []
            suuid = str(uuid4())
            svalues.append(['connection', 'uuid', suuid, 's'])
            svalues.append(['connection', 'id', slave_name, 's'])
            svalues.append(['connection', 'slave-type', 'bond', 's'])
            svalues.append(['connection', 'master', devname, 's'])
            svalues.append(['connection', 'type', '802-3-ethernet', 's'])
            mac = nm.nm_device_perm_hwaddress(slave)
            mac = [int(b, 16) for b in mac.split(":")]
            svalues.append(['802-3-ethernet', 'mac-address', mac, 'ay'])

            # disconnect slaves
            if networkdata.activate:
                nm.nm_disconnect_device(slave)
            # remove ifcfg file
            ifcfg_path = find_ifcfg_file_of_device(slave)
            if ifcfg_path and os.access(ifcfg_path, os.R_OK):
                os.unlink(ifcfg_path)

            nm.nm_add_connection(svalues)
            added_connections.append((suuid, slave))
        dev_spec = None
    # type "team"
    elif networkdata.teamslaves:
        values.append(['connection', 'type', 'team', 's'])
        values.append(['connection', 'id', devname, 's'])
        values.append(['team', 'interface-name', devname, 's'])
        values.append(['team', 'config', networkdata.teamconfig, 's'])
        for _i, (slave, cfg) in enumerate(networkdata.teamslaves):

            # assume ethernet, TODO: infiniband, wifi, vlan
            #slave_name = "%s slave %d" % (devname, i)
            slave_name = slave

            svalues = []
            suuid = str(uuid4())
            svalues.append(['connection', 'uuid', suuid, 's'])
            svalues.append(['connection', 'id', slave_name, 's'])
            svalues.append(['connection', 'slave-type', 'team', 's'])
            svalues.append(['connection', 'master', devname, 's'])
            svalues.append(['connection', 'type', '802-3-ethernet', 's'])
            mac = nm.nm_device_perm_hwaddress(slave)
            mac = [int(b, 16) for b in mac.split(":")]
            svalues.append(['802-3-ethernet', 'mac-address', mac, 'ay'])
            svalues.append(['team-port', 'config', cfg, 's'])

            # disconnect slaves
            if networkdata.activate:
                nm.nm_disconnect_device(slave)
            # remove ifcfg file
            ifcfg_path = find_ifcfg_file_of_device(slave)
            if ifcfg_path and os.access(ifcfg_path, os.R_OK):
                os.unlink(ifcfg_path)

            nm.nm_add_connection(svalues)
            added_connections.append((suuid, slave))
        dev_spec = None
    # type "vlan"
    elif networkdata.vlanid:
        parent, _sep, _vlanid = devname.partition(".")
        values.append(['vlan', 'parent', parent, 's'])
        values.append(['connection', 'type', 'vlan', 's'])
        values.append(['connection', 'id', devname, 's'])
        values.append(['vlan', 'interface-name', devname, 's'])
        values.append(['vlan', 'id', int(networkdata.vlanid), 'u'])
        dev_spec = None
    # type "802-3-ethernet"
    else:
        values.append(['connection', 'type', '802-3-ethernet', 's'])
        values.append(['connection', 'id', devname, 's'])
        mac = nm.nm_device_perm_hwaddress(devname)
        mac = [int(b, 16) for b in mac.split(":")]
        values.append(['802-3-ethernet', 'mac-address', mac, 'ay'])
        dev_spec = devname

    nm.nm_add_connection(values)
    added_connections.insert(0, (con_uuid, dev_spec))
    return added_connections