Exemplo n.º 1
0
def read_logical_netwrok():
    networks = logical_to_physical_networks()
    net_entry = []
    for key in networks.iterkeys():
        device, mac = networks[key]
        key = pad_or_trim(12, key)
        device = pad_or_trim(8, device)
        net_entry.append([key, device, mac])
    return net_entry
Exemplo n.º 2
0
def read_logical_netwrok():
    networks = logical_to_physical_networks()
    net_entry = []
    for key in networks.iterkeys():
        device, mac = networks[key]
        key = pad_or_trim(12, key)
        device = pad_or_trim(8, device)
        net_entry.append([key, device, mac])
    return net_entry
Exemplo n.º 3
0
def filter_rn_get_list(allinfos):
    nics = []
    nic_dict = allinfos[0]
    for key in sorted(nic_dict.iterkeys()):
        (dev_interface, dev_bootproto, dev_vendor, dev_address, dev_driver,
         dev_conf_status, dev_bridge) = (nic_dict[key].split(",", 6))
        dev_vendor = pad_or_trim(10, dev_vendor)
        if len(dev_interface.strip()) == 0:
            continue
        else:
            nics.append(
                [dev_interface, dev_conf_status, dev_vendor, dev_address])
    return nics
Exemplo n.º 4
0
def filter_rn_get_list(allinfos):
    nics = []
    nic_dict = allinfos[0]
    for key in sorted(nic_dict.iterkeys()):
        (
            dev_interface, dev_bootproto, dev_vendor, dev_address,
            dev_driver, dev_conf_status, dev_bridge) = (
                nic_dict[key].split(",", 6))
        dev_vendor = pad_or_trim(10, dev_vendor)
        if len(dev_interface.strip()) == 0:
            continue
        else:
            nics.append([dev_interface, dev_conf_status,
                        dev_vendor, dev_address])
    return nics
