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_to_interface_policy_leaf_profile.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# Copyright: (c) 2017, Bruno Calogero <brunocalogero@hotmail.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_to_interface_policy_leaf_profile
17short_description: Manage Fabric interface policy leaf profile interface selectors (infra:HPortS, infra:RsAccBaseGrp, infra:PortBlk)
18description:
19- Manage Fabric interface policy leaf profile interface selectors on Cisco ACI fabrics.
20version_added: '2.5'
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 description:
35 description:
36 - The description to assign to the C(access_port_selector)
37 type: str
38 leaf_port_blk:
39 description:
40 - B(Deprecated)
41 - Starting with Ansible 2.8 we recommend using the module L(aci_access_port_block_to_access_port, aci_access_port_block_to_access_port.html).
42 - The parameter will be removed in Ansible 2.12.
43 - HORIZONTALLINE
44 - The name of the Fabric access policy leaf interface profile access port block.
45 type: str
46 required: yes
47 aliases: [ leaf_port_blk_name ]
48 leaf_port_blk_description:
49 description:
50 - B(Deprecated)
51 - Starting with Ansible 2.8 we recommend using the module L(aci_access_port_block_to_access_port, aci_access_port_block_to_access_port.html).
52 - The parameter will be removed in Ansible 2.12.
53 - HORIZONTALLINE
54 - The description to assign to the C(leaf_port_blk)
55 type: str
56 from_port:
57 description:
58 - B(Deprecated)
59 - Starting with Ansible 2.8 we recommend using the module L(aci_access_port_block_to_access_port, aci_access_port_block_to_access_port.html).
60 - The parameter will be removed in Ansible 2.12.
61 - HORIZONTALLINE
62 - The beginning (from-range) of the port range block for the leaf access port block.
63 type: str
64 required: yes
65 aliases: [ from, fromPort, from_port_range ]
66 to_port:
67 description:
68 - B(Deprecated)
69 - Starting with Ansible 2.8 we recommend using the module L(aci_access_port_block_to_access_port, aci_access_port_block_to_access_port.html).
70 - The parameter will be removed in Ansible 2.12.
71 - HORIZONTALLINE
72 - The end (to-range) of the port range block for the leaf access port block.
73 type: str
74 required: yes
75 aliases: [ to, toPort, to_port_range ]
76 from_card:
77 description:
78 - B(Deprecated)
79 - Starting with Ansible 2.8 we recommend using the module L(aci_access_port_block_to_access_port, aci_access_port_block_to_access_port.html).
80 - The parameter will be removed in Ansible 2.12.
81 - HORIZONTALLINE
82 - The beginning (from-range) of the card range block for the leaf access port block.
83 type: str
84 aliases: [ from_card_range ]
85 version_added: '2.6'
86 to_card:
87 description:
88 - B(Deprecated)
89 - Starting with Ansible 2.8 we recommend using the module L(aci_access_port_block_to_access_port, aci_access_port_block_to_access_port.html).
90 - The parameter will be removed in Ansible 2.12.
91 - HORIZONTALLINE
92 - The end (to-range) of the card range block for the leaf access port block.
93 type: str
94 aliases: [ to_card_range ]
95 version_added: '2.6'
96 policy_group:
97 description:
98 - The name of the fabric access policy group to be associated with the leaf interface profile interface selector.
99 type: str
100 aliases: [ policy_group_name ]
101 interface_type:
102 description:
103 - The type of interface for the static EPG deployment.
104 type: str
105 choices: [ breakout, fex, port_channel, switch_port, vpc ]
106 default: switch_port
107 version_added: '2.6'
108 state:
109 description:
110 - Use C(present) or C(absent) for adding or removing.
111 - Use C(query) for listing an object or multiple objects.
112 type: str
113 choices: [ absent, present, query ]
114 default: present
115extends_documentation_fragment: aci
116seealso:
117- name: APIC Management Information Model reference
118 description: More information about the internal APIC classes B(infra:HPortS), B(infra:RsAccBaseGrp) and B(infra:PortBlk).
119 link: https://developer.cisco.com/docs/apic-mim-ref/
120author:
121- Bruno Calogero (@brunocalogero)
122'''
123
124EXAMPLES = r'''
125- name: Associate an Interface Access Port Selector to an Interface Policy Leaf Profile with a Policy Group
126 aci_access_port_to_interface_policy_leaf_profile:
127 host: apic
128 username: admin
129 password: SomeSecretPassword
130 leaf_interface_profile: leafintprfname
131 access_port_selector: accessportselectorname
132 leaf_port_blk: leafportblkname
133 from_port: 13
134 to_port: 16
135 policy_group: policygroupname
136 state: present
137 delegate_to: localhost
138
139- name: Associate an interface access port selector to an Interface Policy Leaf Profile (w/o policy group) (check if this works)
140 aci_access_port_to_interface_policy_leaf_profile:
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 from_port: 13
148 to_port: 16
149 state: present
150 delegate_to: localhost
151
152- name: Remove an interface access port selector associated with an Interface Policy Leaf Profile
153 aci_access_port_to_interface_policy_leaf_profile:
154 host: apic
155 username: admin
156 password: SomeSecretPassword
157 leaf_interface_profile: leafintprfname
158 access_port_selector: accessportselectorname
159 state: absent
160 delegate_to: localhost
161
162- name: Query Specific access_port_selector under given leaf_interface_profile
163 aci_access_port_to_interface_policy_leaf_profile:
164 host: apic
165 username: admin
166 password: SomeSecretPassword
167 leaf_interface_profile: leafintprfname
168 access_port_selector: accessportselectorname
169 state: query
170 delegate_to: localhost
171 register: query_result
172'''
173
174RETURN = r'''
175current:
176 description: The existing configuration from the APIC after the module has finished
177 returned: success
178 type: list
179 sample:
180 [
181 {
182 "fvTenant": {
183 "attributes": {
184 "descr": "Production environment",
185 "dn": "uni/tn-production",
186 "name": "production",
187 "nameAlias": "",
188 "ownerKey": "",
189 "ownerTag": ""
190 }
191 }
192 }
193 ]
194error:
195 description: The error information as returned from the APIC
196 returned: failure
197 type: dict
198 sample:
199 {
200 "code": "122",
201 "text": "unknown managed object class foo"
202 }
203raw:
204 description: The raw output returned by the APIC REST API (xml or json)
205 returned: parse error
206 type: str
207 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
208sent:
209 description: The actual/minimal configuration pushed to the APIC
210 returned: info
211 type: list
212 sample:
213 {
214 "fvTenant": {
215 "attributes": {
216 "descr": "Production environment"
217 }
218 }
219 }
220previous:
221 description: The original configuration from the APIC before the module has started
222 returned: info
223 type: list
224 sample:
225 [
226 {
227 "fvTenant": {
228 "attributes": {
229 "descr": "Production",
230 "dn": "uni/tn-production",
231 "name": "production",
232 "nameAlias": "",
233 "ownerKey": "",
234 "ownerTag": ""
235 }
236 }
237 }
238 ]
239proposed:
240 description: The assembled configuration from the user-provided parameters
241 returned: info
242 type: dict
243 sample:
244 {
245 "fvTenant": {
246 "attributes": {
247 "descr": "Production environment",
248 "name": "production"
249 }
250 }
251 }
252filter_string:
253 description: The filter string used for the request
254 returned: failure or debug
255 type: str
256 sample: ?rsp-prop-include=config-only
257method:
258 description: The HTTP method used for the request to the APIC
259 returned: failure or debug
260 type: str
261 sample: POST
262response:
263 description: The HTTP response from the APIC
264 returned: failure or debug
265 type: str
266 sample: OK (30 bytes)
267status:
268 description: The HTTP status from the APIC
269 returned: failure or debug
270 type: int
271 sample: 200
272url:
273 description: The HTTP url used for the request to the APIC
274 returned: failure or debug
275 type: str
276 sample: https://10.11.12.13/api/mo/uni/tn-production.json
277'''
278
279from ansible.module_utils.basic import AnsibleModule
280from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
281
282INTERFACE_TYPE_MAPPING = dict(
283 breakout='uni/infra/funcprof/brkoutportgrp-{0}',
284 fex='uni/infra/funcprof/accportgrp-{0}',
285 port_channel='uni/infra/funcprof/accbundle-{0}',
286 switch_port='uni/infra/funcprof/accportgrp-{0}',
287 vpc='uni/infra/funcprof/accbundle-{0}',
288)
289
290
291def main():
292 argument_spec = aci_argument_spec()
293 argument_spec.update(
294 leaf_interface_profile=dict(type='str', aliases=['leaf_interface_profile_name']), # Not required for querying all objects
295 access_port_selector=dict(type='str', aliases=['name', 'access_port_selector_name']), # Not required for querying all objects
296 description=dict(type='str'),
297 leaf_port_blk=dict(type='str', aliases=['leaf_port_blk_name']),
298 leaf_port_blk_description=dict(type='str'),
299 from_port=dict(type='str', aliases=['from', 'fromPort', 'from_port_range']),
300 to_port=dict(type='str', aliases=['to', 'toPort', 'to_port_range']),
301 from_card=dict(type='str', aliases=['from_card_range']),
302 to_card=dict(type='str', aliases=['to_card_range']),
303 policy_group=dict(type='str', aliases=['policy_group_name']),
304 interface_type=dict(type='str', default='switch_port', choices=['breakout', 'fex', 'port_channel', 'switch_port', 'vpc']),
305 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
306 )
307
308 module = AnsibleModule(
309 argument_spec=argument_spec,
310 supports_check_mode=True,
311 required_if=[
312 ['state', 'absent', ['leaf_interface_profile', 'access_port_selector']],
313 ['state', 'present', ['leaf_interface_profile', 'access_port_selector']],
314 ],
315 )
316
317 leaf_interface_profile = module.params['leaf_interface_profile']
318 access_port_selector = module.params['access_port_selector']
319 description = module.params['description']
320 leaf_port_blk = module.params['leaf_port_blk']
321 leaf_port_blk_description = module.params['leaf_port_blk_description']
322 from_port = module.params['from_port']
323 to_port = module.params['to_port']
324 from_card = module.params['from_card']
325 to_card = module.params['to_card']
326 policy_group = module.params['policy_group']
327 interface_type = module.params['interface_type']
328 state = module.params['state']
329
330 # Build child_configs dynamically
331 child_configs = [dict(
332 infraPortBlk=dict(
333 attributes=dict(
334 descr=leaf_port_blk_description,
335 name=leaf_port_blk,
336 fromPort=from_port,
337 toPort=to_port,
338 fromCard=from_card,
339 toCard=to_card,
340 ),
341 ),
342 )]
343
344 # Add infraRsAccBaseGrp only when policy_group was defined
345 if policy_group is not None:
346 child_configs.append(dict(
347 infraRsAccBaseGrp=dict(
348 attributes=dict(
349 tDn=INTERFACE_TYPE_MAPPING[interface_type].format(policy_group),
350 ),
351 ),
352 ))
353
354 aci = ACIModule(module)
355 aci.construct_url(
356 root_class=dict(
357 aci_class='infraAccPortP',
358 aci_rn='infra/accportprof-{0}'.format(leaf_interface_profile),
359 module_object=leaf_interface_profile,
360 target_filter={'name': leaf_interface_profile},
361 ),
362 subclass_1=dict(
363 aci_class='infraHPortS',
364 # NOTE: normal rn: hports-{name}-typ-{type}, hence here hardcoded to range for purposes of module
365 aci_rn='hports-{0}-typ-range'.format(access_port_selector),
366 module_object=access_port_selector,
367 target_filter={'name': access_port_selector},
368 ),
369 child_classes=['infraPortBlk', 'infraRsAccBaseGrp'],
370 )
371
372 aci.get_existing()
373
374 if state == 'present':
375 aci.payload(
376 aci_class='infraHPortS',
377 class_config=dict(
378 descr=description,
379 name=access_port_selector,
380 # type='range',
381 ),
382 child_configs=child_configs,
383 )
384
385 aci.get_diff(aci_class='infraHPortS')
386
387 aci.post_config()
388
389 elif state == 'absent':
390 aci.delete_config()
391
392 aci.exit_json()
393
394
395if __name__ == "__main__":
396 main()