Debian Codegraph @

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

raw
1 #!/usr/bin/python
2 # -*- coding: utf-8 -*-
3
4 # Copyright: (c) 2023, Gaspard Micol (@gmicol) <[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 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"}
12
13 DOCUMENTATION = r"""
14 ---
15 module: aci_maintenance_group_node
16 short_description: Manage maintenance group nodes (fabric:NodeBlk)
17 description:
18 - Manage maintenance group nodes.
19 options:
20 group:
21 description:
22 - The maintenance group name that you want to add the node to.
23 type: str
24 node:
25 description:
26 - The node to be added to the maintenance group.
27 - The value equals the NodeID.
28 type: str
29 state:
30 description:
31 - Use C(present) or C(absent) for adding or removing.
32 - Use C(query) for listing an object or multiple objects.
33 type: str
34 choices: [ absent, present, query ]
35 default: present
36 name_alias:
37 description:
38 - The alias for the current object. This relates to the nameAlias field in ACI.
39 type: str
40 extends_documentation_fragment:
41 - cisco.aci.aci
42 - cisco.aci.annotation
43
44 seealso:
45 - module: cisco.aci.aci_maintenance_group
46 - name: APIC Management Information Model reference
47 description: More information about the internal APIC class B(fabric:NodeBlk).
48 link: https://developer.cisco.com/docs/apic-mim-ref/
49 author:
50 - Steven Gerhart (@sgerhart)
51 - Gaspard Micol (@gmicol)
52 """
53
54 EXAMPLES = r"""
55 - name: Create a maintenance group node
56 cisco.aci.aci_maintenance_group_node:
57 host: apic
58 username: admin
59 password: SomeSecretPassword
60 group: my_maintenance_group
61 node: 1001
62 state: present
63 delegate_to: localhost
64
65 - name: Delete a maintenance group node
66 cisco.aci.aci_maintenance_group_node:
67 host: apic
68 username: admin
69 password: SomeSecretPassword
70 group: my_maintenance_group
71 node: 1001
72 state: absent
73 delegate_to: localhost
74
75 - name: Query all maintenance group nodes
76 cisco.aci.aci_maintenance_group_node:
77 host: apic
78 username: admin
79 password: SomeSecretPassword
80 state: query
81 delegate_to: localhost
82 register: query_result
83
84 - name: Query a maintenance group node
85 cisco.aci.aci_maintenance_group_node:
86 host: apic
87 username: admin
88 password: SomeSecretPassword
89 group: my_maintenance_group
90 node: 1001
91 state: query
92 delegate_to: localhost
93 register: query_result
94 """
95
96 RETURN = r"""
97 current:
98 description: The existing configuration from the APIC after the module has finished
99 returned: success
100 type: list
101 sample:
102 [
103 {
104 "fvTenant": {
105 "attributes": {
106 "descr": "Production environment",
107 "dn": "uni/tn-production",
108 "name": "production",
109 "nameAlias": "",
110 "ownerKey": "",
111 "ownerTag": ""
112 }
113 }
114 }
115 ]
116 error:
117 description: The error information as returned from the APIC
118 returned: failure
119 type: dict
120 sample:
121 {
122 "code": "122",
123 "text": "unknown managed object class foo"
124 }
125 raw:
126 description: The raw output returned by the APIC REST API (xml or json)
127 returned: parse error
128 type: str
129 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
130 sent:
131 description: The actual/minimal configuration pushed to the APIC
132 returned: info
133 type: list
134 sample:
135 {
136 "fvTenant": {
137 "attributes": {
138 "descr": "Production environment"
139 }
140 }
141 }
142 previous:
143 description: The original configuration from the APIC before the module has started
144 returned: info
145 type: list
146 sample:
147 [
148 {
149 "fvTenant": {
150 "attributes": {
151 "descr": "Production",
152 "dn": "uni/tn-production",
153 "name": "production",
154 "nameAlias": "",
155 "ownerKey": "",
156 "ownerTag": ""
157 }
158 }
159 }
160 ]
161 proposed:
162 description: The assembled configuration from the user-provided parameters
163 returned: info
164 type: dict
165 sample:
166 {
167 "fvTenant": {
168 "attributes": {
169 "descr": "Production environment",
170 "name": "production"
171 }
172 }
173 }
174 filter_string:
175 description: The filter string used for the request
176 returned: failure or debug
177 type: str
178 sample: ?rsp-prop-include=config-only
179 method:
180 description: The HTTP method used for the request to the APIC
181 returned: failure or debug
182 type: str
183 sample: POST
184 response:
185 description: The HTTP response from the APIC
186 returned: failure or debug
187 type: str
188 sample: OK (30 bytes)
189 status:
190 description: The HTTP status from the APIC
191 returned: failure or debug
192 type: int
193 sample: 200
194 url:
195 description: The HTTP url used for the request to the APIC
196 returned: failure or debug
197 type: str
198 sample: https://10.11.12.13/api/mo/uni/tn-production.json
199
200 """
201
202 from ansible.module_utils.basic import AnsibleModule
203 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
204
205
206 def main():
207 argument_spec = aci_argument_spec()
208 argument_spec.update(aci_annotation_spec())
209 argument_spec.update(
210 group=dict(type="str"), # Not required for querying all objects
211 node=dict(type="str"),
212 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
213 name_alias=dict(type="str"),
214 )
215
216 module = AnsibleModule(
217 argument_spec=argument_spec,
218 supports_check_mode=True,
219 required_if=[
220 ["state", "absent", ["node", "group"]],
221 ["state", "present", ["node", "group"]],
222 ],
223 )
224
225 state = module.params.get("state")
226 group = module.params.get("group")
227 node = module.params.get("node")
228 name_alias = module.params.get("name_alias")
229 block_name = None
230 if node is not None:
231 block_name = "blk{0}-{0}".format(node)
232
233 aci = ACIModule(module)
234 aci.construct_url(
235 root_class=dict(
236 aci_class="maintMaintGrp",
237 aci_rn="fabric/maintgrp-{0}".format(group),
238 target_filter={"name": group},
239 module_object=group,
240 ),
241 subclass_1=dict(
242 aci_class="fabricNodeBlk",
243 aci_rn="nodeblk-blk{0}-{0}".format(node),
244 target_filter={"name": block_name},
245 module_object=node,
246 ),
247 )
248
249 aci.get_existing()
250
251 if state == "present":
252 aci.payload(
253 aci_class="fabricNodeBlk",
254 class_config=dict(
255 from_=node,
256 to_=node,
257 nameAlias=name_alias,
258 ),
259 )
260
261 aci.get_diff(aci_class="fabricNodeBlk")
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()