Exemplo n.º 5
0
def get_system_nics():
    # Re-trigger udev for rhbz#866584
    for sysfspath in glob("/sys/class/net/*"):
        _functions.system_closefds("udevadm test %s > /dev/null 2> /dev/null" % quote(sysfspath))

    client = _functions.gudev.Client(['net'])
    configured_nics = 0
    ntp_dhcp = 0
    nic_dict = {}
    for device in client.query_by_subsystem("net"):
        try:
            dev_interface = device.get_property("INTERFACE")
            dev_vendor = device.get_property("ID_VENDOR_FROM_DATABASE")
            dev_type = device.get_property("DEVTYPE")
            dev_path = device.get_property("DEVPATH")

            if (dev_interface == "lo" or \
                dev_interface.startswith("bond") or \
                dev_interface.startswith("sit") or \
                dev_interface.startswith("vnet") or \
                "." in dev_interface or \
                dev_type == "bridge"):
                logger.info("Skipping interface '%s'" % dev_interface)
                continue
            else:
                logger.info("Gathering informations for '%s'" % dev_interface)

            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:
                logger.debug("2. vendor approach: %s" % dev_vendor)
                try:
                    # rhevh workaround since udev version
                    # doesn't have vendor info
                    dev_path = dev_path.split('/')
                    if "virtio" in dev_path[4]:
                        pci_dev = dev_path[3].replace("0000:", "")
                    else:
                        pci_dev = dev_path[4].replace("0000:", "")
                    pci_lookup_cmd = (("lspci|grep '%s'|awk -F \":\" " % pci_dev) +
                                     "{'print $3'}")
                    pci_lookup = _functions.subprocess_closefds(pci_lookup_cmd,
                                 shell=True, stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
                    dev_vendor = pci_lookup.stdout.read().strip()
                except:
                    dev_vendor = "unknown"
                    logger.debug("3. vendor approach: %s" % dev_vendor)
            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:
                dev_vendor = "unknown"
                logger.debug("4. vendor approach: %s" % dev_vendor)

            dev_vendor = _functions.pad_or_trim(25, dev_vendor)
            dev_driver = ""
            try:
                dev_driver = os.readlink("/sys/class/net/" + dev_interface + \
                                         "/device/driver")
                dev_driver = os.path.basename(dev_driver)
            except Exception as e:
                logger.debug("Exception while determining NIC driver: %s" % (
                             repr(e)))
            nic_addr_file = open("/sys/class/net/" + dev_interface + \
                                 "/address")
            dev_address = nic_addr_file.read().strip()
            cmd = ("/files/etc/sysconfig/network-scripts/" + \
                   "ifcfg-%s/BOOTPROTO") % str(dev_interface)
            dev_bootproto = _functions.augtool_get(cmd)
            type_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                        "ifcfg-%s/TYPE") % str(dev_interface)
            bridge_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                          "ifcfg-%s/BRIDGE") % str(dev_interface)
            dev_bridge = _functions.augtool_get(bridge_cmd)

            # check for vlans
            logger.debug("checking for vlan")
            vlans = glob("/etc/sysconfig/network-scripts/ifcfg-%s.*" %
                                                                 dev_interface)
            if (len(vlans) > 0):
                dev_conf_status = "Configured  "
                vlanid = vlans[0].split(".")[-1]
                logger.debug("found vlan %s" % vlanid)

                # if no bridge in nic, check clan-nic for bridge
                if not dev_bridge:
                    vlancfg = "ifcfg-%s.%s" % (str(dev_interface), vlanid)
                    cmd = ("/files/etc/sysconfig/network-scripts/%s/" +
                           "BRIDGE") % vlancfg
                    dev_bridge = augtool_get(cmd)
                    logger.debug("Getting bridge '%s' from vlan: %s" % (
                                                              dev_bridge, cmd))

            if dev_bootproto is None:
                logger.debug("Looking for bootproto in %s" % dev_bridge)
                cmd = ("/files/etc/sysconfig/network-scripts/" + \
                       "ifcfg-%s/BOOTPROTO") % str(dev_bridge)
                dev_bootproto = _functions.augtool_get(cmd)
                if dev_bootproto is None:
                    dev_bootproto = "Disabled"
                    dev_conf_status = "Unconfigured"
                else:
                    dev_conf_status = "Configured  "
            else:
                dev_conf_status = "Configured  "
            if dev_conf_status == "Configured  ":
                configured_nics = configured_nics + 1
        except Exception as e:
            logger.warning("Error while determining NICs: %s" % repr(e))

        nic_info = "%s,%s,%s,%s,%s,%s,%s" % ( \
                   dev_interface, dev_bootproto, \
                   dev_vendor, dev_address, \
                   dev_driver, dev_conf_status, \
                   dev_bridge)
        logger.debug("NIC info: %s" % nic_info)
        nic_dict[dev_interface] = nic_info

        if dev_bootproto == "dhcp":
            ntp_dhcp = 1
    return nic_dict, configured_nics, ntp_dhcp
