Skip to content

Commit

Permalink
Sync bitbucket and GitHub
Browse files Browse the repository at this point in the history
  • Loading branch information
carchi8py committed Jul 13, 2022
1 parent 7c0ef88 commit 633c75a
Show file tree
Hide file tree
Showing 7 changed files with 738 additions and 79 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ The following modules do not have REST equivalent APIs. They will stop working o
- na_ontap_interface - enforce requirement for address/netmask for interfaces other than FC.
- na_ontap_interface - fix idempotency issue for cluster scoped interfaces when using REST.
- na_ontap_interface - fix potential node and uuid issues with LIF migration.
- na_ontap_interface - FC interfaces - scope is not supported.
- na_ontap_interface - FC interfaces - home_port is not supported for ONTAP 9.7 or earlier.
- na_ontap_interface - FC interfaces - home_node should not be sent as location.home_node.
- na_ontap_interface - FC interfaces - service_policy is not supported.
- na_ontap_interface - ignore 'none' when using REST rather than reporting unexpected protocol.
- na_ontap_lun - catch ZAPI error on get LUN.
- na_ontap_lun - ignore resize error if no change was required.
- na_ontap_lun - report error if flexvol_name is missing when using ZAPI.
Expand All @@ -94,7 +99,8 @@ The following modules do not have REST equivalent APIs. They will stop working o

### New Module
- na_ontap_ntp_key - Manage NTP keys.
- na_ontap_s3_policies - manage S3 policies.
- na_ontap_s3_groups - Manage s3 groups.
- na_ontap_s3_policies - Manage S3 policies.

### Minor Changes
- na_ontap_info - add quota-policy-info.
Expand Down
6 changes: 6 additions & 0 deletions changelogs/fragments/DEVOPS-5229.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
bugfixes:
- na_ontap_interface - FC interfaces - scope is not supported.
- na_ontap_interface - FC interfaces - home_port is not supported for ONTAP 9.7 or earlier.
- na_ontap_interface - FC interfaces - home_node should not be sent as location.home_node.
- na_ontap_interface - FC interfaces - service_policy is not supported.
- na_ontap_interface - ignore 'none' when using REST rather than reporting unexpected protocol.
1 change: 1 addition & 0 deletions meta/runtime.yml
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ action_groups:
- na_ontap_rest_info
- na_ontap_restit
- na_ontap_s3_buckets
- na_ontap_s3_groups
- na_ontap_s3_policies
- na_ontap_s3_services
- na_ontap_s3_users
Expand Down
148 changes: 98 additions & 50 deletions plugins/modules/na_ontap_interface.py

Large diffs are not rendered by default.

222 changes: 222 additions & 0 deletions plugins/modules/na_ontap_s3_groups.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
#!/usr/bin/python

# (c) 2022, 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

DOCUMENTATION = '''
module: na_ontap_s3_groups
short_description: NetApp ONTAP S3 groups
extends_documentation_fragment:
- netapp.ontap.netapp.na_ontap
version_added: 21.21.0
author: NetApp Ansible Team (@carchi8py) <[email protected]>
description:
- Create, delete, or modify S3 groups on NetApp ONTAP.
options:
state:
description:
- Whether the specified S3 group should exist or not.
choices: ['present', 'absent']
type: str
default: 'present'
name:
description:
- The name of the S3 group.
type: str
required: true
vserver:
description:
- Name of the vserver to use.
type: str
required: true
comment:
description:
- comment about the group
type: str
users:
description: List of users to to add the the group
type: list
elements: dict
suboptions:
name:
description: username
type: str
policies:
description: Policies to add the the group
type: list
elements: dict
suboptions:
name:
description: policy name
type: str
'''

EXAMPLES = """
- name: Create and modify a S3 Group
netapp.ontap.na_ontap_s3_groups:
state: present
name: dev-group
comment: group for devs
vserver: ansibleSVM
users:
- name: carchi8py
- name: carchi8py2
policies:
- name: allow_policy
- name: deny_policy
hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
https: true
validate_certs: false
use_rest: always
- name: Delete a S3 Group
netapp.ontap.na_ontap_s3_groups:
state: absent
name: dev-group
vserver: ansibleSVM
hostname: "{{ netapp_hostname }}"
username: "{{ netapp_username }}"
password: "{{ netapp_password }}"
https: true
validate_certs: false
use_rest: always
"""

RETURN = """
"""

import traceback
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils._text import to_native
import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils
from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule
from ansible_collections.netapp.ontap.plugins.module_utils.netapp import OntapRestAPI
from ansible_collections.netapp.ontap.plugins.module_utils import rest_generic
from ansible_collections.netapp.ontap.plugins.module_utils import rest_vserver


