mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Add GetMemoryInventory command to Systems category in redfish facts module (#54125)
* Add GetMemoryInventory command to CATEGORY_COMMANDS_ALL['Systems'] * Add elif command == GetMemoryInventory to Systems category, to use forthcoming get_memory_inventory() function from redfish_utils * Add get_memory_inventory() function to redfish_utils.py, which does not include any Absent dimms * Remove trailing whitespace * Add get_multi_memory_inventory() function to aggregate get_memory_inventory * Call new function get_multi_memory_inventory() * Add memory example in docstring * Fix comment referring to CPUs instead of DIMMs
This commit is contained in:
parent
414ac12ddd
commit
840ceb2777
2 changed files with 72 additions and 4 deletions
|
@ -280,7 +280,7 @@ class RedfishUtils(object):
|
||||||
ret = inventory.pop('ret') and ret
|
ret = inventory.pop('ret') and ret
|
||||||
if 'entries' in inventory:
|
if 'entries' in inventory:
|
||||||
entries.append(({'systems_uri': systems_uri},
|
entries.append(({'systems_uri': systems_uri},
|
||||||
inventory['entries']))
|
inventory['entries']))
|
||||||
return dict(ret=ret, entries=entries)
|
return dict(ret=ret, entries=entries)
|
||||||
|
|
||||||
def get_storage_controller_inventory(self, systems_uri):
|
def get_storage_controller_inventory(self, systems_uri):
|
||||||
|
@ -903,6 +903,63 @@ class RedfishUtils(object):
|
||||||
def get_multi_cpu_inventory(self):
|
def get_multi_cpu_inventory(self):
|
||||||
return self.aggregate(self.get_cpu_inventory)
|
return self.aggregate(self.get_cpu_inventory)
|
||||||
|
|
||||||
|
def get_memory_inventory(self, systems_uri):
|
||||||
|
result = {}
|
||||||
|
memory_list = []
|
||||||
|
memory_results = []
|
||||||
|
key = "Memory"
|
||||||
|
# Get these entries, but does not fail if not found
|
||||||
|
properties = ['SerialNumber', 'MemoryDeviceType', 'PartNuber',
|
||||||
|
'MemoryLocation', 'RankCount', 'CapacityMiB', 'OperatingMemoryModes', 'Status', 'Manufacturer', 'Name']
|
||||||
|
|
||||||
|
# Search for 'key' entry and extract URI from it
|
||||||
|
response = self.get_request(self.root_uri + systems_uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
result['ret'] = True
|
||||||
|
data = response['data']
|
||||||
|
|
||||||
|
if key not in data:
|
||||||
|
return {'ret': False, 'msg': "Key %s not found" % key}
|
||||||
|
|
||||||
|
memory_uri = data[key]["@odata.id"]
|
||||||
|
|
||||||
|
# Get a list of all DIMMs and build respective URIs
|
||||||
|
response = self.get_request(self.root_uri + memory_uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
result['ret'] = True
|
||||||
|
data = response['data']
|
||||||
|
|
||||||
|
for dimm in data[u'Members']:
|
||||||
|
memory_list.append(dimm[u'@odata.id'])
|
||||||
|
|
||||||
|
for m in memory_list:
|
||||||
|
dimm = {}
|
||||||
|
uri = self.root_uri + m
|
||||||
|
response = self.get_request(uri)
|
||||||
|
if response['ret'] is False:
|
||||||
|
return response
|
||||||
|
data = response['data']
|
||||||
|
|
||||||
|
if "Status" in data:
|
||||||
|
if "State" in data["Status"]:
|
||||||
|
if data["Status"]["State"] == "Absent":
|
||||||
|
continue
|
||||||
|
else:
|
||||||
|
continue
|
||||||
|
|
||||||
|
for property in properties:
|
||||||
|
if property in data:
|
||||||
|
dimm[property] = data[property]
|
||||||
|
|
||||||
|
memory_results.append(dimm)
|
||||||
|
result["entries"] = memory_results
|
||||||
|
return result
|
||||||
|
|
||||||
|
def get_multi_memory_inventory(self):
|
||||||
|
return self.aggregate(self.get_memory_inventory)
|
||||||
|
|
||||||
def get_nic_inventory(self, resource_uri):
|
def get_nic_inventory(self, resource_uri):
|
||||||
result = {}
|
result = {}
|
||||||
nic_list = []
|
nic_list = []
|
||||||
|
|
|
@ -74,6 +74,14 @@ EXAMPLES = '''
|
||||||
- debug:
|
- debug:
|
||||||
msg: "{{ redfish_facts.cpu.entries.0.Model }}"
|
msg: "{{ redfish_facts.cpu.entries.0.Model }}"
|
||||||
|
|
||||||
|
- name: Get memory inventory
|
||||||
|
redfish_facts:
|
||||||
|
category: Systems
|
||||||
|
command: GetMemoryInventory
|
||||||
|
baseuri: "{{ baseuri }}"
|
||||||
|
username: "{{ username }}"
|
||||||
|
password: "{{ password }}"
|
||||||
|
|
||||||
- name: Get fan inventory with a timeout of 20 seconds
|
- name: Get fan inventory with a timeout of 20 seconds
|
||||||
redfish_facts:
|
redfish_facts:
|
||||||
category: Chassis
|
category: Chassis
|
||||||
|
@ -150,9 +158,10 @@ from ansible.module_utils.basic import AnsibleModule
|
||||||
from ansible.module_utils.redfish_utils import RedfishUtils
|
from ansible.module_utils.redfish_utils import RedfishUtils
|
||||||
|
|
||||||
CATEGORY_COMMANDS_ALL = {
|
CATEGORY_COMMANDS_ALL = {
|
||||||
"Systems": ["GetSystemInventory", "GetCpuInventory",
|
"Systems": ["GetSystemInventory", "GetPsuInventory", "GetCpuInventory",
|
||||||
"GetNicInventory", "GetStorageControllerInventory",
|
"GetMemoryInventory", "GetNicInventory",
|
||||||
"GetDiskInventory", "GetBiosAttributes", "GetBootOrder"],
|
"GetStorageControllerInventory", "GetDiskInventory",
|
||||||
|
"GetBiosAttributes", "GetBootOrder"],
|
||||||
"Chassis": ["GetFanInventory", "GetPsuInventory"],
|
"Chassis": ["GetFanInventory", "GetPsuInventory"],
|
||||||
"Accounts": ["ListUsers"],
|
"Accounts": ["ListUsers"],
|
||||||
"Update": ["GetFirmwareInventory"],
|
"Update": ["GetFirmwareInventory"],
|
||||||
|
@ -238,6 +247,8 @@ def main():
|
||||||
result["system"] = rf_utils.get_multi_system_inventory()
|
result["system"] = rf_utils.get_multi_system_inventory()
|
||||||
elif command == "GetCpuInventory":
|
elif command == "GetCpuInventory":
|
||||||
result["cpu"] = rf_utils.get_multi_cpu_inventory()
|
result["cpu"] = rf_utils.get_multi_cpu_inventory()
|
||||||
|
elif command == "GetMemoryInventory":
|
||||||
|
result["memory"] = rf_utils.get_multi_memory_inventory()
|
||||||
elif command == "GetNicInventory":
|
elif command == "GetNicInventory":
|
||||||
result["nic"] = rf_utils.get_multi_nic_inventory(category)
|
result["nic"] = rf_utils.get_multi_nic_inventory(category)
|
||||||
elif command == "GetStorageControllerInventory":
|
elif command == "GetStorageControllerInventory":
|
||||||
|
|
Loading…
Reference in a new issue