Debian Codegraph @

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

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