Fix get_disk_inventory() not using Storage resource and add more prop… (#52939)

* Fix get_disk_inventory() not using Storage resource and add more properties to output

* don't include null entries

* Add the SimpleStorage resources as well

* Fix misspelling of disk_result
This commit is contained in:
Xander Madsen 2019-03-06 07:39:06 -05:00 committed by John R Barker
parent d32df92d3e
commit 539cab89e1

View file

@ -324,12 +324,16 @@ class RedfishUtils(object):
return {'ret': False, 'msg': "Storage resource not found"}
def get_disk_inventory(self):
result = {}
result = {'entries': []}
controller_list = []
disk_results = []
# Get these entries, but does not fail if not found
properties = ['Name', 'Manufacturer', 'Model', 'Status',
'CapacityBytes']
properties = ['BlockSizeBytes', 'CapableSpeedGbs', 'CapacityBytes',
'EncryptionAbility', 'EncryptionStatus',
'FailurePredicted', 'HotspareType', 'Id', 'Identifiers',
'Manufacturer', 'MediaType', 'Model', 'Name',
'PartNumber', 'PhysicalLocation', 'Protocol', 'Revision',
'RotationSpeedRPM', 'SerialNumber', 'Status']
# Find Storage service
response = self.get_request(self.root_uri + self.systems_uri)
@ -337,34 +341,69 @@ class RedfishUtils(object):
return response
data = response['data']
if 'SimpleStorage' not in data:
return {'ret': False, 'msg': "SimpleStorage resource not found"}
if 'SimpleStorage' not in data and 'Storage' not in data:
return {'ret': False, 'msg': "SimpleStorage and Storage resource \
not found"}
# Get a list of all storage controllers and build respective URIs
storage_uri = data["SimpleStorage"]["@odata.id"]
response = self.get_request(self.root_uri + storage_uri)
if response['ret'] is False:
return response
result['ret'] = True
data = response['data']
for controller in data[u'Members']:
controller_list.append(controller[u'@odata.id'])
for c in controller_list:
uri = self.root_uri + c
response = self.get_request(uri)
if 'Storage' in data:
# Get a list of all storage controllers and build respective URIs
storage_uri = data[u'Storage'][u'@odata.id']
response = self.get_request(self.root_uri + storage_uri)
if response['ret'] is False:
return response
result['ret'] = True
data = response['data']
for device in data[u'Devices']:
disk = {}
for property in properties:
if property in device:
disk[property] = device[property]
disk_results.append(disk)
result["entries"] = disk_results
if data[u'Members']:
for controller in data[u'Members']:
controller_list.append(controller[u'@odata.id'])
for c in controller_list:
uri = self.root_uri + c
response = self.get_request(uri)
if response['ret'] is False:
return response
data = response['data']
if 'Drives' in data:
for device in data[u'Drives']:
disk_uri = self.root_uri + device[u'@odata.id']
response = self.get_request(disk_uri)
data = response['data']
disk_result = {}
for property in properties:
if property in data:
if data[property] is not None:
disk_result[property] = data[property]
disk_results.append(disk_result)
result["entries"].append(disk_results)
if 'SimpleStorage' in data:
# Get a list of all storage controllers and build respective URIs
storage_uri = data["SimpleStorage"]["@odata.id"]
response = self.get_request(self.root_uri + storage_uri)
if response['ret'] is False:
return response
result['ret'] = True
data = response['data']
for controller in data[u'Members']:
controller_list.append(controller[u'@odata.id'])
for c in controller_list:
uri = self.root_uri + c
response = self.get_request(uri)
if response['ret'] is False:
return response
data = response['data']
for device in data[u'Devices']:
disk_result = {}
for property in properties:
if property in device:
disk_result[property] = device[property]
disk_results.append(disk_result)
result["entries"].append(disk_results)
return result
def restart_manager_gracefully(self):