Change in vdsm[ovirt-3.2]: adding getHardwareInfo API to vdsm

ybronhei at redhat.com ybronhei at redhat.com
Fri Jan 18 13:20:39 UTC 2013


Hello Shu Ming, Saggi Mizrahi, Barak Azulay,

I'd like you to do a code review.  Please visit

    http://gerrit.ovirt.org/11171

to review the following change.

Change subject: adding getHardwareInfo API to vdsm
......................................................................

adding getHardwareInfo API to vdsm

Super vdsm retrieves system info about host hardware
parameters. This info will be shown as part of getHardwareInfo
API call in a structure called HardwareInformation.

This feature currently available only for x86 cpu platfroms, for other
platfroms the api call returns empty dictionary.

Feature-Description:
http://wiki.ovirt.org/wiki/Features/Design/HostHardwareInfo

Change-Id: I265645bc67c9bcf14b4479a1fab22c7bd5e865fd
Signed-off-by: Yaniv Bronhaim <ybronhei at redhat.com>
Reviewed-on: http://gerrit.ovirt.org/9258
Reviewed-by: Barak Azulay <bazulay at redhat.com>
Reviewed-by: Shu Ming <shuming at linux.vnet.ibm.com>
Reviewed-by: Saggi Mizrahi <smizrahi at redhat.com>
---
M vdsm.spec.in
M vdsm/API.py
M vdsm/BindingXMLRPC.py
M vdsm/Makefile.am
M vdsm/define.py
A vdsm/dmidecodeUtil.py
M vdsm/supervdsmServer.py
M vdsm_api/vdsmapi-schema.json
M vdsm_cli/vdsClient.py
9 files changed, 166 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/71/11171/1

diff --git a/vdsm.spec.in b/vdsm.spec.in
index 14381e5..5b13419 100644
--- a/vdsm.spec.in
+++ b/vdsm.spec.in
@@ -45,6 +45,9 @@
 BuildRequires: genisoimage
 BuildRequires: openssl
 BuildRequires: m2crypto
+%ifarch x86_64
+BuildRequires: python-dmidecode
+%endif
 %if 0%{?rhel} == 6
 BuildRequires: python-ordereddict
 %endif
@@ -77,6 +80,7 @@
 Requires: %{name}-xmlrpc = %{version}-%{release}
 
 %ifarch x86_64
+Requires: python-dmidecode
 Requires: dmidecode
 %endif
 
@@ -610,6 +614,7 @@
 %{_datadir}/%{vdsm_name}/blkid.py*
 %{_datadir}/%{vdsm_name}/caps.py*
 %{_datadir}/%{vdsm_name}/clientIF.py*
+%{_datadir}/%{vdsm_name}/dmidecodeUtil.py*
 %{_datadir}/%{vdsm_name}/API.py*
 %{_datadir}/%{vdsm_name}/hooking.py*
 %{_datadir}/%{vdsm_name}/hooks.py*
diff --git a/vdsm/API.py b/vdsm/API.py
index a1e3f2c..732f8a3 100644
--- a/vdsm/API.py
+++ b/vdsm/API.py
@@ -1119,6 +1119,17 @@
 
         return {'status': doneCode, 'info': c}
 
