mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 15:41:22 -07:00
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:
parent
d32df92d3e
commit
539cab89e1
1 changed files with 65 additions and 26 deletions
|
@ -324,12 +324,16 @@ class RedfishUtils(object):
|
||||||
return {'ret': False, 'msg': "Storage resource not found"}
|
return {'ret': False, 'msg': "Storage resource not found"}
|
||||||
|
|
||||||
def get_disk_inventory(self):
|
def get_disk_inventory(self):
|
||||||
result = {}
|
result = {'entries': []}
|
||||||
controller_list = []
|
controller_list = []
|
||||||
disk_results = []
|
disk_results = []
|
||||||
# Get these entries, but does not fail if not found
|
# Get these entries, but does not fail if not found
|
||||||
properties = ['Name', 'Manufacturer', 'Model', 'Status',
|
properties = ['BlockSizeBytes', 'CapableSpeedGbs', 'CapacityBytes',
|
||||||
'CapacityBytes']
|
'EncryptionAbility', 'EncryptionStatus',
|
||||||
|
'FailurePredicted', 'HotspareType', 'Id', 'Identifiers',
|
||||||
|
'Manufacturer', 'MediaType', 'Model', 'Name',
|
||||||
|
'PartNumber', 'PhysicalLocation', 'Protocol', 'Revision',
|
||||||
|
'RotationSpeedRPM', 'SerialNumber', 'Status']
|
||||||
|
|
||||||
# Find Storage service
|
# Find Storage service
|
||||||
response = self.get_request(self.root_uri + self.systems_uri)
|
response = self.get_request(self.root_uri + self.systems_uri)
|
||||||
|
@ -337,34 +341,69 @@ class RedfishUtils(object):
|
||||||
return response
|
return response
|
||||||
data = response['data']
|
data = response['data']
|
||||||
|
|
||||||
if 'SimpleStorage' not in data:
|
if 'SimpleStorage' not in data and 'Storage' not in data:
|
||||||
return {'ret': False, 'msg': "SimpleStorage resource not found"}
|
return {'ret': False, 'msg': "SimpleStorage and Storage resource \
|
||||||
|
not found"}
|
||||||
|
|
||||||
# Get a list of all storage controllers and build respective URIs
|
if 'Storage' in data:
|
||||||
storage_uri = data["SimpleStorage"]["@odata.id"]
|
# Get a list of all storage controllers and build respective URIs
|
||||||
response = self.get_request(self.root_uri + storage_uri)
|
storage_uri = data[u'Storage'][u'@odata.id']
|
||||||
if response['ret'] is False:
|
response = self.get_request(self.root_uri + storage_uri)
|
||||||
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:
|
if response['ret'] is False:
|
||||||
return response
|
return response
|
||||||
|
result['ret'] = True
|
||||||
data = response['data']
|
data = response['data']
|
||||||
|
|
||||||
for device in data[u'Devices']:
|
if data[u'Members']:
|
||||||
disk = {}
|
for controller in data[u'Members']:
|
||||||
for property in properties:
|
controller_list.append(controller[u'@odata.id'])
|
||||||
if property in device:
|
for c in controller_list:
|
||||||
disk[property] = device[property]
|
uri = self.root_uri + c
|
||||||
disk_results.append(disk)
|
response = self.get_request(uri)
|
||||||
result["entries"] = disk_results
|
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
|
return result
|
||||||
|
|
||||||
def restart_manager_gracefully(self):
|
def restart_manager_gracefully(self):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue