Esempio n. 1
0
    def translate_network_servers(self):
        # For all of these, make sure it's not actually set already by
        # install parameters. If it isn't, we won't overwrite anything
        # by checking the actual values from the configuration files, which
        # will properly be set

        if self.aug.get('/files/etc/default/ovirt/OVIRT_DNS') is None and \
                self.__is_persisted("/etc/resolv.conf"):
            dns = [ovirtfunctions.augtool_get(
                   "/files/etc/resolv.conf/nameserver[1]"),
                   ovirtfunctions.augtool_get(
                       "/files/etc/resolv.conf/nameserver[2]")]
            self.aug.set("/files/etc/default/ovirt/OVIRT_DNS",
                         ",".join((filter(None, dns))))

        if self.aug.get('/files/etc/default/ovirt/OVIRT_NTP') is None and \
                self.__is_persisted("/etc/ntp.conf"):
            ntp = [ovirtfunctions.augtool_get(
                   "/files/etc/ntp.conf/server[1]"),
                   ovirtfunctions.augtool_get(
                       "/files/etc/ntp.conf/server[2]")]
            self.aug.set("/files/etc/default/ovirt/OVIRT_NTP",
                         ",".join((filter(None, ntp))))

        if self.aug.get('/files/etc/default/ovirt/OVIRT_HOSTNAME') is None \
                and self.__is_persisted("/etc/hosts"):
            self.aug.set("/files/etc/default/ovirt/OVIRT_HOSTNAME",
                         os.uname()[1])
Esempio n. 2
0
    def translate_network_servers(self):
        # For all of these, make sure it's not actually set already by
        # install parameters. If it isn't, we won't overwrite anything
        # by checking the actual values from the configuration files, which
        # will properly be set

        if self.aug.get('/files/etc/default/ovirt/OVIRT_DNS') is None and \
                self.__is_persisted("/etc/resolv.conf"):
            dns = [ovirtfunctions.augtool_get(
                   "/files/etc/resolv.conf/nameserver[1]"),
                   ovirtfunctions.augtool_get(
                       "/files/etc/resolv.conf/nameserver[2]")]
            self.aug.set("/files/etc/default/ovirt/OVIRT_DNS",
                         ",".join((filter(None, dns))))

        if self.aug.get('/files/etc/default/ovirt/OVIRT_NTP') is None and \
                self.__is_persisted("/etc/ntp.conf"):
            ntp = [ovirtfunctions.augtool_get(
                   "/files/etc/ntp.conf/server[1]"),
                   ovirtfunctions.augtool_get(
                       "/files/etc/ntp.conf/server[2]")]
            self.aug.set("/files/etc/default/ovirt/OVIRT_NTP",
                         ",".join((filter(None, ntp))))

        if self.aug.get('/files/etc/default/ovirt/OVIRT_HOSTNAME') is None \
                and self.__is_persisted("/etc/hosts"):
            self.aug.set("/files/etc/default/ovirt/OVIRT_HOSTNAME",
                         os.uname()[1])
