2017-08-14 23:48:27 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
|
|
|
|
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-08-14 23:48:27 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
|
|
|
DOCUMENTATION = r'''
|
2017-08-17 00:27:42 +00:00
|
|
|
---
|
2017-08-14 23:48:27 +00:00
|
|
|
module: aci_contract
|
2017-08-17 00:27:42 +00:00
|
|
|
short_description: Manage contract resources on Cisco ACI fabrics (vz:BrCP)
|
2017-08-14 23:48:27 +00:00
|
|
|
description:
|
2017-08-17 00:27:42 +00:00
|
|
|
- Manage Contract resources on Cisco ACI fabrics.
|
2018-01-12 07:07:59 +00:00
|
|
|
- More information from the internal APIC class I(vz:BrCP) at
|
2018-01-14 04:53:11 +00:00
|
|
|
U(https://developer.cisco.com/docs/apic-mim-ref/).
|
2017-08-14 23:48:27 +00:00
|
|
|
author:
|
|
|
|
- Dag Wieers (@dagwieers)
|
|
|
|
version_added: '2.4'
|
|
|
|
notes:
|
2017-08-17 00:27:42 +00:00
|
|
|
- This module does not manage Contract Subjects, see M(aci_contract_subject) to do this.
|
|
|
|
Contract Subjects can still be removed using this module.
|
|
|
|
- The C(tenant) used must exist before using this module in your playbook.
|
|
|
|
The M(aci_tenant) module can be used for this.
|
2017-08-14 23:48:27 +00:00
|
|
|
options:
|
|
|
|
contract:
|
|
|
|
description:
|
|
|
|
- The name of the contract.
|
|
|
|
required: yes
|
|
|
|
aliases: [ contract_name, name ]
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Description for the contract.
|
|
|
|
aliases: [ descr ]
|
|
|
|
tenant:
|
|
|
|
description:
|
|
|
|
- The name of the tenant.
|
|
|
|
required: yes
|
|
|
|
aliases: [ tenant_name ]
|
|
|
|
scope:
|
|
|
|
description:
|
|
|
|
- The scope of a service contract.
|
|
|
|
choices: [ application-profile, context, global, tenant ]
|
2017-08-25 01:15:23 +00:00
|
|
|
default: context
|
2017-08-14 23:48:27 +00:00
|
|
|
priority:
|
|
|
|
description:
|
|
|
|
- The desired QoS class to be used.
|
|
|
|
default: unspecified
|
|
|
|
choices: [ level1, level2, level3, unspecified ]
|
|
|
|
dscp:
|
|
|
|
description:
|
|
|
|
- The target Differentiated Service (DSCP) value.
|
|
|
|
choices: [ AF11, AF12, AF13, AF21, AF22, AF23, AF31, AF32, AF33, AF41, AF42, AF43, CS0, CS1, CS2, CS3, CS4, CS5, CS6, CS7, EF, VA, unspecified ]
|
|
|
|
default: unspecified
|
|
|
|
aliases: [ target ]
|
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- Use C(present) or C(absent) for adding or removing.
|
|
|
|
- Use C(query) for listing an object or multiple objects.
|
|
|
|
choices: [ absent, present, query ]
|
|
|
|
default: present
|
|
|
|
extends_documentation_fragment: aci
|
|
|
|
'''
|
|
|
|
|
|
|
|
# FIXME: Add more, better examples
|
|
|
|
EXAMPLES = r'''
|
|
|
|
- aci_contract:
|
2018-01-22 21:06:56 +00:00
|
|
|
host: '{{ inventory_hostname }}'
|
2017-08-14 23:48:27 +00:00
|
|
|
username: '{{ username }}'
|
|
|
|
password: '{{ password }}'
|
|
|
|
contract: '{{ contract }}'
|
|
|
|
description: '{{ descr }}'
|
|
|
|
tenant: '{{ tenant }}'
|
|
|
|
scope: '{{ scope }}'
|
|
|
|
priority: '{{ priority }}'
|
|
|
|
target: '{{ target }}'
|
|
|
|
'''
|
|
|
|
|
|
|
|
RETURN = r'''
|
|
|
|
#
|
|
|
|
'''
|
|
|
|
|
2017-12-03 16:12:30 +00:00
|
|
|
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
|
2017-08-14 23:48:27 +00:00
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
2018-01-17 16:11:30 +00:00
|
|
|
argument_spec = aci_argument_spec()
|
2017-08-14 23:48:27 +00:00
|
|
|
argument_spec.update(
|
|
|
|
contract=dict(type='str', required=False, aliases=['contract_name', 'name']), # Not required for querying all objects
|
2017-08-25 01:15:23 +00:00
|
|
|
tenant=dict(type='str', required=False, aliases=['tenant_name']), # Not required for querying all objects
|
2017-08-14 23:48:27 +00:00
|
|
|
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
|
|
|
|
dscp=dict(type='str',
|
|
|
|
choices=['AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42', 'AF43',
|
|
|
|
'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified'],
|
|
|
|
aliases=['target']), # No default provided on purpose
|
|
|
|
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
|
|
|
|
method=dict(type='str', choices=['delete', 'get', 'post'], aliases=['action'], removed_in_version='2.6'), # Deprecated starting from v2.6
|
2018-01-18 18:18:43 +00:00
|
|
|
protocol=dict(type='str', removed_in_version='2.6'), # Deprecated in v2.6
|
2017-08-14 23:48:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=argument_spec,
|
|
|
|
supports_check_mode=True,
|
2017-08-25 01:15:23 +00:00
|
|
|
required_if=[
|
|
|
|
['state', 'absent', ['tenant', 'contract']],
|
|
|
|
['state', 'present', ['tenant', 'contract']],
|
|
|
|
],
|
2017-08-14 23:48:27 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
contract = module.params['contract']
|
|
|
|
description = module.params['description']
|
|
|
|
scope = module.params['scope']
|
|
|
|
priority = module.params['priority']
|
2017-08-17 19:00:23 +00:00
|
|
|
dscp = module.params['dscp']
|
2017-08-14 23:48:27 +00:00
|
|
|
state = module.params['state']
|
2017-11-22 15:07:39 +00:00
|
|
|
tenant = module.params['tenant']
|
2017-08-14 23:48:27 +00:00
|
|
|
|
|
|
|
aci = ACIModule(module)
|
2017-11-22 15:07:39 +00:00
|
|
|
aci.construct_url(
|
|
|
|
root_class=dict(
|
|
|
|
aci_class='fvTenant',
|
2018-01-12 07:07:59 +00:00
|
|
|
aci_rn='tn-{0}'.format(tenant),
|
|
|
|
filter_target='eq(fvTenant.name, "{0}")'.format(tenant),
|
2017-11-22 15:07:39 +00:00
|
|
|
module_object=tenant,
|
|
|
|
),
|
|
|
|
subclass_1=dict(
|
|
|
|
aci_class='vzBrCP',
|
2018-01-12 07:07:59 +00:00
|
|
|
aci_rn='brc-{0}'.format(contract),
|
|
|
|
filter_target='eq(vzBrCP.name, "{0}")'.format(contract),
|
2017-11-22 15:07:39 +00:00
|
|
|
module_object=contract,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
|
2017-08-14 23:48:27 +00:00
|
|
|
aci.get_existing()
|
|
|
|
|
|
|
|
if state == 'present':
|
|
|
|
# Filter out module parameters with null values
|
2017-08-25 01:15:23 +00:00
|
|
|
aci.payload(
|
|
|
|
aci_class='vzBrCP',
|
|
|
|
class_config=dict(
|
|
|
|
name=contract,
|
|
|
|
descr=description,
|
|
|
|
scope=scope,
|
|
|
|
prio=priority,
|
|
|
|
targetDscp=dscp,
|
|
|
|
),
|
|
|
|
)
|
2017-08-14 23:48:27 +00:00
|
|
|
|
|
|
|
# Generate config diff which will be used as POST request body
|
|
|
|
aci.get_diff(aci_class='vzBrCP')
|
|
|
|
|
|
|
|
# Submit changes if module not in check_mode and the proposed is different than existing
|
|
|
|
aci.post_config()
|
|
|
|
|
|
|
|
elif state == 'absent':
|
|
|
|
aci.delete_config()
|
|
|
|
|
|
|
|
module.exit_json(**aci.result)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|