|
|
|
@ -49,7 +49,7 @@ options:
|
|
|
|
|
description:
|
|
|
|
|
- The scope of a service contract.
|
|
|
|
|
choices: [ application-profile, context, global, tenant ]
|
|
|
|
|
default: 'context'
|
|
|
|
|
default: context
|
|
|
|
|
priority:
|
|
|
|
|
description:
|
|
|
|
|
- The desired QoS class to be used.
|
|
|
|
@ -96,7 +96,7 @@ def main():
|
|
|
|
|
argument_spec = aci_argument_spec
|
|
|
|
|
argument_spec.update(
|
|
|
|
|
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']),
|
|
|
|
|
scope=dict(type='str', choices=['application-profile', 'context', 'global', 'tenant']),
|
|
|
|
|
priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']), # No default provided on purpose
|
|
|
|
@ -111,10 +111,13 @@ def main():
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
|
argument_spec=argument_spec,
|
|
|
|
|
supports_check_mode=True,
|
|
|
|
|
required_if=[
|
|
|
|
|
['state', 'absent', ['tenant', 'contract']],
|
|
|
|
|
['state', 'present', ['tenant', 'contract']],
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
contract = module.params['contract']
|
|
|
|
|
tenant = module.params['tenant']
|
|
|
|
|
description = module.params['description']
|
|
|
|
|
scope = module.params['scope']
|
|
|
|
|
priority = module.params['priority']
|
|
|
|
@ -122,28 +125,21 @@ def main():
|
|
|
|
|
state = module.params['state']
|
|
|
|
|
|
|
|
|
|
aci = ACIModule(module)
|
|
|
|
|
|
|
|
|
|
# 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.construct_url(root_class='tenant', subclass_1='contract')
|
|
|
|
|
aci.get_existing()
|
|
|
|
|
|
|
|
|
|
if state == 'present':
|
|
|
|
|
# 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
|
|
|
|
|
aci.get_diff(aci_class='vzBrCP')
|
|
|
|
|