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

77 changes: 76 additions & 1 deletion 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\_snapshot`\ .


filters (False, list, None)
List of filters to support filtered output for storage entities.
Expand Down Expand Up @@ -219,6 +221,32 @@ Parameters

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

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


writable_snapshot (optional, dict, None)
The query parameters for \ :emphasis:`gather\_subset`\ 'writable\_snapshot'.

Supports the following query parameters.


dir (optional, str, None)
The direction of the sort.


limit (optional, int, None)
The limit.


sort (optional, str, None)
The field that is used for sorting.


state (optional, str, None)
To list the writable snapshot matching this state.




onefs_host (True, str, None)
IP address or FQDN of the PowerScale cluster.
Expand Down Expand Up @@ -254,7 +282,7 @@ Notes
- 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\_snapshot'.
- 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 +810,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_snapshot

- name: To get the specific writable snapshot.
Kritika-Bhateja-03 marked this conversation as resolved.
Show resolved Hide resolved
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshot
query_parameters:
writable_snapshot:
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_snapshot
query_parameters:
writable_snapshot:
dir: ASC
limit: 1

- name: To sort 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_snapshot
query_parameters:
writable_snapshot:
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_snapshot

- name: To get the specific writable snapshot.
Kritika-Bhateja-03 marked this conversation as resolved.
Show resolved Hide resolved
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshot
query_parameters:
writable_snapshot:
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_snapshot
query_parameters:
writable_snapshot:
dir: ASC
limit: 1
sachin-apa marked this conversation as resolved.
Show resolved Hide resolved

- name: To sort the writable snapshot in ascending order.
Kritika-Bhateja-03 marked this conversation as resolved.
Show resolved Hide resolved
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshot
query_parameters:
writable_snapshot:
sort: src_snap
state: active
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Copyright: (c) 2024, Dell Technologies
Kritika-Bhateja-03 marked this conversation as resolved.
Show resolved Hide resolved

# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)

from __future__ import (absolute_import, division, print_function)

__metaclass__ = type

from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell \
import utils

LOG = utils.get_logger('snapshot')


class WritableSnapshot:

'''Class with shared snapshot operations'''

def __init__(self, snapshot_api, module):
"""
Initialize the snapshot class
:param snapshot_api: The snapshot sdk instance
:param module: Ansible module object
"""
self.snapshot_api = snapshot_api
self.module = module

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_snapshot', []) if query_params else []
filter_params = {}
if writable_snapshot_query_params:
if "wspath" in writable_snapshot_query_params:
return self.snapshot_api.get_snapshot_writable_wspath(
snapshot_writable_wspath=writable_snapshot_query_params["wspath"]
).to_dict()
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)
100 changes: 94 additions & 6 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_snapshot).
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_snapshot]
type: list
elements: str
filters:
Expand Down Expand Up @@ -184,13 +185,38 @@
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).
- If C(writable_snapshot) is passed as I(gather_subset), if I(wspath) is given,
Kritika-Bhateja-03 marked this conversation as resolved.
Show resolved Hide resolved
all other query parameters inside I(writable_snapshot) will be ignored.
suboptions:
writable_snapshot:
description:
- The query parameters for I(gather_subset) 'writable_snapshot'.
- Supports the following query parameters.
type: dict
suboptions:
dir:
description: The direction of the sort.
type: str
choices: [ASC, DESC]
limit:
description: The limit.
type: int
sort:
description: The field that is used for sorting.
type: str
choices: [created, src_path, phys_size, state, src_snap]
state:
description: To list the writable snapshot matching this state.
type: str
choices: [all, active, deleting]
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.
Kritika-Bhateja-03 marked this conversation as resolved.
Show resolved Hide resolved
- 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_snapshot'.
'''

EXAMPLES = r'''
Expand Down Expand Up @@ -709,6 +735,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_snapshot

- 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_snapshot
query_parameters:
writable_snapshot:
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_snapshot
query_parameters:
writable_snapshot:
dir: ASC
limit: 1

- name: To sort the writable snapshot in ascending order.
Kritika-Bhateja-03 marked this conversation as resolved.
Show resolved Hide resolved
dellemc.powerscale.info:
onefs_host: "{{ onefs_host }}"
verify_ssl: "{{ verify_ssl }}"
api_user: "{{ api_user }}"
api_password: "{{ api_password }}"
gather_subset:
- writable_snapshot
query_parameters:
writable_snapshot:
sort: src_snap
state: active
'''

RETURN = r'''
Expand Down Expand Up @@ -3158,6 +3231,8 @@
import Quota
from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell.shared_library.snapshot \
import Snapshot
from ansible_collections.dellemc.powerscale.plugins.module_utils.storage.dell.shared_library.writable_snapshot \
import WritableSnapshot

LOG = utils.get_logger('info')

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

def get_writable_snapshots(self):
writable_snapshots = WritableSnapshot(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 @@ -3974,7 +4059,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_snapshot': self.get_writable_snapshots
}

key_mapping = {
Expand Down Expand Up @@ -4017,7 +4103,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_snapshot': 'writable_snapshots'
}

# Map the subset to the appropriate Key
Expand All @@ -4028,7 +4115,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_snapshot']
for key in subset:
if key not in subset_list:
result[key] = subset_mapping[key]()
Expand Down Expand Up @@ -4080,7 +4168,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_snapshot']),
filters=dict(type='list',
required=False,
elements='dict',
Expand Down
Loading
Loading