Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added writable snapshot in info module #101

60 changes: 57 additions & 3 deletions docs/modules/info.rst
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ Parameters

Event groups - \ :literal:`event\_group`\ .

Writable snapshots - \ :literal:`writable\_snapshots`\ .


filters (False, list, None)
List of filters to support filtered output for storage entities.
Expand All @@ -217,7 +219,13 @@ Parameters
query_parameters (optional, dict, None)
Contains dictionary of query parameters for specific \ :emphasis:`gather\_subset`\ .

Applicable to \ :literal:`alert\_rules`\ , \ :literal:`event\_group`\ , \ :literal:`event\_channels`\ and \ :literal:`filesystem`\ .
Applicable to \ :literal:`alert\_rules`\ , \ :literal:`event\_group`\ , \ :literal:`event\_channels`\ , \ :literal:`filesystem`\ and \ :literal:`writable\_snapshots`\ .

If \ :literal:`writable\_snapshots`\ is passed as \ :emphasis:`gather\_subset`\ , if \ :emphasis:`wspath`\ is given, all other query parameters inside \ :emphasis:`writable\_snapshots`\ will be ignored.

To view the list of supported query parameters for \ :literal:`writable\_snapshots`\ .

Refer Query Parameters section from \ https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/%20paths/~1platform~114~1snapshot~1writable/get\ .


onefs_host (True, str, None)
Expand Down Expand Up @@ -252,9 +260,8 @@ Notes

.. note::
- The parameters \ :emphasis:`access\_zone`\ and \ :emphasis:`include\_all\_access\_zones`\ are mutually exclusive.
- Listing of SyncIQ target cluster certificates is not supported by isi\_sdk\_8\_1\_1 version.
- The \ :emphasis:`check\_mode`\ is supported.
- Filter functionality is supported only for the following 'gather\_subset'- 'nfs', 'smartquota', 'filesystem'.
- Filter functionality is supported only for the following 'gather\_subset'- 'nfs', 'smartquota', 'filesystem' 'writable\_snapshots'.
- The modules present in this collection named as 'dellemc.powerscale' are built to support the Dell PowerScale storage platform.


Expand Down Expand Up @@ -782,6 +789,53 @@ Examples
filter_operator: "equal"
filter_value: "xxx"

- name: Get all writable snapshots from PowerScale cluster
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots

- name: To get the specific writable snapshot
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots
query_parameters:
writable_snapshots:
wspath: "/ifs/test_mkdir"

- name: To filter the writable snapshot in ascending order
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots
query_parameters:
writable_snapshots:
dir: ASC
limit: 1

- name: To filter the writable snapshot using sort
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots
query_parameters:
writable_snapshots:
sort: src_snap
state: active



Return Values
Expand Down
47 changes: 47 additions & 0 deletions playbooks/modules/info.yml
Original file line number Diff line number Diff line change
Expand Up @@ -395,3 +395,50 @@
- filter_key: "name"
filter_operator: "equal"
filter_value: "xxx"

- name: Get all writable snapshots from PowerScale cluster
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots

- name: To get the specific writable snapshot
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots
query_parameters:
writable_snapshots:
wspath: "/ifs/test_mkdir"

- name: To filter the writable snapshot in ascending order
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots
query_parameters:
writable_snapshots:
dir: ASC
limit: 1

- name: To filter the writable snapshot using sort
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots
query_parameters:
writable_snapshots:
sort: src_snap
state: active
44 changes: 44 additions & 0 deletions plugins/module_utils/storage/dell/shared_library/snapshot.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,47 @@ def get_filesystem_snapshots(self, effective_path):
'due to error {0}'.format((str(error_msg)))
LOG.error(error_message)
self.module.fail_json(msg=error_message)

