From 11717ce52475244dbc460b2b2885abf4b5deee16 Mon Sep 17 00:00:00 2001 From: Kushal Date: Thu, 29 Jun 2023 22:00:28 +0530 Subject: [PATCH 01/21] Adding create volume functionality --- plugins/module_utils/redfish_utils.py | 82 +++++++++++++++++++++++++++ plugins/modules/redfish_config.py | 31 +++++++++- 2 files changed, 111 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index fc6e11b3e77..6a9d5a60ad5 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3544,3 +3544,85 @@ def delete_volumes(self, storage_subsystem_id, volume_ids): return {'ret': True, 'changed': True, 'msg': "The following volumes were deleted: %s" % str(volume_ids)} + + def create_volume(self, volume_details, storage_subsystem_id): + # Find the Storage resource from the requested ComputerSystem resource + response = self.get_request(self.root_uri + self.systems_uri) + if response['ret'] is False: + return response + data = response['data'] + storage_uri = data.get('Storage', {}).get('@odata.id') + if storage_uri is None: + return {'ret': False, 'msg': 'Storage resource not found'} + + # Get Storage Collection + response = self.get_request(self.root_uri + storage_uri) + if response['ret'] is False: + return response + data = response['data'] + + # Collect Storage Subsystems + self.storage_subsystems_uris = [i['@odata.id'] for i in response['data'].get('Members', [])] + if not self.storage_subsystems_uris: + return { + 'ret': False, + 'msg': "StorageCollection's Members array is either empty or missing"} + + # Matching Storage Subsystem ID with user input + self.storage_subsystem_uri = "" + for storage_subsystem_uri in self.storage_subsystems_uris: + if storage_subsystem_uri.split("/")[-2] == storage_subsystem_id: + self.storage_subsystem_uri = storage_subsystem_uri + + if not self.storage_subsystem_uri: + return { + 'ret': False, + 'msg': "Provided Storage Subsystem ID %s does not exist on the server" % storage_subsystem_id} + + # Validate input parameters + required_parameters = ['RAIDType', 'Drives'] + allowed_parameters = ['CapacityBytes', 'DisplayName', 'InitializeMethod', 'MediaSpanCount', + 'Name', 'ReadCachePolicy', 'StripSizeBytes', 'VolumeUsage', 'WriteCachePolicy'] + + for parameter in required_parameters: + if not volume_details.get(parameter): + return { + 'ret': False, + 'msg': "%s are required parameter to create a volume" % str(required_parameters)} + + # Navigate to the volume uri of the correct storage subsystem + response = self.get_request(self.root_uri + self.storage_subsystem_uri) + if response['ret'] is False: + return response + data = response['data'] + + # Deleting any volumes of RAIDType None present on the Storage Subsystem + response = self.get_request(self.root_uri + data['Volumes']['@odata.id']) + if response['ret'] is False: + return response + volume_data = response['data'] + + if "Members" in volume_data: + for member in volume_data["Members"]: + response = self.get_request(self.root_uri + member['@odata.id']) + if response['ret'] is False: + return response + member_data = response['data'] + + if member_data["RAIDType"] == "None": + response = self.delete_request(self.root_uri + member['@odata.id']) + if response['ret'] is False: + return response + + # Construct payload and issue POST command to create volume + volume_details["Links"] = {} + volume_details["Links"]["Drives"] = [] + for drive in volume_details["Drives"]: + volume_details["Links"]["Drives"].append({"@odata.id": drive}) + del volume_details["Drives"] + payload = volume_details + response = self.post_request(self.root_uri + data['Volumes']['@odata.id'], payload) + if response['ret'] is False: + return response + return {'ret': True, 'changed': True, + 'msg': "Volume Created"} diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index 65d933bdbd2..112d8706c11 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -152,6 +152,13 @@ type: bool default: True version_added: '7.5.0' + volume_details: + required: false + description: + - Setting dict of volume to be created. + type: dict + default: {} + version_added: '7.2.0' author: - "Jose Delarosa (@jose-delarosa)" - "T S Kushal (@TSKushal)" @@ -312,6 +319,20 @@ password: "{{ password }}" storage_subsystem_id: "DExxxxxx" volume_ids: ["volume1", "volume2"] + + - name: Create Volume + community.general.redfish_config: + category: Systems + command: CreateVolume + baseuri: "{{ baseuri }}" + username: "{{ username }}" + password: "{{ password }}" + volume_details: + Name: "MR Volume" + RAIDType: "RAID0" + Links: + Drives: + - "@odata.id": "/redfish/v1/Systems/1/Storage/DE00B000/Drives/1" ''' RETURN = ''' @@ -330,7 +351,7 @@ # More will be added as module features are expanded CATEGORY_COMMANDS_ALL = { "Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder", - "SetDefaultBootOrder", "EnableSecureBoot", "SetSecureBoot", "DeleteVolumes"], + "SetDefaultBootOrder", "EnableSecureBoot", "SetSecureBoot", "DeleteVolumes", "CreateVolume"], "Manager": ["SetNetworkProtocols", "SetManagerNic", "SetHostInterface"], "Sessions": ["SetSessionService"], } @@ -365,7 +386,8 @@ def main(): sessions_config=dict(type='dict', default={}), storage_subsystem_id=dict(type='str', default=''), volume_ids=dict(type='list', default=[], elements='str'), - secure_boot_enable=dict(type='bool', default=True) + secure_boot_enable=dict(type='bool', default=True), + volume_details=dict(type='dict', default={}) ), required_together=[ ('username', 'password'), @@ -422,6 +444,9 @@ def main(): # Set SecureBoot options secure_boot_enable = module.params['secure_boot_enable'] + # Volume creation options + volume_details = module.params['volume_details'] + # Build root URI root_uri = "https://" + module.params['baseuri'] rf_utils = RedfishUtils(creds, root_uri, timeout, module, @@ -459,6 +484,8 @@ def main(): result = rf_utils.set_secure_boot(secure_boot_enable) elif command == "DeleteVolumes": result = rf_utils.delete_volumes(storage_subsystem_id, volume_ids) + elif command == "CreateVolume": + result = rf_utils.create_volume(volume_details) elif category == "Manager": # execute only if we find a Manager service resource From 0b4a076176d025d97734c03964590aa48178cf02 Mon Sep 17 00:00:00 2001 From: Kushal Date: Thu, 29 Jun 2023 22:08:03 +0530 Subject: [PATCH 02/21] Adding changelog fragment --- changelogs/fragments/6813-redfish-config-add-create-volume.yml | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 changelogs/fragments/6813-redfish-config-add-create-volume.yml diff --git a/changelogs/fragments/6813-redfish-config-add-create-volume.yml b/changelogs/fragments/6813-redfish-config-add-create-volume.yml new file mode 100644 index 00000000000..06c2efbcd86 --- /dev/null +++ b/changelogs/fragments/6813-redfish-config-add-create-volume.yml @@ -0,0 +1,2 @@ +minor_changes: + - redfish_config - add ``CreateVolume`` command to allow creation of volumes on servers (https://github.com/ansible-collections/community.general/pull/6813). From f5c5b9beff8f98c8d09e05ff0ead14e162de2a35 Mon Sep 17 00:00:00 2001 From: Kushal Date: Thu, 29 Jun 2023 22:19:53 +0530 Subject: [PATCH 03/21] Sanity Fix --- plugins/module_utils/redfish_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index 6a9d5a60ad5..5537ca3f7ad 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3625,4 +3625,4 @@ def create_volume(self, volume_details, storage_subsystem_id): if response['ret'] is False: return response return {'ret': True, 'changed': True, - 'msg': "Volume Created"} + 'msg': "Volume Created"} \ No newline at end of file From 76adc70b50d881c647227831bc3bd5317373bb10 Mon Sep 17 00:00:00 2001 From: Kushal Date: Thu, 29 Jun 2023 22:30:05 +0530 Subject: [PATCH 04/21] Sanity fix --- changelogs/fragments/6813-redfish-config-add-create-volume.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/changelogs/fragments/6813-redfish-config-add-create-volume.yml b/changelogs/fragments/6813-redfish-config-add-create-volume.yml index 06c2efbcd86..325ebf4ad12 100644 --- a/changelogs/fragments/6813-redfish-config-add-create-volume.yml +++ b/changelogs/fragments/6813-redfish-config-add-create-volume.yml @@ -1,2 +1,3 @@ +--- minor_changes: - redfish_config - add ``CreateVolume`` command to allow creation of volumes on servers (https://github.com/ansible-collections/community.general/pull/6813). From 52b50a6e7b1ed71358152d435f738fbaa7395e80 Mon Sep 17 00:00:00 2001 From: TSKushal <44438079+TSKushal@users.noreply.github.com> Date: Thu, 29 Jun 2023 22:38:17 +0530 Subject: [PATCH 05/21] Update 6813-redfish-config-add-create-volume.yml From 4a9241c02fc527947f8b680f1880fe0dbb14df0e Mon Sep 17 00:00:00 2001 From: Kushal Date: Thu, 29 Jun 2023 22:43:21 +0530 Subject: [PATCH 06/21] Sanity fix --- changelogs/fragments/6813-redfish-config-add-create-volume.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/changelogs/fragments/6813-redfish-config-add-create-volume.yml b/changelogs/fragments/6813-redfish-config-add-create-volume.yml index 325ebf4ad12..a1a544f3520 100644 --- a/changelogs/fragments/6813-redfish-config-add-create-volume.yml +++ b/changelogs/fragments/6813-redfish-config-add-create-volume.yml @@ -1,3 +1,3 @@ --- minor_changes: - - redfish_config - add ``CreateVolume`` command to allow creation of volumes on servers (https://github.com/ansible-collections/community.general/pull/6813). + - redfish_config - add ``CreateVolume`` command to allow creation of volumes on servers (https://github.com/ansible-collections/community.general/pull/6813). \ No newline at end of file From ac0eb2243c8ee46568a784ab877b2df4f4f60624 Mon Sep 17 00:00:00 2001 From: Kushal Date: Thu, 29 Jun 2023 22:49:20 +0530 Subject: [PATCH 07/21] Sanity fix --- .../fragments/6813-redfish-config-add-create-volume.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/changelogs/fragments/6813-redfish-config-add-create-volume.yml b/changelogs/fragments/6813-redfish-config-add-create-volume.yml index a1a544f3520..96bd532c0d5 100644 --- a/changelogs/fragments/6813-redfish-config-add-create-volume.yml +++ b/changelogs/fragments/6813-redfish-config-add-create-volume.yml @@ -1,3 +1,2 @@ ---- -minor_changes: - - redfish_config - add ``CreateVolume`` command to allow creation of volumes on servers (https://github.com/ansible-collections/community.general/pull/6813). \ No newline at end of file +minor_changes: + - redfish_config - add ``CreateVolume`` command to allow creation of volumes on servers (https://github.com/ansible-collections/community.general/pull/6813). From ad331115b129d8439f4e38af47052233255c915b Mon Sep 17 00:00:00 2001 From: Kushal Date: Mon, 3 Jul 2023 20:14:21 +0530 Subject: [PATCH 08/21] Removing capabilities check and correcting controllers terminology to storage subsystem --- plugins/modules/redfish_config.py | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index 112d8706c11..8e26d81c3e6 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -159,6 +159,13 @@ type: dict default: {} version_added: '7.2.0' + storage_subsystem_id: + required: false + description: + - Id of the Storage Subsystem on which the volume is to be created. + type: str + default: '' + version_added: '7.2.0' author: - "Jose Delarosa (@jose-delarosa)" - "T S Kushal (@TSKushal)" @@ -384,10 +391,15 @@ def main(): hostinterface_config=dict(type='dict', default={}), hostinterface_id=dict(), sessions_config=dict(type='dict', default={}), +<<<<<<< HEAD storage_subsystem_id=dict(type='str', default=''), volume_ids=dict(type='list', default=[], elements='str'), secure_boot_enable=dict(type='bool', default=True), volume_details=dict(type='dict', default={}) +======= + volume_details=dict(type='dict', default={}), + storage_subsystem_id=dict(type='str', default='') +>>>>>>> 1bef8445 (Removing capabilities check and correcting controllers terminology to storage subsystem) ), required_together=[ ('username', 'password'), @@ -446,6 +458,7 @@ def main(): # Volume creation options volume_details = module.params['volume_details'] + storage_subsystem_id = module.params['storage_subsystem_id'] # Build root URI root_uri = "https://" + module.params['baseuri'] @@ -485,7 +498,7 @@ def main(): elif command == "DeleteVolumes": result = rf_utils.delete_volumes(storage_subsystem_id, volume_ids) elif command == "CreateVolume": - result = rf_utils.create_volume(volume_details) + result = rf_utils.create_volume(volume_details, storage_subsystem_id) elif category == "Manager": # execute only if we find a Manager service resource From 98c61a4c2517e7181b663daf18ed9c5a6618d00a Mon Sep 17 00:00:00 2001 From: Kushal Date: Wed, 19 Jul 2023 17:21:06 +0530 Subject: [PATCH 09/21] Updating as per PR suggestions --- plugins/modules/redfish_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index 8e26d81c3e6..c0a81fdd2da 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -334,12 +334,12 @@ baseuri: "{{ baseuri }}" username: "{{ username }}" password: "{{ password }}" + storage_subsystem_id: "DExxxxxx" volume_details: Name: "MR Volume" RAIDType: "RAID0" - Links: Drives: - - "@odata.id": "/redfish/v1/Systems/1/Storage/DE00B000/Drives/1" + - "/redfish/v1/Systems/1/Storage/DE00B000/Drives/1" ''' RETURN = ''' From 640eb77786f4f31588ba7eaa8ed7906e120ccd00 Mon Sep 17 00:00:00 2001 From: Kushal Date: Wed, 19 Jul 2023 17:29:49 +0530 Subject: [PATCH 10/21] sanity fix --- plugins/modules/redfish_config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index c0a81fdd2da..274803de2ac 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -338,8 +338,8 @@ volume_details: Name: "MR Volume" RAIDType: "RAID0" - Drives: - - "/redfish/v1/Systems/1/Storage/DE00B000/Drives/1" + Drives: + - "/redfish/v1/Systems/1/Storage/DE00B000/Drives/1" ''' RETURN = ''' From bd8c2c19db0e33aa2976bdf2da3db3d6f248658e Mon Sep 17 00:00:00 2001 From: TSKushal <44438079+TSKushal@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:21:59 +0530 Subject: [PATCH 11/21] Update plugins/modules/redfish_config.py Co-authored-by: Felix Fontein --- plugins/modules/redfish_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index 274803de2ac..dfde927c968 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -158,7 +158,7 @@ - Setting dict of volume to be created. type: dict default: {} - version_added: '7.2.0' + version_added: '7.4.0' storage_subsystem_id: required: false description: From 75b32a61d8425190f92ee1b64f6d6a5d033de6ff Mon Sep 17 00:00:00 2001 From: TSKushal <44438079+TSKushal@users.noreply.github.com> Date: Fri, 18 Aug 2023 16:22:23 +0530 Subject: [PATCH 12/21] Update plugins/modules/redfish_config.py Agreed Co-authored-by: Felix Fontein --- plugins/modules/redfish_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index dfde927c968..e57c64d6988 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -165,7 +165,7 @@ - Id of the Storage Subsystem on which the volume is to be created. type: str default: '' - version_added: '7.2.0' + version_added: '7.4.0' author: - "Jose Delarosa (@jose-delarosa)" - "T S Kushal (@TSKushal)" From 5859e077cb4288cb8d4bbd8498a8c52ab6ca3f47 Mon Sep 17 00:00:00 2001 From: Kushal Date: Wed, 20 Sep 2023 22:33:25 +0530 Subject: [PATCH 13/21] Fixing merge issue --- plugins/modules/redfish_config.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index e57c64d6988..09d6fb3e5fb 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -391,15 +391,10 @@ def main(): hostinterface_config=dict(type='dict', default={}), hostinterface_id=dict(), sessions_config=dict(type='dict', default={}), -<<<<<<< HEAD storage_subsystem_id=dict(type='str', default=''), volume_ids=dict(type='list', default=[], elements='str'), secure_boot_enable=dict(type='bool', default=True), volume_details=dict(type='dict', default={}) -======= - volume_details=dict(type='dict', default={}), - storage_subsystem_id=dict(type='str', default='') ->>>>>>> 1bef8445 (Removing capabilities check and correcting controllers terminology to storage subsystem) ), required_together=[ ('username', 'password'), From ebf5f73ed911c44752004ad5886b1cdcd2f91277 Mon Sep 17 00:00:00 2001 From: Kushal Date: Wed, 20 Sep 2023 22:38:06 +0530 Subject: [PATCH 14/21] Fixing sanity issues --- plugins/module_utils/redfish_utils.py | 2 +- plugins/modules/redfish_config.py | 7 ------- 2 files changed, 1 insertion(+), 8 deletions(-) diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index 5537ca3f7ad..6a9d5a60ad5 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3625,4 +3625,4 @@ def create_volume(self, volume_details, storage_subsystem_id): if response['ret'] is False: return response return {'ret': True, 'changed': True, - 'msg': "Volume Created"} \ No newline at end of file + 'msg': "Volume Created"} diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index 09d6fb3e5fb..2300fbc6a90 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -159,13 +159,6 @@ type: dict default: {} version_added: '7.4.0' - storage_subsystem_id: - required: false - description: - - Id of the Storage Subsystem on which the volume is to be created. - type: str - default: '' - version_added: '7.4.0' author: - "Jose Delarosa (@jose-delarosa)" - "T S Kushal (@TSKushal)" From 688ff53b377cc76055b6eafea96e8cd545ce0729 Mon Sep 17 00:00:00 2001 From: Kushal Date: Wed, 27 Sep 2023 20:51:45 +0530 Subject: [PATCH 15/21] Adding CapacityBytes as a mandatory parameter and adding failure message when run for server below iLO6 --- plugins/module_utils/redfish_utils.py | 32 +++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index 6a9d5a60ad5..0e763b35c2f 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -10,6 +10,7 @@ import os import random import string +import re from ansible.module_utils.urls import open_url from ansible.module_utils.common.text.converters import to_native from ansible.module_utils.common.text.converters import to_text @@ -3546,6 +3547,33 @@ def delete_volumes(self, storage_subsystem_id, volume_ids): 'msg': "The following volumes were deleted: %s" % str(volume_ids)} def create_volume(self, volume_details, storage_subsystem_id): + # Fail message if run for iLO5 or lower server + vendor = self._get_vendor()['Vendor'] + if vendor == 'HPE': + response = self._find_managers_resource() + if response['ret'] is False: + return response + + response = self.get_request(self.root_uri + self.manager_uri) + if response['ret'] is False: + return response + + resp = response['data'] + if 'FirmwareVersion' not in resp.keys(): + return { + "ret": False, + "msg": "Key 'FirmwareVersion' not found in response: %s" % (resp) + } + + fw_version = resp['FirmwareVersion'] + ilo_gen = re.sub("\D", "", fw_version).strip()[0] + + if int(ilo_gen) < 6: + return { + "ret": False, + "msg": "This operation is not supported for iLO %s servers" % (str(ilo_gen)) + } + # Find the Storage resource from the requested ComputerSystem resource response = self.get_request(self.root_uri + self.systems_uri) if response['ret'] is False: @@ -3580,8 +3608,8 @@ def create_volume(self, volume_details, storage_subsystem_id): 'msg': "Provided Storage Subsystem ID %s does not exist on the server" % storage_subsystem_id} # Validate input parameters - required_parameters = ['RAIDType', 'Drives'] - allowed_parameters = ['CapacityBytes', 'DisplayName', 'InitializeMethod', 'MediaSpanCount', + required_parameters = ['RAIDType', 'Drives', 'CapacityBytes'] + allowed_parameters = ['DisplayName', 'InitializeMethod', 'MediaSpanCount', 'Name', 'ReadCachePolicy', 'StripSizeBytes', 'VolumeUsage', 'WriteCachePolicy'] for parameter in required_parameters: From 4f28af72e6def5af76ddb337f8902815e9497709 Mon Sep 17 00:00:00 2001 From: Kushal Date: Wed, 27 Sep 2023 21:55:54 +0530 Subject: [PATCH 16/21] Sanity fix --- plugins/module_utils/redfish_utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index 0e763b35c2f..f30d3bfb55c 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3566,7 +3566,7 @@ def create_volume(self, volume_details, storage_subsystem_id): } fw_version = resp['FirmwareVersion'] - ilo_gen = re.sub("\D", "", fw_version).strip()[0] + ilo_gen = re.sub(r"\D", "", fw_version).strip()[0] if int(ilo_gen) < 6: return { From a4d850eea925cbe79a82e045e1b2c50851bf0e45 Mon Sep 17 00:00:00 2001 From: Kushal Date: Wed, 27 Sep 2023 22:00:41 +0530 Subject: [PATCH 17/21] Sanity fix --- plugins/module_utils/redfish_utils.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index f30d3bfb55c..b178ba70a3c 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3561,9 +3561,9 @@ def create_volume(self, volume_details, storage_subsystem_id): resp = response['data'] if 'FirmwareVersion' not in resp.keys(): return { - "ret": False, - "msg": "Key 'FirmwareVersion' not found in response: %s" % (resp) - } + "ret": False, + "msg": "Key 'FirmwareVersion' not found in response: %s" % (resp) + } fw_version = resp['FirmwareVersion'] ilo_gen = re.sub(r"\D", "", fw_version).strip()[0] From 7d0f032404c0f2ad2f93e94b21832aba4e713b31 Mon Sep 17 00:00:00 2001 From: Kushal Date: Thu, 28 Sep 2023 20:53:24 +0530 Subject: [PATCH 18/21] Updating vendor specific failure --- plugins/module_utils/redfish_utils.py | 53 +++++++++++++-------------- 1 file changed, 26 insertions(+), 27 deletions(-) diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index b178ba70a3c..c4f61b2fcb6 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3547,33 +3547,6 @@ def delete_volumes(self, storage_subsystem_id, volume_ids): 'msg': "The following volumes were deleted: %s" % str(volume_ids)} def create_volume(self, volume_details, storage_subsystem_id): - # Fail message if run for iLO5 or lower server - vendor = self._get_vendor()['Vendor'] - if vendor == 'HPE': - response = self._find_managers_resource() - if response['ret'] is False: - return response - - response = self.get_request(self.root_uri + self.manager_uri) - if response['ret'] is False: - return response - - resp = response['data'] - if 'FirmwareVersion' not in resp.keys(): - return { - "ret": False, - "msg": "Key 'FirmwareVersion' not found in response: %s" % (resp) - } - - fw_version = resp['FirmwareVersion'] - ilo_gen = re.sub(r"\D", "", fw_version).strip()[0] - - if int(ilo_gen) < 6: - return { - "ret": False, - "msg": "This operation is not supported for iLO %s servers" % (str(ilo_gen)) - } - # Find the Storage resource from the requested ComputerSystem resource response = self.get_request(self.root_uri + self.systems_uri) if response['ret'] is False: @@ -3651,6 +3624,32 @@ def create_volume(self, volume_details, storage_subsystem_id): payload = volume_details response = self.post_request(self.root_uri + data['Volumes']['@odata.id'], payload) if response['ret'] is False: + # Fail message if run for iLO5 or lower server + vendor = self._get_vendor()['Vendor'] + if vendor == 'HPE': + response = self._find_managers_resource() + if response['ret'] is False: + return response + + response = self.get_request(self.root_uri + self.manager_uri) + if response['ret'] is False: + return response + + resp = response['data'] + if 'FirmwareVersion' not in resp.keys(): + return { + "ret": False, + "msg": "Key 'FirmwareVersion' not found in response: %s" % (resp) + } + + fw_version = resp['FirmwareVersion'] + ilo_gen = re.sub(r"\D", "", fw_version).strip()[0] + + if int(ilo_gen) < 6: + return { + "ret": False, + "msg": "This operation is not supported for iLO %s servers" % (str(ilo_gen)) + } return response return {'ret': True, 'changed': True, 'msg': "Volume Created"} From 83ff41807ef0b367af9854b841f0fa9830b6d6a2 Mon Sep 17 00:00:00 2001 From: TSKushal <44438079+TSKushal@users.noreply.github.com> Date: Tue, 3 Oct 2023 17:26:42 +0530 Subject: [PATCH 19/21] Update plugins/modules/redfish_config.py Agreed Co-authored-by: Felix Fontein --- plugins/modules/redfish_config.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/modules/redfish_config.py b/plugins/modules/redfish_config.py index 2300fbc6a90..e3f498952f1 100644 --- a/plugins/modules/redfish_config.py +++ b/plugins/modules/redfish_config.py @@ -158,7 +158,7 @@ - Setting dict of volume to be created. type: dict default: {} - version_added: '7.4.0' + version_added: '7.5.0' author: - "Jose Delarosa (@jose-delarosa)" - "T S Kushal (@TSKushal)" From 5a0f855800943da395d0eef5cca563eaa70c9e62 Mon Sep 17 00:00:00 2001 From: Kushal Date: Fri, 6 Oct 2023 20:14:58 +0530 Subject: [PATCH 20/21] Removing vendor specific failure case --- plugins/module_utils/redfish_utils.py | 27 +-------------------------- 1 file changed, 1 insertion(+), 26 deletions(-) diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index c4f61b2fcb6..2357037fd45 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -3624,32 +3624,7 @@ def create_volume(self, volume_details, storage_subsystem_id): payload = volume_details response = self.post_request(self.root_uri + data['Volumes']['@odata.id'], payload) if response['ret'] is False: - # Fail message if run for iLO5 or lower server - vendor = self._get_vendor()['Vendor'] - if vendor == 'HPE': - response = self._find_managers_resource() - if response['ret'] is False: - return response - - response = self.get_request(self.root_uri + self.manager_uri) - if response['ret'] is False: - return response - - resp = response['data'] - if 'FirmwareVersion' not in resp.keys(): - return { - "ret": False, - "msg": "Key 'FirmwareVersion' not found in response: %s" % (resp) - } - - fw_version = resp['FirmwareVersion'] - ilo_gen = re.sub(r"\D", "", fw_version).strip()[0] - - if int(ilo_gen) < 6: - return { - "ret": False, - "msg": "This operation is not supported for iLO %s servers" % (str(ilo_gen)) - } return response + return {'ret': True, 'changed': True, 'msg': "Volume Created"} From 8bb2baeb6ef510c5fd2ef7b063824abe33890748 Mon Sep 17 00:00:00 2001 From: Kushal Date: Fri, 6 Oct 2023 20:18:38 +0530 Subject: [PATCH 21/21] removing unused import --- plugins/module_utils/redfish_utils.py | 1 - 1 file changed, 1 deletion(-) diff --git a/plugins/module_utils/redfish_utils.py b/plugins/module_utils/redfish_utils.py index 2357037fd45..2ee41769329 100644 --- a/plugins/module_utils/redfish_utils.py +++ b/plugins/module_utils/redfish_utils.py @@ -10,7 +10,6 @@ import os import random import string -import re from ansible.module_utils.urls import open_url from ansible.module_utils.common.text.converters import to_native from ansible.module_utils.common.text.converters import to_text