Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2020, Sudhakar Shet Kudtarkar (@kudtarkar1)
5 # Copyright: (c) 2020, Lionel Hercot <[email protected]>
6 # Copyright: (c) 2020, Shreyas Srish <[email protected]>
7 # GNU General Public License v3.0+ (see LICENSE or https://www.gnu.org/licenses/gpl-3.0.txt)
8
9 from __future__ import absolute_import, division, print_function
10
11 __metaclass__ = type
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_static_node_mgmt_address
16 short_description: In band or Out of band management IP address (mgmt:RsOoBStNode and mgmt:RsInBStNode)
17 description:
18 - Cisco ACI Fabric Node IP address
19 options:
20 epg:
21 description:
22 - The name of the end point group
23 type: str
24 pod_id:
25 description:
26 - The pod number of the leaf, spine or APIC
27 type: int
28 node_id:
29 description:
30 - ACI Fabric's node id of a leaf, spine or APIC
31 type: int
32 ipv4_address:
33 description:
34 - ipv4 address of in band/out of band mgmt
35 type: str
36 aliases: [ ip ]
37 ipv4_gw:
38 description:
39 - Gateway address of in band / out of band mgmt network
40 type: str
41 aliases: [ gw ]
42 ipv6_address:
43 description:
44 - ipv6 address of in band/out of band mgmt
45 type: str
46 aliases: [ ipv6 ]
47 ipv6_gw:
48 description:
49 - GW address of in band/out of band mgmt
50 type: str
51 type:
52 description:
53 - type of management interface
54 type: str
55 choices: [ in_band, out_of_band ]
56 required: true
57 state:
58 description:
59 - Use C(present) or C(absent) for adding or removing.
60 - Use C(query) for listing an object or multiple objects.
61 type: str
62 choices: [ absent, present, query ]
63 default: present
64 extends_documentation_fragment:
65 - cisco.aci.aci
66 - cisco.aci.annotation
67
68 seealso:
69 - name: APIC Management Information Model reference
70 description: More information about the internal APIC classes B(mgmt:RsOoBStNode) and B(mgmt:RsInBStNode).
71 link: https://developer.cisco.com/docs/apic-mim-ref/
72 author:
73 - Sudhakar Shet Kudtarkar (@kudtarkar1)
74 - Lionel Hercot (@lhercot)
75 - Shreyas Srish (@shrsr)
76 """
77
78 EXAMPLES = r"""
79 - name: Add ipv4 address to in band mgmt interface
80 cisco.aci.aci_static_node_mgmt_address:
81 host: "Host IP"
82 username: admin
83 password: SomeSecretePassword
84 epg: default
85 pod_id: 1
86 type: in_band
87 node_id: 1102
88 ipv4_address: "3.1.1.2/24"
89 ipv4_gw: "3.1.1.1"
90 state: present
91 delegate_to: localhost
92
93 - name: Add ipv4 address to out of band mgmt interface
94 cisco.aci.aci_static_node_mgmt_address:
95 host: "Host IP"
96 username: admin
97 password: SomeSecretePassword
98 epg: default
99 pod_id: 1
100 type: out_of_band
101 node_id: 1102
102 ipv4_address: "3.1.1.2/24"
103 ipv4_gw: "3.1.1.1"
104 state: present
105 delegate_to: localhost
106
107 - name: Remove ipv4 address to in band mgmt interface
108 cisco.aci.aci_static_node_mgmt_address:
109 host: "Host IP"
110 username: admin
111 password: SomeSecretePassword
112 epg: default
113 pod_id: 1
114 type: in_band
115 node_id: 1102
116 ipv4_address: "3.1.1.2/24"
117 ipv4_gw: "3.1.1.1"
118 state: absent
119 delegate_to: localhost
120
121 - name: Query the in band mgmt ipv4 address
122 cisco.aci.aci_static_node_mgmt_address:
123 host: "Host IP"
124 username: admin
125 password: SomeSecretePassword
126 epg: default
127 pod_id: 1
128 type: in_band
129 node_id: 1102
130 ipv4_address: "3.1.1.2/24"
131 ipv4_gw: "3.1.1.1"
132 state: query
133 delegate_to: localhost
134
135 - name: Query all addresses in epg out of band25wf
136 cisco.aci.aci_static_node_mgmt_address:
137 host: "Host IP"
138 username: admin
139 password: SomeSecretePassword
140 epg: default
141 type: out_of_band
142 state: query
143 delegate_to: localhost
144
145 - name: Query all in band addresses
146 cisco.aci.aci_static_node_mgmt_address:
147 host: "Host IP"
148 username: admin
149 password: SomeSecretePassword
150 type: in_band
151 state: query
152 delegate_to: localhost
153 """
154
155 RETURN = r"""
156 current:
157 description: The existing configuration from the APIC after the module has finished
158 returned: success
159 type: list
160 sample:
161 [
162 {
163 "fvTenant": {
164 "attributes": {
165 "descr": "Production environment",
166 "dn": "uni/tn-production",
167 "name": "production",
168 "nameAlias": "",
169 "ownerKey": "",
170 "ownerTag": ""
171 }
172 }
173 }
174 ]
175 error:
176 description: The error information as returned from the APIC
177 returned: failure
178 type: dict
179 sample:
180 {
181 "code": "122",
182 "text": "unknown managed object class foo"
183 }
184 raw:
185 description: The raw output returned by the APIC REST API (xml or json)
186 returned: parse error
187 type: str
188 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class "/></imdata>'
189 sent:
190 description: The actual/minimal configuration pushed to the APIC
191 returned: info
192 type: list
193 sample:
194 {
195 "fvTenant": {
196 "attributes": {
197 "descr": "Production environment"
198 }
199 }
200 }
201 previous:
202 description: The original configuration from the APIC before the module has started
203 returned: info
204 type: list
205 sample:
206 [
207 {
208 "fvTenant": {
209 "attributes": {
210 "descr": "Production",
211 "dn": "uni/tn-production",
212 "name": "production",
213 "nameAlias": "",
214 "ownerKey": "",
215 "ownerTag": ""
216 }
217 }
218 }
219 ]
220 proposed:
221 description: The assembled configuration from the user-provided parameters
222 returned: info
223 type: dict
224 sample:
225 {
226 "fvTenant": {
227 "attributes": {
228 "descr": "Production environment",
229 "name": "production"
230 }
231 }
232 }
233 filter_string:
234 description: The filter string used for the request
235 returned: failure or debug
236 type: str
237 sample: ?rsp-prop-include=config-only
238 method:
239 description: The HTTP method used for the request to the APIC
240 returned: failure or debug
241 type: str
242 sample: POST
243 response:
244 description: The HTTP response from the APIC
245 returned: failure or debug
246 type: str
247 sample: class_map (30 bytes)
248 status:
249 description: The HTTP status from the APIC
250 returned: failure or debug
251 type: int
252 sample: 200
253 url:
254 description: The HTTP url used for the request to the APIC
255 returned: failure or debug
256 type: str
257 sample: https://10.11.12.13/api/mo/uni/tn-production.json
258 """
259
260 from ansible.module_utils.basic import AnsibleModule
261 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
262
263
264 def main():
265 argument_spec = aci_argument_spec()
266 argument_spec.update(aci_annotation_spec())
267 argument_spec.update(
268 node_id=dict(type="int"),
269 pod_id=dict(type="int"),
270 type=dict(type="str", choices=["in_band", "out_of_band"], required=True),
271 epg=dict(type="str"),
272 ipv4_address=dict(type="str", aliases=["ip"]),
273 ipv4_gw=dict(type="str", aliases=["gw"]),
274 ipv6_address=dict(type="str", aliases=["ipv6"]),
275 ipv6_gw=dict(type="str"),
276 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
277 )
278
279 module = AnsibleModule(
280 argument_spec=argument_spec,
281 supports_check_mode=True,
282 required_if=[["state", "absent", ["node_id", "epg"]], ["state", "present", ["node_id", "epg", "ipv4_address", "ipv4_gw"]]],
283 )
284
285 pod_id = module.params.get("pod_id")
286 node_id = module.params.get("node_id")
287 type = module.params.get("type")
288 epg = module.params.get("epg")
289 ipv4_address = module.params.get("ipv4_address")
290 ipv4_gw = module.params.get("ipv4_gw")
291 ipv6_address = module.params.get("ipv6_address")
292 ipv6_gw = module.params.get("ipv6_gw")
293 state = module.params.get("state")
294
295 class_map = dict(
296 in_band=list([dict(aci_class="mgmtInb", aci_rn="inb-{0}"), dict(aci_class="mgmtRsInBStNode", aci_rn="rsinBStNode-[{0}]")]),
297 out_of_band=list([dict(aci_class="mgmtOob", aci_rn="oob-{0}"), dict(aci_class="mgmtRsOoBStNode", aci_rn="rsooBStNode-[{0}]")]),
298 )
299
300 static_path = None
301 if pod_id is not None and node_id is not None:
302 static_path = "topology/pod-{0}/node-{1}".format(pod_id, node_id)
303
304 aci = ACIModule(module)
305 aci.construct_url(
306 root_class=dict(
307 aci_class="fvTenant",
308 aci_rn="tn-mgmt",
309 module_object="mgmt",
310 target_filter={"name": "mgmt"},
311 ),
312 subclass_1=dict(
313 aci_class="mgmtMgmtP",
314 aci_rn="mgmtp-default",
315 module_object="default",
316 target_filter={"name": "default"},
317 ),
318 subclass_2=dict(
319 aci_class=class_map.get(type)[0]["aci_class"],
320 aci_rn=class_map.get(type)[0]["aci_rn"].format(epg),
321 module_object=epg,
322 target_filter={"name": epg},
323 ),
324 subclass_3=dict(
325 aci_class=class_map.get(type)[1]["aci_class"],
326 aci_rn=class_map.get(type)[1]["aci_rn"].format(static_path),
327 module_object=static_path,
328 target_filter={"name": static_path},
329 ),
330 )
331
332 aci.get_existing()
333
334 if state == "present":
335 aci.payload(
336 aci_class=class_map.get(type)[1]["aci_class"],
337 class_config=dict(addr=ipv4_address, gw=ipv4_gw, v6Addr=ipv6_address, v6Gw=ipv6_gw),
338 )
339 aci.get_diff(aci_class=class_map.get(type)[1]["aci_class"])
340
341 aci.post_config()
342
343 elif state == "absent":
344 aci.delete_config()
345
346 aci.exit_json()
347
348
349 if __name__ == "__main__":
350 main()