Esempio n. 3
0
def read_status_datas():
    status_text = []
    if network_up():
        network_status = {}
        client = gudev.Client(['net'])
        # reload augeas tree
        aug.load()
        for nic in client.query_by_subsystem("net"):
            try:
                interface = nic.get_property("INTERFACE")
                logger.debug(interface)
                if not interface == "lo":
                    if(has_ip_address(interface) or
                            get_ipv6_address(interface)):
                        ipv4_address = get_ip_address(interface)
                        try:
                            ipv6_address, netmask = get_ipv6_address(interface)
                        except:
                            ipv6_address = ""
                        network_status[interface] = (
                            ipv4_address,
                            ipv6_address)
            except:
                pass
        # remove parent/bridge duplicates
        for key in sorted(network_status.iterkeys()):
            if key.startswith("br"):
                parent_dev = key[+2:]
                if network_status.has_key(parent_dev):
                    del network_status[parent_dev]
        for key in sorted(network_status.iterkeys()):
            ipv4_addr, ipv6_addr = network_status[key]
            cmd = "/files/etc/sysconfig/network-scripts/" +\
                "ifcfg-%s/BOOTPROTO" % str(key)
            dev_bootproto = augtool_get(cmd)
            if dev_bootproto is None:
                cmd = "/files/etc/sysconfig/network-scripts/" +\
                    "ifcfg-br%s/BOOTPROTO" % str(key)
                dev_bootproto = augtool_get(cmd)
                if dev_bootproto is None:
                    dev_bootproto = "Disabled"
            if not nic_link_detected(key):
                ipv4_addr = "(Link Inactive)"
            if ipv4_addr.strip() == "" and dev_bootproto.strip() == "dhcp":
                if "Inactive" in ipv4_addr:
                    ipv4_addr = "(Link Inactive)"
                else:
                    ipv4_addr = "(DHCP Failed)"
            if OVIRT_VARS.has_key("OVIRT_IPV6") and ipv6_addr != "":
                pass
            else:
                ipv6_addr = ""
            status_text.append([key.strip(), dev_bootproto.strip(),
                                ipv4_addr.strip(), ipv6_addr.strip()])
            logger.debug(status_text)
            logger.debug(network_status)
    else:
        status_text.append(["Not Connected", "", "", ""])
    return status_text
Esempio n. 4
0
 def translate_netconsole(self):
     if self.__is_persisted("/etc/sysconfig/netconsole"):
         netconsole_server = ovirtfunctions.augtool_get(
             "/files/etc/sysconfig/netconsole/SYSLOGADDR")
         netconsole_port = ovirtfunctions.augtool_get(
             "/files/etc/sysconfig/netconsole/SYSLOGPORT")
         if netconsole_server:
             self.aug.set(
                 "/files/etc/default/ovirt/OVIRT_NETCONSOLE_SERVER",
                 netconsole_server or "")
             self.aug.set("/files/etc/default/ovirt/OVIRT_NETCONSOLE_PORT",
                          str(netconsole_port) or "")
Esempio n. 5
0
 def translate_netconsole(self):
     if self.__is_persisted("/etc/sysconfig/netconsole"):
         netconsole_server = ovirtfunctions.augtool_get(
             "/files/etc/sysconfig/netconsole/SYSLOGADDR")
         netconsole_port = ovirtfunctions.augtool_get(
             "/files/etc/sysconfig/netconsole/SYSLOGPORT")
         if netconsole_server:
             self.aug.set(
                 "/files/etc/default/ovirt/OVIRT_NETCONSOLE_SERVER",
                 netconsole_server or "")
             self.aug.set("/files/etc/default/ovirt/OVIRT_NETCONSOLE_PORT",
                          str(netconsole_port) or "")
Esempio n. 6
0
def read_log_status():
    logging_status_text = ""
    if not get_rsyslog_config() is None:
        host, port = get_rsyslog_config()
        logging_status_text += "Rsyslog: %s:%s\n" % (host, port)
    netconsole_server = augtool_get("/files/etc/sysconfig/netconsole/" +
                                    "SYSLOGADDR")
    netconsole_server_port = augtool_get("/files/etc/sysconfig/" +
                                         "netconsole/SYSLOGPORT")
    if netconsole_server and netconsole_server_port:
        logging_status_text += "Netconsole: %s:%s" % (netconsole_server,
                                                      netconsole_server_port)
    if len(logging_status_text) == 0:
        logging_status_text = "Local Only"
    return logging_status_text
Esempio n. 7
0
def read_log_status():
    logging_status_text = ""
    if not get_rsyslog_config() is None:
        host, port = get_rsyslog_config()
        logging_status_text += "Rsyslog: %s:%s\n" % (host, port)
    netconsole_server = augtool_get("/files/etc/sysconfig/netconsole/" +
                                    "SYSLOGADDR")
    netconsole_server_port = augtool_get("/files/etc/sysconfig/" +
                                         "netconsole/SYSLOGPORT")
    if netconsole_server and netconsole_server_port:
        logging_status_text += "Netconsole: %s:%s" % (
            netconsole_server,
            netconsole_server_port)
    if len(logging_status_text) == 0:
        logging_status_text = "Local Only"
    return logging_status_text
