ansible  2.9.27
About: Ansible is an IT Configuration Management, Deployment \
About: Ansible (2.x) is an IT Configuration Management, Deployment & Orchestration tool.
ansible download page.
  Fossies Dox: ansible-2.9.27.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

aci_vlan_pool.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# Copyright: (c) 2017, Jacob McGill (@jmcgill298)
5# Copyright: (c) 2018, Dag Wieers (@dagwieers) <dag@wieers.com>
6# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
7
8from __future__ import absolute_import, division, print_function
9__metaclass__ = type
10
11ANSIBLE_METADATA = {'metadata_version': '1.1',
12 'status': ['preview'],
13 'supported_by': 'certified'}
14
15DOCUMENTATION = r'''
16---
17module: aci_vlan_pool
18short_description: Manage VLAN pools (fvns:VlanInstP)
19description:
20- Manage VLAN pools on Cisco ACI fabrics.
21version_added: '2.5'
22options:
23 pool_allocation_mode:
24 description:
25 - The method used for allocating VLANs to resources.
26 type: str
27 choices: [ dynamic, static]
28 aliases: [ allocation_mode, mode ]
29 description:
30 description:
31 - Description for the C(pool).
32 type: str
33 aliases: [ descr ]
34 pool:
35 description:
36 - The name of the pool.
37 type: str
38 aliases: [ name, pool_name ]
39 state:
40 description:
41 - Use C(present) or C(absent) for adding or removing.
42 - Use C(query) for listing an object or multiple objects.
43 type: str
44 choices: [ absent, present, query ]
45 default: present
46extends_documentation_fragment: aci
47seealso:
48- module: aci_encap_pool
49- module: aci_vlan_pool_encap_block
50- name: APIC Management Information Model reference
51 description: More information about the internal APIC class B(fvns:VlanInstP).
52 link: https://developer.cisco.com/docs/apic-mim-ref/
53author:
54- Jacob McGill (@jmcgill298)
55- Dag Wieers (@dagwieers)
56'''
57
58EXAMPLES = r'''
59- name: Add a new VLAN pool
60 aci_vlan_pool:
61 host: apic
62 username: admin
63 password: SomeSecretPassword
64 pool: production
65 pool_allocation_mode: dynamic
66 description: Production VLANs
67 state: present
68 delegate_to: localhost
69
70- name: Remove a VLAN pool
71 aci_vlan_pool:
72 host: apic
73 username: admin
74 password: SomeSecretPassword
75 pool: production
76 pool_allocation_mode: dynamic
77 state: absent
78 delegate_to: localhost
79
80- name: Query a VLAN pool
81 aci_vlan_pool:
82 host: apic
83 username: admin
84 password: SomeSecretPassword
85 pool: production
86 pool_allocation_mode: dynamic
87 state: query
88 delegate_to: localhost
89 register: query_result
90
91- name: Query all VLAN pools
92 aci_vlan_pool:
93 host: apic
94 username: admin
95 password: SomeSecretPassword
96 state: query
97 delegate_to: localhost
98 register: query_result
99'''
100
101RETURN = r'''
102current:
103 description: The existing configuration from the APIC after the module has finished
104 returned: success
105 type: list
106 sample:
107 [
108 {
109 "fvTenant": {
110 "attributes": {
111 "descr": "Production environment",
112 "dn": "uni/tn-production",
113 "name": "production",
114 "nameAlias": "",
115 "ownerKey": "",
116 "ownerTag": ""
117 }
118 }
119 }
120 ]
121error:
122 description: The error information as returned from the APIC
123 returned: failure
124 type: dict
125 sample:
126 {
127 "code": "122",
128 "text": "unknown managed object class foo"
129 }
130raw:
131 description: The raw output returned by the APIC REST API (xml or json)
132 returned: parse error
133 type: str
134 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
135sent:
136 description: The actual/minimal configuration pushed to the APIC
137 returned: info
138 type: list
139 sample:
140 {
141 "fvTenant": {
142 "attributes": {
143 "descr": "Production environment"
144 }
145 }
146 }
147previous:
148 description: The original configuration from the APIC before the module has started
149 returned: info
150 type: list
151 sample:
152 [
153 {
154 "fvTenant": {
155 "attributes": {
156 "descr": "Production",
157 "dn": "uni/tn-production",
158 "name": "production",
159 "nameAlias": "",
160 "ownerKey": "",
161 "ownerTag": ""
162 }
163 }
164 }
165 ]
166proposed:
167 description: The assembled configuration from the user-provided parameters
168 returned: info
169 type: dict
170 sample:
171 {
172 "fvTenant": {
173 "attributes": {
174 "descr": "Production environment",
175 "name": "production"
176 }
177 }
178 }
179filter_string:
180 description: The filter string used for the request
181 returned: failure or debug
182 type: str
183 sample: ?rsp-prop-include=config-only
184method:
185 description: The HTTP method used for the request to the APIC
186 returned: failure or debug
187 type: str
188 sample: POST
189response:
190 description: The HTTP response from the APIC
191 returned: failure or debug
192 type: str
193 sample: OK (30 bytes)
194status:
195 description: The HTTP status from the APIC
196 returned: failure or debug
197 type: int
198 sample: 200
199url:
200 description: The HTTP url used for the request to the APIC
201 returned: failure or debug
202 type: str
203 sample: https://10.11.12.13/api/mo/uni/tn-production.json
204'''
205
206from ansible.module_utils.basic import AnsibleModule
207from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
208
209
210def main():
211 argument_spec = aci_argument_spec()
212 argument_spec.update(
213 pool=dict(type='str', aliases=['name', 'pool_name']), # Not required for querying all objects
214 description=dict(type='str', aliases=['descr']),
215 pool_allocation_mode=dict(type='str', aliases=['allocation_mode', 'mode'], choices=['dynamic', 'static']),
216 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
217 )
218
219 module = AnsibleModule(
220 argument_spec=argument_spec,
221 supports_check_mode=True,
222 required_if=[
223 ['state', 'absent', ['pool']],
224 ['state', 'present', ['pool']],
225 ],
226 )
227
228 description = module.params['description']
229 pool = module.params['pool']
230 pool_allocation_mode = module.params['pool_allocation_mode']
231 state = module.params['state']
232
233 pool_name = pool
234
235 # ACI Pool URL requires the allocation mode for vlan and vsan pools (ex: uni/infra/vlanns-[poolname]-static)
236 if pool is not None:
237 if pool_allocation_mode is not None:
238 pool_name = '[{0}]-{1}'.format(pool, pool_allocation_mode)
239 else:
240 module.fail_json(msg="ACI requires the 'pool_allocation_mode' when 'pool' is provided")
241
242 aci = ACIModule(module)
243 aci.construct_url(
244 root_class=dict(
245 aci_class='fvnsVlanInstP',
246 aci_rn='infra/vlanns-{0}'.format(pool_name),
247 module_object=pool,
248 target_filter={'name': pool},
249 ),
250 )
251
252 aci.get_existing()
253
254 if state == 'present':
255 aci.payload(
256 aci_class='fvnsVlanInstP',
257 class_config=dict(
258 allocMode=pool_allocation_mode,
259 descr=description,
260 name=pool,
261 ),
262 )
263
264 aci.get_diff(aci_class='fvnsVlanInstP')
265
266 aci.post_config()
267
268 elif state == 'absent':
269 aci.delete_config()
270
271 aci.exit_json()
272
273
274if __name__ == "__main__":
275 main()