Debian Codegraph @

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

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