
from __future__ import absolute_import

import six

from vdsm.common import cache


def __leafDict(d):
    ret = {}
    for k, v in six.iteritems(d):
        if isinstance(v, dict):
            ret.update(__leafDict(v))
        else:
            ret[k] = v
    return ret


@cache.memoized
def getSystemInfo():
    import dmidecode

    return __leafDict(dmidecode.system())


@cache.memoized
def getHardwareInfoStructure():
    dmiInfo = getSystemInfo()
    sysStruct = {}
    for k in ('Manufacturer', 'Product Name', 'Version', 'Serial Number',
              'UUID', 'Family'):
        val = dmiInfo.get(k, None)
        if val not in [None, 'Not Specified']:
            sysStruct[('system' + k).replace(' ', '')] = val

    return sysStruct
