7from __future__
import absolute_import, division, print_function
10ANSIBLE_METADATA = {
'metadata_version':
'1.1',
11 'status': [
'preview'],
12 'supported_by':
'certified'}
16module: aci_domain_to_vlan_pool
17short_description: Bind Domain to VLAN Pools (infra:RsVlanNs)
19- Bind Domain to VLAN Pools on Cisco ACI fabrics.
24 - Name of the domain being associated with the VLAN Pool.
26 aliases: [ domain_name, domain_profile ]
29 - Determines
if the Domain
is physical (phys)
or virtual (vmm).
31 choices: [ fc, l2dom, l3dom, phys, vmm ]
34 - The name of the pool.
36 aliases: [ pool_name, vlan_pool ]
39 - The method used
for allocating VLANs to resources.
42 choices: [ dynamic, static]
43 aliases: [ allocation_mode, mode ]
46 - Use C(present)
or C(absent)
for adding
or removing.
47 - Use C(query)
for listing an object
or multiple objects.
49 choices: [ absent, present, query ]
53 - The VM platform
for VMM Domains.
54 - Support
for Kubernetes was added
in ACI v3.0.
55 - Support
for CloudFoundry, OpenShift
and Red Hat was added
in ACI v3.1.
57 choices: [ cloudfoundry, kubernetes, microsoft, openshift, openstack, redhat, vmware ]
58extends_documentation_fragment: aci
60- The C(domain)
and C(vlan_pool) parameters should exist before using this module.
61 The M(aci_domain)
and M(aci_vlan_pool) can be used
for these.
64- module: aci_vlan_pool
65- name: APIC Management Information Model reference
66 description: More information about the internal APIC
class B(infra:RsVlanNs).
67 link: https://developer.cisco.com/docs/apic-mim-ref/
69- Dag Wieers (
@dagwieers)
73- name: Bind a VMM domain to VLAN pool
74 aci_domain_to_vlan_pool:
77 password: SomeSecretPassword
81 pool_allocation_mode: dynamic
84 delegate_to: localhost
86- name: Remove a VMM domain to VLAN pool binding
87 aci_domain_to_vlan_pool:
90 password: SomeSecretPassword
94 pool_allocation_mode: dynamic
97 delegate_to: localhost
99- name: Bind a physical domain to VLAN pool
100 aci_domain_to_vlan_pool:
103 password: SomeSecretPassword
107 pool_allocation_mode: static
109 delegate_to: localhost
111- name: Bind a physical domain to VLAN pool
112 aci_domain_to_vlan_pool:
115 password: SomeSecretPassword
119 pool_allocation_mode: static
121 delegate_to: localhost
123- name: Query an domain to VLAN pool binding
124 aci_domain_to_vlan_pool:
127 password: SomeSecretPassword
131 pool_allocation_mode: static
133 delegate_to: localhost
134 register: query_result
136- name: Query all domain to VLAN pool bindings
137 aci_domain_to_vlan_pool:
140 password: SomeSecretPassword
143 delegate_to: localhost
144 register: query_result
149 description: The existing configuration from the APIC after the module has finished
157 "descr":
"Production environment",
158 "dn":
"uni/tn-production",
159 "name":
"production",
168 description: The error information
as returned
from the APIC
174 "text":
"unknown managed object class foo"
177 description: The raw output returned by the APIC REST API (xml
or json)
178 returned: parse error
180 sample:
'<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
182 description: The actual/minimal configuration pushed to the APIC
189 "descr":
"Production environment"
194 description: The original configuration
from the APIC before the module has started
202 "descr":
"Production",
203 "dn":
"uni/tn-production",
204 "name":
"production",
213 description: The assembled configuration
from the user-provided parameters
220 "descr":
"Production environment",
226 description: The filter string used
for the request
227 returned: failure
or debug
229 sample: ?rsp-prop-include=config-only
231 description: The HTTP method used
for the request to the APIC
232 returned: failure
or debug
236 description: The HTTP response
from the APIC
237 returned: failure
or debug
239 sample: OK (30 bytes)
241 description: The HTTP status
from the APIC
242 returned: failure
or debug
246 description: The HTTP url used
for the request to the APIC
247 returned: failure
or debug
249 sample: https://10.11.12.13/api/mo/uni/tn-production.json
252from ansible.module_utils.basic import AnsibleModule
253from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
255VM_PROVIDER_MAPPING = dict(
256 cloudfoundry='CloudFoundry',
257 kubernetes=
'Kubernetes',
258 microsoft=
'Microsoft',
259 openshift=
'OpenShift',
260 openstack=
'OpenStack',
268 argument_spec.update(
269 domain_type=dict(type=
'str', required=
True, choices=[
'fc',
'l2dom',
'l3dom',
'phys',
'vmm']),
270 domain=dict(type=
'str', aliases=[
'domain_name',
'domain_profile']),
271 pool=dict(type=
'str', aliases=[
'pool_name',
'vlan_pool']),
272 pool_allocation_mode=dict(type=
'str', required=
True, aliases=[
'allocation_mode',
'mode'], choices=[
'dynamic',
'static']),
273 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
274 vm_provider=dict(type=
'str', choices=[
'cloudfoundry',
'kubernetes',
'microsoft',
'openshift',
'openstack',
'redhat',
'vmware']),
278 argument_spec=argument_spec,
279 supports_check_mode=
True,
281 [
'domain_type',
'vmm', [
'vm_provider']],
282 [
'state',
'absent', [
'domain',
'domain_type',
'pool']],
283 [
'state',
'present', [
'domain',
'domain_type',
'pool']],
287 domain = module.params[
'domain']
288 domain_type = module.params[
'domain_type']
289 pool = module.params[
'pool']
290 pool_allocation_mode = module.params[
'pool_allocation_mode']
291 vm_provider = module.params[
'vm_provider']
292 state = module.params[
'state']
295 if domain_type !=
'vmm' and vm_provider
is not None:
296 module.fail_json(msg=
"Domain type '{0}' cannot have a 'vm_provider'".
format(domain_type))
301 pool_name =
'[{0}]-{1}'.
format(pool, pool_allocation_mode)
304 if domain_type ==
'fc':
305 domain_class =
'fcDomP'
306 domain_mo =
'uni/fc-{0}'.
format(domain)
307 domain_rn =
'fc-{0}'.
format(domain)
308 elif domain_type ==
'l2dom':
309 domain_class =
'l2extDomP'
310 domain_mo =
'uni/l2dom-{0}'.
format(domain)
311 domain_rn =
'l2dom-{0}'.
format(domain)
312 elif domain_type ==
'l3dom':
313 domain_class =
'l3extDomP'
314 domain_mo =
'uni/l3dom-{0}'.
format(domain)
315 domain_rn =
'l3dom-{0}'.
format(domain)
316 elif domain_type ==
'phys':
317 domain_class =
'physDomP'
318 domain_mo =
'uni/phys-{0}'.
format(domain)
319 domain_rn =
'phys-{0}'.
format(domain)
320 elif domain_type ==
'vmm':
321 domain_class =
'vmmDomP'
322 domain_mo =
'uni/vmmp-{0}/dom-{1}'.
format(VM_PROVIDER_MAPPING[vm_provider], domain)
323 domain_rn =
'vmmp-{0}/dom-{1}'.
format(VM_PROVIDER_MAPPING[vm_provider], domain)
329 aci_mo =
'uni/infra/vlanns-{0}'.
format(pool_name)
334 aci_class=domain_class,
336 module_object=domain_mo,
337 target_filter={
'name': domain},
339 child_classes=[
'infraRsVlanNs'],
344 if state ==
'present':
346 aci_class=domain_class,
347 class_config=dict(name=domain),
349 {
'infraRsVlanNs': {
'attributes': {
'tDn': aci_mo}}},
353 aci.get_diff(aci_class=domain_class)
357 elif state ==
'absent':
363if __name__ ==
"__main__":