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_interface_policy_leaf_policy_group.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_interface_policy_leaf_policy_group
17short_description: Manage fabric interface policy leaf policy groups (infra:AccBndlGrp, infra:AccPortGrp)
18description:
19- Manage fabric interface policy leaf policy groups on Cisco ACI fabrics.
20version_added: '2.5'
21options:
22 policy_group:
23 description:
24 - Name of the leaf policy group to be added/deleted.
25 type: str
26 aliases: [ name, policy_group_name ]
27 description:
28 description:
29 - Description for the leaf policy group to be created.
30 type: str
31 aliases: [ descr ]
32 lag_type:
33 description:
34 - Selector for the type of leaf policy group we want to create.
35 - C(leaf) for Leaf Access Port Policy Group
36 - C(link) for Port Channel (PC)
37 - C(node) for Virtual Port Channel (VPC)
38 type: str
39 required: yes
40 choices: [ leaf, link, node ]
41 aliases: [ lag_type_name ]
42 link_level_policy:
43 description:
44 - Choice of link_level_policy to be used as part of the leaf policy group to be created.
45 type: str
46 aliases: [ link_level_policy_name ]
47 cdp_policy:
48 description:
49 - Choice of cdp_policy to be used as part of the leaf policy group to be created.
50 type: str
51 aliases: [ cdp_policy_name ]
52 mcp_policy:
53 description:
54 - Choice of mcp_policy to be used as part of the leaf policy group to be created.
55 type: str
56 aliases: [ mcp_policy_name ]
57 lldp_policy:
58 description:
59 - Choice of lldp_policy to be used as part of the leaf policy group to be created.
60 type: str
61 aliases: [ lldp_policy_name ]
62 stp_interface_policy:
63 description:
64 - Choice of stp_interface_policy to be used as part of the leaf policy group to be created.
65 type: str
66 aliases: [ stp_interface_policy_name ]
67 egress_data_plane_policing_policy:
68 description:
69 - Choice of egress_data_plane_policing_policy to be used as part of the leaf policy group to be created.
70 type: str
71 aliases: [ egress_data_plane_policing_policy_name ]
72 ingress_data_plane_policing_policy:
73 description:
74 - Choice of ingress_data_plane_policing_policy to be used as part of the leaf policy group to be created.
75 type: str
76 aliases: [ ingress_data_plane_policing_policy_name ]
77 priority_flow_control_policy:
78 description:
79 - Choice of priority_flow_control_policy to be used as part of the leaf policy group to be created.
80 type: str
81 aliases: [ priority_flow_control_policy_name ]
82 fibre_channel_interface_policy:
83 description:
84 - Choice of fibre_channel_interface_policy to be used as part of the leaf policy group to be created.
85 type: str
86 aliases: [ fibre_channel_interface_policy_name ]
87 slow_drain_policy:
88 description:
89 - Choice of slow_drain_policy to be used as part of the leaf policy group to be created.
90 type: str
91 aliases: [ slow_drain_policy_name ]
92 port_channel_policy:
93 description:
94 - Choice of port_channel_policy to be used as part of the leaf policy group to be created.
95 type: str
96 aliases: [ port_channel_policy_name ]
97 monitoring_policy:
98 description:
99 - Choice of monitoring_policy to be used as part of the leaf policy group to be created.
100 type: str
101 aliases: [ monitoring_policy_name ]
102 storm_control_interface_policy:
103 description:
104 - Choice of storm_control_interface_policy to be used as part of the leaf policy group to be created.
105 type: str
106 aliases: [ storm_control_interface_policy_name ]
107 l2_interface_policy:
108 description:
109 - Choice of l2_interface_policy to be used as part of the leaf policy group to be created.
110 type: str
111 aliases: [ l2_interface_policy_name ]
112 port_security_policy:
113 description:
114 - Choice of port_security_policy to be used as part of the leaf policy group to be created.
115 type: str
116 aliases: [ port_security_policy_name ]
117 aep:
118 description:
119 - Choice of attached_entity_profile (AEP) to be used as part of the leaf policy group to be created.
120 type: str
121 aliases: [ aep_name ]
122 state:
123 description:
124 - Use C(present) or C(absent) for adding or removing.
125 - Use C(query) for listing an object or multiple objects.
126 type: str
127 choices: [ absent, present, query ]
128 default: present
129extends_documentation_fragment: aci
130notes:
131- When using the module please select the appropriate link_aggregation_type (lag_type).
132 C(link) for Port Channel(PC), C(node) for Virtual Port Channel(VPC) and C(leaf) for Leaf Access Port Policy Group.
133seealso:
134- name: APIC Management Information Model reference
135 description: More information about the internal APIC classes B(infra:AccBndlGrp) and B(infra:AccPortGrp).
136 link: https://developer.cisco.com/docs/apic-mim-ref/
137author:
138- Bruno Calogero (@brunocalogero)
139'''
140
141EXAMPLES = r'''
142- name: Create a Port Channel (PC) Interface Policy Group
143 aci_interface_policy_leaf_policy_group:
144 host: apic
145 username: admin
146 password: SomeSecretPassword
147 lag_type: link
148 policy_group: policygroupname
149 description: policygroupname description
150 link_level_policy: whateverlinklevelpolicy
151 fibre_channel_interface_policy: whateverfcpolicy
152 state: present
153 delegate_to: localhost
154
155- name: Create a Virtual Port Channel (VPC) Interface Policy Group (no description)
156 aci_interface_policy_leaf_policy_group:
157 host: apic
158 username: admin
159 password: SomeSecretPassword
160 lag_type: node
161 policy_group: policygroupname
162 link_level_policy: whateverlinklevelpolicy
163 fibre_channel_interface_policy: whateverfcpolicy
164 state: present
165 delegate_to: localhost
166
167- name: Create a Leaf Access Port Policy Group (no description)
168 aci_interface_policy_leaf_policy_group:
169 host: apic
170 username: admin
171 password: SomeSecretPassword
172 lag_type: leaf
173 policy_group: policygroupname
174 link_level_policy: whateverlinklevelpolicy
175 fibre_channel_interface_policy: whateverfcpolicy
176 state: present
177 delegate_to: localhost
178
179- name: Query all Leaf Access Port Policy Groups of type link
180 aci_interface_policy_leaf_policy_group:
181 host: apic
182 username: admin
183 password: SomeSecretPassword
184 lag_type: link
185 state: query
186 delegate_to: localhost
187 register: query_result
188
189- name: Query a specific Lead Access Port Policy Group
190 aci_interface_policy_leaf_policy_group:
191 host: apic
192 username: admin
193 password: SomeSecretPassword
194 lag_type: leaf
195 policy_group: policygroupname
196 state: query
197 delegate_to: localhost
198 register: query_result
199
200- name: Delete an Interface policy Leaf Policy Group
201 aci_interface_policy_leaf_policy_group:
202 host: apic
203 username: admin
204 password: SomeSecretPassword
205 lag_type: type_name
206 policy_group: policygroupname
207 state: absent
208 delegate_to: localhost
209'''
210
211RETURN = r'''
212current:
213 description: The existing configuration from the APIC after the module has finished
214 returned: success
215 type: list
216 sample:
217 [
218 {
219 "fvTenant": {
220 "attributes": {
221 "descr": "Production environment",
222 "dn": "uni/tn-production",
223 "name": "production",
224 "nameAlias": "",
225 "ownerKey": "",
226 "ownerTag": ""
227 }
228 }
229 }
230 ]
231error:
232 description: The error information as returned from the APIC
233 returned: failure
234 type: dict
235 sample:
236 {
237 "code": "122",
238 "text": "unknown managed object class foo"
239 }
240raw:
241 description: The raw output returned by the APIC REST API (xml or json)
242 returned: parse error
243 type: str
244 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
245sent:
246 description: The actual/minimal configuration pushed to the APIC
247 returned: info
248 type: list
249 sample:
250 {
251 "fvTenant": {
252 "attributes": {
253 "descr": "Production environment"
254 }
255 }
256 }
257previous:
258 description: The original configuration from the APIC before the module has started
259 returned: info
260 type: list
261 sample:
262 [
263 {
264 "fvTenant": {
265 "attributes": {
266 "descr": "Production",
267 "dn": "uni/tn-production",
268 "name": "production",
269 "nameAlias": "",
270 "ownerKey": "",
271 "ownerTag": ""
272 }
273 }
274 }
275 ]
276proposed:
277 description: The assembled configuration from the user-provided parameters
278 returned: info
279 type: dict
280 sample:
281 {
282 "fvTenant": {
283 "attributes": {
284 "descr": "Production environment",
285 "name": "production"
286 }
287 }
288 }
289filter_string:
290 description: The filter string used for the request
291 returned: failure or debug
292 type: str
293 sample: ?rsp-prop-include=config-only
294method:
295 description: The HTTP method used for the request to the APIC
296 returned: failure or debug
297 type: str
298 sample: POST
299response:
300 description: The HTTP response from the APIC
301 returned: failure or debug
302 type: str
303 sample: OK (30 bytes)
304status:
305 description: The HTTP status from the APIC
306 returned: failure or debug
307 type: int
308 sample: 200
309url:
310 description: The HTTP url used for the request to the APIC
311 returned: failure or debug
312 type: str
313 sample: https://10.11.12.13/api/mo/uni/tn-production.json
314'''
315
316from ansible.module_utils.basic import AnsibleModule
317from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
318
319
320def main():
321 argument_spec = aci_argument_spec()
322 argument_spec.update(
323 # NOTE: Since this module needs to include both infra:AccBndlGrp (for PC and VPC) and infra:AccPortGrp (for leaf access port policy group):
324 # NOTE: I'll allow the user to make the choice here (link(PC), node(VPC), leaf(leaf-access port policy group))
325 lag_type=dict(type='str', required=True, aliases=['lag_type_name'], choices=['leaf', 'link', 'node']),
326 policy_group=dict(type='str', aliases=['name', 'policy_group_name']), # Not required for querying all objects
327 description=dict(type='str', aliases=['descr']),
328 link_level_policy=dict(type='str', aliases=['link_level_policy_name']),
329 cdp_policy=dict(type='str', aliases=['cdp_policy_name']),
330 mcp_policy=dict(type='str', aliases=['mcp_policy_name']),
331 lldp_policy=dict(type='str', aliases=['lldp_policy_name']),
332 stp_interface_policy=dict(type='str', aliases=['stp_interface_policy_name']),
333 egress_data_plane_policing_policy=dict(type='str', aliases=['egress_data_plane_policing_policy_name']),
334 ingress_data_plane_policing_policy=dict(type='str', aliases=['ingress_data_plane_policing_policy_name']),
335 priority_flow_control_policy=dict(type='str', aliases=['priority_flow_control_policy_name']),
336 fibre_channel_interface_policy=dict(type='str', aliases=['fibre_channel_interface_policy_name']),
337 slow_drain_policy=dict(type='str', aliases=['slow_drain_policy_name']),
338 port_channel_policy=dict(type='str', aliases=['port_channel_policy_name']),
339 monitoring_policy=dict(type='str', aliases=['monitoring_policy_name']),
340 storm_control_interface_policy=dict(type='str', aliases=['storm_control_interface_policy_name']),
341 l2_interface_policy=dict(type='str', aliases=['l2_interface_policy_name']),
342 port_security_policy=dict(type='str', aliases=['port_security_policy_name']),
343 aep=dict(type='str', aliases=['aep_name']),
344 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
345 )
346
347 module = AnsibleModule(
348 argument_spec=argument_spec,
349 supports_check_mode=True,
350 required_if=[
351 ['state', 'absent', ['policy_group']],
352 ['state', 'present', ['policy_group']],
353 ],
354 )
355
356 policy_group = module.params['policy_group']
357 description = module.params['description']
358 lag_type = module.params['lag_type']
359 link_level_policy = module.params['link_level_policy']
360 cdp_policy = module.params['cdp_policy']
361 mcp_policy = module.params['mcp_policy']
362 lldp_policy = module.params['lldp_policy']
363 stp_interface_policy = module.params['stp_interface_policy']
364 egress_data_plane_policing_policy = module.params['egress_data_plane_policing_policy']
365 ingress_data_plane_policing_policy = module.params['ingress_data_plane_policing_policy']
366 priority_flow_control_policy = module.params['priority_flow_control_policy']
367 fibre_channel_interface_policy = module.params['fibre_channel_interface_policy']
368 slow_drain_policy = module.params['slow_drain_policy']
369 port_channel_policy = module.params['port_channel_policy']
370 monitoring_policy = module.params['monitoring_policy']
371 storm_control_interface_policy = module.params['storm_control_interface_policy']
372 l2_interface_policy = module.params['l2_interface_policy']
373 port_security_policy = module.params['port_security_policy']
374 aep = module.params['aep']
375 state = module.params['state']
376
377 if lag_type == 'leaf':
378 aci_class_name = 'infraAccPortGrp'
379 dn_name = 'accportgrp'
380 class_config_dict = dict(
381 name=policy_group,
382 descr=description,
383 )
384 # Reset for target_filter
385 lag_type = None
386 elif lag_type in ('link', 'node'):
387 aci_class_name = 'infraAccBndlGrp'
388 dn_name = 'accbundle'
389 class_config_dict = dict(
390 name=policy_group,
391 descr=description,
392 lagT=lag_type,
393 )
394
395 child_configs = [
396 dict(
397 infraRsCdpIfPol=dict(
398 attributes=dict(
399 tnCdpIfPolName=cdp_policy,
400 ),
401 ),
402 ),
403 dict(
404 infraRsFcIfPol=dict(
405 attributes=dict(
406 tnFcIfPolName=fibre_channel_interface_policy,
407 ),
408 ),
409 ),
410 dict(
411 infraRsHIfPol=dict(
412 attributes=dict(
413 tnFabricHIfPolName=link_level_policy,
414 ),
415 ),
416 ),
417 dict(
418 infraRsL2IfPol=dict(
419 attributes=dict(
420 tnL2IfPolName=l2_interface_policy,
421 ),
422 ),
423 ),
424 dict(
425 infraRsL2PortSecurityPol=dict(
426 attributes=dict(
427 tnL2PortSecurityPolName=port_security_policy,
428 ),
429 ),
430 ),
431 dict(
432 infraRsLacpPol=dict(
433 attributes=dict(
434 tnLacpLagPolName=port_channel_policy,
435 ),
436 ),
437 ),
438 dict(
439 infraRsLldpIfPol=dict(
440 attributes=dict(
441 tnLldpIfPolName=lldp_policy,
442 ),
443 ),
444 ),
445 dict(
446 infraRsMcpIfPol=dict(
447 attributes=dict(
448 tnMcpIfPolName=mcp_policy,
449 ),
450 ),
451 ),
452 dict(
453 infraRsMonIfInfraPol=dict(
454 attributes=dict(
455 tnMonInfraPolName=monitoring_policy,
456 ),
457 ),
458 ),
459 dict(
460 infraRsQosEgressDppIfPol=dict(
461 attributes=dict(
462 tnQosDppPolName=egress_data_plane_policing_policy,
463 ),
464 ),
465 ),
466 dict(
467 infraRsQosIngressDppIfPol=dict(
468 attributes=dict(
469 tnQosDppPolName=ingress_data_plane_policing_policy,
470 ),
471 ),
472 ),
473 dict(
474 infraRsQosPfcIfPol=dict(
475 attributes=dict(
476 tnQosPfcIfPolName=priority_flow_control_policy,
477 ),
478 ),
479 ),
480 dict(
481 infraRsQosSdIfPol=dict(
482 attributes=dict(
483 tnQosSdIfPolName=slow_drain_policy,
484 ),
485 ),
486 ),
487 dict(
488 infraRsStormctrlIfPol=dict(
489 attributes=dict(
490 tnStormctrlIfPolName=storm_control_interface_policy,
491 ),
492 ),
493 ),
494 dict(
495 infraRsStpIfPol=dict(
496 attributes=dict(
497 tnStpIfPolName=stp_interface_policy,
498 ),
499 ),
500 ),
501 ]
502
503 # Add infraRsattEntP binding only when aep was defined
504 if aep is not None:
505 child_configs.append(dict(
506 infraRsAttEntP=dict(
507 attributes=dict(
508 tDn='uni/infra/attentp-{0}'.format(aep),
509 ),
510 ),
511 ))
512
513 aci = ACIModule(module)
514 aci.construct_url(
515 root_class=dict(
516 aci_class=aci_class_name,
517 aci_rn='infra/funcprof/{0}-{1}'.format(dn_name, policy_group),
518 module_object=policy_group,
519 target_filter={'name': policy_group, 'lagT': lag_type},
520 ),
521 child_classes=[
522 'infraRsAttEntP',
523 'infraRsCdpIfPol',
524 'infraRsFcIfPol',
525 'infraRsHIfPol',
526 'infraRsL2IfPol',
527 'infraRsL2PortSecurityPol',
528 'infraRsLacpPol',
529 'infraRsLldpIfPol',
530 'infraRsMcpIfPol',
531 'infraRsMonIfInfraPol',
532 'infraRsQosEgressDppIfPol',
533 'infraRsQosIngressDppIfPol',
534 'infraRsQosPfcIfPol',
535 'infraRsQosSdIfPol',
536 'infraRsStormctrlIfPol',
537 'infraRsStpIfPol',
538 ],
539 )
540
541 aci.get_existing()
542
543 if state == 'present':
544 aci.payload(
545 aci_class=aci_class_name,
546 class_config=class_config_dict,
547 child_configs=child_configs,
548 )
549
550 aci.get_diff(aci_class=aci_class_name)
551
552 aci.post_config()
553
554 elif state == 'absent':
555 aci.delete_config()
556
557 aci.exit_json()
558
559
560if __name__ == "__main__":
561 main()