class NetAppOntapS3Groups:
def __init__(self):
self.argument_spec = netapp_utils.na_ontap_host_argument_spec()
self.argument_spec.update(dict(
state=dict(required=False, type='str', choices=['present', 'absent'], default='present'),
vserver=dict(required=True, type='str'),
name=dict(required=True, type='str'),
comment=dict(required=False, type='str'),
users=dict(required=False, type='list', elements='dict', options=dict(
name=dict(required=False, type='str'))),
policies=dict(required=False, type='list', elements='dict', options=dict(
name=dict(required=False, type='str')))))
self.module = AnsibleModule(
argument_spec=self.argument_spec,
supports_check_mode=True,
)
self.svm_uuid = None
self.group_id = None
self.na_helper = NetAppModule(self.module)
self.parameters = self.na_helper.check_and_set_parameters(self.module)
self.rest_api = OntapRestAPI(self.module)
self.use_rest = self.rest_api.is_rest()
self.rest_api.fail_if_not_rest_minimum_version('na_ontap_s3_groups', 9, 8)

def get_s3_groups(self):
self.get_svm_uuid()
api = 'protocols/s3/services/%s/groups' % self.svm_uuid
fields = ','.join(('name',
'comment',
'users.name',
'policies.name'))
params = {'name': self.parameters['name'],
'fields': fields}
record, error = rest_generic.get_one_record(self.rest_api, api, params)
if error:
self.module.fail_json(msg='Error fetching S3 groups %s: %s' % (self.parameters['name'], to_native(error)),
exception=traceback.format_exc())
if record:
self.group_id = record.get('id')
# even with the above, the APi Returning _link which is causing modify to get called
for each in self.na_helper.safe_get(record, ['users']):
each.pop('_links')
for each in self.na_helper.safe_get(record, ['policies']):
each.pop('_links')
return record

def create_s3_groups(self):
api = 'protocols/s3/services/%s/groups' % self.svm_uuid
body = {'name': self.parameters['name'],
'users': self.parameters['users'],
'policies': self.parameters['policies']}
if self.parameters.get('comment'):
body['comment'] = self.parameters['comment']
dummy, error = rest_generic.post_async(self.rest_api, api, body)
if error:
self.module.fail_json(msg='Error creating S3 groups %s: %s' % (self.parameters['name'], to_native(error)),
exception=traceback.format_exc())

def delete_s3_groups(self):
api = 'protocols/s3/services/%s/groups' % self.svm_uuid
dummy, error = rest_generic.delete_async(self.rest_api, api, self.group_id)
if error:
self.module.fail_json(msg='Error deleting S3 group %s: %s' % (self.parameters['name'], to_native(error)),
exception=traceback.format_exc())

def modify_s3_groups(self, modify):
api = 'protocols/s3/services/%s/groups' % self.svm_uuid
body = {}
if modify.get('comment') is not None:
body['comment'] = self.parameters['comment']
if modify.get('users') is not None:
body['users'] = self.parameters['users']
if modify.get('policies') is not None:
body['policies'] = self.parameters['policies']
dummy, error = rest_generic.patch_async(self.rest_api, api, self.group_id, body)
if error:
self.module.fail_json(msg='Error modifying S3 group %s: %s' % (self.parameters['name'], to_native(error)),
exception=traceback.format_exc())

def get_svm_uuid(self):
record, error = rest_vserver.get_vserver_uuid(self.rest_api, self.parameters['vserver'], self.module, True)
self.svm_uuid = record

def apply(self):
current = self.get_s3_groups()
cd_action, modify = None, None
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 cd_action == 'create' and (self.na_helper.safe_get(self.parameters, ['users']) is None
or self.na_helper.safe_get(self.parameters, ['policies']) is None):
self.module.fail_json(msg='policies and users are required for a creating a group.')
if modify and (self.na_helper.safe_get(self.parameters, ['users']) is None
or self.na_helper.safe_get(self.parameters, ['policies']) is None):
self.module.fail_json(msg='policies and users can not be empty when modifying a group.')
if self.na_helper.changed and not self.module.check_mode:
if cd_action == 'create':
self.create_s3_groups()
if cd_action == 'delete':
self.delete_s3_groups()
if modify:
self.modify_s3_groups(modify)
self.module.exit_json(changed=self.na_helper.changed)


def main():
obj = NetAppOntapS3Groups()
obj.apply()


if __name__ == '__main__':
main()
Loading

0 comments on commit 633c75a

Please sign in to comment.