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_vrf.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_vrf
16short_description: Manage contexts or VRFs (fv:Ctx)
17description:
18- Manage contexts or VRFs on Cisco ACI fabrics.
19- Each context is a private network associated to a tenant, i.e. VRF.
20version_added: '2.4'
21options:
22 tenant:
23 description:
24 - The name of the Tenant the VRF should belong to.
25 type: str
26 aliases: [ tenant_name ]
27 vrf:
28 description:
29 - The name of the VRF.
30 type: str
31 aliases: [ context, name, vrf_name ]
32 policy_control_direction:
33 description:
34 - Determines if the policy should be enforced by the fabric on ingress or egress.
35 type: str
36 choices: [ egress, ingress ]
37 policy_control_preference:
38 description:
39 - Determines if the fabric should enforce contract policies to allow routing and packet forwarding.
40 type: str
41 choices: [ enforced, unenforced ]
42 description:
43 description:
44 - The description for the VRF.
45 type: str
46 aliases: [ descr ]
47 state:
48 description:
49 - Use C(present) or C(absent) for adding or removing.
50 - Use C(query) for listing an object or multiple objects.
51 type: str
52 choices: [ absent, present, query ]
53 default: present
54extends_documentation_fragment: aci
55notes:
56- The C(tenant) used must exist before using this module in your playbook.
57 The M(aci_tenant) module can be used for this.
58seealso:
59- module: aci_tenant
60- name: APIC Management Information Model reference
61 description: More information about the internal APIC class B(fv:Ctx).
62 link: https://developer.cisco.com/docs/apic-mim-ref/
63author:
64- Jacob McGill (@jmcgill298)
65'''
66
67EXAMPLES = r'''
68- name: Add a new VRF to a tenant
69 aci_vrf:
70 host: apic
71 username: admin
72 password: SomeSecretPassword
73 vrf: vrf_lab
74 tenant: lab_tenant
75 descr: Lab VRF
76 policy_control_preference: enforced
77 policy_control_direction: ingress
78 state: present
79 delegate_to: localhost
80
81- name: Remove a VRF for a tenant
82 aci_vrf:
83 host: apic
84 username: admin
85 password: SomeSecretPassword
86 vrf: vrf_lab
87 tenant: lab_tenant
88 state: absent
89 delegate_to: localhost
90
91- name: Query a VRF of a tenant
92 aci_vrf:
93 host: apic
94 username: admin
95 password: SomeSecretPassword
96 vrf: vrf_lab
97 tenant: lab_tenant
98 state: query
99 delegate_to: localhost
100 register: query_result
101
102- name: Query all VRFs
103 aci_vrf:
104 host: apic
105 username: admin
106 password: SomeSecretPassword
107 state: query
108 delegate_to: localhost
109 register: query_result
110'''
111
112RETURN = r'''
113current:
114 description: The existing configuration from the APIC after the module has finished
115 returned: success
116 type: list
117 sample:
118 [
119 {
120 "fvTenant": {
121 "attributes": {
122 "descr": "Production environment",
123 "dn": "uni/tn-production",
124 "name": "production",
125 "nameAlias": "",
126 "ownerKey": "",
127 "ownerTag": ""
128 }
129 }
130 }
131 ]
132error:
133 description: The error information as returned from the APIC
134 returned: failure
135 type: dict
136 sample:
137 {
138 "code": "122",
139 "text": "unknown managed object class foo"
140 }
141raw:
142 description: The raw output returned by the APIC REST API (xml or json)
143 returned: parse error
144 type: str
145 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
146sent:
147 description: The actual/minimal configuration pushed to the APIC
148 returned: info
149 type: list
150 sample:
151 {
152 "fvTenant": {
153 "attributes": {
154 "descr": "Production environment"
155 }
156 }
157 }
158previous:
159 description: The original configuration from the APIC before the module has started
160 returned: info
161 type: list
162 sample:
163 [
164 {
165 "fvTenant": {
166 "attributes": {
167 "descr": "Production",
168 "dn": "uni/tn-production",
169 "name": "production",
170 "nameAlias": "",
171 "ownerKey": "",
172 "ownerTag": ""
173 }
174 }
175 }
176 ]
177proposed:
178 description: The assembled configuration from the user-provided parameters
179 returned: info
180 type: dict
181 sample:
182 {
183 "fvTenant": {
184 "attributes": {
185 "descr": "Production environment",
186 "name": "production"
187 }
188 }
189 }
190filter_string:
191 description: The filter string used for the request
192 returned: failure or debug
193 type: str
194 sample: ?rsp-prop-include=config-only
195method:
196 description: The HTTP method used for the request to the APIC
197 returned: failure or debug
198 type: str
199 sample: POST
200response:
201 description: The HTTP response from the APIC
202 returned: failure or debug
203 type: str
204 sample: OK (30 bytes)
205status:
206 description: The HTTP status from the APIC
207 returned: failure or debug
208 type: int
209 sample: 200
210url:
211 description: The HTTP url used for the request to the APIC
212 returned: failure or debug
213 type: str
214 sample: https://10.11.12.13/api/mo/uni/tn-production.json
215'''
216
217from ansible.module_utils.basic import AnsibleModule
218from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
219
220
221def main():
222 argument_spec = aci_argument_spec()
223 argument_spec.update(
224 tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects
225 vrf=dict(type='str', aliases=['context', 'name', 'vrf_name']), # Not required for querying all objects
226 description=dict(type='str', aliases=['descr']),
227 policy_control_direction=dict(type='str', choices=['egress', 'ingress']),
228 policy_control_preference=dict(type='str', choices=['enforced', 'unenforced']),
229 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
230 )
231
232 module = AnsibleModule(
233 argument_spec=argument_spec,
234 supports_check_mode=True,
235 required_if=[
236 ['state', 'absent', ['tenant', 'vrf']],
237 ['state', 'present', ['tenant', 'vrf']],
238 ],
239 )
240
241 description = module.params['description']
242 policy_control_direction = module.params['policy_control_direction']
243 policy_control_preference = module.params['policy_control_preference']
244 state = module.params['state']
245 tenant = module.params['tenant']
246 vrf = module.params['vrf']
247
248 aci = ACIModule(module)
249 aci.construct_url(
250 root_class=dict(
251 aci_class='fvTenant',
252 aci_rn='tn-{0}'.format(tenant),
253 module_object=tenant,
254 target_filter={'name': tenant},
255 ),
256 subclass_1=dict(
257 aci_class='fvCtx',
258 aci_rn='ctx-{0}'.format(vrf),
259 module_object=vrf,
260 target_filter={'name': vrf},
261 ),
262 )
263
264 aci.get_existing()
265
266 if state == 'present':
267 aci.payload(
268 aci_class='fvCtx',
269 class_config=dict(
270 descr=description,
271 pcEnfDir=policy_control_direction,
272 pcEnfPref=policy_control_preference,
273 name=vrf,
274 ),
275 )
276
277 aci.get_diff(aci_class='fvCtx')
278
279 aci.post_config()
280
281 elif state == 'absent':
282 aci.delete_config()
283
284 aci.exit_json()
285
286
287if __name__ == "__main__":
288 main()