1#!/usr/local/bin/python3.8
2
3# (c) 2020, NetApp, Inc
4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6'''
7na_um_list_volumes
8'''
9
10from __future__ import absolute_import, division, print_function
11__metaclass__ = type
12
13
14ANSIBLE_METADATA = {'metadata_version': '1.1',
15                    'status': ['preview'],
16                    'supported_by': 'certified'}
17
18
19DOCUMENTATION = '''
20module: na_um_volumes_info
21short_description: NetApp Unified Manager list volumes.
22extends_documentation_fragment:
23    - netapp.um_info.netapp.um
24version_added: '20.6.0'
25author: NetApp Ansible Team (@carchi8py) <ng-ansibleteam@netapp.com>
26
27description:
28- List Volumes on AIQUM.
29'''
30
31EXAMPLES = """
32- name: List Volumes
33  netapp.um_info.na_um_volumes_info:
34    hostname: "{{ hostname }}"
35    username: "{{ username }}"
36    password: "{{ password }}"
37"""
38
39RETURN = """
40records:
41    description: Returns list of Volumes information
42    returned: always
43    type: list
44    sample: [{'style': '...',
45              'svm':
46                {'_links':
47                    {'self': {...}
48                    },
49                '...'
50                },
51              'qos': {...},
52              'name': '...',
53              'language': '...',
54              'space': {...},
55              'aggregates':
56                [
57                    {...}
58                ],
59              'tiering': {...},
60              'autosize': {...},
61              'cluster': {...},
62              'state': '...',
63              'create_time': '...',
64              '_links':
65                {'self':
66                    {'href': '...'
67                    }
68                },
69              'key': '...',
70              'snapmirror': {...},
71              'snapshot_policy': {...},
72              'type': '...',
73              'uuid': '...'
74              }]
75"""
76
77from ansible.module_utils.basic import AnsibleModule
78import ansible_collections.netapp.um_info.plugins.module_utils.netapp as netapp_utils
79from ansible_collections.netapp.um_info.plugins.module_utils.netapp_module import NetAppModule
80from ansible_collections.netapp.um_info.plugins.module_utils.netapp import UMRestAPI
81
82
83class NetAppUMVolume(object):
84    ''' volumes initialize and class methods '''
85
86    def __init__(self):
87        self.argument_spec = netapp_utils.na_um_host_argument_spec()
88        self.module = AnsibleModule(
89            argument_spec=self.argument_spec,
90            supports_check_mode=True
91        )
92
93        self.na_helper = NetAppModule()
94        self.parameters = self.na_helper.set_parameters(self.module.params)
95
96        self.rest_api = UMRestAPI(self.module)
97
98    def get_volumes(self):
99        """
100        Fetch details of volumes.
101        :return:
102            Dictionary of current details if volumes found
103            None if volumes is not found
104        """
105        data = {}
106        api = "datacenter/storage/volumes"
107        message, error = self.rest_api.get(api, data)
108        if error:
109            self.module.fail_json(msg=error)
110        return self.rest_api.get_records(message, api)
111
112    def apply(self):
113        """
114        Apply action to the volumes listing
115        :return: None
116        """
117        current = self.get_volumes()
118        if current is not None:
119            self.na_helper.changed = True
120        self.module.exit_json(changed=self.na_helper.changed, msg=current)
121
122
123def main():
124    """
125    Create Volume class instance and invoke apply
126    :return: None
127    """
128    list_volumes_obj = NetAppUMVolume()
129    list_volumes_obj.apply()
130
131
132if __name__ == '__main__':
133    main()
134