Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

edgify / rook   python

Repository URL to install this package:

Version: 0.1.176 

/ machine.py

import platform
import socket

from .logger import logger


def add_info(obj):
    try:
        obj.hostname = socket.gethostname()
    except Exception:
        logger.warning("Failed to get hostname", exc_info=1)
        obj.hostname = ""

    with socket.socket(socket.AF_INET, socket.SOCK_DGRAM) as s:
        try:
            # doesn't even have to be reachable
            s.connect(('10.255.255.255', 1))
            obj.ip = s.getsockname()[0]
        except Exception:
            logger.warning("Failed to get ip", exc_info=1)
            obj.ip = ""

    obj.machine_type = platform.machine()
    obj.network = platform.node()

    obj.os = platform.system()
    obj.os_release = platform.release()
    obj.os_version = platform.version()
    obj.os_string = platform.platform()