+    def getHardwareInfo(self):
+        """
+        Report host hardware information
+        """
+        try:
+            hw = supervdsm.getProxy().getHardwareInfo()
+            return {'status': doneCode, 'info': hw}
+        except:
+            self.log.error("failed to retrieve hardware info", exc_info=True)
+            return errCode['hwInfoErr']
+
     def getStats(self):
         """
         Report host statistics.
diff --git a/vdsm/BindingXMLRPC.py b/vdsm/BindingXMLRPC.py
index 73185b9..f19a8bb 100644
--- a/vdsm/BindingXMLRPC.py
+++ b/vdsm/BindingXMLRPC.py
@@ -288,6 +288,10 @@
         ret['info'].update(self.getServerInfo())
         return ret
 
+    def getHardwareInfo(self):
+        api = API.Global()
+        return api.getHardwareInfo()
+
     def getStats(self):
         api = API.Global()
         return api.getStats()
@@ -768,6 +772,7 @@
                 (self.vmGetMigrationStatus, 'migrateStatus'),
                 (self.vmMigrationCancel, 'migrateCancel'),
                 (self.getCapabilities, 'getVdsCapabilities'),
+                (self.getHardwareInfo, 'getVdsHardwareInfo'),
                 (self.getStats, 'getVdsStats'),
                 (self.vmGetStats, 'getVmStats'),
                 (self.getAllVmStats, 'getAllVmStats'),
diff --git a/vdsm/Makefile.am b/vdsm/Makefile.am
index dc0590e..88b3287 100644
--- a/vdsm/Makefile.am
+++ b/vdsm/Makefile.am
@@ -32,6 +32,7 @@
 	configNetwork.py \
 	debugPluginClient.py \
 	dummybr.py \
+	dmidecodeUtil.py \
 	guestIF.py \
 	hooking.py \
 	hooks.py \
diff --git a/vdsm/define.py b/vdsm/define.py
index efebea1..01b0c60 100644
--- a/vdsm/define.py
+++ b/vdsm/define.py
@@ -127,6 +127,9 @@
             'updateDevice': {'status':
                              {'code': 56,
                               'message': 'Failed to update device'}},
+            'hwInfoErr': {'status':
+                          {'code': 57,
+                           'message': 'Failed to read hardware information'}},
             'recovery': {'status':
                          {'code': 99,
                           'message':
diff --git a/vdsm/dmidecodeUtil.py b/vdsm/dmidecodeUtil.py
new file mode 100644
index 0000000..eb8d834
--- /dev/null
+++ b/vdsm/dmidecodeUtil.py
@@ -0,0 +1,99 @@
+#
+# Copyright 2012 Red Hat, Inc.
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301 USA
+#
+# Refer to the README and COPYING files for full details of the license
+#
+
+import dmidecode
+from vdsm import utils
+
+
+# This function gets dict and returns new dict that includes only string
+# value for each key. Keys in d that their value is a dictionary will be
+# ignored because those keys define a lable for the sub dictionary
+# (and those keys are irrelevant for us in dmidecode output)
+def __leafDict(d):
+    ret = {}
+    for k, v in d.iteritems():
+        if isinstance(v, dict):
+            ret.update(__leafDict(v))
+        else:
+            ret[k] = v
+    return ret
+
+
+ at utils.memoized
+def getAllDmidecodeInfo():
+    myLeafDict = {}
+    for k in ('system', 'bios', 'cache', 'processor', 'chassis', 'memory'):
+        myLeafDict[k] = __leafDict(getattr(dmidecode, k)())
+    return myLeafDict
+
+
+ at utils.memoized
+def getHardwareInfoStructure():
+    dmiInfo = getAllDmidecodeInfo()
+    sysStruct = {}
+    for k1, k2 in (('system', 'Manufacturer'),
+                   ('system', 'Product Name'),
+                   ('system', 'Version'),
+                   ('system', 'Serial Number'),
+                   ('system', 'UUID'),
+                   ('system', 'Family')):
+        sysStruct[(k1 + k2).replace(' ', '')] = dmiInfo[k1][k2]
+
+    return sysStruct
+
+
+def printInfo(d):
+
+    def formatData(data):
+        return '\n'.join(['%s - %s' % (k, v) for k, v in data.iteritems()])
+
+    print(
+        """
+        SYSTEM INFORMATION
+        ==================
+{system}
+
+        BIOS INFORMATION
+        ================
+{bios}
+
+        CACHE INFORMATION
+        =================
+{cache}
+
+        PROCESSOR INFO
+        ==============
+{processor}
+
+        CHASSIS INFO
+        ============
+{chassis}
+
+        MEMORY INFORMATION
+        ==================
+{memory}
+        """.format(
+        system=formatData(d['system']),
+        bios=formatData(d['bios']),
+        cache=formatData(d['cache']),
+        processor=formatData(d['processor']),
+        chassis=formatData(d['chassis']),
+        memory=formatData(d['memory']))
+    )
diff --git a/vdsm/supervdsmServer.py b/vdsm/supervdsmServer.py
index 5effd41..dc89218 100755
--- a/vdsm/supervdsmServer.py
+++ b/vdsm/supervdsmServer.py
@@ -17,6 +17,7 @@
 # Refer to the README and COPYING files for full details of the license
 #
 
+import platform
 import logging
 import logging.config
 import sys
@@ -94,6 +95,15 @@
         return True
 
     @logDecorator
+    def getHardwareInfo(self, *args, **kwargs):
+        if platform.machine() in ('x86_64', 'i686'):
+            from dmidecodeUtil import getHardwareInfoStructure
+            return getHardwareInfoStructure()
+        else:
+            #  not implemented over other architecture
+            return {}
+
+    @logDecorator
     def getDevicePartedInfo(self, *args, **kwargs):
         return _getDevicePartedInfo(*args, **kwargs)
 
diff --git a/vdsm_api/vdsmapi-schema.json b/vdsm_api/vdsmapi-schema.json
index 7c9ef22..b69d33e 100644
--- a/vdsm_api/vdsmapi-schema.json
+++ b/vdsm_api/vdsmapi-schema.json
@@ -690,6 +690,31 @@
  'data': {'release': 'str', 'version': 'str', 'name': 'OSName'}}
 
 ##
+# @HardwareInformation:
+#
+# Host hardware fields.
+#
+# @systemManufacturer:  Host manufacturer's name
+#
+# @systemProductName:   Host's hardware module
+#
+# @systemSerialNumber:  Hardware serial number
+#
+# @systemFamily:        Processor type
+#
+# @systemUUID:          Host's hardware UUID
+#
+# @systemVersion:       Host's hardware version
+#
+# Since: 4.10.3
+##
+{'type': 'HardwareInformation',
+ 'data': {'systemManufacturer': 'str',
+          'systemProductName': 'str', 'systemVersion': 'str',
+          'systemSerialNumber': 'str', 'systemUUID': 'str',
+          'systemFamily': 'str'}}
+
+##
 # @SoftwarePackage:
 #
 # An enumeration of aliases for important software components.
diff --git a/vdsm_cli/vdsClient.py b/vdsm_cli/vdsClient.py
index c67e3fe..884dc5d 100644
--- a/vdsm_cli/vdsClient.py
+++ b/vdsm_cli/vdsClient.py
@@ -411,6 +411,9 @@
     def do_getCap(self, args):
         return self.ExecAndExit(self.s.getVdsCapabilities())
 
+    def do_getHardware(self, args):
+        return self.ExecAndExit(self.s.getVdsHardwareInfo())
+
     def do_getVdsStats(self, args):
         return self.ExecAndExit(self.s.getVdsStats())
 
@@ -1900,6 +1903,10 @@
                        ('',
                         'Get Capabilities info of the VDS'
                         )),
+        'getVdsHardwareInfo': (serv.do_getHardware,
+                               ('',
+                                'Get hardware info of the VDS'
+                                )),
         'getVdsStats': (serv.do_getVdsStats,
                        ('',
                         'Get Statistics info on the VDS'


--
To view, visit http://gerrit.ovirt.org/11171
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I265645bc67c9bcf14b4479a1fab22c7bd5e865fd
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: ovirt-3.2
Gerrit-Owner: Yaniv Bronhaim <ybronhei at redhat.com>
Gerrit-Reviewer: Barak Azulay <bazulay at redhat.com>
Gerrit-Reviewer: Saggi Mizrahi <smizrahi at redhat.com>
Gerrit-Reviewer: Shu Ming <shuming at linux.vnet.ibm.com>


More information about the vdsm-patches mailing list