Exemplo n.º 1
0
    def fetch_system_data(cls) -> None:
        """Fetch info from the host system.

        The function should be the only one that use system calls or programs
        to fetch information from the current system. Overriding this method
        should be enough for example for testing purposes as all the other
        methods use information retrieved in this function.

        The function should set all the class attributes described at the
        beginning of this class.
        """
        # Compute result of uname
        cls.uname = Uname(*platform_uname())

        # Fetch linux distribution info on linux OS
        if cls.uname.system == "Linux":  # linux-only
            import ld

            cls.ld_info = {
                "name": ld.name(),
                "major_version": ld.major_version(),
                "version": ld.version(),
            }

        # Fetch core numbers. Note that the methods does not work
        # on AIX platform but we usually override manually that
        # setting anyway.
        cls.core_number = 1
        try:
            import multiprocessing

            cls.core_number = multiprocessing.cpu_count()
        except Exception:  # defensive code
            e3.log.debug("multiprocessing error", exc_info=True)
            try:
                import psutil

                cls.core_number = psutil.cpu_count()
            except Exception:
                e3.log.debug("psutil error", exc_info=True)

        cls.nis_domain = UNKNOWN

        if sys.platform != "win32":  # windows: no cover
            try:
                import nis
            except ImportError:  # defensive code
                e3.log.debug("cannot import nis", exc_info=True)
                nis = None  # type: ignore

            if nis is not None:
                try:
                    cls.nis_domain = nis.get_default_domain()
                    if not cls.nis_domain:  # defensive code
                        cls.nis_domain = UNKNOWN
                except nis.error:  # defensive code
                    e3.log.debug("nis error", exc_info=True)
Exemplo n.º 2
0
    def fetch_system_data(cls):
        """Fetch info from the host system.

        The function should be the only one that use system calls or programs
        to fetch information from the current system. Overriding this method
        should be enough for example for testing purposes as all the other
        methods use information retrieved in this function.

        The function should set all the class attributes described at the
        beginning of this class.
        """
        # Compute result of uname
        cls.uname = Uname(*platform_uname())

        # Fetch linux distribution info on linux OS
        if cls.uname.system == 'Linux':  # linux-only
            import ld
            cls.ld_info = {
                'name': ld.name(),
                'major_version': ld.major_version(),
                'version': ld.version()
            }

        # Fetch network interfaces
        try:
            from netifaces import interfaces, ifaddresses, address_families
            # use string for address families instead of integers which are
            # system dependents
            cls.network_ifs = {
                itf: {
                    address_families[k]: v
                    for k, v in ifaddresses(itf).iteritems()
                }
                for itf in interfaces()
            }
        except Exception:  # defensive code
            e3.log.debug('cannot get network info', exc_info=True)
            cls.network_ifs = None

        # Fetch core numbers. Note that the methods does not work
        # on AIX platform but we usually override manually that
        # setting anyway.
        cls.core_number = 1
        try:
            import multiprocessing
            cls.core_number = multiprocessing.cpu_count()
        except Exception:  # defensive code
            e3.log.debug('multiprocessing error', exc_info=True)
            try:
                import psutil
                cls.core_number = psutil.cpu_count()
            except Exception:
                e3.log.debug('psutil error', exc_info=True)

        cls.nis_domain = UNKNOWN

        if sys.platform != 'win32':  # windows: no cover
            try:
                import nis
            except ImportError:  # defensive code
                e3.log.debug('cannot import nis', exc_info=True)
                nis = None

            if nis is not None:
                try:
                    cls.nis_domain = nis.get_default_domain()
                    if not cls.nis_domain:  # defensive code
                        cls.nis_domain = UNKNOWN
                except nis.error:  # defensive code
                    e3.log.debug('nis error', exc_info=True)
Exemplo n.º 3
0
def uname():
    return tuple(platform_uname())
Exemplo n.º 4
0
    def fetch_system_data(cls):
        """Fetch info from the host system.

        The function should be the only one that use system calls or programs
        to fetch information from the current system. Overriding this method
        should be enough for example for testing purposes as all the other
        methods use information retrieved in this function.

        The function should set all the class attributes described at the
        beginning of this class.
        """
        # Compute result of uname
        cls.uname = Uname(*platform_uname())

        # Fetch linux distribution info on linux OS
        if cls.uname.system == 'Linux':
            import ld
            cls.ld_info = {'name': ld.name(),
                           'major_version': ld.major_version(),
                           'version': ld.version()}

        # Fetch network interfaces
        try:
            from netifaces import interfaces, ifaddresses, address_families
            # use string for address families instead of integers which are
            # system dependents
            cls.network_ifs = {itf: {address_families[k]: v
                                     for k, v in ifaddresses(itf).iteritems()}
                               for itf in interfaces()}
        except Exception:
            e3.log.debug('cannot get network info', exc_info=True)
            cls.network_ifs = None

        # Fetch core numbers. Note that the methods does not work
        # on AIX platform but we usually override manually that
        # setting anyway.
        cls.core_number = 1
        try:
            import multiprocessing
            cls.core_number = multiprocessing.cpu_count()
        except Exception:
            e3.log.debug('multiprocessing error', exc_info=True)
            try:
                import psutil
                cls.core_number = psutil.cpu_count()
            except Exception:
                e3.log.debug('psutil error', exc_info=True)
                pass

        cls.nis_domain = UNKNOWN

        try:
            import nis
        except ImportError:
            e3.log.debug('cannot import nis', exc_info=True)
            nis = None

        if nis is not None:
            try:
                cls.nis_domain = nis.get_default_domain()
                if not cls.nis_domain:
                    cls.nis_domain = UNKNOWN
            except nis.error:
                e3.log.debug('nis error', exc_info=True)
                pass