-
Notifications
You must be signed in to change notification settings - Fork 23.7k
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
Adding ontap_node.py Module #44211
Merged
Merged
Adding ontap_node.py Module #44211
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
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,144 @@ | ||
#!/usr/bin/python | ||
|
||
# (c) 2018, NetApp, Inc | ||
# 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 | ||
|
||
|
||
ANSIBLE_METADATA = {'metadata_version': '1.1', | ||
'status': ['preview'], | ||
'supported_by': 'community'} | ||
|
||
DOCUMENTATION = ''' | ||
module: na_ontap_node | ||
short_description: NetApp ONTAP Rename a node. | ||
extends_documentation_fragment: | ||
- netapp.na_ontap | ||
version_added: '2.7' | ||
author: NetApp Ansible Team (ng-ansibleteam@netapp.com) | ||
description: | ||
- Rename an ONTAP node. | ||
options: | ||
name: | ||
description: | ||
- The new name for the node | ||
required: true | ||
|
||
from_name: | ||
description: | ||
- The name of the node to be renamed. If I(name) already exists, no action will be performed. | ||
required: true | ||
|
||
''' | ||
|
||
EXAMPLES = """ | ||
- name: rename node | ||
na_ontap_node: | ||
hostname: "{{ netapp_hostname }}" | ||
username: "{{ netapp_username }}" | ||
password: "{{ netapp_password }}" | ||
from_name: laurentn-vsim1 | ||
name: laurentncluster-2 | ||
""" | ||
|
||
RETURN = """ | ||
|
||
""" | ||
import traceback | ||
|
||
from ansible.module_utils.basic import AnsibleModule | ||
from ansible.module_utils._text import to_native | ||
import ansible.module_utils.netapp as netapp_utils | ||
from ansible.module_utils.netapp_module import NetAppModule | ||
|
||
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib() | ||
|
||
|
||
class NetAppOntapNode(object): | ||
""" | ||
Rename node | ||
""" | ||
|
||
def __init__(self): | ||
self.argument_spec = netapp_utils.na_ontap_host_argument_spec() | ||
self.argument_spec.update(dict( | ||
name=dict(required=True, type='str'), | ||
from_name=dict(required=True, 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) | ||
|
||
if HAS_NETAPP_LIB is False: | ||
self.module.fail_json(msg="the python NetApp-Lib module is required") | ||
else: | ||
self.cluster = netapp_utils.setup_na_ontap_zapi(module=self.module) | ||
return | ||
|
||
def rename_node(self): | ||
""" | ||
Rename an existing node | ||
:return: none | ||
""" | ||
node_obj = netapp_utils.zapi.NaElement('system-node-rename') | ||
node_obj.add_new_child('node', self.parameters['from_name']) | ||
node_obj.add_new_child('new-name', self.parameters['name']) | ||
try: | ||
self.cluster.invoke_successfully(node_obj, True) | ||
except netapp_utils.zapi.NaApiError as error: | ||
self.module.fail_json(msg='Error creating node: %s' % | ||
(to_native(error)), | ||
exception=traceback.format_exc()) | ||
|
||
def get_node(self, name): | ||
node_obj = netapp_utils.zapi.NaElement('system-node-get') | ||
node_obj.add_new_child('node', name) | ||
try: | ||
self.cluster.invoke_successfully(node_obj, True) | ||
except netapp_utils.zapi.NaApiError as error: | ||
if to_native(error.code) == "13115": | ||
# 13115 (EINVALIDINPUTERROR) if the node does not exist | ||
return None | ||
else: | ||
self.module.fail_json(msg=to_native( | ||
error), exception=traceback.format_exc()) | ||
return True | ||
|
||
def apply(self): | ||
# logging ems event | ||
results = netapp_utils.get_cserver(self.cluster) | ||
cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results) | ||
netapp_utils.ems_log_event("na_ontap_node", cserver) | ||
|
||
exists = self.get_node(self.parameters['name']) | ||
from_exists = self.get_node(self.parameters['from_name']) | ||
changed = False | ||
if exists: | ||
pass | ||
else: | ||
if from_exists: | ||
self.rename_node() | ||
changed = True | ||
else: | ||
self.module.fail_json(msg='Error renaming node, from_name %s does not exist' % self.parameters['from_name']) | ||
|
||
self.module.exit_json(changed=changed) | ||
|
||
|
||
def main(): | ||
""" | ||
Start, Stop and Enable node services. | ||
""" | ||
obj = NetAppOntapNode() | ||
obj.apply() | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |
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.
What happens if this playbook is run twice, ie if
laurentn-vsim1
doesn't exist on the 2nd run?Code needs to deal wit that and the documentation needs to explain it
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 code does deal with it, it returns no change because it sees that the new node name already exists and the old doesn't. What explanation in the documentation are you looking for?