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