Esempio n. 8
0
    def translate_network_servers(self):
        dns = [ovirtfunctions.augtool_get(
               "/files/etc/resolv.conf/nameserver[1]"),
               ovirtfunctions.augtool_get(
                   "/files/etc/resolv.conf/nameserver[2]")]
        self.aug.set("/files/etc/default/ovirt/OVIRT_DNS",
                     ",".join((filter(None, dns))))

        ntp = [ovirtfunctions.augtool_get(
               "/files/etc/ntp.conf/server[1]"),
               ovirtfunctions.augtool_get(
                   "/files/etc/ntp.conf/server[2]")]
        self.aug.set("/files/etc/default/ovirt/OVIRT_NTP",
                     ",".join((filter(None, ntp))))

        self.aug.set("/files/etc/default/ovirt/OVIRT_HOSTNAME",
                     os.uname()[1])
Esempio n. 9
0
def convert_to_biosdevname():
    if not "BIOSDEVNAMES_CONVERSION" in OVIRT_VARS:
        # check for appropriate bios version
        cmd = "dmidecode|grep SMBIOS|awk {'print $2'}"
        proc = _functions.passthrough(cmd, log_func=logger.debug)
        ver = proc.stdout.split()[0]
        if not float(ver) >= 2.6:
            logger.debug("Skipping biosdevname conversion, SMBIOS too old")
            _functions.augtool(
                "set", "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y")
            return
        nics = {}
        cmd = "biosdevname -d"
        biosdevname, err = subprocess.Popen(
            cmd, shell=True, stdout=subprocess.PIPE).communicate()
        biosdevname_output = biosdevname.splitlines()

        for line in biosdevname_output:
            if line is not None:
                if "BIOS device:" in line:
                    nic = line.split()[2]
                if "Permanent" in line:
                    mac = line.split()[2]
                    nics[mac.upper()] = nic
        logger.debug(nics)
        scripts_path = "/etc/sysconfig/network-scripts"
        logger.debug(glob(scripts_path + "/ifcfg-*"))
        for file in glob(scripts_path + "/ifcfg-*"):
            logger.debug("Processing %s" % file)
            # get mac for matching
            existing_mac = _functions.augtool_get("/files/" + file + "/HWADDR")
            # check dictionary for mac
            if not existing_mac is None and existing_mac.upper() in nics:
                old_nic_script = os.path.basename(file)
                new_nic_name = nics[existing_mac.upper()]
                logger.debug("Found %s in %s" % (existing_mac, file))
                # change device name within script file
                logger.debug("Setting to new device name: %s" % new_nic_name)
                _functions.augtool("set", \
                                   "/files" + file + "/DEVICE", new_nic_name)
                new_nic_file = "%s/ifcfg-%s" % (scripts_path, new_nic_name)
                cmd = "cp %s %s" % (file, new_nic_file)
                _functions.remove_config(file)
                if _functions.system(cmd):
                    logging.debug("Conversion on %s to %s succeed" %
                                  (file, new_nic_file))
                    _functions.ovirt_store_config(new_nic_file)
                else:
                    return False
        _functions.system("service network restart")
        _functions.augtool("set", \
                       "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y")
        _functions.ovirt_store_config("/etc/default/ovirt")
    return True
