mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ACI Contract: Update module to use new URL Method (#28622)
This commit is contained in:
parent
037ef743c3
commit
28f76166d0
1 changed files with 17 additions and 21 deletions
|
@ -49,7 +49,7 @@ options:
|
||||||
description:
|
description:
|
||||||
- The scope of a service contract.
|
- The scope of a service contract.
|
||||||
choices: [ application-profile, context, global, tenant ]
|
choices: [ application-profile, context, global, tenant ]
|
||||||
default: 'context'
|
default: context
|
||||||
priority:
|
priority:
|
||||||
description:
|
description:
|
||||||
- The desired QoS class to be used.
|
- The desired QoS class to be used.
|
||||||
|
@ -96,7 +96,7 @@ def main():
|
||||||
argument_spec = aci_argument_spec
|
argument_spec = aci_argument_spec
|
||||||
argument_spec.update(
|
argument_spec.update(
|
||||||
contract=dict(type='str', required=False, aliases=['contract_name', 'name']), # Not required for querying all objects
|
contract=dict(type='str', required=False, aliases=['contract_name', 'name']), # Not required for querying all objects
|
||||||
tenant=dict(type='str', required=True, aliases=['tenant_name']), # Not required for querying all objects
|
tenant=dict(type='str', required=False, aliases=['tenant_name']), # Not required for querying all objects
|
||||||
description=dict(type='str', aliases=['descr']),
|
description=dict(type='str', aliases=['descr']),
|
||||||
scope=dict(type='str', choices=['application-profile', 'context', 'global', 'tenant']),
|
scope=dict(type='str', choices=['application-profile', 'context', 'global', 'tenant']),
|
||||||
priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']), # No default provided on purpose
|
priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']), # No default provided on purpose
|
||||||
|
@ -111,10 +111,13 @@ def main():
|
||||||
module = AnsibleModule(
|
module = AnsibleModule(
|
||||||
argument_spec=argument_spec,
|
argument_spec=argument_spec,
|
||||||
supports_check_mode=True,
|
supports_check_mode=True,
|
||||||
|
required_if=[
|
||||||
|
['state', 'absent', ['tenant', 'contract']],
|
||||||
|
['state', 'present', ['tenant', 'contract']],
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
contract = module.params['contract']
|
contract = module.params['contract']
|
||||||
tenant = module.params['tenant']
|
|
||||||
description = module.params['description']
|
description = module.params['description']
|
||||||
scope = module.params['scope']
|
scope = module.params['scope']
|
||||||
priority = module.params['priority']
|
priority = module.params['priority']
|
||||||
|
@ -122,28 +125,21 @@ def main():
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
|
||||||
aci = ACIModule(module)
|
aci = ACIModule(module)
|
||||||
|
aci.construct_url(root_class='tenant', subclass_1='contract')
|
||||||
# TODO: This logic could be cleaner.
|
|
||||||
if contract is not None:
|
|
||||||
if tenant is not None:
|
|
||||||
path = 'api/mo/uni/tn-%(tenant)s/brc-%(contract)s.json' % module.params
|
|
||||||
elif state == 'query':
|
|
||||||
path = 'api/mo/uni/tn-%(tenant)s.json?rsp-subtree=children&rsp-subtree-class=vzBrCP&rsp-subtree-include=no-scoped' % module.params
|
|
||||||
else:
|
|
||||||
module.fail_json(msg="Parameters 'tenant' is required for state 'absent' or 'present'")
|
|
||||||
elif state == 'query':
|
|
||||||
# Query all objects
|
|
||||||
path = 'api/node/class/vzBrCP.json'
|
|
||||||
else:
|
|
||||||
module.fail_json(msg="Parameter 'contract' is required for state 'absent' or 'present'")
|
|
||||||
|
|
||||||
aci.result['url'] = '%(protocol)s://%(hostname)s/' % aci.params + path
|
|
||||||
|
|
||||||
aci.get_existing()
|
aci.get_existing()
|
||||||
|
|
||||||
if state == 'present':
|
if state == 'present':
|
||||||
# Filter out module parameters with null values
|
# Filter out module parameters with null values
|
||||||
aci.payload(aci_class='vzBrCP', class_config=dict(name=contract, descr=description, scope=scope, prio=priority, targetDscp=dscp))
|
aci.payload(
|
||||||
|
aci_class='vzBrCP',
|
||||||
|
class_config=dict(
|
||||||
|
name=contract,
|
||||||
|
descr=description,
|
||||||
|
scope=scope,
|
||||||
|
prio=priority,
|
||||||
|
targetDscp=dscp,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
# Generate config diff which will be used as POST request body
|
# Generate config diff which will be used as POST request body
|
||||||
aci.get_diff(aci_class='vzBrCP')
|
aci.get_diff(aci_class='vzBrCP')
|
||||||
|
|
Loading…
Reference in a new issue