diff --git a/lib/ansible/modules/network/aci/aci_contract_subject_to_filter.py b/lib/ansible/modules/network/aci/aci_contract_subject_to_filter.py index 2b176888a0..50f8196544 100644 --- a/lib/ansible/modules/network/aci/aci_contract_subject_to_filter.py +++ b/lib/ansible/modules/network/aci/aci_contract_subject_to_filter.py @@ -33,15 +33,16 @@ options: description: - The name of the contract. aliases: [ contract_name ] - filter_name: + filter: description: - The name of the Filter to bind to the Subject. log: description: - 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 ] aliases: [ directive ] + default: none subject: description: - The name of the Contract Subject. @@ -69,7 +70,7 @@ EXAMPLES = r''' tenant: '{{ tenant }}' contract: '{{ contract }}' subject: '{{ subject }}' - filter_name: '{{ filter_name }}' + filter: '{{ filter }}' log: '{{ log }}' ''' @@ -96,8 +97,10 @@ def main(): module = AnsibleModule( argument_spec=argument_spec, supports_check_mode=True, - required_if=[['state', 'absent', ['contract', 'filter', 'subject', 'tenant']], - ['state', 'present', ['contract', 'filter', 'subject', 'tenant']]] + required_if=[ + ['state', 'absent', ['contract', 'filter', 'subject', 'tenant']], + ['state', 'present', ['contract', 'filter', 'subject', 'tenant']], + ], ) # contract = module.params['contract'] @@ -107,26 +110,26 @@ def main(): # tenant = module.params['tenant'] 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. if log == 'none': 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.result['url'] = '%(protocol)s://%(hostname)s/' % aci.params + path - + aci.construct_url(root_class='tenant', subclass_1='contract', subclass_2='subject', subclass_3='subject_filter') aci.get_existing() if state == 'present': # 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 aci.get_diff(aci_class='vzRsSubjFiltAtt') @@ -137,6 +140,9 @@ def main(): elif state == 'absent': aci.delete_config() + # Remove subject_filter used to build URL from module.params + module.params.pop('subject_filter') + module.exit_json(**aci.result)