Skip to content
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

Added new module avi_user.py #57116

Open
wants to merge 4 commits into
base: devel
from
Open
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

Added new module avi_user.py and tests for that

  • Loading branch information...
Rohan-sss1 committed May 29, 2019
commit 9d5bd35286be12645fa3b045970f3cc5d02031d9
@@ -0,0 +1,158 @@
#!/usr/bin/python
"""
# Created on Aug 2, 2018
#
# @author: Shrikant Chaudhari (shrikant.chaudhari@avinetworks.com) GitHub ID: gitshrikant
#
# module_check: supported
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
#
"""


ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}

DOCUMENTATION = '''
---
module: avi_user
author: Shrikant Chaudhari (@gitshrikant) <shrikant.chaudhari@avinetworks.com>
short_description: Avi User Module
description:
- This module can be used for creation, updation and deletion of a user.
version_added: 2.9
requirements: [ avisdk ]
options:
state:
description:
- The state that should be applied on the entity.
default: present
choices: ["absent", "present"]
name:
This conversation was marked as resolved by Qalthos

This comment has been minimized.

Copy link
@Qalthos

Qalthos Jun 12, 2019

Contributor

Should have reqiured: true, along with obj_username and obj_password according to the module argspec

description:
- Full name of the user.
obj_username:
description:
- Name that the user will supply when signing into Avi Vantage, such as jdoe or jdoe@avinetworks.com.
obj_password:
description:
- You may either enter a case-sensitive password in this field for the new or existing user.
email:
description:
- Email address of the user. This field is used when a user loses their password and requests to have it reset. See Password Recovery.
access:
description:
- Access settings (write, read, or no access) for each type of resource within Vantage.
is_superuser:
description:
- If the user will need to have the same privileges as the admin account, set it to true.
is_active:
description:
- Activates the current user account.
avi_api_update_method:
description:
- Default method for object update is HTTP PUT.
- Setting to patch will override that behavior to use HTTP PATCH.
default: put
choices: ["post", "put", "patch"]
avi_api_patch_op:
description:
- Patch operation to use when using avi_api_update_method as patch.
choices: ["add", "replace", "delete"]
user_profile_ref:
description:
- Refer user profile.
default_tenant_ref:
description:
- Default tenant reference.
default: /api/tenant?name=admin
extends_documentation_fragment:
- avi
'''

EXAMPLES = '''
- name: user creation
avi_user:
controller: ""
username: ""
password: ""
api_version: ""
name: "testuser"
obj_username: "testuser"
obj_password: "test123"
email: "test@abc.com"
access:
- role_ref: "/api/role?name=Tenant-Admin"
tenant_ref: "/api/tenant/admin#admin"
user_profile_ref: "/api/useraccountprofile?name=Default-User-Account-Profile"
is_active: true
is_superuser: true
default_tenant_ref: "/api/tenant?name=admin"
'''

RETURN = '''
obj:
description: Avi REST resource
returned: success, changed
type: dict
'''


from ansible.module_utils.basic import AnsibleModule


try:
from ansible.module_utils.network.avi.avi import (
avi_common_argument_spec, ansible_return, HAS_AVI)
from ansible.module_utils.network.avi.ansible_utils import (
avi_ansible_api)
except ImportError:
HAS_AVI = False


def main():
argument_specs = dict(
state=dict(default='present',
choices=['absent', 'present']),
name=dict(type='str', required=True),
obj_username=dict(type='str', required=True),
obj_password=dict(type='str', required=True, no_log=True),
access=dict(type='list',),
email=dict(type='str',),
is_superuser=dict(type='bool',),
is_active=dict(type='bool',),
avi_api_update_method=dict(default='put',
choices=['post', 'put', 'patch']),
avi_api_patch_op=dict(choices=['add', 'replace', 'delete']),
user_profile_ref=dict(type='str',),
default_tenant_ref=dict(type='str', default='/api/tenant?name=admin'),
)
argument_specs.update(avi_common_argument_spec())
module = AnsibleModule(argument_spec=argument_specs, supports_check_mode=True)
if not HAS_AVI:
return module.fail_json(msg=(
'Avi python API SDK (avisdk>=17.1) or requests is not installed. '
'For more details visit https://github.com/avinetworks/sdk.'))
return avi_ansible_api(module, 'user',
set([]))