Exemplo n.º 6
0
def get_system_nics():
    # Re-trigger udev for rhbz#866584
    for sysfspath in glob("/sys/class/net/*"):
        _functions.system_closefds("udevadm test %s > /dev/null 2> /dev/null" %
                                   sysfspath)

    client = _functions.gudev.Client(['net'])
    configured_nics = 0
    ntp_dhcp = 0
    nic_dict = {}
    for device in client.query_by_subsystem("net"):
        try:
            dev_interface = device.get_property("INTERFACE")
            dev_vendor = device.get_property("ID_VENDOR_FROM_DATABASE")
            dev_type = device.get_property("DEVTYPE")
            dev_path = device.get_property("DEVPATH")

            if (dev_interface == "lo" or \
                dev_interface.startswith("bond") or \
                dev_interface.startswith("sit") or \
                dev_interface.startswith("vnet") or \
                "." in dev_interface or \
                dev_type == "bridge"):
                logger.info("Skipping interface '%s'" % dev_interface)
                continue
            else:
                logger.info("Gathering informations for '%s'" % dev_interface)

            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:

                logger.debug("2. vendor approach: %s" % dev_vendor)
                try:
                    # rhevh workaround since udev version
                    # doesn't have vendor info
                    dev_path = dev_path.split('/')
                    if "virtio" in dev_path[4]:
                        pci_dev = dev_path[3].replace("0000:", "")
                    else:
                        pci_dev = dev_path[4].replace("0000:", "")
                    pci_lookup_cmd = (
                        ("lspci|grep '%s'|awk -F \":\" " % pci_dev) +
                        "{'print $3'}")
                    pci_lookup = _functions.subprocess_closefds(
                        pci_lookup_cmd,
                        shell=True,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.STDOUT)
                    dev_vendor = pci_lookup.stdout.read().strip()
                except:
                    dev_vendor = "unknown"
                    logger.debug("3. vendor approach: %s" % dev_vendor)
            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:
                dev_vendor = "unknown"
                logger.debug("4. vendor approach: %s" % dev_vendor)

            dev_vendor = _functions.pad_or_trim(25, dev_vendor)
            dev_driver = ""
            try:
                dev_driver = os.readlink("/sys/class/net/" + dev_interface + \
                                         "/device/driver")
                dev_driver = os.path.basename(dev_driver)
            except Exception as e:
                logger.debug("Exception while determining NIC driver: %s" %
                             (repr(e)))
            nic_addr_file = open("/sys/class/net/" + dev_interface + \
                                 "/address")
            dev_address = nic_addr_file.read().strip()
            cmd = ("/files/etc/sysconfig/network-scripts/" + \
                   "ifcfg-%s/BOOTPROTO") % str(dev_interface)
            dev_bootproto = _functions.augtool_get(cmd)
            type_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                        "ifcfg-%s/TYPE") % str(dev_interface)
            bridge_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                          "ifcfg-%s/BRIDGE") % str(dev_interface)
            dev_bridge = _functions.augtool_get(bridge_cmd)

            # check for vlans
            logger.debug("checking for vlan")
            vlans = glob("/etc/sysconfig/network-scripts/ifcfg-%s.*" %
                         dev_interface)
            if (len(vlans) > 0):
                dev_conf_status = "Configured  "
                vlanid = vlans[0].split(".")[-1]
                logger.debug("found vlan %s" % vlanid)

                # if no bridge in nic, check clan-nic for bridge
                if not dev_bridge:
                    vlancfg = "ifcfg-%s.%s" % (str(dev_interface), vlanid)
                    cmd = ("/files/etc/sysconfig/network-scripts/%s/" +
                           "BRIDGE") % vlancfg
                    dev_bridge = augtool_get(cmd)
                    logger.debug("Getting bridge '%s' from vlan: %s" %
                                 (dev_bridge, cmd))

            if dev_bootproto is None:
                logger.debug("Looking for bootproto in %s" % dev_bridge)
                cmd = ("/files/etc/sysconfig/network-scripts/" + \
                       "ifcfg-%s/BOOTPROTO") % str(dev_bridge)
                dev_bootproto = _functions.augtool_get(cmd)
                if dev_bootproto is None:
                    dev_bootproto = "Disabled"
                    dev_conf_status = "Unconfigured"
                else:
                    dev_conf_status = "Configured  "
            else:
                dev_conf_status = "Configured  "
            if dev_conf_status == "Configured  ":
                configured_nics = configured_nics + 1
        except Exception as e:
            logger.warning("Error while determining NICs: %s" % repr(e))

        nic_info = "%s,%s,%s,%s,%s,%s,%s" % ( \
                   dev_interface, dev_bootproto, \
                   dev_vendor, dev_address, \
                   dev_driver, dev_conf_status, \
                   dev_bridge)
        logger.debug("NIC info: %s" % nic_info)
        nic_dict[dev_interface] = nic_info

        if dev_bootproto == "dhcp":
            ntp_dhcp = 1
    return nic_dict, configured_nics, ntp_dhcp
