Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_epg_to_contract_interface.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
13 DOCUMENTATION = r"""
14 ---
15 module: aci_epg_to_contract_interface
16 short_description: Bind EPGs to Consumed Contracts Interface (fv:RsConsIf)
17
18 description:
19 - Bind EPGs to Consumed Contracts Interface on Cisco ACI fabrics.
20 notes:
21 - The C(tenant), C(app_profile), C(EPG), and C(Contract Interface) used must exist before using this module in your playbook.
22 The M(cisco.aci.aci_tenant), M(cisco.aci.aci_ap), M(cisco.aci.aci_epg), and M(cisco.aci.aci_contract_export) modules can be used for this.
23 options:
24 tenant:
25 description:
26 - Name of an existing tenant.
27 type: str
28 aliases: [ tenant_name ]
29 ap:
30 description:
31 - Name of an existing application profile, that will contain the EPGs.
32 type: str
33 aliases: [ app_profile, app_profile_name ]
34 epg:
35 description:
36 - The name of the end point group.
37 type: str
38 aliases: [ epg_name ]
39 contract_interface:
40 description:
41 - Name of the Contract interface, which is the contract with a "Global" scope which is exported to the tenant.
42 type: str
43 aliases: [ contract_interface_name ]
44 priority:
45 description:
46 - QoS class.
47 - The default value of QoS is C(unspecified) during the creation.
48 type: str
49 choices: [ level1, level2, level3, level4, level5, level6, unspecified ]
50 state:
51 description:
52 - Use C(present) or C(absent) for adding or removing.
53 - Use C(query) for listing an object or multiple objects.
54 type: str
55 choices: [ absent, present, query ]
56 default: present
57 extends_documentation_fragment:
58 - cisco.aci.aci
59 - cisco.aci.annotation
60
61 seealso:
62 - module: cisco.aci.aci_ap
63 - module: cisco.aci.aci_epg
64 - module: cisco.aci.aci_contract_export
65 - name: APIC Management Information Model reference
66 description: More information about the internal APIC classes B(fv:RsCons) and B(fv:RsProv).
67 link: https://developer.cisco.com/docs/apic-mim-ref/
68 author:
69 - Sabari Jaganathan (@sajagana)
70 """
71 EXAMPLES = r"""
72 - name: Add a new consumed contract interface to EPG
73 cisco.aci.aci_epg_to_contract_interface:
74 host: apic
75 username: admin
76 password: SomeSecretPassword
77 tenant: anstest
78 ap: anstest
79 epg: anstest
80 contract_interface: anstest_http
81 state: present
82 delegate_to: localhost
83
84 - name: Remove an existing consumed contract interface
85 cisco.aci.aci_epg_to_contract_interface:
86 host: apic
87 username: admin
88 password: SomeSecretPassword
89 tenant: anstest
90 ap: anstest
91 epg: anstest
92 contract_interface: anstest_http
93 state: absent
94 delegate_to: localhost
95
96 - name: Query a specific consumed contract interface
97 cisco.aci.aci_epg_to_contract_interface:
98 host: apic
99 username: admin
100 password: SomeSecretPassword
101 tenant: anstest
102 ap: anstest
103 epg: anstest
104 contract_interface: anstest_http
105 state: query
106 delegate_to: localhost
107 register: query_result
108
109 - name: Query all consumed contract interfaces
110 cisco.aci.aci_epg_to_contract_interface:
111 host: apic
112 username: admin
113 password: SomeSecretPassword
114 state: query
115 delegate_to: localhost
116 register: query_result
117 """
118
119 RETURN = r"""
120 current:
121 description: The existing configuration from the APIC after the module has finished
122 returned: success
123 type: list
124 sample:
125 [
126 {
127 "fvTenant": {
128 "attributes": {
129 "descr": "Production environment",
130 "dn": "uni/tn-production",
131 "name": "production",
132 "nameAlias": "",
133 "ownerKey": "",
134 "ownerTag": ""
135 }
136 }
137 }
138 ]
139 error:
140 description: The error information as returned from the APIC
141 returned: failure
142 type: dict
143 sample:
144 {
145 "code": "122",
146 "text": "unknown managed object class foo"
147 }
148 raw:
149 description: The raw output returned by the APIC REST API (xml or json)
150 returned: parse error
151 type: str
152 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
153 sent:
154 description: The actual/minimal configuration pushed to the APIC
155 returned: info
156 type: list
157 sample:
158 {
159 "fvTenant": {
160 "attributes": {
161 "descr": "Production environment"
162 }
163 }
164 }
165 previous:
166 description: The original configuration from the APIC before the module has started
167 returned: info
168 type: list
169 sample:
170 [
171 {
172 "fvTenant": {
173 "attributes": {
174 "descr": "Production",
175 "dn": "uni/tn-production",
176 "name": "production",
177 "nameAlias": "",
178 "ownerKey": "",
179 "ownerTag": ""
180 }
181 }
182 }
183 ]
184 proposed:
185 description: The assembled configuration from the user-provided parameters
186 returned: info
187 type: dict
188 sample:
189 {
190 "fvTenant": {
191 "attributes": {
192 "descr": "Production environment",
193 "name": "production"
194 }
195 }
196 }
197 filter_string:
198 description: The filter string used for the request
199 returned: failure or debug
200 type: str
201 sample: ?rsp-prop-include=config-only
202 method:
203 description: The HTTP method used for the request to the APIC
204 returned: failure or debug
205 type: str
206 sample: POST
207 response:
208 description: The HTTP response from the APIC
209 returned: failure or debug
210 type: str
211 sample: OK (30 bytes)
212 status:
213 description: The HTTP status from the APIC
214 returned: failure or debug
215 type: int
216 sample: 200
217 url:
218 description: The HTTP url used for the request to the APIC
219 returned: failure or debug
220 type: str
221 sample: https://10.11.12.13/api/mo/uni/tn-production.json
222 """
223
224 from ansible.module_utils.basic import AnsibleModule
225 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
226
227
228 def main():
229 argument_spec = aci_argument_spec()
230 argument_spec.update(aci_annotation_spec())
231 argument_spec.update(
232 tenant=dict(type="str", aliases=["tenant_name"]), # Not required for querying all objects
233 ap=dict(type="str", aliases=["app_profile", "app_profile_name"]), # Not required for querying all objects
234 epg=dict(type="str", aliases=["epg_name"]), # Not required for querying all objects
235 contract_interface=dict(type="str", aliases=["contract_interface_name"]), # Not required for querying all objects
236 priority=dict(type="str", choices=["level1", "level2", "level3", "level4", "level5", "level6", "unspecified"]),
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", "absent", ["tenant", "ap", "epg", "contract_interface"]],
245 ["state", "present", ["tenant", "ap", "epg", "contract_interface"]],
246 ],
247 )
248
249 tenant = module.params.get("tenant")
250 ap = module.params.get("ap")
251 epg = module.params.get("epg")
252 contract_interface = module.params.get("contract_interface")
253 priority = module.params.get("priority")
254 state = module.params.get("state")
255
256 aci = ACIModule(module)
257 aci.construct_url(
258 root_class=dict(
259 aci_class="fvTenant",
260 aci_rn="tn-{0}".format(tenant),
261 module_object=tenant,
262 target_filter={"name": tenant},
263 ),
264 subclass_1=dict(
265 aci_class="fvAp",
266 aci_rn="ap-{0}".format(ap),
267 module_object=ap,
268 target_filter={"name": ap},
269 ),
270 subclass_2=dict(
271 aci_class="fvAEPg",
272 aci_rn="epg-{0}".format(epg),
273 module_object=epg,
274 target_filter={"name": epg},
275 ),
276 subclass_3=dict(
277 aci_class="fvRsConsIf",
278 aci_rn="rsconsIf-{0}".format(contract_interface),
279 module_object=contract_interface,
280 target_filter={"name": contract_interface},
281 ),
282 )
283
284 aci.get_existing()
285
286 if state == "present":
287 aci.payload(
288 aci_class="fvRsConsIf",
289 class_config=dict(
290 prio=priority,
291 tnVzCPIfName=contract_interface,
292 ),
293 )
294
295 aci.get_diff(aci_class="fvRsConsIf")
296
297 aci.post_config()
298
299 elif state == "absent":
300 aci.delete_config()
301
302 aci.exit_json()
303
304
305 if __name__ == "__main__":
306 main()