def list_writable_snapshots(self):
"""
List the writable snapshots.

:param filter: The filter for the list.
:type filter: dict
:returns: The list of snapshots.
:rtype: list
"""
try:
query_params = self.module.params.get('query_parameters')
writable_snapshot_query_params = query_params.get('writable_snapshots', []) if query_params else []
filter_params = {}
if writable_snapshot_query_params:
if "wspath" in writable_snapshot_query_params:
return self.get_writable_snapshot_by_wspath(wspath=writable_snapshot_query_params.get("wspath"))
else:
filter_params = dict(writable_snapshot_query_params.items())
writable_snapshots = []
snapshot_list = \
self.snapshot_api.list_snapshot_writable(**filter_params).to_dict()
writable_snapshots.extend(snapshot_list['writable'])
return writable_snapshots
except Exception as e:
error_msg = utils.determine_error(error_obj=e)
error_message = 'Failed to get writeable snapshots ' \
'due to error {0}'.format((str(error_msg)))
LOG.error(error_message)
self.module.fail_json(msg=error_message)

def get_writable_snapshot_by_wspath(self, wspath):
try:
return self.snapshot_api.get_snapshot_writable_wspath(
snapshot_writable_wspath=wspath
).to_dict().get("writable")
except utils.ApiException as e:
return {}
except Exception as e:
error_msg = utils.determine_error(error_obj=e)
error_message = 'Failed to get writeable snapshot ' \
'due to error {0}'.format((str(error_msg)))
LOG.error(error_message)
self.module.fail_json(msg=error_message)
95 changes: 80 additions & 15 deletions plugins/modules/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
- Alert channels - C(alert_channels).
- Alert categories - C(alert_categories).
- Event groups - C(event_group).
- Writable snapshots - C(writable_snapshots).
required: true
choices: [attributes, access_zones, nodes, providers, users, groups,
smb_shares, nfs_exports, nfs_aliases, clients, synciq_reports, synciq_target_reports,
Expand All @@ -151,7 +152,7 @@
nfs_zone_settings, nfs_default_settings, nfs_global_settings, synciq_global_settings, s3_buckets,
smb_global_settings, ntp_servers, email_settings, cluster_identity, cluster_owner, snmp_settings,
server_certificate, roles, support_assist_settings, smartquota, filesystem, alert_settings,
alert_rules, alert_channels, alert_categories, event_group]
alert_rules, alert_channels, alert_categories, event_group, writable_snapshots]
type: list
elements: str
filters:
Expand Down Expand Up @@ -183,14 +184,21 @@
query_parameters:
description:
- Contains dictionary of query parameters for specific I(gather_subset).
- Applicable to C(alert_rules), C(event_group), C(event_channels) and C(filesystem).
- Applicable to C(alert_rules), C(event_group), C(event_channels), C(filesystem)
and C(writable_snapshots).
- If C(writable_snapshots) is passed as I(gather_subset), if I(wspath) is given,
all other query parameters inside I(writable_snapshots) will be ignored.
- To view the list of supported query parameters for C(writable_snapshots).
- Refer Query Parameters section from
U(https://developer.dell.com/apis/4088/versions/9.5.0/9.5.0.0_ISLANDER_OAS2.json/
paths/~1platform~114~1snapshot~1writable/get).
type: dict
version_added: '3.2.0'
notes:
- The parameters I(access_zone) and I(include_all_access_zones) are mutually exclusive.
- Listing of SyncIQ target cluster certificates is not supported by isi_sdk_8_1_1 version.
- The I(check_mode) is supported.
- Filter functionality is supported only for the following 'gather_subset'- 'nfs', 'smartquota', 'filesystem'.
- Filter functionality is supported only for the following 'gather_subset'- 'nfs', 'smartquota', 'filesystem'
'writable_snapshots'.
'''

EXAMPLES = r'''
Expand Down Expand Up @@ -709,6 +717,53 @@
- filter_key: "name"
filter_operator: "equal"
filter_value: "xxx"

- name: Get all writable snapshots from PowerScale cluster
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots

- name: To get the specific writable snapshot
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots
query_parameters:
writable_snapshots:
wspath: "/ifs/test_mkdir"

