|
|
@ -40,10 +40,14 @@ options:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Unique username for this account. (May be 1 to 64 characters in length).
|
|
|
|
- Unique username for this account. (May be 1 to 64 characters in length).
|
|
|
|
required: true
|
|
|
|
required: true
|
|
|
|
|
|
|
|
aliases:
|
|
|
|
|
|
|
|
- account_id
|
|
|
|
|
|
|
|
|
|
|
|
new_element_username:
|
|
|
|
from_name:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- New name for the user account.
|
|
|
|
- ID or Name of the account to rename.
|
|
|
|
|
|
|
|
- Required to create an account called 'element_username' by renaming 'from_name'.
|
|
|
|
|
|
|
|
version_added: '2.8'
|
|
|
|
|
|
|
|
|
|
|
|
initiator_secret:
|
|
|
|
initiator_secret:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
@ -61,10 +65,6 @@ options:
|
|
|
|
attributes:
|
|
|
|
attributes:
|
|
|
|
description: List of Name/Value pairs in JSON object format.
|
|
|
|
description: List of Name/Value pairs in JSON object format.
|
|
|
|
|
|
|
|
|
|
|
|
account_id:
|
|
|
|
|
|
|
|
description:
|
|
|
|
|
|
|
|
- The ID of the account to manage or update.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
status:
|
|
|
|
status:
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Status of the account.
|
|
|
|
- Status of the account.
|
|
|
@ -86,8 +86,27 @@ EXAMPLES = """
|
|
|
|
username: "{{ elementsw_username }}"
|
|
|
|
username: "{{ elementsw_username }}"
|
|
|
|
password: "{{ elementsw_password }}"
|
|
|
|
password: "{{ elementsw_password }}"
|
|
|
|
state: present
|
|
|
|
state: present
|
|
|
|
|
|
|
|
status: locked
|
|
|
|
element_username: TenantA
|
|
|
|
element_username: TenantA
|
|
|
|
new_element_username: TenantA-Renamed
|
|
|
|
|
|
|
|
|
|
|
|
- name: Rename Account
|
|
|
|
|
|
|
|
na_elementsw_account:
|
|
|
|
|
|
|
|
hostname: "{{ elementsw_hostname }}"
|
|
|
|
|
|
|
|
username: "{{ elementsw_username }}"
|
|
|
|
|
|
|
|
password: "{{ elementsw_password }}"
|
|
|
|
|
|
|
|
state: present
|
|
|
|
|
|
|
|
element_username: TenantA_Renamed
|
|
|
|
|
|
|
|
from_name: TenantA
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
- name: Rename and modify Account
|
|
|
|
|
|
|
|
na_elementsw_account:
|
|
|
|
|
|
|
|
hostname: "{{ elementsw_hostname }}"
|
|
|
|
|
|
|
|
username: "{{ elementsw_username }}"
|
|
|
|
|
|
|
|
password: "{{ elementsw_password }}"
|
|
|
|
|
|
|
|
state: present
|
|
|
|
|
|
|
|
status: locked
|
|
|
|
|
|
|
|
element_username: TenantA_Renamed
|
|
|
|
|
|
|
|
from_name: TenantA
|
|
|
|
|
|
|
|
|
|
|
|
- name: Delete Account
|
|
|
|
- name: Delete Account
|
|
|
|
na_elementsw_account:
|
|
|
|
na_elementsw_account:
|
|
|
@ -95,7 +114,7 @@ EXAMPLES = """
|
|
|
|
username: "{{ elementsw_username }}"
|
|
|
|
username: "{{ elementsw_username }}"
|
|
|
|
password: "{{ elementsw_password }}"
|
|
|
|
password: "{{ elementsw_password }}"
|
|
|
|
state: absent
|
|
|
|
state: absent
|
|
|
|
element_username: TenantA-Renamed
|
|
|
|
element_username: TenantA_Renamed
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
RETURN = """
|
|
|
|
RETURN = """
|
|
|
@ -121,10 +140,8 @@ class ElementSWAccount(object):
|
|
|
|
self.argument_spec = netapp_utils.ontap_sf_host_argument_spec()
|
|
|
|
self.argument_spec = netapp_utils.ontap_sf_host_argument_spec()
|
|
|
|
self.argument_spec.update(dict(
|
|
|
|
self.argument_spec.update(dict(
|
|
|
|
state=dict(required=True, choices=['present', 'absent']),
|
|
|
|
state=dict(required=True, choices=['present', 'absent']),
|
|
|
|
element_username=dict(required=True, type='str'),
|
|
|
|
element_username=dict(required=True, aliases=["account_id"], type='str'),
|
|
|
|
account_id=dict(required=False, type='int', default=None),
|
|
|
|
from_name=dict(required=False, default=None),
|
|
|
|
|
|
|
|
|
|
|
|
new_element_username=dict(required=False, type='str', default=None),
|
|
|
|
|
|
|
|
initiator_secret=dict(required=False, type='str'),
|
|
|
|
initiator_secret=dict(required=False, type='str'),
|
|
|
|
target_secret=dict(required=False, type='str'),
|
|
|
|
target_secret=dict(required=False, type='str'),
|
|
|
|
attributes=dict(required=False, type='dict'),
|
|
|
|
attributes=dict(required=False, type='dict'),
|
|
|
@ -139,15 +156,13 @@ class ElementSWAccount(object):
|
|
|
|
params = self.module.params
|
|
|
|
params = self.module.params
|
|
|
|
|
|
|
|
|
|
|
|
# set up state variables
|
|
|
|
# set up state variables
|
|
|
|
self.state = params['state']
|
|
|
|
self.state = params.get('state')
|
|
|
|
self.element_username = params['element_username']
|
|
|
|
self.element_username = params.get('element_username')
|
|
|
|
self.account_id = params['account_id']
|
|
|
|
self.from_name = params.get('from_name')
|
|
|
|
|
|
|
|
self.initiator_secret = params.get('initiator_secret')
|
|
|
|
self.new_element_username = params['new_element_username']
|
|
|
|
self.target_secret = params.get('target_secret')
|
|
|
|
self.initiator_secret = params['initiator_secret']
|
|
|
|
self.attributes = params.get('attributes')
|
|
|
|
self.target_secret = params['target_secret']
|
|
|
|
self.status = params.get('status')
|
|
|
|
self.attributes = params['attributes']
|
|
|
|
|
|
|
|
self.status = params['status']
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if HAS_SF_SDK is False:
|
|
|
|
if HAS_SF_SDK is False:
|
|
|
|
self.module.fail_json(msg="Unable to import the Element SW Python SDK")
|
|
|
|
self.module.fail_json(msg="Unable to import the Element SW Python SDK")
|
|
|
@ -162,29 +177,24 @@ class ElementSWAccount(object):
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
self.attributes = self.elementsw_helper.set_element_attributes(source='na_elementsw_account')
|
|
|
|
self.attributes = self.elementsw_helper.set_element_attributes(source='na_elementsw_account')
|
|
|
|
|
|
|
|
|
|
|
|
def get_account(self):
|
|
|
|
def get_account(self, username):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Get Account
|
|
|
|
Get Account
|
|
|
|
:description: Get Account object from account id
|
|
|
|
:description: Get Account object from account id or name
|
|
|
|
|
|
|
|
|
|
|
|
:return: Details about the account. None if not found.
|
|
|
|
:return: Details about the account. None if not found.
|
|
|
|
:rtype: object (Account object)
|
|
|
|
:rtype: object (Account object)
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
|
|
account_list = self.sfe.list_accounts()
|
|
|
|
account_list = self.sfe.list_accounts()
|
|
|
|
account_obj = None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for account in account_list.accounts:
|
|
|
|
for account in account_list.accounts:
|
|
|
|
if account.username == self.element_username:
|
|
|
|
# Check and get account object for a given name
|
|
|
|
# Update self.account_id:
|
|
|
|
if str(account.account_id) == username:
|
|
|
|
if self.account_id is not None:
|
|
|
|
return account
|
|
|
|
if account.account_id == self.account_id:
|
|
|
|
elif account.username == username:
|
|
|
|
account_obj = account
|
|
|
|
return account
|
|
|
|
else:
|
|
|
|
return None
|
|
|
|
self.account_id = account.account_id
|
|
|
|
|
|
|
|
account_obj = account
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return account_obj
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def create_account(self):
|
|
|
|
def create_account(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
@ -196,7 +206,7 @@ class ElementSWAccount(object):
|
|
|
|
target_secret=self.target_secret,
|
|
|
|
target_secret=self.target_secret,
|
|
|
|
attributes=self.attributes)
|
|
|
|
attributes=self.attributes)
|
|
|
|
except Exception as e:
|
|
|
|
except Exception as e:
|
|
|
|
self.module.fail_json(msg='Error creating account %s: %s)' % (self.element_username, to_native(e)),
|
|
|
|
self.module.fail_json(msg='Error creating account %s: %s' % (self.element_username, to_native(e)),
|
|
|
|
exception=traceback.format_exc())
|
|
|
|
exception=traceback.format_exc())
|
|
|
|
|
|
|
|
|
|
|
|
def delete_account(self):
|
|
|
|
def delete_account(self):
|
|
|
@ -210,13 +220,28 @@ class ElementSWAccount(object):
|
|
|
|
self.module.fail_json(msg='Error deleting account %s: %s' % (self.account_id, to_native(e)),
|
|
|
|
self.module.fail_json(msg='Error deleting account %s: %s' % (self.account_id, to_native(e)),
|
|
|
|
exception=traceback.format_exc())
|
|
|
|
exception=traceback.format_exc())
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def rename_account(self):
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
Rename the Account
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
|
|
|
self.sfe.modify_account(account_id=self.account_id,
|
|
|
|
|
|
|
|
username=self.element_username,
|
|
|
|
|
|
|
|
status=self.status,
|
|
|
|
|
|
|
|
initiator_secret=self.initiator_secret,
|
|
|
|
|
|
|
|
target_secret=self.target_secret,
|
|
|
|
|
|
|
|
attributes=self.attributes)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
except Exception as e:
|
|
|
|
|
|
|
|
self.module.fail_json(msg='Error renaming account %s: %s' % (self.account_id, to_native(e)),
|
|
|
|
|
|
|
|
exception=traceback.format_exc())
|
|
|
|
|
|
|
|
|
|
|
|
def update_account(self):
|
|
|
|
def update_account(self):
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
Update the Account
|
|
|
|
Update the Account if account already exists
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
try:
|
|
|
|
self.sfe.modify_account(account_id=self.account_id,
|
|
|
|
self.sfe.modify_account(account_id=self.account_id,
|
|
|
|
username=self.new_element_username,
|
|
|
|
|
|
|
|
status=self.status,
|
|
|
|
status=self.status,
|
|
|
|
initiator_secret=self.initiator_secret,
|
|
|
|
initiator_secret=self.initiator_secret,
|
|
|
|
target_secret=self.target_secret,
|
|
|
|
target_secret=self.target_secret,
|
|
|
@ -231,24 +256,24 @@ class ElementSWAccount(object):
|
|
|
|
Process the account operation on the Element OS Cluster
|
|
|
|
Process the account operation on the Element OS Cluster
|
|
|
|
"""
|
|
|
|
"""
|
|
|
|
changed = False
|
|
|
|
changed = False
|
|
|
|
account_exists = False
|
|
|
|
|
|
|
|
update_account = False
|
|
|
|
update_account = False
|
|
|
|
account_detail = self.get_account()
|
|
|
|
account_detail = self.get_account(self.element_username)
|
|
|
|
|
|
|
|
|
|
|
|
if account_detail:
|
|
|
|
if account_detail is None and self.state == 'present':
|
|
|
|
account_exists = True
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
elif account_detail is not None:
|
|
|
|
|
|
|
|
# If account found
|
|
|
|
|
|
|
|
self.account_id = account_detail.account_id
|
|
|
|
|
|
|
|
|
|
|
|
if self.state == 'absent':
|
|
|
|
if self.state == 'absent':
|
|
|
|
changed = True
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
else:
|
|
|
|
elif self.state == 'present':
|
|
|
|
# If state - present, check for any parameter of exising account needs modification.
|
|
|
|
# Check if we need to update the account
|
|
|
|
if account_detail.username is not None and self.element_username is not None and \
|
|
|
|
|
|
|
|
account_detail.username != self.element_username:
|
|
|
|
if account_detail.username is not None and self.new_element_username is not None and \
|
|
|
|
|
|
|
|
account_detail.username != self.new_element_username:
|
|
|
|
|
|
|
|
update_account = True
|
|
|
|
update_account = True
|
|
|
|
changed = True
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
|
|
|
|
elif account_detail.status is not None and self.status is not None \
|
|
|
|
elif account_detail.status is not None and self.status is not None \
|
|
|
|
and account_detail.status != self.status:
|
|
|
|
and account_detail.status != self.status:
|
|
|
|
update_account = True
|
|
|
|
update_account = True
|
|
|
@ -268,20 +293,28 @@ class ElementSWAccount(object):
|
|
|
|
and account_detail.attributes != self.attributes:
|
|
|
|
and account_detail.attributes != self.attributes:
|
|
|
|
update_account = True
|
|
|
|
update_account = True
|
|
|
|
changed = True
|
|
|
|
changed = True
|
|
|
|
else:
|
|
|
|
|
|
|
|
if self.state == 'present' and self.status is None:
|
|
|
|
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if changed:
|
|
|
|
if changed:
|
|
|
|
if self.module.check_mode:
|
|
|
|
if self.module.check_mode:
|
|
|
|
|
|
|
|
# Skipping the changes
|
|
|
|
pass
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
else:
|
|
|
|
if self.state == 'present':
|
|
|
|
if self.state == 'present':
|
|
|
|
if not account_exists:
|
|
|
|
if update_account:
|
|
|
|
self.create_account()
|
|
|
|
|
|
|
|
elif update_account:
|
|
|
|
|
|
|
|
self.update_account()
|
|
|
|
self.update_account()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
if self.from_name is not None:
|
|
|
|
|
|
|
|
# If from_name is defined
|
|
|
|
|
|
|
|
account_exists = self.get_account(self.from_name)
|
|
|
|
|
|
|
|
if account_exists is not None:
|
|
|
|
|
|
|
|
# If resource pointed by from_name exists, rename the account to name
|
|
|
|
|
|
|
|
self.account_id = account_exists.account_id
|
|
|
|
|
|
|
|
self.rename_account()
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
# If resource pointed by from_name does not exists, error out
|
|
|
|
|
|
|
|
self.module.fail_json(msg="Resource does not exist : %s" % self.from_name)
|
|
|
|
|
|
|
|
else:
|
|
|
|
|
|
|
|
# If from_name is not defined, create from scratch.
|
|
|
|
|
|
|
|
self.create_account()
|
|
|
|
elif self.state == 'absent':
|
|
|
|
elif self.state == 'absent':
|
|
|
|
self.delete_account()
|
|
|
|
self.delete_account()
|
|
|
|
|
|
|
|
|
|
|
|