Update to base Netapp.py for Azure, and Rest API (#59151)

* base changes

* updateS

* fixes

* fies

* updates

* fix issues

* updates
pull/59254/head
Chris Archibald 5 years ago committed by Jake Jackson
parent b2d8ef69f9
commit 2fbc226509

@ -117,7 +117,8 @@ def na_ontap_host_argument_spec():
https=dict(required=False, type='bool', default=False),
validate_certs=dict(required=False, type='bool', default=True),
http_port=dict(required=False, type='int'),
ontapi=dict(required=False, type='int')
ontapi=dict(required=False, type='int'),
use_rest=dict(required=False, type='str', default='Auto', choices=['Never', 'Always', 'Auto'])
)
@ -542,6 +543,7 @@ class OntapRestAPI(object):
self.username = self.module.params['username']
self.password = self.module.params['password']
self.hostname = self.module.params['hostname']
self.use_rest = self.module.params['use_rest']
self.verify = self.module.params['validate_certs']
self.timeout = timeout
self.url = 'https://' + self.hostname + '/api/'
@ -615,6 +617,10 @@ class OntapRestAPI(object):
return self.send_request(method, api, params, json=data)
def is_rest(self):
if self.use_rest == "Always":
return True
if self.use_rest == 'Never':
return False
method = 'HEAD'
api = 'cluster/software'
status_code, junk = self.send_request(method, api, params=None, return_status_code=True)

@ -168,6 +168,28 @@ class NetAppModule(object):
'''
pass
@staticmethod
def compare_lists(current, desired, get_list_diff):
''' compares two lists and return a list of elements that are either the desired elements or elements that are modified from the current state
depending on the get_list_diff flag
:param: current: current item attribute in ONTAP
:param: desired: attributes from playbook
:param: get_list_diff: specifies whether to have a diff of desired list w.r.t current list for an attribute
:return: list of attributes to be modified
:rtype: list
'''
desired_diff_list = [item for item in desired if item not in current] # get what in desired and not in current
current_diff_list = [item for item in current if item not in desired] # get what in current but not in desired
if desired_diff_list or current_diff_list:
# there are changes
if get_list_diff:
return desired_diff_list
else:
return desired
else:
return []
def get_modified_attributes(self, current, desired, get_list_diff=False):
''' takes two dicts of attributes and return a dict of attributes that are
not in the current state
@ -195,13 +217,11 @@ class NetAppModule(object):
for key, value in current.items():
if key in desired and desired[key] is not None:
if type(value) is list:
value.sort()
desired[key].sort()
if cmp(value, desired[key]) != 0:
if not get_list_diff:
modified[key] = desired[key]
else:
modified[key] = [item for item in desired[key] if item not in value]
modified_list = self.compare_lists(value, desired[key], get_list_diff) # get modified list from current and desired
if modified_list:
modified[key] = modified_list
elif cmp(value, desired[key]) != 0:
modified[key] = desired[key]
if modified:
self.changed = True
return modified

@ -15,6 +15,30 @@ notes:
- Ansible modules are available for the following NetApp Storage Platforms: E-Series, ONTAP, SolidFire
'''
# Documentation fragment for Cloud Volume Services on Azure NetApp (azure_rm_netapp)
AZURE_RM_NETAPP = r'''
options:
resource_group:
description:
- Name of the resource group.
required: true
type: str
requirements:
- python >= 2.7
- azure >= 2.0.0
- Python netapp-mgmt. Install using 'pip install netapp-mgmt'
- Python netapp-mgmt-netapp. Install using 'pip install netapp-mgmt-netapp'
- For authentication with Azure NetApp log in before you run your tasks or playbook with C(az login).
notes:
- The modules prefixed with azure_rm_netapp are built to support the Cloud Volume Services for Azure NetApp Files.
seealso:
- name: Sign in with Azure CLI
link: https://docs.microsoft.com/en-us/cli/azure/authenticate-azure-cli?view=azure-cli-latest
description: How to authenticate using the C(az login) command.
'''
# Documentation fragment for ONTAP (na_ontap)
NA_ONTAP = r'''
options:
@ -55,6 +79,15 @@ options:
description:
- The ontap api version to use
type: int
use_rest:
description:
- REST API if supported by the target system for all the resources and attributes the module requires. Otherwise will revert to ZAPI.
- Always -- will always use the REST API
- Never -- will always use the ZAPI
- Auto -- will try to use the REST Api
default: Auto
choices: ['Never', 'Always', 'Auto']
type: str
requirements:

Loading…
Cancel
Save