mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
* 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:
parent
7eaf795774
commit
1e5e0824d2
3 changed files with 49 additions and 10 deletions
2
changelogs/fragments/719-manageiq-resource_id.yml
Normal file
2
changelogs/fragments/719-manageiq-resource_id.yml
Normal 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).
|
|
@ -37,7 +37,7 @@ options:
|
||||||
resource_type:
|
resource_type:
|
||||||
type: str
|
type: str
|
||||||
description:
|
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
|
required: true
|
||||||
choices: ['provider', 'host', 'vm', 'blueprint', 'category', 'cluster',
|
choices: ['provider', 'host', 'vm', 'blueprint', 'category', 'cluster',
|
||||||
'data store', 'group', 'resource pool', 'service', 'service template',
|
'data store', 'group', 'resource pool', 'service', 'service template',
|
||||||
|
@ -45,8 +45,14 @@ options:
|
||||||
resource_name:
|
resource_name:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- the name of the resource to which the profile should be [un]assigned
|
- The name of the resource to which the profile should be [un]assigned.
|
||||||
required: true
|
- 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 = '''
|
EXAMPLES = '''
|
||||||
|
@ -296,7 +302,8 @@ def main():
|
||||||
actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'}
|
actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'}
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
policy_profiles=dict(type='list'),
|
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',
|
resource_type=dict(required=True, type='str',
|
||||||
choices=list(manageiq_entities().keys())),
|
choices=list(manageiq_entities().keys())),
|
||||||
state=dict(required=False, type='str',
|
state=dict(required=False, type='str',
|
||||||
|
@ -307,6 +314,8 @@ def main():
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
|
mutually_exclusive=[["resource_id", "resource_name"]],
|
||||||
|
required_one_of=[["resource_id", "resource_name"]],
|
||||||
required_if=[
|
required_if=[
|
||||||
('state', 'present', ['policy_profiles']),
|
('state', 'present', ['policy_profiles']),
|
||||||
('state', 'absent', ['policy_profiles'])
|
('state', 'absent', ['policy_profiles'])
|
||||||
|
@ -314,6 +323,7 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
policy_profiles = module.params['policy_profiles']
|
policy_profiles = module.params['policy_profiles']
|
||||||
|
resource_id = module.params['resource_id']
|
||||||
resource_type_key = module.params['resource_type']
|
resource_type_key = module.params['resource_type']
|
||||||
resource_name = module.params['resource_name']
|
resource_name = module.params['resource_name']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
@ -325,7 +335,8 @@ def main():
|
||||||
manageiq = ManageIQ(module)
|
manageiq = ManageIQ(module)
|
||||||
|
|
||||||
# query resource id, fail if resource does not exist
|
# 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)
|
manageiq_policies = ManageIQPolicies(manageiq, resource_type, resource_id)
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ options:
|
||||||
resource_type:
|
resource_type:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- the relevant resource type in manageiq
|
- The relevant resource type in manageiq.
|
||||||
required: true
|
required: true
|
||||||
choices: ['provider', 'host', 'vm', 'blueprint', 'category', 'cluster',
|
choices: ['provider', 'host', 'vm', 'blueprint', 'category', 'cluster',
|
||||||
'data store', 'group', 'resource pool', 'service', 'service template',
|
'data store', 'group', 'resource pool', 'service', 'service template',
|
||||||
|
@ -45,8 +45,14 @@ options:
|
||||||
resource_name:
|
resource_name:
|
||||||
type: str
|
type: str
|
||||||
description:
|
description:
|
||||||
- the relevant resource name in manageiq
|
- The name of the resource at which tags will be controlled.
|
||||||
required: true
|
- 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 = '''
|
EXAMPLES = '''
|
||||||
|
@ -65,6 +71,21 @@ EXAMPLES = '''
|
||||||
password: 'smartvm'
|
password: 'smartvm'
|
||||||
validate_certs: False
|
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
|
- name: Remove tags for a provider in ManageIQ
|
||||||
community.general.manageiq_tags:
|
community.general.manageiq_tags:
|
||||||
state: absent
|
state: absent
|
||||||
|
@ -241,7 +262,8 @@ def main():
|
||||||
actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'}
|
actions = {'present': 'assign', 'absent': 'unassign', 'list': 'list'}
|
||||||
argument_spec = dict(
|
argument_spec = dict(
|
||||||
tags=dict(type='list'),
|
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',
|
resource_type=dict(required=True, type='str',
|
||||||
choices=list(manageiq_entities().keys())),
|
choices=list(manageiq_entities().keys())),
|
||||||
state=dict(required=False, type='str',
|
state=dict(required=False, type='str',
|
||||||
|
@ -252,6 +274,8 @@ def main():
|
||||||
|
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
|
mutually_exclusive=[["resource_id", "resource_name"]],
|
||||||
|
required_one_of=[["resource_id", "resource_name"]],
|
||||||
required_if=[
|
required_if=[
|
||||||
('state', 'present', ['tags']),
|
('state', 'present', ['tags']),
|
||||||
('state', 'absent', ['tags'])
|
('state', 'absent', ['tags'])
|
||||||
|
@ -259,6 +283,7 @@ def main():
|
||||||
)
|
)
|
||||||
|
|
||||||
tags = module.params['tags']
|
tags = module.params['tags']
|
||||||
|
resource_id = module.params['resource_id']
|
||||||
resource_type_key = module.params['resource_type']
|
resource_type_key = module.params['resource_type']
|
||||||
resource_name = module.params['resource_name']
|
resource_name = module.params['resource_name']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
@ -270,7 +295,8 @@ def main():
|
||||||
manageiq = ManageIQ(module)
|
manageiq = ManageIQ(module)
|
||||||
|
|
||||||
# query resource id, fail if resource does not exist
|
# 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)
|
manageiq_tags = ManageIQTags(manageiq, resource_type, resource_id)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue