-
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 na_ontap_disks.py Module #44192
Merged
Merged
Changes from all commits
Commits
Show all changes
4 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,147 @@ | ||
#!/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_disks | ||
|
||
short_description: NetApp ONTAP Assign disks to nodes | ||
extends_documentation_fragment: | ||
- netapp.na_ontap | ||
version_added: '2.7' | ||
author: NetApp Ansible Team (ng-ansibleteam@netapp.com) | ||
|
||
description: | ||
- Assign all or part of disks to nodes. | ||
|
||
options: | ||
|
||
node: | ||
required: true | ||
description: | ||
- It specifies the node to assign all visible unowned disks. | ||
|
||
''' | ||
|
||
EXAMPLES = """ | ||
- name: Assign unowned disks | ||
na_ontap_disks: | ||
node: cluster-01 | ||
hostname: "{{ hostname }} " | ||
username: "{{ admin username }}" | ||
password: "{{ admin password }}" | ||
""" | ||
|
||
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 | ||
|
||
|
||
HAS_NETAPP_LIB = netapp_utils.has_netapp_lib() | ||
|
||
|
||
class NetAppOntapDisks(object): | ||
''' object initialize and class methods ''' | ||
|
||
def __init__(self): | ||
self.argument_spec = netapp_utils.na_ontap_host_argument_spec() | ||
self.argument_spec.update(dict( | ||
node=dict(required=True, type='str'), | ||
)) | ||
|
||
self.module = AnsibleModule( | ||
argument_spec=self.argument_spec, | ||
supports_check_mode=True | ||
) | ||
|
||
parameters = self.module.params | ||
|
||
# set up state variables | ||
self.node = parameters['node'] | ||
|
||
if HAS_NETAPP_LIB is False: | ||
self.module.fail_json(msg="the python NetApp-Lib module is required") | ||
else: | ||
self.server = netapp_utils.setup_na_ontap_zapi(module=self.module) | ||
|
||
def disk_check(self): | ||
""" | ||
Check for disks | ||
""" | ||
disk_iter = netapp_utils.zapi.NaElement('storage-disk-get-iter') | ||
disk_storage_info = netapp_utils.zapi.NaElement('storage-disk-info') | ||
disk_raid_info = netapp_utils.zapi.NaElement('disk-raid-info') | ||
disk_raid_info.add_new_child('container-type', 'unassigned') | ||
disk_storage_info.add_child_elem(disk_raid_info) | ||
|
||
disk_query = netapp_utils.zapi.NaElement('query') | ||
disk_query.add_child_elem(disk_storage_info) | ||
|
||
disk_iter.add_child_elem(disk_query) | ||
result = self.server.invoke_successfully(disk_iter, True) | ||
|
||
if result.get_child_by_name('num-records') and \ | ||
int(result.get_child_content('num-records')) >= 1: | ||
has_disks = "true" | ||
return has_disks | ||
|
||
def disk_assign(self): | ||
""" | ||
enable aggregate (online). | ||
""" | ||
assign_disk = netapp_utils.zapi.NaElement.create_node_with_children( | ||
'disk-sanown-assign', **{'node-name': self.node, | ||
'all': 'true'}) | ||
try: | ||
self.server.invoke_successfully(assign_disk, | ||
enable_tunneling=True) | ||
return True | ||
except netapp_utils.zapi.NaApiError as error: | ||
if to_native(error.code) == "13001": | ||
# Error 13060 denotes aggregate is already online | ||
return False | ||
else: | ||
self.module.fail_json(msg='Error assigning disks %s' % | ||
(to_native(error)), | ||
exception=traceback.format_exc()) | ||
|
||
def apply(self): | ||
'''Apply action to disks''' | ||
changed = False | ||
results = netapp_utils.get_cserver(self.server) | ||
cserver = netapp_utils.setup_na_ontap_zapi( | ||
module=self.module, vserver=results) | ||
netapp_utils.ems_log_event("na_ontap_disks", cserver) | ||
|
||
# check if anything needs to be changed (add/delete/update) | ||
unowned_disks = self.disk_check() | ||
if unowned_disks == 'true': | ||
self.disk_assign() | ||
changed = True | ||
self.module.exit_json(changed=changed) | ||
|
||
|
||
def main(): | ||
''' Create object and call apply ''' | ||
obj_aggr = NetAppOntapDisks() | ||
obj_aggr.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.
How would you unassign, set
node:
to empty, null?Would be worth adding an example for that.
If it's not possible then I think
short_description
may need updating