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_l3out_extepg.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_l3out_extepg
16short_description: Manage External Network Instance Profile (ExtEpg) objects (l3extInstP:instP)
17description:
18- Manage External Network Instance Profile (ExtEpg) objects (l3extInstP:instP)
19version_added: '2.9'
20options:
21 tenant:
22 description:
23 - Name of an existing tenant.
24 type: str
25 required: yes
26 aliases: [ tenant_name ]
27 l3out:
28 description:
29 - Name of an existing L3Out.
30 type: str
31 required: yes
32 aliases: [ l3out_name ]
33 extepg:
34 description:
35 - Name of ExtEpg being created.
36 type: str
37 required: yes
38 aliases: [ extepg_name, name ]
39 description:
40 description:
41 - Description for the ExtEpg.
42 type: str
43 aliases: [ descr ]
44 preferred_group:
45 description:
46 - Whether ot not the EPG is part of the Preferred Group and can communicate without contracts.
47 - This is very convenient for migration scenarios, or when ACI is used for network automation but not for policy.
48 - The APIC defaults to C(no) when unset during creation.
49 type: bool
50 dscp:
51 description:
52 - The target Differentiated Service (DSCP) value.
53 - The APIC defaults to C(unspecified) when unset during creation.
54 type: str
55 choices: [ AF11, AF12, AF13, AF21, AF22, AF23, AF31, AF32, AF33, AF41, AF42, AF43, CS0, CS1, CS2, CS3, CS4, CS5, CS6, CS7, EF, VA, unspecified ]
56 aliases: [ target ]
57 state:
58 description:
59 - Use C(present) or C(absent) for adding or removing.
60 - Use C(query) for listing an object or multiple objects.
61 type: str
62 choices: [ absent, present, query ]
63 default: present
64extends_documentation_fragment: aci
65notes:
66- The C(tenant) and C(domain) and C(vrf) used must exist before using this module in your playbook.
67 The M(aci_tenant) and M(aci_domain) and M(aci_vrf) modules can be used for this.
68seealso:
69- module: aci_tenant
70- module: aci_domain
71- module: aci_vrf
72- name: APIC Management Information Model reference
73 description: More information about the internal APIC class B(l3ext:Out).
74 link: https://developer.cisco.com/docs/apic-mim-ref/
75author:
76- Rostyslav Davydenko (@rost-d)
77'''
78
79EXAMPLES = r'''
80- name: Add a new ExtEpg
81 aci_l3out_extepg:
82 host: apic
83 username: admin
84 password: SomeSecretPassword
85 tenant: production
86 l3out: prod_l3out
87 name: prod_extepg
88 description: ExtEpg for Production L3Out
89 state: present
90 delegate_to: localhost
91
92- name: Delete ExtEpg
93 extepg:
94 host: apic
95 username: admin
96 password: SomeSecretPassword
97 tenant: production
98 l3out: prod_l3out
99 name: prod_extepg
100 state: absent
101 delegate_to: localhost
102
103- name: Query ExtEpg information
104 aci_l3out_extepg:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 tenant: production
109 l3out: prod_l3out
110 name: prod_extepg
111 state: query
112 delegate_to: localhost
113 register: query_result
114'''
115
116RETURN = r'''
117current:
118 description: The existing configuration from the APIC after the module has finished
119 returned: success
120 type: list
121 sample:
122 [
123 {
124 "fvTenant": {
125 "attributes": {
126 "descr": "Production environment",
127 "dn": "uni/tn-production",
128 "name": "production",
129 "nameAlias": "",
130 "ownerKey": "",
131 "ownerTag": ""
132 }
133 }
134 }
135 ]
136error:
137 description: The error information as returned from the APIC
138 returned: failure
139 type: dict
140 sample:
141 {
142 "code": "122",
143 "text": "unknown managed object class foo"
144 }
145raw:
146 description: The raw output returned by the APIC REST API (xml or json)
147 returned: parse error
148 type: str
149 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
150sent:
151 description: The actual/minimal configuration pushed to the APIC
152 returned: info
153 type: list
154 sample:
155 {
156 "fvTenant": {
157 "attributes": {
158 "descr": "Production environment"
159 }
160 }
161 }
162previous:
163 description: The original configuration from the APIC before the module has started
164 returned: info
165 type: list
166 sample:
167 [
168 {
169 "fvTenant": {
170 "attributes": {
171 "descr": "Production",
172 "dn": "uni/tn-production",
173 "name": "production",
174 "nameAlias": "",
175 "ownerKey": "",
176 "ownerTag": ""
177 }
178 }
179 }
180 ]
181proposed:
182 description: The assembled configuration from the user-provided parameters
183 returned: info
184 type: dict
185 sample:
186 {
187 "fvTenant": {
188 "attributes": {
189 "descr": "Production environment",
190 "name": "production"
191 }
192 }
193 }
194filter_string:
195 description: The filter string used for the request
196 returned: failure or debug
197 type: str
198 sample: ?rsp-prop-include=config-only
199method:
200 description: The HTTP method used for the request to the APIC
201 returned: failure or debug
202 type: str
203 sample: POST
204response:
205 description: The HTTP response from the APIC
206 returned: failure or debug
207 type: str
208 sample: OK (30 bytes)
209status:
210 description: The HTTP status from the APIC
211 returned: failure or debug
212 type: int
213 sample: 200
214url:
215 description: The HTTP url used for the request to the APIC
216 returned: failure or debug
217 type: str
218 sample: https://10.11.12.13/api/mo/uni/tn-production.json
219'''
220
221from ansible.module_utils.basic import AnsibleModule
222from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
223
224
225def main():
226 argument_spec = aci_argument_spec()
227 argument_spec.update(
228 tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects
229 l3out=dict(type='str', aliases=['l3out_name']), # Not required for querying all objects
230 extepg=dict(type='str', aliases=['extepg_name', 'name']), # Not required for querying all objects
231 description=dict(type='str', aliases=['descr']),
232 preferred_group=dict(type='bool'),
233 dscp=dict(type='str',
234 choices=['AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42',
235 'AF43', 'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified'],
236 aliases=['target']),
237 state=dict(type='str', default='present', choices=['absent', 'present', 'query'])
238 )
239
240 module = AnsibleModule(
241 argument_spec=argument_spec,
242 supports_check_mode=True,
243 required_if=[
244 ['state', 'present', ['extepg', 'l3out', 'tenant']],
245 ['state', 'absent', ['extepg', 'l3out', 'tenant']],
246 ],
247 )
248
249 aci = ACIModule(module)
250
251 tenant = module.params['tenant']
252 l3out = module.params['l3out']
253 extepg = module.params['extepg']
254 description = module.params['description']
255 preferred_group = aci.boolean(module.params['preferred_group'], 'include', 'exclude')
256 dscp = module.params['dscp']
257 state = module.params['state']
258
259 aci.construct_url(
260 root_class=dict(
261 aci_class='fvTenant',
262 aci_rn='tn-{0}'.format(tenant),
263 module_object=tenant,
264 target_filter={'name': tenant},
265 ),
266 subclass_1=dict(
267 aci_class='l3extOut',
268 aci_rn='out-{0}'.format(l3out),
269 module_object=l3out,
270 target_filter={'name': l3out},
271 ),
272 subclass_2=dict(
273 aci_class='l3extInstP',
274 aci_rn='instP-{0}'.format(extepg),
275 module_object=extepg,
276 target_filter={'name': extepg},
277 ),
278 )
279
280 aci.get_existing()
281
282 if state == 'present':
283 aci.payload(
284 aci_class='l3extInstP',
285 class_config=dict(
286 name=extepg,
287 descr=description,
288 prefGrMemb=preferred_group,
289 targetDscp=dscp
290 ),
291 )
292
293 aci.get_diff(aci_class='l3extInstP')
294
295 aci.post_config()
296
297 elif state == 'absent':
298 aci.delete_config()
299
300 aci.exit_json()
301
302
303if __name__ == "__main__":
304 main()