Esempio n. 10
0
def convert_to_biosdevname():
    if not "BIOSDEVNAMES_CONVERSION" in OVIRT_VARS:
        # check for appropriate bios version
        cmd="dmidecode|grep SMBIOS|awk {'print $2'}"
        proc = _functions.passthrough(cmd, log_func=logger.debug)
        ver = proc.stdout.split()[0]
        if not float(ver) >= 2.6:
            logger.debug("Skipping biosdevname conversion, SMBIOS too old")
            _functions.augtool("set", "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y")
            return
        nics = {}
        cmd = "biosdevname -d"
        biosdevname, err = subprocess.Popen(cmd, shell=True,
                                          stdout=subprocess.PIPE).communicate()
        biosdevname_output = biosdevname.splitlines()

        for line in biosdevname_output:
            if line is not None:
                if "BIOS device:" in line:
                    nic = line.split()[2]
                if "Permanent" in line:
                    mac = line.split()[2]
                    nics[mac.upper()] = nic
        logger.debug(nics)
        scripts_path = "/etc/sysconfig/network-scripts"
        logger.debug(glob(scripts_path + "/ifcfg-*"))
        for file in glob(scripts_path + "/ifcfg-*"):
            logger.debug("Processing %s" % file)
            # get mac for matching
            existing_mac = _functions.augtool_get("/files/" + file + "/HWADDR")
            # check dictionary for mac
            if not existing_mac is None and existing_mac.upper() in nics:
                old_nic_script = os.path.basename(file)
                new_nic_name = nics[existing_mac.upper()]
                logger.debug("Found %s in %s" % (existing_mac, file))
                # change device name within script file
                logger.debug("Setting to new device name: %s" % new_nic_name)
                _functions.augtool("set", \
                                   "/files" + file + "/DEVICE", new_nic_name)
                new_nic_file = "%s/ifcfg-%s" % (scripts_path, new_nic_name)
                cmd = "cp %s %s" % (file, new_nic_file)
                _functions.remove_config(file)
                if _functions.system(cmd):
                    logging.debug("Conversion on %s to %s succeed" % (file,
                                  new_nic_file))
                    _functions.ovirt_store_config(new_nic_file)
                else:
                    return False
        _functions.system("service network restart")
        _functions.augtool("set", \
                       "/files/etc/default/ovirt/BIOSDEVNAMES_CONVERSION", "y")
        _functions.ovirt_store_config("/etc/default/ovirt")
    return True
Esempio n. 11
0
 def get_ssh_conf(self, path):
     try:
         from ocsetup import ocs
         state = augtool_get(path)
         if state == "no":
             ocs.page_security.enable_ssh_CheckButton.set_active(False)
         elif state == "yes":
             ocs.page_security.enable_ssh_CheckButton.set_active(True)
         else:
             log('ssh PasswordAuthentication invail val:' + state)
     except Exception, e:
         log(e)
         pass
Esempio n. 12
0
 def get_ssh_conf(self, path):
     try:
         from ocsetup import ocs
         state = augtool_get(path)
         if state == "no":
             ocs.page_security.enable_ssh_CheckButton.set_active(False)
         elif state == "yes":
             ocs.page_security.enable_ssh_CheckButton.set_active(True)
         else:
             log('ssh PasswordAuthentication invail val:' + state)
     except Exception, e:
         log(e)
         pass
Esempio n. 13
0
 def set_ssh_conf(self, path, _):
     try:
         from ocsetup import ocs
         ssh_btn = ocs.page_security.enable_ssh_CheckButton
         check_button_state = ssh_btn.get_active()
         current_state = augtool_get(path)
         if check_button_state is False:
             datautil.augtool_set(path, "no")
         else:
             datautil.augtool_set(path, "yes")
         if ((current_state == "no" and check_button_state is True) or
                 (current_state != "no" and check_button_state is False)):
                 # SSHD CONFIGURE CHANGED, RESTART.
                 system_closefds("service sshd restart &>/dev/null")
     except Exception, e:
         print e
Esempio n. 14
0
 def set_ssh_conf(self, path, _):
     try:
         from ocsetup import ocs
         ssh_btn = ocs.page_security.enable_ssh_CheckButton
         check_button_state = ssh_btn.get_active()
         current_state = augtool_get(path)
         if check_button_state is False:
             datautil.augtool_set(path, "no")
         else:
             datautil.augtool_set(path, "yes")
         if ((current_state == "no" and check_button_state is True) or
             (current_state != "no" and check_button_state is False)):
             # SSHD CONFIGURE CHANGED, RESTART.
             system_closefds("service sshd restart &>/dev/null")
     except Exception, e:
         print e
