-
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: Cloud Volumes for AWS, active Directory #61342
Merged
Merged
Changes from all commits
Commits
Show all changes
3 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
270 changes: 270 additions & 0 deletions
270
lib/ansible/modules/cloud/amazon/aws_netapp_cvs_active_directory.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,270 @@ | ||
#!/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: true | ||
type: str | ||
|
||
DNS: | ||
description: | ||
- DNS server address for the Active Directory domain | ||
- Required when C(state=present) | ||
- Required when C(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: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would report an error here, as we did not complete the action. But this change can be delayed. |
||
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() |
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.
The else: is not really necessary here since there is a return just above.
But it does not change the behavior.