Debian Codegraph @

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