2017-08-15 22:59:43 +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-15 22:59:43 +00:00
|
|
|
'status': ['preview'],
|
2018-10-11 20:34:35 +00:00
|
|
|
'supported_by': 'certified'}
|
2017-08-15 22:59:43 +00:00
|
|
|
|
|
|
|
DOCUMENTATION = r'''
|
|
|
|
---
|
|
|
|
module: aci_aep
|
2018-02-25 18:13:16 +00:00
|
|
|
short_description: Manage attachable Access Entity Profile (AEP) objects (infra:AttEntityP, infra:ProvAcc)
|
2017-08-15 22:59:43 +00:00
|
|
|
description:
|
2017-08-17 00:27:42 +00:00
|
|
|
- Connect to external virtual and physical domains by using
|
|
|
|
attachable Access Entity Profiles (AEP) on Cisco ACI fabrics.
|
2018-02-21 18:35:59 +00:00
|
|
|
notes:
|
2018-03-05 23:05:13 +00:00
|
|
|
- More information about the internal APIC classes B(infra:AttEntityP) and B(infra:ProvAcc) from
|
|
|
|
L(the APIC Management Information Model reference,https://developer.cisco.com/docs/apic-mim-ref/).
|
2017-08-15 22:59:43 +00:00
|
|
|
author:
|
|
|
|
- Swetha Chunduri (@schunduri)
|
|
|
|
version_added: '2.4'
|
|
|
|
options:
|
|
|
|
aep:
|
|
|
|
description:
|
|
|
|
- The name of the Attachable Access Entity Profile.
|
|
|
|
required: yes
|
|
|
|
aliases: [ aep_name, name ]
|
|
|
|
description:
|
|
|
|
description:
|
|
|
|
- Description for the AEP.
|
2018-01-16 22:03:29 +00:00
|
|
|
aliases: [ descr ]
|
2018-01-12 11:20:20 +00:00
|
|
|
infra_vlan:
|
|
|
|
description:
|
|
|
|
- Enable infrastructure VLAN.
|
|
|
|
- The hypervisor functions of the AEP.
|
2018-01-14 03:20:31 +00:00
|
|
|
- C(no) will disable the infrastructure vlan if it is enabled.
|
2018-01-12 11:20:20 +00:00
|
|
|
type: bool
|
|
|
|
default: 'no'
|
|
|
|
aliases: [ infrastructure_vlan ]
|
|
|
|
version_added: '2.5'
|
2017-08-15 22:59:43 +00:00
|
|
|
state:
|
|
|
|
description:
|
|
|
|
- Use C(present) or C(absent) for adding or removing.
|
|
|
|
- Use C(query) for listing an object or multiple objects.
|
|
|
|
default: present
|
|
|
|
choices: [ absent, present, query ]
|
|
|
|
extends_documentation_fragment: aci
|
|
|
|
'''
|
|
|
|
|
|
|
|
EXAMPLES = r'''
|
|
|
|
- name: Add a new AEP
|
|
|
|
aci_aep:
|
2018-01-22 21:06:56 +00:00
|
|
|
host: apic
|
2017-08-15 22:59:43 +00:00
|
|
|
username: admin
|
|
|
|
password: SomeSecretPassword
|
|
|
|
aep: ACI-AEP
|
|
|
|
description: default
|
|
|
|
state: present
|
2018-08-08 21:24:50 +00:00
|
|
|
delegate_to: localhost
|
2017-08-15 22:59:43 +00:00
|
|
|
|
|
|
|
- name: Remove an existing AEP
|
|
|
|
aci_aep:
|
2018-01-22 21:06:56 +00:00
|
|
|
host: apic
|
2017-08-15 22:59:43 +00:00
|
|
|
username: admin
|
|
|
|
password: SomeSecretPassword
|
|
|
|
aep: ACI-AEP
|
|
|
|
state: absent
|
2018-08-08 21:24:50 +00:00
|
|
|
delegate_to: localhost
|
2017-08-15 22:59:43 +00:00
|
|
|
|
2018-02-20 02:04:17 +00:00
|
|
|
- name: Query all AEPs
|
2017-08-15 22:59:43 +00:00
|
|
|
aci_aep:
|
2018-01-22 21:06:56 +00:00
|
|
|
host: apic
|
2017-08-15 22:59:43 +00:00
|
|
|
username: admin
|
|
|
|
password: SomeSecretPassword
|
|
|
|
state: query
|
2018-08-08 21:24:50 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
register: query_result
|
2017-08-15 22:59:43 +00:00
|
|
|
|
2018-02-20 02:04:17 +00:00
|
|
|
- name: Query a specific AEP
|
2017-08-15 22:59:43 +00:00
|
|
|
aci_aep:
|
2018-01-22 21:06:56 +00:00
|
|
|
host: apic
|
2017-08-15 22:59:43 +00:00
|
|
|
username: admin
|
|
|
|
password: SomeSecretPassword
|
2018-02-20 02:04:17 +00:00
|
|
|
aep: ACI-AEP
|
2017-08-15 22:59:43 +00:00
|
|
|
state: query
|
2018-08-08 21:24:50 +00:00
|
|
|
delegate_to: localhost
|
|
|
|
register: query_result
|
2017-08-15 22:59:43 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
RETURN = r'''
|
2018-02-02 23:41:56 +00:00
|
|
|
current:
|
|
|
|
description: The existing configuration from the APIC after the module has finished
|
|
|
|
returned: success
|
|
|
|
type: list
|
|
|
|
sample:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"fvTenant": {
|
|
|
|
"attributes": {
|
|
|
|
"descr": "Production environment",
|
|
|
|
"dn": "uni/tn-production",
|
|
|
|
"name": "production",
|
|
|
|
"nameAlias": "",
|
|
|
|
"ownerKey": "",
|
|
|
|
"ownerTag": ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
error:
|
|
|
|
description: The error information as returned from the APIC
|
|
|
|
returned: failure
|
|
|
|
type: dict
|
|
|
|
sample:
|
|
|
|
{
|
|
|
|
"code": "122",
|
|
|
|
"text": "unknown managed object class foo"
|
|
|
|
}
|
|
|
|
raw:
|
|
|
|
description: The raw output returned by the APIC REST API (xml or json)
|
|
|
|
returned: parse error
|
|
|
|
type: string
|
|
|
|
sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
|
|
|
|
sent:
|
|
|
|
description: The actual/minimal configuration pushed to the APIC
|
|
|
|
returned: info
|
|
|
|
type: list
|
|
|
|
sample:
|
|
|
|
{
|
|
|
|
"fvTenant": {
|
|
|
|
"attributes": {
|
|
|
|
"descr": "Production environment"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
previous:
|
|
|
|
description: The original configuration from the APIC before the module has started
|
|
|
|
returned: info
|
|
|
|
type: list
|
|
|
|
sample:
|
|
|
|
[
|
|
|
|
{
|
|
|
|
"fvTenant": {
|
|
|
|
"attributes": {
|
|
|
|
"descr": "Production",
|
|
|
|
"dn": "uni/tn-production",
|
|
|
|
"name": "production",
|
|
|
|
"nameAlias": "",
|
|
|
|
"ownerKey": "",
|
|
|
|
"ownerTag": ""
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
]
|
|
|
|
proposed:
|
|
|
|
description: The assembled configuration from the user-provided parameters
|
|
|
|
returned: info
|
|
|
|
type: dict
|
|
|
|
sample:
|
|
|
|
{
|
|
|
|
"fvTenant": {
|
|
|
|
"attributes": {
|
|
|
|
"descr": "Production environment",
|
|
|
|
"name": "production"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
filter_string:
|
|
|
|
description: The filter string used for the request
|
|
|
|
returned: failure or debug
|
|
|
|
type: string
|
|
|
|
sample: ?rsp-prop-include=config-only
|
|
|
|
method:
|
|
|
|
description: The HTTP method used for the request to the APIC
|
|
|
|
returned: failure or debug
|
|
|
|
type: string
|
|
|
|
sample: POST
|
|
|
|
response:
|
|
|
|
description: The HTTP response from the APIC
|
|
|
|
returned: failure or debug
|
|
|
|
type: string
|
|
|
|
sample: OK (30 bytes)
|
|
|
|
status:
|
|
|
|
description: The HTTP status from the APIC
|
|
|
|
returned: failure or debug
|
|
|
|
type: int
|
|
|
|
sample: 200
|
|
|
|
url:
|
|
|
|
description: The HTTP url used for the request to the APIC
|
|
|
|
returned: failure or debug
|
|
|
|
type: string
|
|
|
|
sample: https://10.11.12.13/api/mo/uni/tn-production.json
|
2017-08-15 22:59:43 +00:00
|
|
|
'''
|
|
|
|
|
2017-12-03 16:12:30 +00:00
|
|
|
from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
|
2017-08-15 22:59:43 +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-15 22:59:43 +00:00
|
|
|
argument_spec.update(
|
2018-02-21 18:35:59 +00:00
|
|
|
aep=dict(type='str', aliases=['name', 'aep_name']), # Not required for querying all objects
|
2017-08-15 22:59:43 +00:00
|
|
|
description=dict(type='str', aliases=['descr']),
|
2018-01-14 03:20:31 +00:00
|
|
|
infra_vlan=dict(type='bool', aliases=['infrastructure_vlan']),
|
2017-08-15 22:59:43 +00:00
|
|
|
state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
|
|
|
|
)
|
|
|
|
|
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=argument_spec,
|
|
|
|
supports_check_mode=True,
|
2017-08-25 00:46:09 +00:00
|
|
|
required_if=[
|
|
|
|
['state', 'absent', ['aep']],
|
|
|
|
['state', 'present', ['aep']],
|
|
|
|
],
|
2017-08-15 22:59:43 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
aep = module.params['aep']
|
|
|
|
description = module.params['description']
|
2018-01-12 11:20:20 +00:00
|
|
|
infra_vlan = module.params['infra_vlan']
|
2017-08-15 22:59:43 +00:00
|
|
|
state = module.params['state']
|
|
|
|
|
2018-01-12 11:20:20 +00:00
|
|
|
if infra_vlan:
|
|
|
|
child_configs = [dict(infraProvAcc=dict(attributes=dict(name='provacc')))]
|
2018-01-14 03:20:31 +00:00
|
|
|
elif infra_vlan is False:
|
|
|
|
child_configs = [dict(infraProvAcc=dict(attributes=dict(name='provacc', status='deleted')))]
|
2018-01-12 11:20:20 +00:00
|
|
|
else:
|
|
|
|
child_configs = []
|
|
|
|
|
2017-08-15 22:59:43 +00:00
|
|
|
aci = ACIModule(module)
|
2017-11-22 15:07:39 +00:00
|
|
|
aci.construct_url(
|
|
|
|
root_class=dict(
|
|
|
|
aci_class='infraAttEntityP',
|
2018-01-12 01:26:14 +00:00
|
|
|
aci_rn='infra/attentp-{0}'.format(aep),
|
2017-11-22 15:07:39 +00:00
|
|
|
module_object=aep,
|
2018-08-07 21:54:54 +00:00
|
|
|
target_filter={'name': aep},
|
2017-11-22 15:07:39 +00:00
|
|
|
),
|
|
|
|
)
|
2017-08-15 22:59:43 +00:00
|
|
|
aci.get_existing()
|
|
|
|
|
|
|
|
if state == 'present':
|
2017-08-25 00:46:09 +00:00
|
|
|
aci.payload(
|
|
|
|
aci_class='infraAttEntityP',
|
|
|
|
class_config=dict(
|
|
|
|
name=aep,
|
|
|
|
descr=description,
|
|
|
|
),
|
2018-01-12 11:20:20 +00:00
|
|
|
child_configs=child_configs,
|
2017-08-25 00:46:09 +00:00
|
|
|
)
|
2017-08-15 22:59:43 +00:00
|
|
|
|
|
|
|
aci.get_diff(aci_class='infraAttEntityP')
|
|
|
|
|
|
|
|
aci.post_config()
|
|
|
|
|
|
|
|
elif state == 'absent':
|
|
|
|
aci.delete_config()
|
|
|
|
|
2018-02-02 23:41:56 +00:00
|
|
|
aci.exit_json()
|
2017-08-15 22:59:43 +00:00
|
|
|
|
2018-07-29 11:46:06 +00:00
|
|
|
|
2017-08-15 22:59:43 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
main()
|