mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
[PR #6814/47865284 backport][stable-7] Adding DeleteVolumes functionality (#7066)
Adding DeleteVolumes functionality (#6814)
* Adding DeleteAllVolumes functionality
* Adding changelog fragment and sanity fix
* Sanity Fix
* Updating as per PR suggestions
* Sanity fix
* Adjust version_added.
---------
Co-authored-by: Kushal <t-s.kushal@hpe.com>
Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit 478652843f
)
Co-authored-by: TSKushal <44438079+TSKushal@users.noreply.github.com>
This commit is contained in:
parent
3c067aa2c3
commit
14625a214a
3 changed files with 98 additions and 2 deletions
|
@ -0,0 +1,2 @@
|
|||
minor_changes:
|
||||
- redfish_config - add ``DeleteAllVolumes`` command to allow deletion of all volumes on servers (https://github.com/ansible-collections/community.general/pull/6814).
|
|
@ -3411,3 +3411,65 @@ class RedfishUtils(object):
|
|||
fan_percent_min_config = hpe.get('FanPercentMinimum')
|
||||
result["fan_percent_min"] = fan_percent_min_config
|
||||
return result
|
||||
|
||||
def delete_volumes(self, storage_subsystem_id, volume_ids):
|
||||
# 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}
|
||||
|
||||
# Get Volume Collection
|
||||
response = self.get_request(self.root_uri + self.storage_subsystem_uri)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
data = response['data']
|
||||
|
||||
response = self.get_request(self.root_uri + data['Volumes']['@odata.id'])
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
data = response['data']
|
||||
|
||||
# Collect Volumes
|
||||
self.volume_uris = [i['@odata.id'] for i in response['data'].get('Members', [])]
|
||||
if not self.volume_uris:
|
||||
return {
|
||||
'ret': True, 'changed': False,
|
||||
'msg': "VolumeCollection's Members array is either empty or missing"}
|
||||
|
||||
# Delete each volume
|
||||
for volume in self.volume_uris:
|
||||
if volume.split("/")[-1] in volume_ids:
|
||||
response = self.delete_request(self.root_uri + volume)
|
||||
if response['ret'] is False:
|
||||
return response
|
||||
|
||||
return {'ret': True, 'changed': True,
|
||||
'msg': "The following volumes were deleted: %s" % str(volume_ids)}
|
||||
|
|
|
@ -130,7 +130,21 @@ options:
|
|||
type: dict
|
||||
default: {}
|
||||
version_added: '5.7.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.3.0'
|
||||
volume_ids:
|
||||
required: false
|
||||
description:
|
||||
- List of IDs of volumes to be deleted.
|
||||
type: list
|
||||
default: []
|
||||
elements: str
|
||||
version_added: '7.3.0'
|
||||
author:
|
||||
- "Jose Delarosa (@jose-delarosa)"
|
||||
- "T S Kushal (@TSKushal)"
|
||||
|
@ -272,6 +286,16 @@ EXAMPLES = '''
|
|||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
|
||||
- name: Delete All Volumes
|
||||
community.general.redfish_config:
|
||||
category: Systems
|
||||
command: DeleteVolumes
|
||||
baseuri: "{{ baseuri }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
storage_subsystem_id: "DExxxxxx"
|
||||
volume_ids: ["volume1", "volume2"]
|
||||
'''
|
||||
|
||||
RETURN = '''
|
||||
|
@ -290,7 +314,7 @@ from ansible.module_utils.common.text.converters import to_native
|
|||
# More will be added as module features are expanded
|
||||
CATEGORY_COMMANDS_ALL = {
|
||||
"Systems": ["SetBiosDefaultSettings", "SetBiosAttributes", "SetBootOrder",
|
||||
"SetDefaultBootOrder", "EnableSecureBoot"],
|
||||
"SetDefaultBootOrder", "EnableSecureBoot", "DeleteVolumes"],
|
||||
"Manager": ["SetNetworkProtocols", "SetManagerNic", "SetHostInterface"],
|
||||
"Sessions": ["SetSessionService"],
|
||||
}
|
||||
|
@ -323,6 +347,8 @@ def main():
|
|||
hostinterface_config=dict(type='dict', default={}),
|
||||
hostinterface_id=dict(),
|
||||
sessions_config=dict(type='dict', default={}),
|
||||
storage_subsystem_id=dict(type='str', default=''),
|
||||
volume_ids=dict(type='list', default=[], elements='str')
|
||||
),
|
||||
required_together=[
|
||||
('username', 'password'),
|
||||
|
@ -372,6 +398,10 @@ def main():
|
|||
# Sessions config options
|
||||
sessions_config = module.params['sessions_config']
|
||||
|
||||
# Volume deletion options
|
||||
storage_subsystem_id = module.params['storage_subsystem_id']
|
||||
volume_ids = module.params['volume_ids']
|
||||
|
||||
# Build root URI
|
||||
root_uri = "https://" + module.params['baseuri']
|
||||
rf_utils = RedfishUtils(creds, root_uri, timeout, module,
|
||||
|
@ -405,6 +435,8 @@ def main():
|
|||
result = rf_utils.set_default_boot_order()
|
||||
elif command == "EnableSecureBoot":
|
||||
result = rf_utils.enable_secure_boot()
|
||||
elif command == "DeleteVolumes":
|
||||
result = rf_utils.delete_volumes(storage_subsystem_id, volume_ids)
|
||||
|
||||
elif category == "Manager":
|
||||
# execute only if we find a Manager service resource
|
||||
|
|
Loading…
Reference in a new issue