Esempio n. 15
0
    def translate_ssh(self):
        if self.__is_persisted("/etc/ssh/sshd_config"):
            pw_auth_enabled = ovirtfunctions.augtool_get(
                "/files/etc/ssh/sshd_config/PasswordAuthentication")
            rng_bytes, aes_enabled = ovirtfunctions.rng_status()

            rng_bytes = None if rng_bytes == 0 else rng_bytes
            aes_disabled = False if aes_enabled == "1" else True
            ssh_is_enabled = parse_bool(pw_auth_enabled)

            if rng_bytes:
                self.aug.set("/files/etc/default/ovirt/OVIRT_USE_STRONG_RNG",
                             str(rng_bytes))
            if aes_disabled:
                self.aug.set("/files/etc/default/ovirt/OVIRT_DISABLE_AES_NI",
                             "true")
            if ssh_is_enabled:
                self.aug.set("/files/etc/default/ovirt/OVIRT_SSH_PWAUTH",
                             "yes")
Esempio n. 16
0
    def translate_ssh(self):
        if self.__is_persisted("/etc/ssh/sshd_config"):
            pw_auth_enabled = ovirtfunctions.augtool_get(
                "/files/etc/ssh/sshd_config/PasswordAuthentication")
            rng_bytes, aes_disabled = ovirtfunctions.rng_status()

            rng_bytes = None if rng_bytes == 0 else rng_bytes
            aes_disabled = aes_disabled == 1
            ssh_is_enabled = parse_bool(pw_auth_enabled)

            if rng_bytes:
                self.aug.set("/files/etc/default/ovirt/OVIRT_USE_STRONG_RNG",
                             str(rng_bytes))
            if aes_disabled:
                self.aug.set("/files/etc/default/ovirt/OVIRT_DISABLE_AES_NI",
                             "true")
            if ssh_is_enabled:
                self.aug.set("/files/etc/default/ovirt/OVIRT_SSH_PWAUTH",
                             "yes")
Esempio n. 17
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
Esempio n. 18
0
def read_status_datas():
    status_text = []
    if network_up():
        network_status = {}
        client = gudev.Client(['net'])
        # reload augeas tree
        aug.load()
        for nic in client.query_by_subsystem("net"):
            try:
                interface = nic.get_property("INTERFACE")
                logger.debug(interface)
                if not interface == "lo":
                    if (has_ip_address(interface)
                            or get_ipv6_address(interface)):
                        ipv4_address = get_ip_address(interface)
                        try:
                            ipv6_address, netmask = get_ipv6_address(interface)
                        except:
                            ipv6_address = ""
                        network_status[interface] = (ipv4_address,
                                                     ipv6_address)
            except:
                pass
        # remove parent/bridge duplicates
        for key in sorted(network_status.iterkeys()):
            if key.startswith("br"):
                parent_dev = key[+2:]
                if network_status.has_key(parent_dev):
                    del network_status[parent_dev]
        for key in sorted(network_status.iterkeys()):
            ipv4_addr, ipv6_addr = network_status[key]
            cmd = "/files/etc/sysconfig/network-scripts/" +\
                "ifcfg-%s/BOOTPROTO" % str(key)
            dev_bootproto = augtool_get(cmd)
            if dev_bootproto is None:
                cmd = "/files/etc/sysconfig/network-scripts/" +\
                    "ifcfg-br%s/BOOTPROTO" % str(key)
                dev_bootproto = augtool_get(cmd)
                if dev_bootproto is None:
                    dev_bootproto = "Disabled"
            if not nic_link_detected(key):
                ipv4_addr = "(Link Inactive)"
            if ipv4_addr.strip() == "" and dev_bootproto.strip() == "dhcp":
                if "Inactive" in ipv4_addr:
                    ipv4_addr = "(Link Inactive)"
                else:
                    ipv4_addr = "(DHCP Failed)"
            if OVIRT_VARS.has_key("OVIRT_IPV6") and ipv6_addr != "":
                pass
            else:
                ipv6_addr = ""
            status_text.append([
                key.strip(),
                dev_bootproto.strip(),
                ipv4_addr.strip(),
                ipv6_addr.strip()
            ])
            logger.debug(status_text)
            logger.debug(network_status)
    else:
        status_text.append(["Not Connected", "", "", ""])
    return status_text
Esempio n. 19
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
Esempio n. 20
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