Exemplo n.º 7
0
def get_system_nics():
    client = _functions.gudev.Client(['net'])
    configured_nics = 0
    ntp_dhcp = 0
    nic_dict = {}
    for device in client.query_by_subsystem("net"):
        try:
            dev_interface = device.get_property("INTERFACE")
            dev_vendor = device.get_property("ID_VENDOR_FROM_DATABASE")
            dev_type = device.get_property("DEVTYPE")
            dev_path = device.get_property("DEVPATH")
            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:
                try:
                    # rhevh workaround since udev version
                    # doesn't have vendor info
                    dev_path = dev_path.split('/')
                    if "virtio" in dev_path[4]:
                        pci_dev = dev_path[3].replace("0000:", "")
                    else:
                        pci_dev = dev_path[4].replace("0000:", "")
                    pci_lookup_cmd = ((" lspci|grep %s|awk -F \":\" " +
                                     "{'print $3'}" % pci_dev))
                    pci_lookup = _functions.subprocess_closefds(pci_lookup_cmd,
                                 shell=True, stdout=subprocess.PIPE,
                                 stderr=subprocess.STDOUT)
                    dev_vendor = pci_lookup.stdout.read().strip()
                except:
                    dev_vendor = "unknown"
            try:
                dev_vendor = dev_vendor.replace(",", "")
            except AttributeError:
                dev_vendor = "unknown"
            dev_vendor = _functions.pad_or_trim(25, dev_vendor)
            try:
                dev_driver = os.readlink("/sys/class/net/" + dev_interface + \
                                         "/device/driver")
                dev_driver = os.path.basename(dev_driver)
            except:
                pass
            nic_addr_file = open("/sys/class/net/" + dev_interface + \
                                 "/address")
            dev_address = nic_addr_file.read().strip()
            cmd = ("/files/etc/sysconfig/network-scripts/" + \
                   "ifcfg-%s/BOOTPROTO") % str(dev_interface)
            dev_bootproto = _functions.augtool_get(cmd)
            type_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                        "ifcfg-%s/TYPE") % str(dev_interface)
            bridge_cmd = ("/files/etc/sysconfig/network-scripts/" + \
                          "ifcfg-%s/BRIDGE") % str(dev_interface)
            dev_bridge = _functions.augtool_get(bridge_cmd)
            if dev_bootproto is None:
                cmd = ("/files/etc/sysconfig/network-scripts/" + \
                       "ifcfg-%s/BOOTPROTO") % str(dev_bridge)
                dev_bootproto = _functions.augtool_get(cmd)
                if dev_bootproto is None:
                    dev_bootproto = "Disabled"
                    dev_conf_status = "Unconfigured"
                    # check for vlans
                    logger.debug("checking for vlan")
                    if (len(glob("/etc/sysconfig/network-scripts/ifcfg-" + \
                        dev_interface + ".*")) > 0):
                        logger.debug("found vlan")
                        dev_conf_status = "Configured  "
                else:
                    dev_conf_status = "Configured  "
            else:
                dev_conf_status = "Configured  "
            if dev_conf_status == "Configured  ":
                configured_nics = configured_nics + 1
        except:
            pass
        if (not dev_interface == "lo" and \
            not dev_interface.startswith("bond") and \
            not dev_interface.startswith("sit") and \
            not "." in dev_interface):
            if not dev_type == "bridge":
                nic_dict[dev_interface] = "%s,%s,%s,%s,%s,%s,%s" % ( \
                                          dev_interface, dev_bootproto, \
                                          dev_vendor, dev_address, \
                                          dev_driver, dev_conf_status, \
                                          dev_bridge)
                if dev_bootproto == "dhcp":
                    ntp_dhcp = 1
    return nic_dict, configured_nics, ntp_dhcp