Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_firmware_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_firmware_group_node
16 short_description: Manage firmware group nodes (fabric:NodeBlk)
17 description:
18 - This module adds/deletes a node to the firmware group.
19 options:
20 group:
21 description:
22 - This is the name of the firmware group.
23 type: str
24 node:
25 description:
26 - The node to be added to the firmware 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 default: present
35 choices: [ absent, present, query ]
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_firmware_group
46 - name: APIC Management Information Model reference
47 description: More information about the internal APIC class B(l3ext:Out).
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: Add a firmware group node
56 cisco.aci.aci_firmware_group_node:
57 host: apic
58 username: admin
59 password: SomeSecretPassword
60 group: fmgroup
61 node: 1001
62 state: present
63 delegate_to: localhost
64
65 - name: Remove a firmware group node
66 cisco.aci.aci_firmware_group_node:
67 host: apic
68 username: admin
69 password: SomeSecretPassword
70 group: fmgroup
71 node: 1001
72 state: absent
73 delegate_to: localhost
74
75 - name: Query all firmware groups nodes
76 cisco.aci.aci_firmware_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 specific firmware group node
85 cisco.aci.aci_firmware_group_node:
86 host: apic
87 username: admin
88 password: SomeSecretPassword
89 group: fmgroup
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 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec
202 from ansible.module_utils.basic import AnsibleModule
203
204
205 def main():
206 argument_spec = aci_argument_spec()
207 argument_spec.update(aci_annotation_spec())
208 argument_spec.update(
209 group=dict(type="str"), # Not required for querying all objects
210 node=dict(type="str"),
211 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
212 name_alias=dict(type="str"),
213 )
214
215 module = AnsibleModule(
216 argument_spec=argument_spec,
217 supports_check_mode=True,
218 required_if=[
219 ["state", "absent", ["node", "group"]],
220 ["state", "present", ["node", "group"]],
221 ],
222 )
223
224 state = module.params.get("state")
225 group = module.params.get("group")
226 node = module.params.get("node")
227 name_alias = module.params.get("name_alias")
228 block_name = None
229 if node is not None:
230 block_name = "blk{0}-{0}".format(node)
231
232 aci = ACIModule(module)
233 aci.construct_url(
234 root_class=dict(
235 aci_class="firmwareFwGrp",
236 aci_rn="fabric/fwgrp-{0}".format(group),
237 target_filter={"name": group},
238 module_object=group,
239 ),
240 subclass_1=dict(
241 aci_class="fabricNodeBlk",
242 aci_rn="nodeblk-blk{0}-{0}".format(node),
243 target_filter={"name": block_name},
244 module_object=node,
245 ),
246 )
247
248 aci.get_existing()
249
250 if state == "present":
251 aci.payload(
252 aci_class="fabricNodeBlk",
253 class_config=dict(
254 from_=node,
255 to_=node,
256 nameAlias=name_alias,
257 ),
258 )
259
260 aci.get_diff(aci_class="fabricNodeBlk")
261
262 aci.post_config()
263
264 elif state == "absent":
265 aci.delete_config()
266
267 aci.exit_json()
268
269
270 if __name__ == "__main__":
271 main()