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_l2.py
Go to the documentation of this file.
1#!/usr/bin/python
2# -*- coding: utf-8 -*-
3
4# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6from __future__ import absolute_import, division, print_function
7__metaclass__ = type
8
9ANSIBLE_METADATA = {'metadata_version': '1.1',
10 'status': ['preview'],
11 'supported_by': 'certified'}
12
13DOCUMENTATION = r'''
14---
15module: aci_interface_policy_l2
16short_description: Manage Layer 2 interface policies (l2:IfPol)
17description:
18- Manage Layer 2 interface policies on Cisco ACI fabrics.
19version_added: '2.4'
20options:
21 l2_policy:
22 description:
23 - The name of the Layer 2 interface policy.
24 type: str
25 required: yes
26 aliases: [ name ]
27 description:
28 description:
29 - The description of the Layer 2 interface policy.
30 type: str
31 aliases: [ descr ]
32 qinq:
33 description:
34 - Determines if QinQ is disabled or if the port should be considered a core or edge port.
35 - The APIC defaults to C(disabled) when unset during creation.
36 type: str
37 choices: [ core, disabled, edge ]
38 vepa:
39 description:
40 - Determines if Virtual Ethernet Port Aggregator is disabled or enabled.
41 - The APIC defaults to C(no) when unset during creation.
42 type: bool
43 vlan_scope:
44 description:
45 - The scope of the VLAN.
46 - The APIC defaults to C(global) when unset during creation.
47 type: str
48 choices: [ global, portlocal ]
49 state:
50 description:
51 - Use C(present) or C(absent) for adding or removing.
52 - Use C(query) for listing an object or multiple objects.
53 type: str
54 choices: [ absent, present, query ]
55 default: present
56extends_documentation_fragment: aci
57seealso:
58- name: APIC Management Information Model reference
59 description: More information about the internal APIC class B(l2:IfPol).
60 link: https://developer.cisco.com/docs/apic-mim-ref/
61author:
62- Dag Wieers (@dagwieers)
63'''
64
65EXAMPLES = r'''
66- aci_interface_policy_l2:
67 host: '{{ hostname }}'
68 username: '{{ username }}'
69 password: '{{ password }}'
70 l2_policy: '{{ l2_policy }}'
71 vlan_scope: '{{ vlan_policy }}'
72 description: '{{ description }}'
73 delegate_to: localhost
74'''
75
76RETURN = r'''
77current:
78 description: The existing configuration from the APIC after the module has finished
79 returned: success
80 type: list
81 sample:
82 [
83 {
84 "fvTenant": {
85 "attributes": {
86 "descr": "Production environment",
87 "dn": "uni/tn-production",
88 "name": "production",
89 "nameAlias": "",
90 "ownerKey": "",
91 "ownerTag": ""
92 }
93 }
94 }
95 ]
96error:
97 description: The error information as returned from the APIC
98 returned: failure
99 type: dict
100 sample:
101 {
102 "code": "122",
103 "text": "unknown managed object class foo"
104 }
105raw:
106 description: The raw output returned by the APIC REST API (xml or json)
107 returned: parse error
108 type: str
109 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
110sent:
111 description: The actual/minimal configuration pushed to the APIC
112 returned: info
113 type: list
114 sample:
115 {
116 "fvTenant": {
117 "attributes": {
118 "descr": "Production environment"
119 }
120 }
121 }
122previous:
123 description: The original configuration from the APIC before the module has started
124 returned: info
125 type: list
126 sample:
127 [
128 {
129 "fvTenant": {
130 "attributes": {
131 "descr": "Production",
132 "dn": "uni/tn-production",
133 "name": "production",
134 "nameAlias": "",
135 "ownerKey": "",
136 "ownerTag": ""
137 }
138 }
139 }
140 ]
141proposed:
142 description: The assembled configuration from the user-provided parameters
143 returned: info
144 type: dict
145 sample:
146 {
147 "fvTenant": {
148 "attributes": {
149 "descr": "Production environment",
150 "name": "production"
151 }
152 }
153 }
154filter_string:
155 description: The filter string used for the request
156 returned: failure or debug
157 type: str
158 sample: ?rsp-prop-include=config-only
159method:
160 description: The HTTP method used for the request to the APIC
161 returned: failure or debug
162 type: str
163 sample: POST
164response:
165 description: The HTTP response from the APIC
166 returned: failure or debug
167 type: str
168 sample: OK (30 bytes)
169status:
170 description: The HTTP status from the APIC
171 returned: failure or debug
172 type: int
173 sample: 200
174url:
175 description: The HTTP url used for the request to the APIC
176 returned: failure or debug
177 type: str
178 sample: https://10.11.12.13/api/mo/uni/tn-production.json
179'''
180
181from ansible.module_utils.basic import AnsibleModule
182from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
183
184# Mapping dicts are used to normalize the proposed data to what the APIC expects, which will keep diffs accurate
185QINQ_MAPPING = dict(
186 core='corePort',
187 disabled='disabled',
188 edge='edgePort',
189)
190
191
192def main():
193 argument_spec = aci_argument_spec()
194 argument_spec.update(
195 l2_policy=dict(type='str', aliases=['name']), # Not required for querying all policies
196 description=dict(type='str', aliases=['descr']),
197 vlan_scope=dict(type='str', choices=['global', 'portlocal']), # No default provided on purpose
198 qinq=dict(type='str', choices=['core', 'disabled', 'edge']),
199 vepa=dict(type='bool'),
200 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
201 )
202
203 module = AnsibleModule(
204 argument_spec=argument_spec,
205 supports_check_mode=True,
206 required_if=[
207 ['state', 'absent', ['l2_policy']],
208 ['state', 'present', ['l2_policy']],
209 ],
210 )
211
212 aci = ACIModule(module)
213
214 l2_policy = module.params['l2_policy']
215 vlan_scope = module.params['vlan_scope']
216 qinq = module.params['qinq']
217 if qinq is not None:
218 qinq = QINQ_MAPPING[qinq]
219 vepa = aci.boolean(module.params['vepa'], 'enabled', 'disabled')
220 description = module.params['description']
221 state = module.params['state']
222
223 aci.construct_url(
224 root_class=dict(
225 aci_class='l2IfPol',
226 aci_rn='infra/l2IfP-{0}'.format(l2_policy),
227 module_object=l2_policy,
228 target_filter={'name': l2_policy},
229 ),
230 )
231
232 aci.get_existing()
233
234 if state == 'present':
235 aci.payload(
236 aci_class='l2IfPol',
237 class_config=dict(
238 name=l2_policy,
239 descr=description,
240 vlanScope=vlan_scope,
241 qinq=qinq, vepa=vepa,
242 ),
243 )
244
245 aci.get_diff(aci_class='l2IfPol')
246
247 aci.post_config()
248
249 elif state == 'absent':
250 aci.delete_config()
251
252 aci.exit_json()
253
254
255if __name__ == "__main__":
256 main()