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
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_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
Example #3
0
    def refresh(self):
        self._nicCombo.remove_all()

        for devname in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(devname):
                self._nicCombo.append_text("%s - %s" % (devname, nm.nm_device_hwaddress(devname)))

        self._nicCombo.set_active(0)
    def refresh(self):
        self._nicCombo.remove_all()

        for devname in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(devname):
                self._nicCombo.append_text("%s - %s" % (devname, nm.nm_device_hwaddress(devname)))

        self._nicCombo.set_active(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_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_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
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_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_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
Example #7
0
    def refresh(self):
        self._addButton = self.builder.get_object("addButton")
        self._cancelButton = self.builder.get_object("cancelButton")
        self._addSpinner = self.builder.get_object("addSpinner")
        self._errorBox = self.builder.get_object("errorBox")

        self._nicCombo = self.builder.get_object("nicCombo")
        self._nicCombo.remove_all()

        self._dcbCheckbox = self.builder.get_object("dcbCheckbox")
        self._autoCheckbox = self.builder.get_object("autoCheckbox")

        for devname in nm.nm_devices():
            if nm.nm_device_type_is_ethernet(devname):
                self._nicCombo.append_text("%s - %s" % (devname, nm.nm_device_hwaddress(devname)))

        self._nicCombo.set_active(0)
Example #8
0
def find_ifcfg_file_of_device(devname, root_path=""):
    ifcfg_path = None

    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)], root_path)
    if not ifcfg_path:
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)], root_path)
    return ifcfg_path
Example #9
0
def find_ifcfg_file_of_device(devname, root_path=""):
    ifcfg_path = None

    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)], root_path)
    if not ifcfg_path:
        ifcfg_path = find_ifcfg_file([("DEVICE", devname)], root_path)
    return ifcfg_path
Example #10
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
Example #11
0
def add_connection_for_ksdata(networkdata, devname):

    added_connections = []
    con_uuid = str(uuid.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(uuid.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_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_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_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
Example #12
0
def add_connection_for_ksdata(networkdata, devname):

    added_connections = []
    con_uuid = str(uuid.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(uuid.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_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_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_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
Example #13
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_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
Example #14
0
    def _set_storage_boot_args(self, storage):
        """Set the storage boot args."""
        fcoe_proxy = STORAGE.get_proxy(FCOE)

        # FIPS
        boot_device = storage.mountpoints.get("/boot")
        if flags.cmdline.get("fips") == "1" and boot_device:
            self.boot_args.add("boot=%s" % self.stage2_device.fstab_spec)

        # Storage
        dracut_devices = [storage.root_device]
        if self.stage2_device != storage.root_device:
            dracut_devices.append(self.stage2_device)

        swap_devices = storage.fsset.swap_devices
        dracut_devices.extend(swap_devices)

        # Add resume= option to enable hibernation on x86.
        # Choose the largest swap device for that.
        if blivet.arch.is_x86() and swap_devices:
            resume_device = max(swap_devices, key=lambda x: x.size)
            self.boot_args.add("resume=%s" % resume_device.fstab_spec)

        # Does /usr have its own device? If so, we need to tell dracut
        usr_device = storage.mountpoints.get("/usr")
        if usr_device:
            dracut_devices.extend([usr_device])

        netdevs = [d for d in storage.devices \
                   if (getattr(d, "complete", True) and
                       isinstance(d, NetworkStorageDevice))]

        rootdev = storage.root_device
        if any(rootdev.depends_on(netdev) for netdev in netdevs):
            dracut_devices = set(dracut_devices)
            # By this time this thread should be the only one running, and also
            # mountpoints is a property function that returns a new dict every
            # time, so iterating over the values is safe.
            for dev in storage.mountpoints.values():
                if any(dev.depends_on(netdev) for netdev in netdevs):
                    dracut_devices.add(dev)

        done = []
        for device in dracut_devices:
            for dep in storage.devices:
                if dep in done:
                    continue

                if device != dep and not device.depends_on(dep):
                    continue

                if isinstance(dep, blivet.devices.FcoeDiskDevice):
                    setup_args = fcoe_proxy.GetDracutArguments(dep.nic)
                else:
                    setup_args = dep.dracut_setup_args()

                if not setup_args:
                    continue

                self.boot_args.update(setup_args)
                self.dracut_args.update(setup_args)
                done.append(dep)

                # network storage
                # XXX this is nothing to be proud of
                if isinstance(dep, NetworkStorageDevice):
                    setup_args = pyanaconda.network.dracutSetupArgs(dep)
                    self.boot_args.update(setup_args)
                    self.dracut_args.update(setup_args)

        # This is needed for FCoE, bug #743784. The case:
        # We discover LUN on an iface which is part of multipath setup.
        # If the iface is disconnected after discovery anaconda doesn't
        # write dracut ifname argument for the disconnected iface path
        # (in Network.dracutSetupArgs).
        # Dracut needs the explicit ifname= because biosdevname
        # fails to rename the iface (because of BFS booting from it).
        for nic in fcoe_proxy.GetNics():
            try:
                hwaddr = nm_device_hwaddress(nic)
            except ValueError:
                continue
            self.boot_args.add("ifname=%s:%s" % (nic, hwaddr.lower()))

        # Add rd.iscsi.firmware to trigger dracut running iscsistart
        # See rhbz#1099603 and rhbz#1185792
        if len(glob("/sys/firmware/iscsi_boot*")) > 0:
            self.boot_args.add("rd.iscsi.firmware")