Adding CreateVolume functionality (#6813)

* Adding create volume functionality

* Adding changelog fragment

* Sanity Fix

* Sanity fix

* Update 6813-redfish-config-add-create-volume.yml

* Sanity fix

* Sanity fix

* Removing capabilities check and correcting controllers terminology to storage subsystem

* Updating as per PR suggestions

* sanity fix

* Update plugins/modules/redfish_config.py

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

* Update plugins/modules/redfish_config.py

Agreed

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

* Fixing merge issue

* Fixing sanity issues

* Adding CapacityBytes as a mandatory parameter and adding failure message when run for server below iLO6

* Sanity fix

* Sanity fix

* Updating vendor specific failure

* Update plugins/modules/redfish_config.py

Agreed

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

* Removing vendor specific failure case

* removing unused import

---------

Co-authored-by: Kushal <t-s.kushal@hpe.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
This commit is contained in:
TSKushal 2023-10-07 02:41:38 +05:30 committed by GitHub
parent 0ca07b0b05
commit 55893f27c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 115 additions and 2 deletions

View file

@ -3547,3 +3547,86 @@ class RedfishUtils(object):
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', 'CapacityBytes']
allowed_parameters = ['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"}