Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_taboo_contract.py

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2018, Dag Wieers (dagwieers) <[email protected]>
5 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8
9 __metaclass__ = type
10
11 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "certified"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_taboo_contract
16 short_description: Manage taboo contracts (vz:BrCP)
17 description:
18 - Manage taboo contracts on Cisco ACI fabrics.
19 options:
20 taboo_contract:
21 description:
22 - The name of the Taboo Contract.
23 type: str
24 aliases: [ name ]
25 description:
26 description:
27 - The description for the Taboo Contract.
28 type: str
29 aliases: [ descr ]
30 tenant:
31 description:
32 - The name of the tenant.
33 type: str
34 aliases: [ tenant_name ]
35 scope:
36 description:
37 - The scope of a service contract.
38 - The APIC defaults to C(context) when unset during creation.
39 type: str
40 choices: [ application-profile, context, global, tenant ]
41 state:
42 description:
43 - Use C(present) or C(absent) for adding or removing.
44 - Use C(query) for listing an object or multiple objects.
45 type: str
46 choices: [ absent, present, query ]
47 default: present
48 name_alias:
49 description:
50 - The alias for the current object. This relates to the nameAlias field in ACI.
51 type: str
52 extends_documentation_fragment:
53 - cisco.aci.aci
54 - cisco.aci.annotation
55 - cisco.aci.owner
56
57 notes:
58 - The C(tenant) used must exist before using this module in your playbook.
59 The M(cisco.aci.aci_tenant) module can be used for this.
60 seealso:
61 - module: cisco.aci.aci_tenant
62 - name: APIC Management Information Model reference
63 description: More information about the internal APIC class B(vz:BrCP).
64 link: https://developer.cisco.com/docs/apic-mim-ref/
65 author:
66 - Dag Wieers (@dagwieers)
67 """
68
69 EXAMPLES = r"""
70 - name: Add taboo contract
71 cisco.aci.aci_taboo_contract:
72 host: apic
73 username: admin
74 password: SomeSecretPassword
75 tenant: ansible_test
76 taboo_contract: taboo_contract_test
77 state: present
78 delegate_to: localhost
79
80 - name: Remove taboo contract
81 cisco.aci.aci_taboo_contract:
82 host: apic
83 username: admin
84 password: SomeSecretPassword
85 tenant: ansible_test
86 taboo_contract: taboo_contract_test
87 state: absent
88 delegate_to: localhost
89
90 - name: Query all taboo contracts
91 cisco.aci.aci_taboo_contract:
92 host: apic
93 username: admin
94 password: SomeSecretPassword
95 state: query
96 delegate_to: localhost
97 register: query_result
98
99 - name: Query a specific taboo contract
100 cisco.aci.aci_taboo_contract:
101 host: apic
102 username: admin
103 password: SomeSecretPassword
104 tenant: ansible_test
105 taboo_contract: taboo_contract_test
106 state: query
107 delegate_to: localhost
108 register: query_result
109 """
110
111 RETURN = r"""
112 current:
113 description: The existing configuration from the APIC after the module has finished
114 returned: success
115 type: list
116 sample:
117 [
118 {
119 "fvTenant": {
120 "attributes": {
121 "descr": "Production environment",
122 "dn": "uni/tn-production",
123 "name": "production",
124 "nameAlias": "",
125 "ownerKey": "",
126 "ownerTag": ""
127 }
128 }
129 }
130 ]
131 error:
132 description: The error information as returned from the APIC
133 returned: failure
134 type: dict
135 sample:
136 {
137 "code": "122",
138 "text": "unknown managed object class foo"
139 }
140 raw:
141 description: The raw output returned by the APIC REST API (xml or json)
142 returned: parse error
143 type: str
144 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
145 sent:
146 description: The actual/minimal configuration pushed to the APIC
147 returned: info
148 type: list
149 sample:
150 {
151 "fvTenant": {
152 "attributes": {
153 "descr": "Production environment"
154 }
155 }
156 }
157 previous:
158 description: The original configuration from the APIC before the module has started
159 returned: info
160 type: list
161 sample:
162 [
163 {
164 "fvTenant": {
165 "attributes": {
166 "descr": "Production",
167 "dn": "uni/tn-production",
168 "name": "production",
169 "nameAlias": "",
170 "ownerKey": "",
171 "ownerTag": ""
172 }
173 }
174 }
175 ]
176 proposed:
177 description: The assembled configuration from the user-provided parameters
178 returned: info
179 type: dict
180 sample:
181 {
182 "fvTenant": {
183 "attributes": {
184 "descr": "Production environment",
185 "name": "production"
186 }
187 }
188 }
189 filter_string:
190 description: The filter string used for the request
191 returned: failure or debug
192 type: str
193 sample: ?rsp-prop-include=config-only
194 method:
195 description: The HTTP method used for the request to the APIC
196 returned: failure or debug
197 type: str
198 sample: POST
199 response:
200 description: The HTTP response from the APIC
201 returned: failure or debug
202 type: str
203 sample: OK (30 bytes)
204 status:
205 description: The HTTP status from the APIC
206 returned: failure or debug
207 type: int
208 sample: 200
209 url:
210 description: The HTTP url used for the request to the APIC
211 returned: failure or debug
212 type: str
213 sample: https://10.11.12.13/api/mo/uni/tn-production.json
214 """
215
216 from ansible.module_utils.basic import AnsibleModule
217 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
218
219
220 def main():
221 argument_spec = aci_argument_spec()
222 argument_spec.update(aci_annotation_spec())
223 argument_spec.update(aci_owner_spec())
224 argument_spec.update(
225 taboo_contract=dict(type="str", aliases=["name"]), # Not required for querying all contracts
226 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all contracts
227 scope=dict(type="str", choices=["application-profile", "context", "global", "tenant"]),
228 description=dict(type="str", aliases=["descr"]),
229 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
230 name_alias=dict(type="str"),
231 )
232
233 module = AnsibleModule(
234 argument_spec=argument_spec,
235 supports_check_mode=True,
236 required_if=[
237 ["state", "absent", ["tenant", "taboo_contract"]],
238 ["state", "present", ["tenant", "taboo_contract"]],
239 ],
240 )
241
242 taboo_contract = module.params.get("taboo_contract")
243 description = module.params.get("description")
244 scope = module.params.get("scope")
245 state = module.params.get("state")
246 tenant = module.params.get("tenant")
247 name_alias = module.params.get("name_alias")
248
249 aci = ACIModule(module)
250 aci.construct_url(
251 root_class=dict(
252 aci_class="fvTenant",
253 aci_rn="tn-{0}".format(tenant),
254 module_object=tenant,
255 target_filter={"name": tenant},
256 ),
257 subclass_1=dict(
258 aci_class="vzTaboo",
259 aci_rn="taboo-{0}".format(taboo_contract),
260 module_object=taboo_contract,
261 target_filter={"name": taboo_contract},
262 ),
263 )
264
265 aci.get_existing()
266
267 if state == "present":
268 aci.payload(
269 aci_class="vzTaboo",
270 class_config=dict(
271 name=taboo_contract,
272 descr=description,
273 scope=scope,
274 nameAlias=name_alias,
275 ),
276 )
277
278 aci.get_diff(aci_class="vzTaboo")
279
280 aci.post_config()
281
282 elif state == "absent":
283 aci.delete_config()
284
285 aci.exit_json()
286
287
288 if __name__ == "__main__":
289 main()