From de4e4c54b99a7b51699875f60c964962902e6618 Mon Sep 17 00:00:00 2001 From: Dimos Alevizos Date: Sat, 7 Dec 2013 17:16:20 +0200 Subject: [PATCH 1/2] Add get_dmi_facts in setup for FreeBSD systems using dmidecode --- library/system/setup | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/library/system/setup b/library/system/setup index 2fbe511bf5..3ae5efb849 100755 --- a/library/system/setup +++ b/library/system/setup @@ -943,6 +943,7 @@ class FreeBSDHardware(Hardware): def populate(self): self.get_cpu_facts() self.get_memory_facts() + self.get_dmi_facts() self.get_device_facts() self.get_mount_facts() return self.facts @@ -1012,6 +1013,41 @@ class FreeBSDHardware(Hardware): if s: self.facts['devices'][d.group(1)].append(s.group(1)) + def get_dmi_facts(self): + ''' learn dmi facts from system + + Use dmidecode executable if available''' + + # Fall back to using dmidecode, if available + dmi_bin = 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) = module.run_command('%s -s %s' % (dmi_bin, v)) + if rc == 0: + # Strip out commented lines (specific dmidecode output) + thisvalue = ''.join([ line for line in out.split('\n') if not line.startswith('#') ]) + try: + json.dumps(thisvalue) + except UnicodeDecodeError: + thisvalue = "NA" + + self.facts[k] = thisvalue + else: + self.facts[k] = 'NA' + else: + self.facts[k] = 'NA' + + class NetBSDHardware(Hardware): """ NetBSD-specific subclass of Hardware. Defines memory and CPU facts: From 8c73aa13e47e40a8a9075210f515cd9aee90021a Mon Sep 17 00:00:00 2001 From: Dimos Alevizos Date: Sun, 8 Dec 2013 09:02:50 +0200 Subject: [PATCH 2/2] Minor changes to simplify code --- library/system/setup | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/library/system/setup b/library/system/setup index 3ae5efb849..7f902b9f37 100755 --- a/library/system/setup +++ b/library/system/setup @@ -1020,28 +1020,26 @@ class FreeBSDHardware(Hardware): # Fall back to using dmidecode, if available dmi_bin = 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' - } + DMI_DICT = 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) = module.run_command('%s -s %s' % (dmi_bin, v)) if rc == 0: # Strip out commented lines (specific dmidecode output) - thisvalue = ''.join([ line for line in out.split('\n') if not line.startswith('#') ]) + self.facts[k] = ''.join([ line for line in out.split('\n') if not line.startswith('#') ]) try: - json.dumps(thisvalue) + json.dumps(self.facts[k]) except UnicodeDecodeError: - thisvalue = "NA" - - self.facts[k] = thisvalue + self.facts[k] = 'NA' else: self.facts[k] = 'NA' else: