1
0
Fork 0
mirror of https://github.com/ansible-collections/community.general.git synced 2024-09-14 20:13:21 +02:00

Extending manageiq modules with parameter resource_id (#719) (#1980)

* Extending modules with resource_id

* Added documentation

* Fixed syntax
Changed resource_type back to required true
Added description identifier

* Added changelog fragment.

* fixed syntax

* Improved changelog fragment content.

* Updated description

* Changed if statement

* Changed changelog fragement filename

* version bump

* removed duplicate type

* Apply suggestions from code review

* Update plugins/modules/remote_management/manageiq/manageiq_tags.py

Co-authored-by: Felix Fontein <felix@fontein.de>
(cherry picked from commit a013e69d67)

Co-authored-by: phospi <phoffmann@spirit21.com>
This commit is contained in:
patchback[bot] 2021-03-08 07:15:51 +01:00 committed by GitHub
parent 7eaf795774
commit 1e5e0824d2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 10 deletions

View file

@ -0,0 +1,2 @@
minor_changes:
- manageiq_tags and manageiq_policies - added new parameter ``resource_id``. This parameter can be used instead of parameter ``resource_name`` (https://github.com/ansible-collections/community.general/pull/719).

View file

@ -37,7 +37,7 @@ options:
resource_type:
type: str
description:
- the type of the resource to which the profile should be [un]assigned
- The type of the resource to which the profile should be [un]assigned.
required: true
choices: ['provider', 'host', 'vm', 'blueprint', 'category', 'cluster',
'data store', 'group', 'resource pool', 'service', 'service template',
@ -45,8 +45,14 @@ options:
resource_name:
type: str
description:
- the name of the resource to which the profile should be [un]assigned
required: true
- The name of the resource to which the profile should be [un]assigned.
- Must be specified if I(resource_id) is not set. Both options are mutually exclusive.
resource_id:
type: int
description:
- The ID of the resource to which the profile should be [un]assigned.
- Must be specified if I(resource_name) is not set. Both options are mutually exclusive.
version_added: 2.2.0
'''
EXAMPLES = '''
@ -296,7 +302,8 @@ def main():
actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'}
argument_spec = dict(
policy_profiles=dict(type='list'),
resource_name=dict(required=True, type='str'),
resource_id=dict(required=False, type='int'),
resource_name=dict(required=False, type='str'),
resource_type=dict(required=True, type='str',
choices=list(manageiq_entities().keys())),
state=dict(required=False, type='str',
@ -307,6 +314,8 @@ def main():
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive=[["resource_id", "resource_name"]],
required_one_of=[["resource_id", "resource_name"]],
required_if=[
('state', 'present', ['policy_profiles']),
('state', 'absent', ['policy_profiles'])
@ -314,6 +323,7 @@ def main():
)
policy_profiles = module.params['policy_profiles']
resource_id = module.params['resource_id']
resource_type_key = module.params['resource_type']
resource_name = module.params['resource_name']
state = module.params['state']
@ -325,7 +335,8 @@ def main():
manageiq = ManageIQ(module)
# query resource id, fail if resource does not exist
resource_id = manageiq.find_collection_resource_or_fail(resource_type, name=resource_name)['id']
if resource_id is None:
resource_id = manageiq.find_collection_resource_or_fail(resource_type, name=resource_name)['id']
manageiq_policies = ManageIQPolicies(manageiq, resource_type, resource_id)

View file

@ -37,7 +37,7 @@ options:
resource_type:
type: str
description:
- the relevant resource type in manageiq
- The relevant resource type in manageiq.
required: true
choices: ['provider', 'host', 'vm', 'blueprint', 'category', 'cluster',
'data store', 'group', 'resource pool', 'service', 'service template',
@ -45,8 +45,14 @@ options:
resource_name:
type: str
description:
- the relevant resource name in manageiq
required: true
- The name of the resource at which tags will be controlled.
- Must be specified if I(resource_id) is not set. Both options are mutually exclusive.
resource_id:
description:
- The ID of the resource at which tags will be controlled.
- Must be specified if I(resource_name) is not set. Both options are mutually exclusive.
type: int
version_added: 2.2.0
'''
EXAMPLES = '''
@ -65,6 +71,21 @@ EXAMPLES = '''
password: 'smartvm'
validate_certs: False
- name: Create new tags for a provider in ManageIQ
community.general.manageiq_tags:
resource_id: 23000000790497
resource_type: 'provider'
tags:
- category: environment
name: prod
- category: owner
name: prod_ops
manageiq_connection:
url: 'http://127.0.0.1:3000'
username: 'admin'
password: 'smartvm'
validate_certs: False
- name: Remove tags for a provider in ManageIQ
community.general.manageiq_tags:
state: absent
@ -241,7 +262,8 @@ def main():
actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'}
argument_spec = dict(
tags=dict(type='list'),
resource_name=dict(required=True, type='str'),
resource_id=dict(required=False, type='int'),
resource_name=dict(required=False, type='str'),
resource_type=dict(required=True, type='str',
choices=list(manageiq_entities().keys())),
state=dict(required=False, type='str',
@ -252,6 +274,8 @@ def main():
module = AnsibleModule(
argument_spec=argument_spec,
mutually_exclusive=[["resource_id", "resource_name"]],
required_one_of=[["resource_id", "resource_name"]],
required_if=[
('state', 'present', ['tags']),
('state', 'absent', ['tags'])
@ -259,6 +283,7 @@ def main():
)
tags = module.params['tags']
resource_id = module.params['resource_id']
resource_type_key = module.params['resource_type']
resource_name = module.params['resource_name']
state = module.params['state']
@ -270,7 +295,8 @@ def main():
manageiq = ManageIQ(module)
# query resource id, fail if resource does not exist
resource_id = query_resource_id(manageiq, resource_type, resource_name)
if resource_id is None:
resource_id = query_resource_id(manageiq, resource_type, resource_name)
manageiq_tags = ManageIQTags(manageiq, resource_type, resource_id)