mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
Allow a miq token as an argument passed into the ManageIQ Python API Client (#28088)
This commit is contained in:
parent
33f342435a
commit
ea51567697
3 changed files with 58 additions and 11 deletions
|
@ -41,6 +41,7 @@ def manageiq_argument_spec():
|
||||||
url=dict(default=os.environ.get('MIQ_URL', None)),
|
url=dict(default=os.environ.get('MIQ_URL', None)),
|
||||||
username=dict(default=os.environ.get('MIQ_USERNAME', None)),
|
username=dict(default=os.environ.get('MIQ_USERNAME', None)),
|
||||||
password=dict(default=os.environ.get('MIQ_PASSWORD', None), no_log=True),
|
password=dict(default=os.environ.get('MIQ_PASSWORD', None), no_log=True),
|
||||||
|
token=dict(default=os.environ.get('MIQ_TOKEN', None), no_log=True),
|
||||||
verify_ssl=dict(default=True, type='bool'),
|
verify_ssl=dict(default=True, type='bool'),
|
||||||
ca_bundle_path=dict(required=False, default=None),
|
ca_bundle_path=dict(required=False, default=None),
|
||||||
)
|
)
|
||||||
|
@ -51,6 +52,21 @@ def check_client(module):
|
||||||
module.fail_json(msg='manageiq_client.api is required for this module')
|
module.fail_json(msg='manageiq_client.api is required for this module')
|
||||||
|
|
||||||
|
|
||||||
|
def validate_connection_params(module):
|
||||||
|
params = module.params['manageiq_connection']
|
||||||
|
error_str = "missing required argument: manageiq_connection[{}]"
|
||||||
|
url = params['url']
|
||||||
|
token = params['token']
|
||||||
|
username = params['username']
|
||||||
|
password = params['password']
|
||||||
|
|
||||||
|
if (url and username and password) or (url and token):
|
||||||
|
return params
|
||||||
|
for arg in ['url', 'username', 'password']:
|
||||||
|
if params[arg] in (None, ''):
|
||||||
|
module.fail_json(msg=error_str.format(arg))
|
||||||
|
|
||||||
|
|
||||||
class ManageIQ(object):
|
class ManageIQ(object):
|
||||||
"""
|
"""
|
||||||
class encapsulating ManageIQ API client.
|
class encapsulating ManageIQ API client.
|
||||||
|
@ -60,22 +76,19 @@ class ManageIQ(object):
|
||||||
# handle import errors
|
# handle import errors
|
||||||
check_client(module)
|
check_client(module)
|
||||||
|
|
||||||
params = module.params['manageiq_connection']
|
params = validate_connection_params(module)
|
||||||
|
|
||||||
# check for required arguments
|
|
||||||
for arg in ['url', 'username', 'password']:
|
|
||||||
if params[arg] in (None, ''):
|
|
||||||
module.fail_json(msg="missing required argument: manageiq_connection[{}]".format(arg))
|
|
||||||
|
|
||||||
url = params['url']
|
url = params['url']
|
||||||
username = params['username']
|
username = params['username']
|
||||||
password = params['password']
|
password = params['password']
|
||||||
|
token = params['token']
|
||||||
verify_ssl = params['verify_ssl']
|
verify_ssl = params['verify_ssl']
|
||||||
ca_bundle_path = params['ca_bundle_path']
|
ca_bundle_path = params['ca_bundle_path']
|
||||||
|
|
||||||
self._module = module
|
self._module = module
|
||||||
self._api_url = url + '/api'
|
self._api_url = url + '/api'
|
||||||
self._client = ManageIQClient(self._api_url, (username, password), verify_ssl=verify_ssl, ca_bundle_path=ca_bundle_path)
|
self._auth = dict(user=username, password=password, token=token)
|
||||||
|
self._client = ManageIQClient(self._api_url, self._auth, verify_ssl=verify_ssl, ca_bundle_path=ca_bundle_path)
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def module(self):
|
def module(self):
|
||||||
|
|
|
@ -84,6 +84,18 @@ EXAMPLES = '''
|
||||||
password: 'smartvm'
|
password: 'smartvm'
|
||||||
verify_ssl: False
|
verify_ssl: False
|
||||||
|
|
||||||
|
- name: Create a new user in ManageIQ using a token
|
||||||
|
manageiq_user:
|
||||||
|
userid: 'jdoe'
|
||||||
|
name: 'Jane Doe'
|
||||||
|
password: 'VerySecret'
|
||||||
|
group: 'EvmGroup-user'
|
||||||
|
email: 'jdoe@example.com'
|
||||||
|
manageiq_connection:
|
||||||
|
url: 'http://127.0.0.1:3000'
|
||||||
|
token: 'sometoken'
|
||||||
|
verify_ssl: False
|
||||||
|
|
||||||
- name: Delete a user in ManageIQ
|
- name: Delete a user in ManageIQ
|
||||||
manageiq_user:
|
manageiq_user:
|
||||||
state: 'absent'
|
state: 'absent'
|
||||||
|
@ -94,6 +106,15 @@ EXAMPLES = '''
|
||||||
password: 'smartvm'
|
password: 'smartvm'
|
||||||
verify_ssl: False
|
verify_ssl: False
|
||||||
|
|
||||||
|
- name: Delete a user in ManageIQ using a token
|
||||||
|
manageiq_user:
|
||||||
|
state: 'absent'
|
||||||
|
userid: 'jdoe'
|
||||||
|
manageiq_connection:
|
||||||
|
url: 'http://127.0.0.1:3000'
|
||||||
|
token: 'sometoken'
|
||||||
|
verify_ssl: False
|
||||||
|
|
||||||
- name: Update email of user in ManageIQ
|
- name: Update email of user in ManageIQ
|
||||||
manageiq_user:
|
manageiq_user:
|
||||||
userid: 'jdoe'
|
userid: 'jdoe'
|
||||||
|
@ -103,6 +124,15 @@ EXAMPLES = '''
|
||||||
username: 'admin'
|
username: 'admin'
|
||||||
password: 'smartvm'
|
password: 'smartvm'
|
||||||
verify_ssl: False
|
verify_ssl: False
|
||||||
|
|
||||||
|
- name: Update email of user in ManageIQ using a token
|
||||||
|
manageiq_user:
|
||||||
|
userid: 'jdoe'
|
||||||
|
email: 'jaustine@example.com'
|
||||||
|
manageiq_connection:
|
||||||
|
url: 'http://127.0.0.1:3000'
|
||||||
|
token: 'sometoken'
|
||||||
|
verify_ssl: False
|
||||||
'''
|
'''
|
||||||
|
|
||||||
RETURN = '''
|
RETURN = '''
|
||||||
|
|
|
@ -32,13 +32,17 @@ options:
|
||||||
description:
|
description:
|
||||||
- ManageIQ environment url. C(MIQ_URL) env var if set. otherwise, it is required to pass it.
|
- ManageIQ environment url. C(MIQ_URL) env var if set. otherwise, it is required to pass it.
|
||||||
username:
|
username:
|
||||||
required: true
|
required: false
|
||||||
description:
|
description:
|
||||||
- ManageIQ username. C(MIQ_USERNAME) env var if set. otherwise, it is required to pass it.
|
- ManageIQ username. C(MIQ_USERNAME) env var if set. otherwise, required if no token is passed in.
|
||||||
password:
|
password:
|
||||||
required: true
|
required: false
|
||||||
description:
|
description:
|
||||||
- ManageIQ password. C(MIQ_PASSWORD) env var if set. otherwise, it is required to pass it.
|
- ManageIQ password. C(MIQ_PASSWORD) env var if set. otherwise, required if no token is passed in.
|
||||||
|
token:
|
||||||
|
required: false
|
||||||
|
description:
|
||||||
|
- ManageIQ token. C(MIQ_TOKEN) env var if set. otherwise, required if no username or password is passed in.
|
||||||
verify_ssl:
|
verify_ssl:
|
||||||
required: false
|
required: false
|
||||||
default: true
|
default: true
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue