diff options
author | Chris Archibald <carchi@netapp.com> | 2019-01-24 07:41:36 -0800 |
---|---|---|
committer | ansibot <ansibot@users.noreply.github.com> | 2019-01-24 10:41:36 -0500 |
commit | c940c6df41221c4b50aca4ad01bd4eff44c7b487 (patch) | |
tree | d02ced12a0da00b7928c1c52e2ef54f3d18b04d4 /lib | |
parent | 8d282de811f134fd4c3224182fbda36088ee4f94 (diff) | |
download | ansible-c940c6df41221c4b50aca4ad01bd4eff44c7b487.tar.gz |
Rewite of na_ontap_cifs to use NetAppModule, new options, and unit tests. (#49782)
* changes to clusteR
* Revert "changes to clusteR"
This reverts commit 33ee1b71e4bc8435fb315762a871f8c4cb6c5f80.
* changes to na_ontap_cifs
* fix dup
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ansible/modules/storage/netapp/na_ontap_cifs.py | 130 |
1 files changed, 80 insertions, 50 deletions
diff --git a/lib/ansible/modules/storage/netapp/na_ontap_cifs.py b/lib/ansible/modules/storage/netapp/na_ontap_cifs.py index 5570d72cfd..edf6c88371 100644 --- a/lib/ansible/modules/storage/netapp/na_ontap_cifs.py +++ b/lib/ansible/modules/storage/netapp/na_ontap_cifs.py @@ -34,13 +34,23 @@ options: The name of the CIFS share. The CIFS share name is a UTF-8 string with the following characters being illegal; control characters from 0x00 to 0x1F, both inclusive, 0x22 (double quotes) required: true + share_properties: + description: + - The list of properties for the CIFS share + required: false + version_added: '2.8' + symlink_properties: + description: + - The list of symlink properties for this CIFS share + required: false + version_added: '2.8' state: choices: ['present', 'absent'] description: - "Whether the specified CIFS share should exist or not." required: false default: present -short_description: "NetApp ONTAP manage cifs-share" +short_description: NetApp ONTAP Manage cifs-share version_added: "2.6" ''' @@ -52,6 +62,8 @@ EXAMPLES = """ share_name: cifsShareName path: / vserver: vserverName + share_properties: browsable,oplocks + symlink_properties: read_only,enable hostname: "{{ netapp_hostname }}" username: "{{ netapp_username }}" password: "{{ netapp_password }}" @@ -69,6 +81,8 @@ EXAMPLES = """ share_name: pb_test vserver: vserverName path: / + share_properties: show_previous_versions + symlink_properties: disable hostname: "{{ netapp_hostname }}" username: "{{ netapp_username }}" password: "{{ netapp_password }}" @@ -83,6 +97,7 @@ 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() @@ -99,31 +114,25 @@ class NetAppONTAPCifsShare(object): 'present', 'absent'], default='present'), share_name=dict(required=True, type='str'), path=dict(required=False, type='str'), - vserver=dict(required=True, type='str') + vserver=dict(required=True, type='str'), + share_properties=dict(required=False, type='list'), + symlink_properties=dict(required=False, type='list') )) self.module = AnsibleModule( argument_spec=self.argument_spec, - required_if=[ - ('state', 'present', ['share_name', 'path']) - ], supports_check_mode=True ) - parameters = self.module.params - - # set up state variables - self.state = parameters['state'] - self.share_name = parameters['share_name'] - self.path = parameters['path'] - self.vserver = parameters['vserver'] + 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.server = netapp_utils.setup_na_ontap_zapi( - module=self.module, vserver=self.vserver) + module=self.module, vserver=self.parameters.get('vserver')) def get_cifs_share(self): """ @@ -135,7 +144,7 @@ class NetAppONTAPCifsShare(object): """ cifs_iter = netapp_utils.zapi.NaElement('cifs-share-get-iter') cifs_info = netapp_utils.zapi.NaElement('cifs-share') - cifs_info.add_new_child('share-name', self.share_name) + cifs_info.add_new_child('share-name', self.parameters.get('share_name')) query = netapp_utils.zapi.NaElement('query') query.add_child_elem(cifs_info) @@ -145,16 +154,26 @@ class NetAppONTAPCifsShare(object): result = self.server.invoke_successfully(cifs_iter, True) return_value = None - print(result.to_string()) # check if query returns the expected cifs-share if result.get_child_by_name('num-records') and \ int(result.get_child_content('num-records')) == 1: - - cifs_acl = result.get_child_by_name('attributes-list').\ + properties_list = [] + symlink_list = [] + cifs_attrs = result.get_child_by_name('attributes-list').\ get_child_by_name('cifs-share') + if cifs_attrs.get_child_by_name('share-properties'): + properties_attrs = cifs_attrs['share-properties'] + if properties_attrs is not None: + properties_list = [property.get_content() for property in properties_attrs.get_children()] + if cifs_attrs.get_child_by_name('symlink-properties'): + symlink_attrs = cifs_attrs['symlink-properties'] + if symlink_attrs is not None: + symlink_list = [symlink.get_content() for symlink in symlink_attrs.get_children()] return_value = { - 'share': cifs_acl.get_child_content('share-name'), - 'path': cifs_acl.get_child_content('path'), + 'share': cifs_attrs.get_child_content('share-name'), + 'path': cifs_attrs.get_child_content('path'), + 'share_properties': properties_list, + 'symlink_properties': symlink_list } return return_value @@ -163,9 +182,20 @@ class NetAppONTAPCifsShare(object): """ Create CIFS share """ + options = {'share-name': self.parameters.get('share_name'), + 'path': self.parameters.get('path')} cifs_create = netapp_utils.zapi.NaElement.create_node_with_children( - 'cifs-share-create', **{'share-name': self.share_name, - 'path': self.path}) + 'cifs-share-create', **options) + if self.parameters.get('share_properties'): + property_attrs = netapp_utils.zapi.NaElement('share-properties') + cifs_create.add_child_elem(property_attrs) + for property in self.parameters.get('share_properties'): + property_attrs.add_new_child('cifs-share-properties', property) + if self.parameters.get('symlink_properties'): + symlink_attrs = netapp_utils.zapi.NaElement('symlink-properties') + cifs_create.add_child_elem(symlink_attrs) + for symlink in self.parameters.get('symlink_properties'): + symlink_attrs.add_new_child('cifs-share-symlink-properties', symlink) try: self.server.invoke_successfully(cifs_create, @@ -173,7 +203,7 @@ class NetAppONTAPCifsShare(object): except netapp_utils.zapi.NaApiError as error: self.module.fail_json(msg='Error creating cifs-share %s: %s' - % (self.share_name, to_native(error)), + % (self.parameters.get('share_name'), to_native(error)), exception=traceback.format_exc()) def delete_cifs_share(self): @@ -181,61 +211,61 @@ class NetAppONTAPCifsShare(object): Delete CIFS share """ cifs_delete = netapp_utils.zapi.NaElement.create_node_with_children( - 'cifs-share-delete', **{'share-name': self.share_name}) + 'cifs-share-delete', **{'share-name': self.parameters.get('share_name')}) try: self.server.invoke_successfully(cifs_delete, enable_tunneling=True) except netapp_utils.zapi.NaApiError as error: self.module.fail_json(msg='Error deleting cifs-share %s: %s' - % (self.share_name, to_native(error)), + % (self.parameters.get('share_name'), to_native(error)), exception=traceback.format_exc()) def modify_cifs_share(self): """ modilfy path for the given CIFS share """ + options = {'share-name': self.parameters.get('share_name')} cifs_modify = netapp_utils.zapi.NaElement.create_node_with_children( - 'cifs-share-modify', **{'share-name': self.share_name, - 'path': self.path}) + 'cifs-share-modify', **options) + if self.parameters.get('path'): + cifs_modify.add_new_child('path', self.parameters.get('path')) + if self.parameters.get('share_properties'): + property_attrs = netapp_utils.zapi.NaElement('share-properties') + cifs_modify.add_child_elem(property_attrs) + for property in self.parameters.get('share_properties'): + property_attrs.add_new_child('cifs-share-properties', property) + if self.parameters.get('symlink_properties'): + symlink_attrs = netapp_utils.zapi.NaElement('symlink-properties') + cifs_modify.add_child_elem(symlink_attrs) + for property in self.parameters.get('symlink_properties'): + symlink_attrs.add_new_child('cifs-share-symlink-properties', property) try: self.server.invoke_successfully(cifs_modify, enable_tunneling=True) except netapp_utils.zapi.NaApiError as error: self.module.fail_json(msg='Error modifying cifs-share %s:%s' - % (self.share_name, to_native(error)), + % (self.parameters.get('share_name'), to_native(error)), exception=traceback.format_exc()) def apply(self): '''Apply action to cifs share''' - changed = False - cifs_exists = False netapp_utils.ems_log_event("na_ontap_cifs", self.server) - cifs_details = self.get_cifs_share() - if cifs_details: - cifs_exists = True - if self.state == 'absent': # delete - changed = True - elif self.state == 'present': - if cifs_details['path'] != self.path: # modify path - changed = True - else: - if self.state == 'present': # create - changed = True - - if changed: + current = self.get_cifs_share() + cd_action = self.na_helper.get_cd_action(current, self.parameters) + if cd_action is None: + modify = self.na_helper.get_modified_attributes(current, self.parameters) + if self.na_helper.changed: if self.module.check_mode: pass else: - if self.state == 'present': # execute create - if not cifs_exists: - self.create_cifs_share() - else: # execute modify path - self.modify_cifs_share() - elif self.state == 'absent': # execute delete + if cd_action == 'create': + self.create_cifs_share() + elif cd_action == 'delete': self.delete_cifs_share() - - self.module.exit_json(changed=changed) + elif modify: + self.modify_cifs_share() + self.module.exit_json(changed=self.na_helper.changed) def main(): |