72
72
# Helper utils to see if running in a container
73
73
CONTAINER_TESTS = ['running-in-container', 'lxc-is-container']
76
DMI_SYS_PATH = "/sys/class/dmi/id"
76
79
class ProcessExecutionError(IOError):
2011
2014
raise ValueError("'%s': cannot be negative" % size_in)
2013
2016
return int(num * mpliers[mplier])
2019
def _read_dmi_syspath(key):
2021
Reads dmi data with from /sys/class/dmi/id
2024
dmi_key = "{}/{}".format(DMI_SYS_PATH, key)
2025
LOG.debug("querying dmi data {}".format(dmi_key))
2027
if not os.path.exists(dmi_key):
2028
LOG.debug("did not find {}".format(dmi_key))
2031
key_data = load_file(dmi_key)
2033
LOG.debug("{} did not return any data".format(key))
2036
LOG.debug("dmi data {} returned {}".format(dmi_key, key_data))
2037
return key_data.strip()
2039
except Exception as e:
2040
logexc(LOG, "failed read of {}".format(dmi_key), e)
2044
def _call_dmidecode(key, dmidecode_path):
2046
Calls out to dmidecode to get the data out. This is mostly for supporting
2047
OS's without /sys/class/dmi/id support.
2050
cmd = [dmidecode_path, "--string", key]
2051
(result, _err) = subp(cmd)
2052
LOG.debug("dmidecode returned '{}' for '{}'".format(result, key))
2054
except OSError, _err:
2055
LOG.debug('failed dmidecode cmd: {}\n{}'.format(cmd, _err.message))
2059
def read_dmi_data(key):
2061
Wrapper for reading DMI data. This tries to determine whether the DMI
2062
Data can be read directly, otherwise it will fallback to using dmidecode.
2064
if os.path.exists(DMI_SYS_PATH):
2065
return _read_dmi_syspath(key)
2067
dmidecode_path = which('dmidecode')
2069
return _call_dmidecode(key, dmidecode_path)
2071
LOG.warn("did not find either path {} or dmidecode command".format(