Debian Codegraph @

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