- name: To filter the writable snapshot in ascending order
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots
query_parameters:
writable_snapshots:
dir: ASC
limit: 1

- name: To filter the writable snapshot using sort
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshots
query_parameters:
writable_snapshots:
sort: src_snap
state: active
'''

RETURN = r'''
Expand Down Expand Up @@ -3159,6 +3214,7 @@
from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell.shared_library.snapshot \
import Snapshot


LOG = utils.get_logger('info')


Expand Down Expand Up @@ -3753,6 +3809,16 @@ def get_smartquota_list(self):
LOG.error(error_msg)
self.module.fail_json(msg=error_msg)

def get_writable_snapshots(self):
writable_snapshots = Snapshot(self.snapshot_api, self.module).list_writable_snapshots()
filtered_writable_snapshots = []
filters = self.module.params.get('filters')
filters_dict = self.get_filters(filters)
if filters_dict:
filtered_writable_snapshots = filter_dict_list(writable_snapshots, filters_dict)
return filtered_writable_snapshots
return writable_snapshots

def get_metadata(self, effective_path):
return Namespace(self.namespace_api, self.module).get_filesystem(effective_path)

Expand Down Expand Up @@ -3840,13 +3906,9 @@ def get_filters(self, filters=None):
if not filters_items:
self.module.fail_json(msg='filter_key, filter_operator, filter_value are expected.')
for item in filters_items:
try:
f_key = item["filter_key"]
f_val = item["filter_value"]
f_op = item["filter_operator"]
except KeyError:
error_msg = "Provide input for filter sub-options."
self.module.fail_json(msg=error_msg)
f_key = item.get("filter_key")
f_val = item.get("filter_value")
f_op = item.get("filter_operator")
if f_op != 'equal':
error_msg = "The filter operator is not supported -- only 'equal' is supported."
self.module.fail_json(msg=error_msg)
Expand Down Expand Up @@ -3974,7 +4036,8 @@ def perform_module_operation(self):
'alert_channels': lambda: Events(self.event_api, self.module).get_event_channels(),
'event_group': lambda: Events(self.event_api, self.module).get_event_groups(),
'smartquota': self.get_smartquota_list,
'filesystem': lambda: self.get_filesystem_list(path, query_params)
'filesystem': lambda: self.get_filesystem_list(path, query_params),
'writable_snapshots': self.get_writable_snapshots
}

key_mapping = {
Expand Down Expand Up @@ -4017,7 +4080,8 @@ def perform_module_operation(self):
'synciq_target_cluster_certificates': 'SynciqTargetClusterCertificate',
'event_group': 'event_groups',
'smartquota': 'smart_quota',
'filesystem': 'file_system'
'filesystem': 'file_system',
'writable_snapshots': 'writable_snapshots'
}

# Map the subset to the appropriate Key
Expand All @@ -4028,7 +4092,8 @@ def perform_module_operation(self):
'storagepool_tiers', 'smb_files', 'user_mapping_rules', 'ldap', 'nfs_zone_settings',
'nfs_default_settings', 'nfs_global_settings', 'synciq_global_settings', 's3_buckets',
'smb_global_settings', 'ntp_servers', 'email_settings', 'cluster_identity', 'cluster_owner',
'snmp_settings', 'server_certificate', 'event_group', 'smartquota', 'filesystem']
'snmp_settings', 'server_certificate', 'event_group', 'smartquota', 'filesystem',
'writable_snapshots']
for key in subset:
if key not in subset_list:
result[key] = subset_mapping[key]()
Expand Down Expand Up @@ -4080,7 +4145,7 @@ def get_info_parameters():
'snmp_settings', 'server_certificate', 'roles',
'support_assist_settings', 'alert_settings', 'alert_rules',
'alert_channels', 'alert_categories', 'event_group',
'filesystem', 'smartquota']),
'filesystem', 'smartquota', 'writable_snapshots']),
filters=dict(type='list',
required=False,
elements='dict',
Expand Down
Loading
Loading