'learn dmi facts from system
Try /sys first for dmi related facts.
If that is not available, fall back to dmidecode executable'

def get_dmi_facts(self):

    dmi_facts = {}
    if os.path.exists('/sys/devices/virtual/dmi/id/product_name'):
        FORM_FACTOR = ['Unknown', 'Other', 'Unknown', 'Desktop', 'Low    Profile    Desktop', 'Pizza    Box', 'Mini    Tower', 'Tower', 'Portable', 'Laptop', 'Notebook', 'Hand    Held', 'Docking    Station', 'All    In    One', 'Sub    Notebook', 'Space-saving', 'Lunch    Box', 'Main    Server    Chassis', 'Expansion    Chassis', 'Sub    Chassis', 'Bus    Expansion    Chassis', 'Peripheral    Chassis', 'RAID    Chassis', 'Rack    Mount    Chassis', 'Sealed-case    PC', 'Multi-system', 'CompactPCI', 'AdvancedTCA', 'Blade']
        DMI_DICT = {'bios_date': '/sys/devices/virtual/dmi/id/bios_date', 'bios_version': '/sys/devices/virtual/dmi/id/bios_version', 'form_factor': '/sys/devices/virtual/dmi/id/chassis_type', 'product_name': '/sys/devices/virtual/dmi/id/product_name', 'product_serial': '/sys/devices/virtual/dmi/id/product_serial', 'product_uuid': '/sys/devices/virtual/dmi/id/product_uuid', 'product_version': '/sys/devices/virtual/dmi/id/product_version', 'system_vendor': '/sys/devices/virtual/dmi/id/sys_vendor'}
        for (key, path) in DMI_DICT.items():
            data = get_file_content(path)
            if (data is not None):
                if (key == 'form_factor'):
                    try:
                        dmi_facts['form_factor'] = FORM_FACTOR[int(data)]
                    except IndexError:
                        dmi_facts['form_factor'] = ('unknown    (%s)' % data)
                else:
                    dmi_facts[key] = data
            else:
                dmi_facts[key] = 'NA'
    else:
        dmi_bin = self.module.get_bin_path('dmidecode')
        DMI_DICT = {'bios_date': 'bios-release-date', 'bios_version': 'bios-version', 'form_factor': 'chassis-type', 'product_name': 'system-product-name', 'product_serial': 'system-serial-number', 'product_uuid': 'system-uuid', 'product_version': 'system-version', 'system_vendor': 'system-manufacturer'}
        for (k, v) in DMI_DICT.items():
            if (dmi_bin is not None):
                (rc, out, err) = self.module.run_command(('%s    -s    %s' % (dmi_bin, v)))
                if (rc == 0):
                    thisvalue = ''.join([line for line in out.splitlines() if (not line.startswith('#'))])
                    try:
                        json.dumps(thisvalue)
                    except UnicodeDecodeError:
                        thisvalue = 'NA'
                    dmi_facts[k] = thisvalue
                else:
                    dmi_facts[k] = 'NA'
            else:
                dmi_facts[k] = 'NA'
    return dmi_facts
