mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
ACI Contract Subject to Filter: Update module to use new URL Method (#28621)
This commit is contained in:
parent
ba420c47cd
commit
037ef743c3
1 changed files with 22 additions and 16 deletions
|
@ -33,15 +33,16 @@ options:
|
||||||
description:
|
description:
|
||||||
- The name of the contract.
|
- The name of the contract.
|
||||||
aliases: [ contract_name ]
|
aliases: [ contract_name ]
|
||||||
filter_name:
|
filter:
|
||||||
description:
|
description:
|
||||||
- The name of the Filter to bind to the Subject.
|
- The name of the Filter to bind to the Subject.
|
||||||
log:
|
log:
|
||||||
description:
|
description:
|
||||||
- Determines if the binding should be set to log.
|
- Determines if the binding should be set to log.
|
||||||
- The APIC defaults new Subject to Filter bindings to a value of none.
|
- The APIC defaults new Subject to Filter bindings to C(none).
|
||||||
choices: [ log, none ]
|
choices: [ log, none ]
|
||||||
aliases: [ directive ]
|
aliases: [ directive ]
|
||||||
|
default: none
|
||||||
subject:
|
subject:
|
||||||
description:
|
description:
|
||||||
- The name of the Contract Subject.
|
- The name of the Contract Subject.
|
||||||
|
@ -69,7 +70,7 @@ EXAMPLES = r'''
|
||||||
tenant: '{{ tenant }}'
|
tenant: '{{ tenant }}'
|
||||||
contract: '{{ contract }}'
|
contract: '{{ contract }}'
|
||||||
subject: '{{ subject }}'
|
subject: '{{ subject }}'
|
||||||
filter_name: '{{ filter_name }}'
|
filter: '{{ filter }}'
|
||||||
log: '{{ log }}'
|
log: '{{ log }}'
|
||||||
'''
|
'''
|
||||||
|
|
||||||
|
@ -96,8 +97,10 @@ 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', ['contract', 'filter', 'subject', 'tenant']],
|
required_if=[
|
||||||
['state', 'present', ['contract', 'filter', 'subject', 'tenant']]]
|
['state', 'absent', ['contract', 'filter', 'subject', 'tenant']],
|
||||||
|
['state', 'present', ['contract', 'filter', 'subject', 'tenant']],
|
||||||
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
# contract = module.params['contract']
|
# contract = module.params['contract']
|
||||||
|
@ -107,26 +110,26 @@ def main():
|
||||||
# tenant = module.params['tenant']
|
# tenant = module.params['tenant']
|
||||||
state = module.params['state']
|
state = module.params['state']
|
||||||
|
|
||||||
|
# Add subject_filter key to modul.params for building the URL
|
||||||
|
module.params['subject_filter'] = filter_name
|
||||||
|
|
||||||
# Convert log to empty string if none, as that is what API expects. An empty string is not a good option to present the user.
|
# Convert log to empty string if none, as that is what API expects. An empty string is not a good option to present the user.
|
||||||
if log == 'none':
|
if log == 'none':
|
||||||
log = ''
|
log = ''
|
||||||
|
|
||||||
# TODO: cleanup this logic and provide better filter_strings for all options
|
|
||||||
if filter_name is not None:
|
|
||||||
# Work with specific binding
|
|
||||||
path = 'api/mo/uni/tn-%(tenant)s/brc-%(contract)s/subj-%(subject)s/rssubjFiltAtt-%(filter)s.json' % module.params
|
|
||||||
else:
|
|
||||||
path = 'api/class/vzRsSubjFiltAtt.json'
|
|
||||||
|
|
||||||
aci = ACIModule(module)
|
aci = ACIModule(module)
|
||||||
|
aci.construct_url(root_class='tenant', subclass_1='contract', subclass_2='subject', subclass_3='subject_filter')
|
||||||
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='vzRsSubjFiltAtt', class_config=dict(tnVzFilterName=filter_name, directives=log))
|
aci.payload(
|
||||||
|
aci_class='vzRsSubjFiltAtt',
|
||||||
|
class_config=dict(
|
||||||
|
tnVzFilterName=filter_name,
|
||||||
|
directives=log,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
# 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='vzRsSubjFiltAtt')
|
aci.get_diff(aci_class='vzRsSubjFiltAtt')
|
||||||
|
@ -137,6 +140,9 @@ def main():
|
||||||
elif state == 'absent':
|
elif state == 'absent':
|
||||||
aci.delete_config()
|
aci.delete_config()
|
||||||
|
|
||||||
|
# Remove subject_filter used to build URL from module.params
|
||||||
|
module.params.pop('subject_filter')
|
||||||
|
|
||||||
module.exit_json(**aci.result)
|
module.exit_json(**aci.result)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue