Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_vlan_pool.py

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