6from __future__
import absolute_import, division, print_function
9ANSIBLE_METADATA = {
'metadata_version':
'1.1',
10 'status': [
'preview'],
11 'supported_by':
'certified'}
15module: aci_encap_pool_range
16short_description: Manage encap ranges assigned to pools (fvns:EncapBlk, fvns:VsanEncapBlk)
18- Manage vlan, vxlan, and vsan ranges that are assigned to pools on Cisco ACI fabrics.
23 - The method used for allocating encaps to resources.
24 - Only vlan
and vsan support allocation modes.
26 choices: [ dynamic, inherit, static]
30 - Description
for the pool range.
35 - The name of the pool that the range should be assigned to.
37 aliases: [ pool_name ]
40 - The method used
for allocating encaps to resources.
41 - Only vlan
and vsan support allocation modes.
43 choices: [ dynamic, static]
44 aliases: [ pool_mode ]
47 - The encap type of C(pool).
51 choices: [ vlan, vxlan, vsan]
54 - The end of encap range.
59 - The name to give to the encap range.
61 aliases: [ name, range ]
64 - The start of the encap range.
69 - Use C(present)
or C(absent)
for adding
or removing.
70 - Use C(query)
for listing an object
or multiple objects.
72 choices: [ absent, present, query ]
74extends_documentation_fragment: aci
76- The C(pool) must exist
in order to add
or delete a range.
78- module: aci_encap_pool
79- module: aci_vlan_pool_encap_block
80- name: APIC Management Information Model reference
81 description: More information about the internal APIC classes B(fvns:EncapBlk)
and B(fvns:VsanEncapBlk).
82 link: https://developer.cisco.com/docs/apic-mim-ref/
84- Jacob McGill (
@jmcgill298)
88- name: Add a new VLAN pool range
92 password: SomeSecretPassword
95 pool_allocation_mode: static
99 allocation_mode: inherit
101 delegate_to: localhost
103- name: Remove a VLAN pool range
104 aci_encap_pool_range:
107 password: SomeSecretPassword
110 pool_allocation_mode: static
115 delegate_to: localhost
117- name: Query a VLAN range
118 aci_encap_pool_range:
121 password: SomeSecretPassword
124 pool_allocation_mode: static
129 delegate_to: localhost
130 register: query_result
132- name: Query a VLAN pool for ranges by range_name
133 aci_encap_pool_range:
136 password: SomeSecretPassword
140 delegate_to: localhost
141 register: query_result
143- name: Query a VLAN pool
for ranges by range_start
144 aci_encap_pool_range:
147 password: SomeSecretPassword
151 delegate_to: localhost
152 register: query_result
154- name: Query a VLAN pool
for ranges by range_start
and range_end
155 aci_encap_pool_range:
158 password: SomeSecretPassword
163 delegate_to: localhost
164 register: query_result
166- name: Query all VLAN pool ranges
167 aci_encap_pool_range:
170 password: SomeSecretPassword
173 delegate_to: localhost
174 register: query_result
179 description: The existing configuration from the APIC after the module has finished
187 "descr":
"Production environment",
188 "dn":
"uni/tn-production",
189 "name":
"production",
198 description: The error information
as returned
from the APIC
204 "text":
"unknown managed object class foo"
207 description: The raw output returned by the APIC REST API (xml
or json)
208 returned: parse error
210 sample:
'<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
212 description: The actual/minimal configuration pushed to the APIC
219 "descr":
"Production environment"
224 description: The original configuration
from the APIC before the module has started
232 "descr":
"Production",
233 "dn":
"uni/tn-production",
234 "name":
"production",
243 description: The assembled configuration
from the user-provided parameters
250 "descr":
"Production environment",
256 description: The filter string used
for the request
257 returned: failure
or debug
259 sample: ?rsp-prop-include=config-only
261 description: The HTTP method used
for the request to the APIC
262 returned: failure
or debug
266 description: The HTTP response
from the APIC
267 returned: failure
or debug
269 sample: OK (30 bytes)
271 description: The HTTP status
from the APIC
272 returned: failure
or debug
276 description: The HTTP url used
for the request to the APIC
277 returned: failure
or debug
279 sample: https://10.11.12.13/api/mo/uni/tn-production.json
282from ansible.module_utils.basic import AnsibleModule
283from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
285ACI_POOL_MAPPING = dict(
287 aci_class='fvnsVlanInstP',
288 aci_mo=
'infra/vlanns-',
291 aci_class=
'fvnsVxlanInstP',
292 aci_mo=
'infra/vxlanns-',
295 aci_class=
'fvnsVsanInstP',
296 aci_mo=
'infra/vsanns-',
303 argument_spec.update(
304 pool_type=dict(type=
'str', required=
True, aliases=[
'type'], choices=[
'vlan',
'vxlan',
'vsan']),
305 allocation_mode=dict(type=
'str', aliases=[
'mode'], choices=[
'dynamic',
'inherit',
'static']),
306 description=dict(type=
'str', aliases=[
'descr']),
307 pool=dict(type=
'str', aliases=[
'pool_name']),
308 pool_allocation_mode=dict(type=
'str', aliases=[
'pool_mode'], choices=[
'dynamic',
'static']),
309 range_end=dict(type=
'int', aliases=[
'end']),
310 range_name=dict(type=
'str', aliases=[
"name",
"range"]),
311 range_start=dict(type=
'int', aliases=[
"start"]),
312 state=dict(type=
'str', default=
'present', choices=[
'absent',
'present',
'query']),
316 argument_spec=argument_spec,
317 supports_check_mode=
True,
319 [
'state',
'absent', [
'pool',
'range_end',
'range_name',
'range_start']],
320 [
'state',
'present', [
'pool',
'range_end',
'range_name',
'range_start']],
324 allocation_mode = module.params[
'allocation_mode']
325 description = module.params[
'description']
326 pool = module.params[
'pool']
327 pool_allocation_mode = module.params[
'pool_allocation_mode']
328 pool_type = module.params[
'pool_type']
329 range_end = module.params[
'range_end']
330 range_name = module.params[
'range_name']
331 range_start = module.params[
'range_start']
332 state = module.params[
'state']
334 if range_end
is not None:
335 encap_end =
'{0}-{1}'.
format(pool_type, range_end)
339 if range_start
is not None:
340 encap_start =
'{0}-{1}'.
format(pool_type, range_start)
344 ACI_RANGE_MAPPING = dict(
346 aci_class=
'fvnsEncapBlk',
347 aci_mo=
'from-[{0}]-to-[{1}]'.
format(encap_start, encap_end),
350 aci_class=
'fvnsEncapBlk',
351 aci_mo=
'from-[{0}]-to-[{1}]'.
format(encap_start, encap_end),
354 aci_class=
'fvnsVsanEncapBlk',
355 aci_mo=
'vsanfrom-[{0}]-to-[{1}]'.
format(encap_start, encap_end),
360 aci_range_class = ACI_RANGE_MAPPING[pool_type][
"aci_class"]
361 aci_range_mo = ACI_RANGE_MAPPING[pool_type][
"aci_mo"]
362 aci_pool_class = ACI_POOL_MAPPING[pool_type][
"aci_class"]
363 aci_pool_mo = ACI_POOL_MAPPING[pool_type][
"aci_mo"]
367 for encap_id
in range_end, range_start:
368 if encap_id
is not None:
369 if pool_type ==
'vlan':
370 if not 1 <= encap_id <= 4094:
371 module.fail_json(msg=
'vlan pools must have "range_start" and "range_end" values between 1 and 4094')
372 elif pool_type ==
'vxlan':
373 if not 5000 <= encap_id <= 16777215:
374 module.fail_json(msg=
'vxlan pools must have "range_start" and "range_end" values between 5000 and 16777215')
375 elif pool_type ==
'vsan':
376 if not 1 <= encap_id <= 4093:
377 module.fail_json(msg=
'vsan pools must have "range_start" and "range_end" values between 1 and 4093')
379 if range_end
is not None and range_start
is not None:
381 if range_start > range_end:
382 module.fail_json(msg=
'The "range_start" must be less than or equal to the "range_end"')
384 elif range_end
is None and range_start
is None:
385 if range_name
is None:
390 if pool_type ==
'vxlan' and allocation_mode
is not None:
391 module.fail_json(msg=
'vxlan pools do not support setting the "allocation_mode"; please omit this parameter for vxlan pools')
394 if pool_type !=
'vxlan' and pool
is not None:
395 if pool_allocation_mode
is not None:
396 pool_name =
'[{0}]-{1}'.
format(pool, pool_allocation_mode)
398 module.fail_json(msg=
'ACI requires the "pool_allocation_mode" for "pool_type" of "vlan" and "vsan" when the "pool" is provided')
403 aci_class=aci_pool_class,
404 aci_rn=
'{0}{1}'.
format(aci_pool_mo, pool_name),
406 target_filter={
'name': pool},
409 aci_class=aci_range_class,
410 aci_rn=
'{0}'.
format(aci_range_mo),
411 module_object=aci_range_mo,
412 target_filter={
'from': encap_start,
'to': encap_end,
'name': range_name},
418 if state ==
'present':
420 aci_class=aci_range_class,
422 "allocMode": allocation_mode,
423 "descr": description,
430 aci.get_diff(aci_class=aci_range_class)
434 elif state ==
'absent':
440if __name__ ==
"__main__":