diff options
author | Ben Howard <ben.howard@canonical.com> | 2015-01-14 12:24:09 -0700 |
---|---|---|
committer | Ben Howard <ben.howard@canonical.com> | 2015-01-14 12:24:09 -0700 |
commit | 28c8aa7270a04adea69065477b13cfc0dd244acc (patch) | |
tree | 76f2535102b42f25995e25a5829ede283510cf03 /cloudinit/util.py | |
parent | 62e9e73e3ed8467fc4d4d95f76ed0443c50f176c (diff) | |
download | vyos-cloud-init-28c8aa7270a04adea69065477b13cfc0dd244acc.tar.gz vyos-cloud-init-28c8aa7270a04adea69065477b13cfc0dd244acc.zip |
Drop reliance on dmidecode executable.
Diffstat (limited to 'cloudinit/util.py')
-rw-r--r-- | cloudinit/util.py | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/cloudinit/util.py b/cloudinit/util.py index bf8e7d80..f7498b01 100644 --- a/cloudinit/util.py +++ b/cloudinit/util.py @@ -72,6 +72,9 @@ FN_ALLOWED = ('_-.()' + string.digits + string.ascii_letters) # Helper utils to see if running in a container CONTAINER_TESTS = ['running-in-container', 'lxc-is-container'] +# Path for DMI Data +DMI_SYS_PATH = "/sys/class/dmi/id" + class ProcessExecutionError(IOError): @@ -2011,3 +2014,28 @@ def human2bytes(size): raise ValueError("'%s': cannot be negative" % size_in) return int(num * mpliers[mplier]) + + +def read_dmi_data(key): + """ + Reads dmi data with from /sys/class/dmi/id + """ + + dmi_key = "{}/{}".format(DMI_SYS_PATH, key) + LOG.debug("querying dmi data {}".format(dmi_key)) + try: + if not os.path.exists(dmi_key): + LOG.debug("did not find {}".format(dmi_key)) + return None + + key_data = load_file(dmi_key) + if not key_data: + LOG.debug("{} did not return any data".format(key)) + return None + + LOG.debug("dmi data {} returned {}".format(dmi_key, key_data)) + return key_data.strip() + + except Exception as e: + logexc(LOG, "failed read of {}".format(dmi_key), e) + return None |