-
Notifications
You must be signed in to change notification settings - Fork 23.8k
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
new module netapp csv pools for aws #61340
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
278 changes: 278 additions & 0 deletions
278
lib/ansible/modules/cloud/amazon/aws_netapp_cvs_pool.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,278 @@ | ||
#!/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 | ||
new_name: | ||
description: | ||
- rename the existing pool name ( The human readable name of the Pool ) | ||
- 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 | ||
name: TestPoolBB12 | ||
new_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'), | ||
new_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): | ||
""" | ||
Returns Pool object if exists else Return None | ||
""" | ||
pool_info = None | ||
new_name_exists = False | ||
is_new_name_check_needed = False | ||
|
||
if 'new_name' in self.parameters.keys(): | ||
is_new_name_check_needed = True | ||
|
||
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'] == self.parameters['name']: | ||
pool_info = pool | ||
|
||
if is_new_name_check_needed is True: | ||
if self.parameters['new_name'] == pool['name']: | ||
new_name_exists = True | ||
else: | ||
if pool_info is not None: | ||
break | ||
|
||
if pool_info is not None and new_name_exists is True: | ||
break | ||
|
||
return pool_info, new_name_exists | ||
|
||
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'] | ||
} | ||
if 'new_name' in self.parameters.keys(): | ||
self.module.exit_json(changed=False) | ||
|
||
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 | ||
new_name_exists = False | ||
|
||
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, new_name_exists = self.get_aws_netapp_cvs_pool() | ||
cd_action = self.na_helper.get_cd_action(current, self.parameters) | ||
|
||
if current and self.parameters['state'] != 'absent': | ||
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 'new_name' in self.parameters.keys(): | ||
if new_name_exists is True: | ||
self.module.fail_json(changed=False, msg="unable to rename pool '%s': already exists" % (self.parameters['new_name'])) | ||
else: | ||
update_pool_info['name'] = self.parameters['new_name'] | ||
update_required = True | ||
|
||
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() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't use new_name. It should be from_name to maintain idempotency