diff options
author | Ansible Core Team <info@ansible.com> | 2020-03-09 09:40:33 +0000 |
---|---|---|
committer | Matt Martz <matt@sivel.net> | 2020-03-23 11:14:21 -0500 |
commit | 0a9205b7c0190b92c2c4149b122c26a69f0f23d4 (patch) | |
tree | d4d2a25c6192f792e1974ee28610c0937abbe388 /lib | |
parent | bdd82adf61bde25bb2ca664e9b1b02fd35f65d4d (diff) | |
download | ansible-0a9205b7c0190b92c2c4149b122c26a69f0f23d4.tar.gz |
Migrated to netapp.aws
Diffstat (limited to 'lib')
4 files changed, 0 insertions, 1142 deletions
diff --git a/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_FileSystems.py b/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_FileSystems.py deleted file mode 100644 index 8007a57247..0000000000 --- a/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_FileSystems.py +++ /dev/null @@ -1,360 +0,0 @@ -#!/usr/bin/python - -# (c) 2019, NetApp Inc -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -"""AWS Cloud Volumes Services - Manage fileSystem""" - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = ''' - -module: aws_netapp_cvs_FileSystems - -short_description: NetApp AWS Cloud Volumes Service Manage FileSystem. -extends_documentation_fragment: - - netapp.awscvs -version_added: '2.9' -author: NetApp Ansible Team (@carchi8py) <ng-ansibleteam@netapp.com> -description: -- Create, Update, Delete fileSystem on AWS Cloud Volumes Service. - -options: - state: - description: - - Whether the specified fileSystem should exist or not. - required: true - choices: ['present', 'absent'] - type: str - - region: - description: - - The region to which the filesystem belongs to. - required: true - type: str - - creationToken: - description: - - Name of the filesystem - required: true - type: str - - quotaInBytes: - description: - - Size of the filesystem - - Required for create - type: int - - serviceLevel: - description: - - Service Level of a filesystem. - choices: ['standard', 'premium', 'extreme'] - type: str - - exportPolicy: - description: - - The policy rules to export the filesystem - type: dict - suboptions: - rules: - description: - - Set of rules to export the filesystem - - Requires allowedClients, access and protocol - type: list - suboptions: - allowedClients: - description: - - Comma separated list of ip address blocks of the clients to access the fileSystem - - Each address block contains the starting IP address and size for the block - type: str - - cifs: - description: - - Enable or disable cifs filesystem - type: bool - - nfsv3: - description: - - Enable or disable nfsv3 fileSystem - type: bool - - nfsv4: - description: - - Enable or disable nfsv4 filesystem - type: bool - - ruleIndex: - description: - - Index number of the rule - type: int - - unixReadOnly: - description: - - Should fileSystem have read only permission or not - type: bool - - unixReadWrite: - description: - - Should fileSystem have read write permission or not - type: bool -''' - -EXAMPLES = """ -- name: Create FileSystem - aws_netapp_cvs_FileSystems: - state: present - region: us-east-1 - creationToken: newVolume-1 - exportPolicy: - rules: - - allowedClients: 172.16.0.4 - cifs: False - nfsv3: True - nfsv4: True - ruleIndex: 1 - unixReadOnly: True - unixReadWrite: False - quotaInBytes: 100000000000 - api_url : cds-aws-bundles.netapp.com - api_key: Q1ZRR0p0VGNuZ3VhMnJBYk5zczM1RkZ3Z0lCbUE3 - secret_key : U1FwdHdKSGRQQUhIdkIwMktMU1ZCV2x6WUowZWRD - -- name: Update FileSystem - aws_netapp_cvs_FileSystems: - state: present - region: us-east-1 - creationToken: newVolume-1 - exportPolicy: - rules: - - allowedClients: 172.16.0.4 - cifs: False - nfsv3: True - nfsv4: True - ruleIndex: 1 - unixReadOnly: True - unixReadWrite: False - quotaInBytes: 200000000000 - api_url : cds-aws-bundles.netapp.com - api_key: Q1ZRR0p0VGNuZ3VhMnJBYk5zczM1RkZ3Z0lCbUE3 - secret_key : U1FwdHdKSGRQQUhIdkIwMktMU1ZCV2x6WUowZWRD - -- name: Delete FileSystem - aws_netapp_cvs_FileSystems: - state: present - region: us-east-1 - creationToken: newVolume-1 - quotaInBytes: 100000000000 - api_url : cds-aws-bundles.netapp.com - api_key: Q1ZRR0p0VGNuZ3VhMnJBYk5zczM1RkZ3Z0lCbUE3 - secret_key : U1FwdHdKSGRQQUhIdkIwMktMU1ZCV2x6WUowZWRD -""" - -RETURN = """ -""" - -import ansible.module_utils.netapp as netapp_utils -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netapp_module import NetAppModule -from ansible.module_utils.netapp import AwsCvsRestAPI - - -class AwsCvsNetappFileSystem(object): - """ - Contains methods to parse arguments, - derive details of AWS_CVS objects - and send requests to AWS CVS via - the restApi - """ - - def __init__(self): - """ - Parse arguments, setup state variables, - check parameters and ensure request module is installed - """ - self.argument_spec = netapp_utils.aws_cvs_host_argument_spec() - self.argument_spec.update(dict( - state=dict(required=True, choices=['present', 'absent']), - region=dict(required=True, type='str'), - creationToken=dict(required=True, type='str'), - quotaInBytes=dict(required=False, type='int'), - serviceLevel=dict(required=False, choices=['standard', 'premium', 'extreme']), - exportPolicy=dict( - type='dict', - options=dict( - rules=dict( - type='list', - options=dict( - allowedClients=dict(required=False, type='str'), - cifs=dict(required=False, type='bool'), - nfsv3=dict(required=False, type='bool'), - nfsv4=dict(required=False, type='bool'), - ruleIndex=dict(required=False, type='int'), - unixReadOnly=dict(required=False, type='bool'), - unixReadWrite=dict(required=False, type='bool') - ) - ) - ) - ), - )) - - self.module = AnsibleModule( - argument_spec=self.argument_spec, - required_if=[ - ('state', 'present', ['region', 'creationToken', 'quotaInBytes']), - ], - supports_check_mode=True - ) - - self.na_helper = NetAppModule() - - # set up state variables - self.parameters = self.na_helper.set_parameters(self.module.params) - - # Calling generic AWSCVS restApi class - self.restApi = AwsCvsRestAPI(self.module) - - self.data = {} - for key in self.parameters.keys(): - self.data[key] = self.parameters[key] - - def get_filesystemId(self): - # Check given FileSystem is exists - # Return fileSystemId is found, None otherwise - list_filesystem, error = self.restApi.get('FileSystems') - if error: - self.module.fail_json(msg=error) - - for FileSystem in list_filesystem: - if FileSystem['creationToken'] == self.parameters['creationToken']: - return FileSystem['fileSystemId'] - return None - - def get_filesystem(self, fileSystemId): - # Get FileSystem information by fileSystemId - # Return fileSystem Information - filesystemInfo, error = self.restApi.get('FileSystems/%s' % fileSystemId) - if error: - self.module.fail_json(msg=error) - else: - return filesystemInfo - return None - - def is_job_done(self, response): - # check jobId is present and equal to 'done' - # return True on success, False otherwise - try: - job_id = response['jobs'][0]['jobId'] - except TypeError: - job_id = None - - if job_id is not None and self.restApi.get_state(job_id) == 'done': - return True - return False - - def create_fileSystem(self): - # Create fileSystem - api = 'FileSystems' - response, error = self.restApi.post(api, self.data) - if not error: - if self.is_job_done(response): - return - error = "Error: unexpected response on FileSystems create: %s" % str(response) - self.module.fail_json(msg=error) - - def delete_fileSystem(self, fileSystemId): - # Delete FileSystem - api = 'FileSystems/' + fileSystemId - self.data = None - response, error = self.restApi.delete(api, self.data) - if not error: - if self.is_job_done(response): - return - error = "Error: unexpected response on FileSystems delete: %s" % str(response) - self.module.fail_json(msg=error) - - def update_fileSystem(self, fileSystemId): - # Update FileSystem - api = 'FileSystems/' + fileSystemId - response, error = self.restApi.put(api, self.data) - if not error: - if self.is_job_done(response): - return - error = "Error: unexpected response on FileSystems update: %s" % str(response) - self.module.fail_json(msg=error) - - def apply(self): - """ - Perform pre-checks, call functions and exit - """ - - fileSystem = None - fileSystemId = self.get_filesystemId() - - if fileSystemId: - # Getting the FileSystem details - fileSystem = self.get_filesystem(fileSystemId) - - cd_action = self.na_helper.get_cd_action(fileSystem, self.parameters) - - if cd_action is None and self.parameters['state'] == 'present': - # Check if we need to update the fileSystem - update_fileSystem = False - if fileSystem['quotaInBytes'] is not None and 'quotaInBytes' in self.parameters \ - and fileSystem['quotaInBytes'] != self.parameters['quotaInBytes']: - update_fileSystem = True - elif fileSystem['creationToken'] is not None and 'creationToken' in self.parameters \ - and fileSystem['creationToken'] != self.parameters['creationToken']: - update_fileSystem = True - elif fileSystem['serviceLevel'] is not None and 'serviceLevel' in self.parameters \ - and fileSystem['serviceLevel'] != self.parameters['serviceLevel']: - update_fileSystem = True - elif fileSystem['exportPolicy']['rules'] is not None and 'exportPolicy' in self.parameters: - for rule_org in fileSystem['exportPolicy']['rules']: - for rule in self.parameters['exportPolicy']['rules']: - if rule_org['allowedClients'] != rule['allowedClients']: - update_fileSystem = True - elif rule_org['unixReadOnly'] != rule['unixReadOnly']: - update_fileSystem = True - elif rule_org['unixReadWrite'] != rule['unixReadWrite']: - update_fileSystem = True - - if update_fileSystem: - self.na_helper.changed = True - - result_message = "" - - if self.na_helper.changed: - if self.module.check_mode: - # Skip changes - result_message = "Check mode, skipping changes" - else: - if cd_action == "create": - self.create_fileSystem() - result_message = "FileSystem Created" - elif cd_action == "delete": - self.delete_fileSystem(fileSystemId) - result_message = "FileSystem Deleted" - else: # modify - self.update_fileSystem(fileSystemId) - result_message = "FileSystem Updated" - self.module.exit_json(changed=self.na_helper.changed, msg=result_message) - - -def main(): - """ - Main function - """ - aws_cvs_netapp_filesystem = AwsCvsNetappFileSystem() - aws_cvs_netapp_filesystem.apply() - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_active_directory.py b/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_active_directory.py deleted file mode 100644 index 9d9f914263..0000000000 --- a/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_active_directory.py +++ /dev/null @@ -1,269 +0,0 @@ -#!/usr/bin/python - -# (c) 2019, NetApp Inc. -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -"""AWS Cloud Volumes Services - Manage ActiveDirectory""" - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'certified'} - - -DOCUMENTATION = ''' - -module: aws_netapp_cvs_active_directory - -short_description: NetApp AWS CloudVolumes Service Manage Active Directory. -extends_documentation_fragment: - - netapp.awscvs -version_added: '2.9' -author: NetApp Ansible Team (@carchi8py) <ng-ansibleteam@netapp.com> -description: - - Create, Update, Delete ActiveDirectory on AWS Cloud Volumes Service. - -options: - state: - description: - - Whether the specified ActiveDirectory should exist or not. - choices: ['present', 'absent'] - required: true - type: str - - region: - description: - - The region to which the Active Directory credentials are associated. - required: true - type: str - - domain: - description: - - Name of the Active Directory domain. - - Required when I(state=present). - type: str - - DNS: - description: - - DNS server address for the Active Directory domain. - - Required when I(state=present), to modify ActiveDirectory properties. - type: str - - netBIOS: - description: - - NetBIOS name of the server. - type: str - - username: - description: - - Username of the Active Directory domain administrator. - type: str - - password: - description: - - Password of the Active Directory domain administrator. - type: str -''' - -EXAMPLES = """ - - name: Create Active Directory - aws_netapp_cvs_active_directory.py: - state: present - region: us-east-1 - DNS: 101.102.103.123 - domain: mydomain.com - password: netapp1! - netBIOS: testing - username: user1 - api_url : My_CVS_Hostname - api_key: My_API_Key - secret_key : My_Secret_Key - - - name: Update Active Directory - aws_netapp_cvs_active_directory.py: - state: present - region: us-east-1 - DNS: 101.102.103.123 - domain: mydomain.com - password: netapp2! - netBIOS: testingBIOS - username: user2 - api_url : My_CVS_Hostname - api_key: My_API_Key - secret_key : My_Secret_Key - - - name: Delete Active Directory - aws_netapp_cvs_active_directory.py: - state: absent - region: us-east-1 - domain: mydomain.com - api_url : My_CVS_Hostname - api_key: My_API_Key - secret_key : My_Secret_Key -""" - -RETURN = ''' -''' - -import ansible.module_utils.netapp as netapp_utils -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netapp_module import NetAppModule -from ansible.module_utils.netapp import AwsCvsRestAPI - - -class AwsCvsNetappActiveDir(object): - """ - Contains methods to parse arguments, - derive details of AWS_CVS objects - and send requests to AWS CVS via - the restApi - """ - - def __init__(self): - """ - Parse arguments, setup state variables, - check paramenters and ensure request module is installed - """ - self.argument_spec = netapp_utils.aws_cvs_host_argument_spec() - self.argument_spec.update(dict( - state=dict(required=True, choices=['present', 'absent'], type='str'), - region=dict(required=True, type='str'), - DNS=dict(required=False, type='str'), - domain=dict(required=False, type='str'), - password=dict(required=False, type='str', no_log=True), - netBIOS=dict(required=False, type='str'), - username=dict(required=False, type='str') - )) - - self.module = AnsibleModule( - argument_spec=self.argument_spec, - required_if=[ - ('state', 'present', ['region', 'domain']), - ], - supports_check_mode=True - ) - - self.na_helper = NetAppModule() - - # set up state variables - self.parameters = self.na_helper.set_parameters(self.module.params) - # Calling generic AWSCVS restApi class - self.restApi = AwsCvsRestAPI(self.module) - - def get_activedirectoryId(self): - # Check if ActiveDirectory exists - # Return UUID for ActiveDirectory is found, None otherwise - try: - list_activedirectory, error = self.restApi.get('Storage/ActiveDirectory') - except Exception as e: - return None - - for ActiveDirectory in list_activedirectory: - if ActiveDirectory['region'] == self.parameters['region']: - return ActiveDirectory['UUID'] - return None - - def get_activedirectory(self, activeDirectoryId=None): - if activeDirectoryId is None: - return None - else: - ActiveDirectoryInfo, error = self.restApi.get('Storage/ActiveDirectory/%s' % activeDirectoryId) - if not error: - return ActiveDirectoryInfo - return None - - def create_activedirectory(self): - # Create ActiveDirectory - api = 'Storage/ActiveDirectory' - data = {"region": self.parameters['region'], "DNS": self.parameters['DNS'], "domain": self.parameters['domain'], - "username": self.parameters['username'], "password": self.parameters['password'], "netBIOS": self.parameters['netBIOS']} - - response, error = self.restApi.post(api, data) - - if not error: - return response - else: - self.module.fail_json(msg=response['message']) - - def delete_activedirectory(self): - activedirectoryId = self.get_activedirectoryId() - # Delete ActiveDirectory - - if activedirectoryId: - api = 'Storage/ActiveDirectory/' + activedirectoryId - data = None - response, error = self.restApi.delete(api, data) - if not error: - return response - else: - self.module.fail_json(msg=response['message']) - - else: - self.module.fail_json(msg="Active Directory does not exist") - - def update_activedirectory(self, activedirectoryId, updated_activedirectory): - # Update ActiveDirectory - api = 'Storage/ActiveDirectory/' + activedirectoryId - data = { - "region": self.parameters['region'], - "DNS": updated_activedirectory['DNS'], - "domain": updated_activedirectory['domain'], - "username": updated_activedirectory['username'], - "password": updated_activedirectory['password'], - "netBIOS": updated_activedirectory['netBIOS'] - } - - response, error = self.restApi.put(api, data) - if not error: - return response - else: - self.module.fail_json(msg=response['message']) - - def apply(self): - """ - Perform pre-checks, call functions and exit - """ - modify = False - activeDirectoryId = self.get_activedirectoryId() - current = self.get_activedirectory(activeDirectoryId) - cd_action = self.na_helper.get_cd_action(current, self.parameters) - - if current and self.parameters['state'] != 'absent': - keys_to_check = ['DNS', 'domain', 'username', 'password', 'netBIOS'] - updated_active_directory, modify = self.na_helper.compare_and_update_values(current, self.parameters, keys_to_check) - - if modify is True: - self.na_helper.changed = True - if 'domain' in self.parameters and self.parameters['domain'] is not None: - ad_exists = self.get_activedirectory(updated_active_directory['domain']) - if ad_exists: - modify = False - self.na_helper.changed = False - - if self.na_helper.changed: - if self.module.check_mode: - pass - else: - if modify is True: - self.update_activedirectory(activeDirectoryId, updated_active_directory) - elif cd_action == 'create': - self.create_activedirectory() - elif cd_action == 'delete': - self.delete_activedirectory() - - self.module.exit_json(changed=self.na_helper.changed) - - -def main(): - """ - Main function - """ - aws_netapp_cvs_active_directory = AwsCvsNetappActiveDir() - aws_netapp_cvs_active_directory.apply() - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_pool.py b/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_pool.py deleted file mode 100644 index d1b5f9aaa7..0000000000 --- a/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_pool.py +++ /dev/null @@ -1,267 +0,0 @@ -#!/usr/bin/python - -# (c) 2019, NetApp Inc. -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -"""AWS Cloud Volumes Services - Manage Pools""" - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = ''' - -module: aws_netapp_cvs_pool - -short_description: NetApp AWS Cloud Volumes Service Manage Pools. -extends_documentation_fragment: - - netapp.awscvs -version_added: '2.9' -author: NetApp Ansible Team (@carchi8py) <ng-ansibleteam@netapp.com> -description: - - Create, Update, Delete Pool on AWS Cloud Volumes Service. - -options: - state: - description: - - Whether the specified pool should exist or not. - choices: ['present', 'absent'] - required: true - type: str - region: - description: - - The region to which the Pool is associated. - required: true - type: str - name: - description: - - pool name ( The human readable name of the Pool ) - - name can be used for create, update and delete operations - required: true - type: str - serviceLevel: - description: - - The service level of the Pool - - can be used with pool create, update operations - choices: ['basic', 'standard', 'extreme'] - type: str - sizeInBytes: - description: - - Size of the Pool in bytes - - can be used with pool create, update operations - - minimum value is 4000000000000 bytes - type: int - vendorID: - description: - - A vendor ID for the Pool. E.g. an ID allocated by a vendor service for the Pool. - - can be used with pool create, update operations - - must be unique - type: str - from_name: - description: - - rename the existing pool name ( The human readable name of the Pool ) - - I(from_name) is the existing name, and I(name) the new name - - can be used with update operation - type: str -''' - -EXAMPLES = """ -- name: Create a new Pool - aws_netapp_cvs_pool: - state: present - name: TestPoolBB12 - serviceLevel: extreme - sizeInBytes: 4000000000000 - vendorID: ansiblePoolTestVendorBB12 - region: us-east-1 - api_url: cds-aws-bundles.netapp.com - api_key: MyAPiKey - secret_key: MySecretKey - -- name: Delete a Pool - aws_netapp_cvs_pool: - state: absent - name: TestPoolBB7 - region: us-east-1 - api_url: cds-aws-bundles.netapp.com - api_key: MyAPiKey - secret_key: MySecretKey - -- name: Update a Pool - aws_netapp_cvs_pool: - state: present - from_name: TestPoolBB12 - name: Mynewpool7 - vendorID: ansibleVendorMynewpool15 - serviceLevel: extreme - sizeInBytes: 4000000000000 - region: us-east-1 - api_url: cds-aws-bundles.netapp.com - api_key: MyAPiKey - secret_key: MySecretKey - -""" - -RETURN = ''' -''' - -import ansible.module_utils.netapp as netapp_utils -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netapp_module import NetAppModule -from ansible.module_utils.netapp import AwsCvsRestAPI - - -class NetAppAWSCVS(object): - '''Class for Pool operations ''' - - def __init__(self): - """ - Parse arguments, setup state variables, - """ - self.argument_spec = netapp_utils.aws_cvs_host_argument_spec() - self.argument_spec.update(dict( - state=dict(required=True, choices=['present', 'absent']), - region=dict(required=True, type='str'), - name=dict(required=True, type='str'), - from_name=dict(required=False, type='str'), - serviceLevel=dict(required=False, choices=['basic', 'standard', 'extreme'], type='str'), - sizeInBytes=dict(required=False, type='int'), - vendorID=dict(required=False, type='str'), - )) - self.module = AnsibleModule( - argument_spec=self.argument_spec, - supports_check_mode=True - ) - - self.na_helper = NetAppModule() - self.parameters = self.na_helper.set_parameters(self.module.params) - self.restApi = AwsCvsRestAPI(self.module) - self.sizeInBytes_min_value = 4000000000000 - - def get_aws_netapp_cvs_pool(self, name=None): - """ - Returns Pool object if exists else Return None - """ - pool_info = None - - if name is None: - name = self.parameters['name'] - - pools, error = self.restApi.get('Pools') - - if error is None and pools is not None: - for pool in pools: - if 'name' in pool and pool['region'] == self.parameters['region']: - if pool['name'] == name: - pool_info = pool - break - - return pool_info - - def create_aws_netapp_cvs_pool(self): - """ - Create a pool - """ - api = 'Pools' - - for key in ['serviceLevel', 'sizeInBytes', 'vendorID']: - if key not in self.parameters.keys() or self.parameters[key] is None: - self.module.fail_json(changed=False, msg="Mandatory key '%s' required" % (key)) - - pool = { - "name": self.parameters['name'], - "region": self.parameters['region'], - "serviceLevel": self.parameters['serviceLevel'], - "sizeInBytes": self.parameters['sizeInBytes'], - "vendorID": self.parameters['vendorID'] - } - - response, error = self.restApi.post(api, pool) - if error is not None: - self.module.fail_json(changed=False, msg=error) - - def update_aws_netapp_cvs_pool(self, update_pool_info, pool_id): - """ - Update a pool - """ - api = 'Pools/' + pool_id - - pool = { - "name": update_pool_info['name'], - "region": self.parameters['region'], - "serviceLevel": update_pool_info['serviceLevel'], - "sizeInBytes": update_pool_info['sizeInBytes'], - "vendorID": update_pool_info['vendorID'] - } - - response, error = self.restApi.put(api, pool) - if error is not None: - self.module.fail_json(changed=False, msg=error) - - def delete_aws_netapp_cvs_pool(self, pool_id): - """ - Delete a pool - """ - api = 'Pools/' + pool_id - data = None - response, error = self.restApi.delete(api, data) - - if error is not None: - self.module.fail_json(changed=False, msg=error) - - def apply(self): - """ - Perform pre-checks, call functions and exit - """ - update_required = False - cd_action = None - - if 'sizeInBytes' in self.parameters.keys() and self.parameters['sizeInBytes'] < self.sizeInBytes_min_value: - self.module.fail_json(changed=False, msg="sizeInBytes should be greater than or equal to %d" % (self.sizeInBytes_min_value)) - - current = self.get_aws_netapp_cvs_pool() - if self.parameters.get('from_name'): - existing = self.get_aws_netapp_cvs_pool(self.parameters['from_name']) - rename = self.na_helper.is_rename_action(existing, current) - if rename is None: - self.module.fail_json(changed=False, msg="unable to rename pool: '%s' does not exist" % self.parameters['from_name']) - if rename: - current = existing - else: - cd_action = self.na_helper.get_cd_action(current, self.parameters) - - if cd_action is None and self.parameters['state'] == 'present': - keys_to_check = ['name', 'vendorID', 'sizeInBytes', 'serviceLevel'] - update_pool_info, update_required = self.na_helper.compare_and_update_values(current, self.parameters, keys_to_check) - - if update_required is True: - self.na_helper.changed = True - cd_action = 'update' - - if self.na_helper.changed: - if self.module.check_mode: - pass - else: - if cd_action == 'update': - self.update_aws_netapp_cvs_pool(update_pool_info, current['poolId']) - elif cd_action == 'create': - self.create_aws_netapp_cvs_pool() - elif cd_action == 'delete': - self.delete_aws_netapp_cvs_pool(current['poolId']) - - self.module.exit_json(changed=self.na_helper.changed) - - -def main(): - '''Main Function''' - aws_cvs_netapp_pool = NetAppAWSCVS() - aws_cvs_netapp_pool.apply() - - -if __name__ == '__main__': - main() diff --git a/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_snapshots.py b/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_snapshots.py deleted file mode 100644 index f5b39ef252..0000000000 --- a/lib/ansible/modules/cloud/amazon/aws_netapp_cvs_snapshots.py +++ /dev/null @@ -1,246 +0,0 @@ -#!/usr/bin/python - -# (c) 2019, NetApp Inc -# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt) - -"""AWS Cloud Volumes Services - Manage Snapshots""" - -from __future__ import absolute_import, division, print_function - -__metaclass__ = type - - -ANSIBLE_METADATA = {'metadata_version': '1.1', - 'status': ['preview'], - 'supported_by': 'community'} - - -DOCUMENTATION = ''' - -module: aws_netapp_cvs_snapshots - -short_description: NetApp AWS Cloud Volumes Service Manage Snapshots. -extends_documentation_fragment: - - netapp.awscvs -version_added: '2.9' -author: NetApp Ansible Team (@carchi8py) <ng-ansibleteam@netapp.com> -description: -- Create, Update, Delete Snapshot on AWS Cloud Volumes Service. - -options: - state: - description: - - Whether the specified snapshot should exist or not. - required: true - type: str - choices: ['present', 'absent'] - - region: - description: - - The region to which the snapshot belongs to. - required: true - type: str - - name: - description: - - Name of the snapshot - required: true - type: str - - fileSystemId: - description: - - Name or Id of the filesystem. - - Required for create operation - type: str - - from_name: - description: - - ID or Name of the snapshot to rename. - - Required to create an snapshot called 'name' by renaming 'from_name'. - type: str -''' - -EXAMPLES = """ -- name: Create Snapshot - aws_netapp_cvs_snapshots: - state: present - region: us-east-1 - name: testSnapshot - fileSystemId: testVolume - api_url : cds-aws-bundles.netapp.com - api_key: myApiKey - secret_key : mySecretKey - -- name: Update Snapshot - aws_netapp_cvs_snapshots: - state: present - region: us-east-1 - name: testSnapshot - renamed - from_name: testSnapshot - fileSystemId: testVolume - api_url : cds-aws-bundles.netapp.com - api_key: myApiKey - secret_key : mySecretKey - -- name: Delete Snapshot - aws_netapp_cvs_snapshots: - state: absent - region: us-east-1 - name: testSnapshot - api_url : cds-aws-bundles.netapp.com - api_key: myApiKey - secret_key : mySecretKey -""" - -RETURN = """ -""" - -import ansible.module_utils.netapp as netapp_utils -from ansible.module_utils.basic import AnsibleModule -from ansible.module_utils.netapp_module import NetAppModule -from ansible.module_utils.netapp import AwsCvsRestAPI - - -class AwsCvsNetappSnapshot(object): - """ - Contains methods to parse arguments, - derive details of AWS_CVS objects - and send requests to AWS CVS via - the restApi - """ - - def __init__(self): - """ - Parse arguments, setup state variables, - check parameters and ensure request module is installed - """ - self.argument_spec = netapp_utils.aws_cvs_host_argument_spec() - self.argument_spec.update(dict( - state=dict(required=True, choices=['present', 'absent']), - region=dict(required=True, type='str'), - name=dict(required=True, type='str'), - from_name=dict(required=False, type='str'), - fileSystemId=dict(required=False, type='str') - )) - - self.module = AnsibleModule( - argument_spec=self.argument_spec, - required_if=[ - ('state', 'present', ['name', 'fileSystemId']), - ], - supports_check_mode=True - ) - - self.na_helper = NetAppModule() - - # set up state variables - self.parameters = self.na_helper.set_parameters(self.module.params) - # Calling generic AWSCVS restApi class - self.restApi = AwsCvsRestAPI(self.module) - - # Checking for the parameters passed and create new parameters list - self.data = {} - for key in self.parameters.keys(): - self.data[key] = self.parameters[key] - - def getSnapshotId(self, name): - # Check if snapshot exists - # Return snapshot Id If Snapshot is found, None otherwise - list_snapshots, error = self.restApi.get('Snapshots') - - if error: - self.module.fail_json(msg=error) - - for snapshot in list_snapshots: - if snapshot['name'] == name: - return snapshot['snapshotId'] - return None - - def getfilesystemId(self): - # Check given FileSystem is exists - # Return fileSystemId is found, None otherwise - list_filesystem, error = self.restApi.get('FileSystems') - - if error: - self.module.fail_json(msg=error) - for FileSystem in list_filesystem: - if FileSystem['fileSystemId'] == self.parameters['fileSystemId']: - return FileSystem['fileSystemId'] - elif FileSystem['creationToken'] == self.parameters['fileSystemId']: - return FileSystem['fileSystemId'] - return None - - def create_snapshot(self): - # Create Snapshot - api = 'Snapshots' - response, error = self.restApi.post(api, self.data) - if error: - self.module.fail_json(msg=error) - - def rename_snapshot(self, snapshotId): - # Rename Snapshot - api = 'Snapshots/' + snapshotId - response, error = self.restApi.put(api, self.data) - if error: - self.module.fail_json(msg=error) - - def delete_snapshot(self, snapshotId): - # Delete Snapshot - api = 'Snapshots/' + snapshotId - data = None - response, error = self.restApi.delete(api, self.data) - if error: - self.module.fail_json(msg=error) - - def apply(self): - """ - Perform pre-checks, call functions and exit - """ - self.snapshotId = self.getSnapshotId(self.data['name']) - - if self.snapshotId is None and 'fileSystemId' in self.data: - self.fileSystemId = self.getfilesystemId() - self.data['fileSystemId'] = self.fileSystemId - if self.fileSystemId is None: - self.module.fail_json(msg='Error: Specified filesystem id %s does not exist ' % self.data['fileSystemId']) - - cd_action = self.na_helper.get_cd_action(self.snapshotId, self.data) - result_message = "" - if self.na_helper.changed: - if self.module.check_mode: - # Skip changes - result_message = "Check mode, skipping changes" - else: - if cd_action == "delete": - self.delete_snapshot(self.snapshotId) - result_message = "Snapshot Deleted" - - elif cd_action == "create": - if 'from_name' in self.data: - # If cd_action is create and from_name is given - snapshotId = self.getSnapshotId(self.data['from_name']) - if snapshotId is not None: - # If resource pointed by from_name exists, rename the snapshot to name - self.rename_snapshot(snapshotId) - result_message = "Snapshot Updated" - else: - # If resource pointed by from_name does not exists, error out - self.module.fail_json(msg="Resource does not exist : %s" % self.data['from_name']) - else: - self.create_snapshot() - # If from_name is not defined, Create from scratch. - result_message = "Snapshot Created" - - self.module.exit_json(changed=self.na_helper.changed, msg=result_message) - - -def main(): - """ - Main function - """ - aws_netapp_cvs_snapshots = AwsCvsNetappSnapshot() - aws_netapp_cvs_snapshots.apply() - - -if __name__ == '__main__': - main() |