1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Add redfish_info command to get service identification (#7883)

* Update redfish_info.py

* Create 7882-add-redfish-get-service-identification.yml

* add get_service_identification

* Update changelogs/fragments/7882-add-redfish-get-service-identification.yml

Co-authored-by: Felix Fontein <felix@fontein.de>

* Update plugins/modules/redfish_info.py

Co-authored-by: Felix Fontein <felix@fontein.de>

---------

Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
D Honig 2024-01-23 01:28:54 -05:00 committed by GitHub
parent 44028060c3
commit 5a51929aa3
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 49 additions and 2 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- redfish_info - add command ``GetServiceIdentification`` to get service identification (https://github.com/ansible-collections/community.general/issues/7882).

View file

@ -3365,7 +3365,8 @@ class RedfishUtils(object):
inventory = {} inventory = {}
# Get these entries, but does not fail if not found # Get these entries, but does not fail if not found
properties = ['Id', 'FirmwareVersion', 'ManagerType', 'Manufacturer', 'Model', properties = ['Id', 'FirmwareVersion', 'ManagerType', 'Manufacturer', 'Model',
'PartNumber', 'PowerState', 'SerialNumber', 'Status', 'UUID'] 'PartNumber', 'PowerState', 'SerialNumber', 'ServiceIdentification',
'Status', 'UUID']
response = self.get_request(self.root_uri + manager_uri) response = self.get_request(self.root_uri + manager_uri)
if response['ret'] is False: if response['ret'] is False:
@ -3383,6 +3384,30 @@ class RedfishUtils(object):
def get_multi_manager_inventory(self): def get_multi_manager_inventory(self):
return self.aggregate_managers(self.get_manager_inventory) return self.aggregate_managers(self.get_manager_inventory)
def get_service_identification(self, manager):
result = {}
if manager is None:
if len(self.manager_uris) == 1:
manager = self.manager_uris[0].split('/')[-1]
elif len(self.manager_uris) > 1:
entries = self.get_multi_manager_inventory()['entries']
managers = [m[0]['manager_uri'] for m in entries if m[1].get('ServiceIdentification')]
if len(managers) == 1:
manager = managers[0].split('/')[-1]
else:
self.module.fail_json(msg=[
"Multiple managers with ServiceIdentification were found: %s" % str(managers),
"Please specify by using the 'manager' parameter in your playbook"])
elif len(self.manager_uris) == 0:
self.module.fail_json(msg="No manager identities were found")
response = self.get_request(self.root_uri + '/redfish/v1/Managers/' + manager, override_headers=None)
try:
result['service_identification'] = response['data']['ServiceIdentification']
except Exception as e:
self.module.fail_json(msg="Service ID not found for manager %s" % manager)
result['ret'] = True
return result
def set_session_service(self, sessions_config): def set_session_service(self, sessions_config):
if sessions_config is None: if sessions_config is None:
return {'ret': False, 'msg': return {'ret': False, 'msg':

View file

@ -55,6 +55,11 @@ options:
- Security token for authenticating to OOB controller. - Security token for authenticating to OOB controller.
type: str type: str
version_added: 2.3.0 version_added: 2.3.0
manager:
description:
- Name of manager on OOB controller to target.
type: str
version_added: '8.3.0'
timeout: timeout:
description: description:
- Timeout in seconds for HTTP requests to OOB controller. - Timeout in seconds for HTTP requests to OOB controller.
@ -248,6 +253,15 @@ EXAMPLES = '''
username: "{{ username }}" username: "{{ username }}"
password: "{{ password }}" password: "{{ password }}"
- name: Get service identification
community.general.redfish_info:
category: Manager
command: GetServiceIdentification
manager: "{{ manager }}"
baseuri: "{{ baseuri }}"
username: "{{ username }}"
password: "{{ password }}"
- name: Get software inventory - name: Get software inventory
community.general.redfish_info: community.general.redfish_info:
category: Update category: Update
@ -369,7 +383,7 @@ CATEGORY_COMMANDS_ALL = {
"Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities", "GetSoftwareInventory", "Update": ["GetFirmwareInventory", "GetFirmwareUpdateCapabilities", "GetSoftwareInventory",
"GetUpdateStatus"], "GetUpdateStatus"],
"Manager": ["GetManagerNicInventory", "GetVirtualMedia", "GetLogs", "GetNetworkProtocols", "Manager": ["GetManagerNicInventory", "GetVirtualMedia", "GetLogs", "GetNetworkProtocols",
"GetHealthReport", "GetHostInterfaces", "GetManagerInventory"], "GetHealthReport", "GetHostInterfaces", "GetManagerInventory", "GetServiceIdentification"],
} }
CATEGORY_COMMANDS_DEFAULT = { CATEGORY_COMMANDS_DEFAULT = {
@ -395,6 +409,7 @@ def main():
auth_token=dict(no_log=True), auth_token=dict(no_log=True),
timeout=dict(type='int'), timeout=dict(type='int'),
update_handle=dict(), update_handle=dict(),
manager=dict(),
), ),
required_together=[ required_together=[
('username', 'password'), ('username', 'password'),
@ -429,6 +444,9 @@ def main():
# update handle # update handle
update_handle = module.params['update_handle'] update_handle = module.params['update_handle']
# manager
manager = module.params['manager']
# Build root URI # Build root URI
root_uri = "https://" + module.params['baseuri'] root_uri = "https://" + module.params['baseuri']
rf_utils = RedfishUtils(creds, root_uri, timeout, module) rf_utils = RedfishUtils(creds, root_uri, timeout, module)
@ -579,6 +597,8 @@ def main():
result["host_interfaces"] = rf_utils.get_hostinterfaces() result["host_interfaces"] = rf_utils.get_hostinterfaces()
elif command == "GetManagerInventory": elif command == "GetManagerInventory":
result["manager"] = rf_utils.get_multi_manager_inventory() result["manager"] = rf_utils.get_multi_manager_inventory()
elif command == "GetServiceIdentification":
result["service_id"] = rf_utils.get_service_identification(manager)
# Return data back # Return data back
module.exit_json(redfish_facts=result) module.exit_json(redfish_facts=result)