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_contract.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_contract
16short_description: Manage contract resources (vz:BrCP)
17description:
18- Manage Contract resources on Cisco ACI fabrics.
19version_added: '2.4'
20options:
21 contract:
22 description:
23 - The name of the contract.
24 type: str
25 required: yes
26 aliases: [ contract_name, name ]
27 description:
28 description:
29 - Description for the contract.
30 type: str
31 aliases: [ descr ]
32 tenant:
33 description:
34 - The name of the tenant.
35 type: str
36 required: yes
37 aliases: [ tenant_name ]
38 scope:
39 description:
40 - The scope of a service contract.
41 - The APIC defaults to C(context) when unset during creation.
42 type: str
43 choices: [ application-profile, context, global, tenant ]
44 priority:
45 description:
46 - The desired QoS class to be used.
47 - The APIC defaults to C(unspecified) when unset during creation.
48 type: str
49 choices: [ level1, level2, level3, unspecified ]
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- This module does not manage Contract Subjects, see M(aci_contract_subject) to do this.
67 Contract Subjects can still be removed using this module.
68- The C(tenant) used must exist before using this module in your playbook.
69 The M(aci_tenant) module can be used for this.
70seealso:
71- module: aci_contract_subject
72- module: aci_tenant
73- name: APIC Management Information Model reference
74 description: More information about the internal APIC class B(vz:BrCP).
75 link: https://developer.cisco.com/docs/apic-mim-ref/
76author:
77- Dag Wieers (@dagwieers)
78'''
79
80EXAMPLES = r'''
81- name: Add a new contract
82 aci_contract:
83 host: apic
84 username: admin
85 password: SomeSecretPassword
86 tenant: production
87 contract: web_to_db
88 description: Communication between web-servers and database
89 scope: application-profile
90 state: present
91 delegate_to: localhost
92
93- name: Remove an existing contract
94 aci_contract:
95 host: apic
96 username: admin
97 password: SomeSecretPassword
98 tenant: production
99 contract: web_to_db
100 state: absent
101 delegate_to: localhost
102
103- name: Query a specific contract
104 aci_contract:
105 host: apic
106 username: admin
107 password: SomeSecretPassword
108 tenant: production
109 contract: web_to_db
110 state: query
111 delegate_to: localhost
112 register: query_result
113
114- name: Query all contracts
115 aci_contract:
116 host: apic
117 username: admin
118 password: SomeSecretPassword
119 state: query
120 delegate_to: localhost
121 register: query_result
122'''
123
124RETURN = r'''
125current:
126 description: The existing configuration from the APIC after the module has finished
127 returned: success
128 type: list
129 sample:
130 [
131 {
132 "fvTenant": {
133 "attributes": {
134 "descr": "Production environment",
135 "dn": "uni/tn-production",
136 "name": "production",
137 "nameAlias": "",
138 "ownerKey": "",
139 "ownerTag": ""
140 }
141 }
142 }
143 ]
144error:
145 description: The error information as returned from the APIC
146 returned: failure
147 type: dict
148 sample:
149 {
150 "code": "122",
151 "text": "unknown managed object class foo"
152 }
153raw:
154 description: The raw output returned by the APIC REST API (xml or json)
155 returned: parse error
156 type: str
157 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
158sent:
159 description: The actual/minimal configuration pushed to the APIC
160 returned: info
161 type: list
162 sample:
163 {
164 "fvTenant": {
165 "attributes": {
166 "descr": "Production environment"
167 }
168 }
169 }
170previous:
171 description: The original configuration from the APIC before the module has started
172 returned: info
173 type: list
174 sample:
175 [
176 {
177 "fvTenant": {
178 "attributes": {
179 "descr": "Production",
180 "dn": "uni/tn-production",
181 "name": "production",
182 "nameAlias": "",
183 "ownerKey": "",
184 "ownerTag": ""
185 }
186 }
187 }
188 ]
189proposed:
190 description: The assembled configuration from the user-provided parameters
191 returned: info
192 type: dict
193 sample:
194 {
195 "fvTenant": {
196 "attributes": {
197 "descr": "Production environment",
198 "name": "production"
199 }
200 }
201 }
202filter_string:
203 description: The filter string used for the request
204 returned: failure or debug
205 type: str
206 sample: ?rsp-prop-include=config-only
207method:
208 description: The HTTP method used for the request to the APIC
209 returned: failure or debug
210 type: str
211 sample: POST
212response:
213 description: The HTTP response from the APIC
214 returned: failure or debug
215 type: str
216 sample: OK (30 bytes)
217status:
218 description: The HTTP status from the APIC
219 returned: failure or debug
220 type: int
221 sample: 200
222url:
223 description: The HTTP url used for the request to the APIC
224 returned: failure or debug
225 type: str
226 sample: https://10.11.12.13/api/mo/uni/tn-production.json
227'''
228
229from ansible.module_utils.basic import AnsibleModule
230from ansible.module_utils.network.aci.aci import ACIModule, aci_argument_spec
231
232
233def main():
234 argument_spec = aci_argument_spec()
235 argument_spec.update(
236 contract=dict(type='str', aliases=['contract_name', 'name']), # Not required for querying all objects
237 tenant=dict(type='str', aliases=['tenant_name']), # Not required for querying all objects
238 description=dict(type='str', aliases=['descr']),
239 scope=dict(type='str', choices=['application-profile', 'context', 'global', 'tenant']),
240 priority=dict(type='str', choices=['level1', 'level2', 'level3', 'unspecified']), # No default provided on purpose
241 dscp=dict(type='str',
242 choices=['AF11', 'AF12', 'AF13', 'AF21', 'AF22', 'AF23', 'AF31', 'AF32', 'AF33', 'AF41', 'AF42', 'AF43',
243 'CS0', 'CS1', 'CS2', 'CS3', 'CS4', 'CS5', 'CS6', 'CS7', 'EF', 'VA', 'unspecified'],
244 aliases=['target']), # No default provided on purpose
245 state=dict(type='str', default='present', choices=['absent', 'present', 'query']),
246 )
247
248 module = AnsibleModule(
249 argument_spec=argument_spec,
250 supports_check_mode=True,
251 required_if=[
252 ['state', 'absent', ['contract', 'tenant']],
253 ['state', 'present', ['contract', 'tenant']],
254 ],
255 )
256
257 contract = module.params['contract']
258 description = module.params['description']
259 scope = module.params['scope']
260 priority = module.params['priority']
261 dscp = module.params['dscp']
262 state = module.params['state']
263 tenant = module.params['tenant']
264
265 aci = ACIModule(module)
266 aci.construct_url(
267 root_class=dict(
268 aci_class='fvTenant',
269 aci_rn='tn-{0}'.format(tenant),
270 module_object=tenant,
271 target_filter={'name': tenant},
272 ),
273 subclass_1=dict(
274 aci_class='vzBrCP',
275 aci_rn='brc-{0}'.format(contract),
276 module_object=contract,
277 target_filter={'name': contract},
278 ),
279 )
280
281 aci.get_existing()
282
283 if state == 'present':
284 aci.payload(
285 aci_class='vzBrCP',
286 class_config=dict(
287 name=contract,
288 descr=description,
289 scope=scope,
290 prio=priority,
291 targetDscp=dscp,
292 ),
293 )
294
295 aci.get_diff(aci_class='vzBrCP')
296
297 aci.post_config()
298
299 elif state == 'absent':
300 aci.delete_config()
301
302 aci.exit_json()
303
304
305if __name__ == "__main__":
306 main()