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_access_sub_port_block_to_access_port.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# Copyright: (c) 2019, Simon Metzger <smnmtzgr@gmail.com>
5# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7from __future__ import absolute_import, division, print_function
8__metaclass__ = type
9
10ANSIBLE_METADATA = {'metadata_version': '1.1',
11 'status': ['preview'],
12 'supported_by': 'certified'}
13
14DOCUMENTATION = r'''
15---
16module: aci_access_sub_port_block_to_access_port
17short_description: Manage sub port blocks of Fabric interface policy leaf profile interface selectors (infra:HPortS, infra:SubPortBlk)
18description:
19- Manage sub port blocks of Fabric interface policy leaf profile interface selectors on Cisco ACI fabrics.
20seealso:
21- name: APIC Management Information Model reference
22 description: More information about the internal APIC classes B(infra:HPortS) and B(infra:SubPortBlk).
23 link: https://developer.cisco.com/docs/apic-mim-ref/
24author:
25- Simon Metzger (@smnmtzgr)
26version_added: '2.8'
27options:
28 leaf_interface_profile:
29 description:
30 - The name of the Fabric access policy leaf interface profile.
31 type: str
32 required: yes
33 aliases: [ leaf_interface_profile_name ]
34 access_port_selector:
35 description:
36 - The name of the Fabric access policy leaf interface profile access port selector.
37 type: str
38 required: yes
39 aliases: [ name, access_port_selector_name ]
40 leaf_port_blk:
41 description:
42 - The name of the Fabric access policy leaf interface profile access port block.
43 type: str
44 required: yes
45 aliases: [ leaf_port_blk_name ]
46 leaf_port_blk_description:
47 description:
48 - The description to assign to the C(leaf_port_blk).
49 from_port:
50 description:
51 - The beginning (from-range) of the port range block for the leaf access port block.
52 type: str
53 required: yes
54 aliases: [ from, fromPort, from_port_range ]
55 to_port:
56 description:
57 - The end (to-range) of the port range block for the leaf access port block.
58 type: str
59 required: yes
60 aliases: [ to, toPort, to_port_range ]
61 from_sub_port:
62 description:
63 - The beginning (from-range) of the sub port range block for the leaf access port block.
64 type: str
65 required: yes
66 aliases: [ fromSubPort, from_sub_port_range ]
67 to_sub_port:
68 description:
69 - The end (to-range) of the sub port range block for the leaf access port block.
70 type: str
71 required: yes
72 aliases: [ toSubPort, to_sub_port_range ]
73 from_card:
74 description:
75 - The beginning (from-range) of the card range block for the leaf access port block.
76 type: str
77 aliases: [ from_card_range ]
78 to_card:
79 description:
80 - The end (to-range) of the card range block for the leaf access port block.
81 type: str
82 aliases: [ to_card_range ]
83 state:
84 description:
85 - Use C(present) or C(absent) for adding or removing.
86 - Use C(query) for listing an object or multiple objects.
87 type: str
88 choices: [ absent, present, query ]
89 default: present
90extends_documentation_fragment: aci
91'''
92
93EXAMPLES = r'''
94- name: Associate an access sub port block (single port) to an interface selector
95 aci_access_sub_port_block_to_access_port:
96 host: apic
97 username: admin
98 password: SomeSecretPassword
99 leaf_interface_profile: leafintprfname
100 access_port_selector: accessportselectorname
101 leaf_port_blk: leafportblkname
102 from_port: 13
103 to_port: 13
104 from_sub_port: 1
105 to_sub_port: 1
106 state: present
107 delegate_to: localhost
108
109- name: Associate an access sub port block (port range) to an interface selector
110 aci_access_sub_port_block_to_access_port:
111 host: apic
112 username: admin
113 password: SomeSecretPassword
114 leaf_interface_profile: leafintprfname
115 access_port_selector: accessportselectorname
116 leaf_port_blk: leafportblkname
117 from_port: 13
118 to_port: 13
119 from_sub_port: 1
120 to_sub_port: 3
121 state: present
122 delegate_to: localhost
123
124- name: Remove an access sub port block from an interface selector
125 aci_access_sub_port_block_to_access_port:
126 host: apic
127 username: admin
128 password: SomeSecretPassword
129 leaf_interface_profile: leafintprfname
130 access_port_selector: accessportselectorname
131 leaf_port_blk: leafportblkname
132 from_port: 13
133 to_port: 13
134 from_sub_port: 1
135 to_sub_port: 1
136 state: absent
137 delegate_to: localhost
138
139- name: Query Specific access sub port block under given access port selector
140 aci_access_sub_port_block_to_access_port:
141 host: apic
142 username: admin
143 password: SomeSecretPassword
144 leaf_interface_profile: leafintprfname
145 access_port_selector: accessportselectorname
146 leaf_port_blk: leafportblkname
147 state: query
148 delegate_to: localhost
149 register: query_result
150
151- name: Query all access sub port blocks under given leaf interface profile
152 aci_access_sub_port_block_to_access_port:
153 host: apic
154 username: admin
155 password: SomeSecretPassword
156 leaf_interface_profile: leafintprfname
157 state: query
158 delegate_to: localhost
159 register: query_result
160
161- name: Query all access sub port blocks in the fabric
162 aci_access_sub_port_block_to_access_port:
163 host: apic
164 username: admin
165 password: SomeSecretPassword
166 state: query
167 delegate_to: localhost
168 register: query_result
169'''
170
171RETURN = r'''
172current:
173 description: The existing configuration from the APIC after the module has finished
174 returned: success
175 type: list
176 sample:
177 [
178 {
179 "fvTenant": {
180 "attributes": {
181 "descr": "Production environment",
182 "dn": "uni/tn-production",
183 "name": "production",
184 "nameAlias": "",
185 "ownerKey": "",
186 "ownerTag": ""
187 }
188 }
189 }
190 ]
191error:
192 description: The error information as returned from the APIC
193 returned: failure
194 type: dict
195 sample:
196 {
197 "code": "122",
198 "text": "unknown managed object class foo"
199 }
200raw:
201 description: The raw output returned by the APIC REST API (xml or json)
202 returned: parse error
203 type: str
204 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
205sent:
206 description: The actual/minimal configuration pushed to the APIC
207 returned: info
208 type: list
209 sample:
210 {
211 "fvTenant": {
212 "attributes": {
213 "descr": "Production environment"
214 }
215 }
216 }
217previous:
218 description: The original configuration from the APIC before the module has started
219 returned: info
220 type: list
221 sample:
222 [
223 {
224 "fvTenant": {
225 "attributes": {
226 "descr": "Production",
227 "dn": "uni/tn-production",
228 "name": "production",
229 "nameAlias": "",
230 "ownerKey": "",
231 "ownerTag": ""
232 }
233 }
234 }
235 ]
236proposed:
237 description: The assembled configuration from the user-provided parameters
238 returned: info
239 type: dict
240 sample:
241 {
242 "fvTenant": {
243 "attributes": {
244 "descr": "Production environment",
245 "name": "production"
246 }
247 }
248 }
249filter_string:
250 description: The filter string used for the request
251 returned: failure or debug
252 type: str
253 sample: ?rsp-prop-include=config-only
254method:
255 description: The HTTP method used for the request to the APIC
256 returned: failure or debug
257 type: str
258 sample: POST
259response:
260 description: The HTTP response from the APIC
261 returned: failure or debug
262 type: str
263 sample: OK (30 bytes)
264status:
265 description: The HTTP status from the APIC
266 returned: failure or debug
267 type: int
268 sample: 200
269url:
270 description: The HTTP url used for the request to the APIC
271 returned: failure or debug
272 type: str
273 sample: https://10.11.12.13/api/mo/uni/tn-production.json
274'''
275
276from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
277from ansible.module_utils.basic import AnsibleModule
278
279
280def main():
281 argument_spec = aci_argument_spec()
282 argument_spec.update(
283 leaf_interface_profile=dict(type='str', aliases=['leaf_interface_profile_name']), # Not required for querying all objects
284 access_port_selector=dict(type='str', aliases=['name', 'access_port_selector_name']), # Not required for querying all objects
285 leaf_port_blk=dict(type='str', aliases=['leaf_port_blk_name']), # Not required for querying all objects
286 leaf_port_blk_description=dict(type='str'),
287 from_port=dict(type='str', aliases=['from', 'fromPort', 'from_port_range']), # Not required for querying all objects and deleting sub port blocks
288 to_port=dict(type='str', aliases=['to', 'toPort', 'to_port_range']), # Not required for querying all objects and deleting sub port blocks
289 from_sub_port=dict(type='str', aliases=['fromSubPort', 'from_sub_port_range']), # Not required for querying all objects and deleting sub port blocks
290 to_sub_port=dict(type='str', aliases=['toSubPort', 'to_sub_port_range']), # Not required for querying all objects and deleting sub port blocks
291 from_card=dict(type='str', aliases=['from_card_range']),
292 to_card=dict(type='str', aliases=['to_card_range']),
293 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
294 )
295
296 module = AnsibleModule(
297 argument_spec=argument_spec,
298 supports_check_mode=True,
299 required_if=[
300 ['state', 'absent', ['access_port_selector', 'leaf_port_blk', 'leaf_interface_profile']],
301 ['state', 'present', ['access_port_selector', 'leaf_port_blk', 'from_port', 'to_port', 'from_sub_port', 'to_sub_port', 'leaf_interface_profile']],
302 ],
303 )
304
305 leaf_interface_profile = module.params['leaf_interface_profile']
306 access_port_selector = module.params['access_port_selector']
307 leaf_port_blk = module.params['leaf_port_blk']
308 leaf_port_blk_description = module.params['leaf_port_blk_description']
309 from_port = module.params['from_port']
310 to_port = module.params['to_port']
311 from_sub_port = module.params['from_sub_port']
312 to_sub_port = module.params['to_sub_port']
313 from_card = module.params['from_card']
314 to_card = module.params['to_card']
315 state = module.params['state']
316
317 aci = ACIModule(module)
318 aci.construct_url(
319 root_class=dict(
320 aci_class='infraAccPortP',
321 aci_rn='infra/accportprof-{0}'.format(leaf_interface_profile),
322 module_object=leaf_interface_profile,
323 target_filter={'name': leaf_interface_profile},
324 ),
325 subclass_1=dict(
326 aci_class='infraHPortS',
327 # NOTE: normal rn: hports-{name}-typ-{type}, hence here hardcoded to range for purposes of module
328 aci_rn='hports-{0}-typ-range'.format(access_port_selector),
329 module_object=access_port_selector,
330 target_filter={'name': access_port_selector},
331 ),
332 subclass_2=dict(
333 aci_class='infraSubPortBlk',
334 aci_rn='subportblk-{0}'.format(leaf_port_blk),
335 module_object=leaf_port_blk,
336 target_filter={'name': leaf_port_blk},
337 ),
338 )
339
340 aci.get_existing()
341
342 if state == 'present':
343 aci.payload(
344 aci_class='infraSubPortBlk',
345 class_config=dict(
346 descr=leaf_port_blk_description,
347 name=leaf_port_blk,
348 fromPort=from_port,
349 toPort=to_port,
350 fromSubPort=from_sub_port,
351 toSubPort=to_sub_port,
352 fromCard=from_card,
353 toCard=to_card,
354 # type='range',
355 ),
356 )
357
358 aci.get_diff(aci_class='infraSubPortBlk')
359
360 aci.post_config()
361
362 elif state == 'absent':
363 aci.delete_config()
364
365 aci.exit_json()
366
367
368if __name__ == "__main__":
369 main()