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

[stable-8] Add redfish_info command to get service identification (#7883) (#7887)

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>
(cherry picked from commit 5a51929aa3)

Co-authored-by: D Honig <namssa@gmail.com>
This commit is contained in:
Felix Fontein 2024-01-23 07:59:06 +01:00 committed by GitHub
parent 08239919de
commit 145686cfe0
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 = {}
# Get these entries, but does not fail if not found
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)
if response['ret'] is False:
@ -3383,6 +3384,30 @@ class RedfishUtils(object):
def get_multi_manager_inventory(self):
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):
if sessions_config is None:
return {'ret': False, 'msg':

View file

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