Hello Yaniv Bronhaim,
I'd like you to do a code review. Please visit
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: Ic429ef101fcf9047c4b552405314dc7ba9ba07a0 Signed-off-by: Yaniv Bronhaim ybronhei@redhat.com Signed-off-by: Douglas Schilling Landgraf dougsland@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, 167 insertions(+), 0 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/68/11168/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 + + +@utils.memoized +def getAllDmidecodeInfo(): + myLeafDict = {} + for k in ('system', 'bios', 'cache', 'processor', 'chassis', 'memory'): + myLeafDict[k] = __leafDict(getattr(dmidecode, k)()) + return myLeafDict + + +@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..486471c 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 @@ -38,6 +39,7 @@ _glusterEnabled = False from parted_utils import getDevicePartedInfo as _getDevicePartedInfo from md_utils import getMdDeviceUuidMap as _getMdDeviceUuidMap + from lsblk import getLsBlk as _getLsBlk from storage.multipath import getScsiSerial as _getScsiSerial from storage.iscsi import forceIScsiScan as _forceIScsiScan @@ -94,6 +96,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..f37f550 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/11168 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange Gerrit-Change-Id: Ic429ef101fcf9047c4b552405314dc7ba9ba07a0 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.2 Gerrit-Owner: Douglas Schilling Landgraf dougsland@redhat.com Gerrit-Reviewer: Yaniv Bronhaim ybronhei@redhat.com
Yaniv Bronhaim has posted comments on this change.
Change subject: adding getHardwareInfo API to vdsm ......................................................................
Patch Set 2: Verified
works, over rhel6.4 and fedora17
-- To view, visit http://gerrit.ovirt.org/11168 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: Ic429ef101fcf9047c4b552405314dc7ba9ba07a0 Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.2 Gerrit-Owner: Douglas Schilling Landgraf dougsland@redhat.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Saggi Mizrahi smizrahi@redhat.com Gerrit-Reviewer: Shu Ming shuming@linux.vnet.ibm.com Gerrit-Reviewer: Yaniv Bronhaim ybronhei@redhat.com
Dan Kenigsberg has submitted this change and it was merged.
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: Ic429ef101fcf9047c4b552405314dc7ba9ba07a0 Signed-off-by: Yaniv Bronhaim ybronhei@redhat.com Reviewed-on: http://gerrit.ovirt.org/9258 Reviewed-by: Barak Azulay bazulay@redhat.com Reviewed-by: Shu Ming shuming@linux.vnet.ibm.com Reviewed-by: Saggi Mizrahi smizrahi@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(-)
Approvals: Yaniv Bronhaim: Verified Dan Kenigsberg: Looks good to me, approved
-- To view, visit http://gerrit.ovirt.org/11168 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: merged Gerrit-Change-Id: Ic429ef101fcf9047c4b552405314dc7ba9ba07a0 Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.2 Gerrit-Owner: Douglas Schilling Landgraf dougsland@redhat.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Saggi Mizrahi smizrahi@redhat.com Gerrit-Reviewer: Shu Ming shuming@linux.vnet.ibm.com Gerrit-Reviewer: Yaniv Bronhaim ybronhei@redhat.com
Dan Kenigsberg has posted comments on this change.
Change subject: adding getHardwareInfo API to vdsm ......................................................................
Patch Set 2: Looks good to me, approved
-- To view, visit http://gerrit.ovirt.org/11168 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: comment Gerrit-Change-Id: Ic429ef101fcf9047c4b552405314dc7ba9ba07a0 Gerrit-PatchSet: 2 Gerrit-Project: vdsm Gerrit-Branch: ovirt-3.2 Gerrit-Owner: Douglas Schilling Landgraf dougsland@redhat.com Gerrit-Reviewer: Barak Azulay bazulay@redhat.com Gerrit-Reviewer: Dan Kenigsberg danken@redhat.com Gerrit-Reviewer: Saggi Mizrahi smizrahi@redhat.com Gerrit-Reviewer: Shu Ming shuming@linux.vnet.ibm.com Gerrit-Reviewer: Yaniv Bronhaim ybronhei@redhat.com
vdsm-patches@lists.fedorahosted.org