if __name__ == '__main__':
main()
@@ -0,0 +1,223 @@
{
"mock_create_res": {
"ansible_facts": {
"avi_api_context": {
"10.10.28.97:admin:None": {
"csrftoken": "qG23CCARDL3rh1KZ66XXPIeUYCUCOZ4q",
"session_id": "h5nynf9u9nompp5byai7vii2v8bbn9kd"
}
}
},
"api_context": null,
"changed": true,
"invocation": {
"module_args": {
"access": [
{
"role_ref": "/api/role?name=Tenant-Admin",
"tenant_ref": "/api/tenant/********#********",
"all_tenants": false
}
],
"api_context": null,
"api_version": "18.2.5",
"avi_api_update_method": "put",
"avi_credentials": null,
"avi_disable_session_cache_as_fact": false,
"avi_login_info": null,
"controller": "10.10.28.97",
"default_tenant_ref": "/api/tenant?name=********",
"email": "test@abc.com",
"is_active": true,
"is_superuser": true,
"name": "testuser",
"obj_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"obj_username": "testuser",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"state": "present",
"tenant": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"tenant_uuid": "",
"user_profile_ref": "/api/useraccountprofile?name=Default-User-Account-Profile",
"username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
}
},
"obj": {
"_last_modified": "1559736767460818",
"access": [
{
"all_tenants": false,
"role_ref": "https://10.10.28.97/api/tenant/********/role/role-ff851004-bd75-485b-87ec-2fe1d6a03fb9#Tenant-Admin",
"tenant_ref": "https://10.10.28.97/api/tenant/********#********"
}
],
"default_tenant_ref": "https://10.10.28.97/api/tenant/********#********",
"email": "test@abc.com",
"full_name": "testuser",
"is_active": true,
"is_superuser": true,
"local": true,
"name": "testuser",
"obj_password": "<sensitive>",
"obj_username": "testuser",
"password": "<sensitive>",
"uid": 2004,
"url": "https://10.10.28.97/api/user/user-7087578f-4dfe-4e06-a153-495a91824a1d#testuser",
"user_profile_ref": "https://10.10.28.97/api/useraccountprofile/useraccountprofile-78063e7c-b443-48d6-b34c-5253ae1fcd2a#Default-User-Account-Profile",
"username": "testuser",
"uuid": "user-7087578f-4dfe-4e06-a153-495a91824a1d"
},
"old_obj": null
},
"mock_put_res" : {
"obj": {
"username": "testuser",
"user_profile_ref": "https://10.10.28.97/api/useraccountprofile/useraccountprofile-546c5e88-6270-4ba1-9cfd-d0c755e68f47#Default-User-Account-Profile",
"name": "testuser",
"url": "https://10.10.28.97/api/user/user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a#testuser",
"is_active": true,
"uuid": "user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a",
"email": "newemail@abc.com",
"access": [{
"tenant_ref": "https://10.10.28.97/api/tenant/tenant-57af0f3f-6f14-4657-8f32-9b289407752b#Test-Admin",
"all_tenants": false,
"role_ref": "https://10.10.28.97/api/tenant/********/role/role-b073ab0d-e1d0-4800-95ef-6ecf2c5ed7d1#Tenant-Admin"
}],
"is_superuser": true,
"obj_username": "testuser",
"full_name": "testuser",
"_last_modified": "1559802772203285",
"password": "<sensitive>",
"local": true,
"obj_password": "<sensitive>",
"default_tenant_ref": "https://10.10.28.97/api/tenant/********#********",
"uid": 2002
},
"changed": true,
"api_context": null,
"invocation": {
"module_args": {
"username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"user_profile_ref": "/api/useraccountprofile?name=Default-User-Account-Profile",
"api_version": "18.2.5",
"name": "testuser",
"state": "present",
"is_active": true,
"api_context": null,
"avi_disable_session_cache_as_fact": false,
"controller": "10.10.28.97",
"avi_api_patch_op": null,
"access": [{
"tenant_ref": "/api/tenant?name=Test-Admin",
"all_tenants": false,
"role_ref": "/api/role?name=Tenant-Admin"
}],
"is_superuser": true,
"avi_credentials": null,
"email": "newemail@abc.com",
"default_tenant_ref": "/api/tenant?name=********",
"obj_username": "testuser",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"tenant_uuid": "",
"obj_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"avi_api_update_method": "put",
"tenant": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
}
},
"ansible_facts": {
"avi_api_context": {
"10.10.28.97:admin:None": {
"csrftoken": "Y7CET6zaIC9VZAzBqEW4cWo1N26jPg55",
"session_id": "364n7o0p3o5so63b9rzd47v6ehya6xg7"
}
}
},
"old_obj": {
"username": "testuser",
"user_profile_ref": "https://10.10.28.97/api/useraccountprofile/useraccountprofile-546c5e88-6270-4ba1-9cfd-d0c755e68f47#Default-User-Account-Profile",
"name": "testuser",
"url": "https://10.10.28.97/api/user/user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a#testuser",
"is_active": true,
"uuid": "user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a",
"access": [{
"tenant_ref": "https://10.10.28.97/api/tenant/tenant-57af0f3f-6f14-4657-8f32-9b289407752b#Test-Admin",
"all_tenants": false,
"role_ref": "https://10.10.28.97/api/tenant/********/role/role-b073ab0d-e1d0-4800-95ef-6ecf2c5ed7d1#Tenant-Admin"
}],
"is_superuser": true,
"full_name": "testuser",
"ui_property": "",
"password": "<sensitive>",
"local": true,
"email": "test@abc.com",
"default_tenant_ref": "https://10.10.28.97/api/tenant/********#********",
"uid": 2002
}
},
"mock_del_res": {
"ansible_facts": {
"avi_api_context": {
"10.10.28.97:admin:None": {
"csrftoken": "Vtkx9GeS2lsrld5yX83cmJqbZO3MAimb",
"session_id": "ix3t1dja8yzwb155de59viyn96hibn6b"
}
}
},
"api_context": null,
"changed": true,
"invocation": {
"module_args": {
"access": [
{
"role_ref": "/api/role?name=Tenant-Admin",
"tenant_ref": "/api/tenant/********#********"
}
],
"api_context": null,
"api_version": "18.2.5",
"avi_api_update_method": "put",
"avi_credentials": null,
"avi_disable_session_cache_as_fact": false,
"avi_login_info": null,
"controller": "10.10.28.97",
"default_tenant_ref": "/api/tenant?name=********",
"email": "test@abc.com",
"is_active": true,
"is_superuser": true,
"name": "testuser",
"obj_password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"obj_username": "testuser",
"password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"state": "absent",
"tenant": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER",
"tenant_uuid": "",
"user_profile_ref": "/api/useraccountprofile?name=Default-User-Account-Profile",
"username": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER"
}
},
"obj": null,
"old_obj": {
"_last_modified": "1559803346264869",
"access": [
{
"all_tenants": false,
"role_ref": "https://10.10.28.97/api/tenant/********/role/role-b073ab0d-e1d0-4800-95ef-6ecf2c5ed7d1#Tenant-Admin",
"tenant_ref": "https://10.10.28.97/api/tenant/tenant-57af0f3f-6f14-4657-8f32-9b289407752b#Test-Admin"
}
],
"default_tenant_ref": "https://10.10.28.97/api/tenant/********#********",
"email": "newemail@abc.com",
"full_name": "testuser",
"is_active": true,
"is_superuser": true,
"local": true,
"name": "testuser",
"password": "<sensitive>",
"ui_property": "",
"uid": 2002,
"url": "https://10.10.28.97/api/user/user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a#testuser",
"user_profile_ref": "https://10.10.28.97/api/useraccountprofile/useraccountprofile-546c5e88-6270-4ba1-9cfd-d0c755e68f47#Default-User-Account-Profile",
"username": "testuser",
"uuid": "user-ed10f328-bd92-4db2-bacd-0cf795fcbf8a"
}
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.