Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_firmware_group.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
16 short_description: Manage firmware groups (firmware:FwGrp)
17 description:
18 - This module creates a firmware group, so that you can apply firmware policy to nodes.
19 options:
20 group:
21 description:
22 - Name of the firmware group.
23 type: str
24 policy:
25 description:
26 - Name of the firmware policy
27 - It is important that you use the same name as the policy created with M(cisco.aci.aci_firmware_policy).
28 type: str
29 aliases: [ firmwarepol ]
30 type_group:
31 description:
32 - Type of the firmware group.
33 - The APIC defaults to C(range) when unset during creation.
34 type: str
35 choices: [ all, all_in_pod, range ]
36 description:
37 description:
38 - Description of the firmware group.
39 type: str
40 aliases: [ descr ]
41 state:
42 description:
43 - Use C(present) or C(absent) for adding or removing.
44 - Use C(query) for listing an object or multiple objects.
45 type: str
46 default: present
47 choices: [ absent, present, query ]
48 name_alias:
49 description:
50 - The alias for the current object. This relates to the nameAlias field in ACI.
51 type: str
52 extends_documentation_fragment:
53 - cisco.aci.aci
54 - cisco.aci.annotation
55 - cisco.aci.owner
56
57 notes:
58 - The C(policy) must exist before using this module in your playbook.
59 - The M(cisco.aci.aci_firmware_policy) module can be used for this.
60 seealso:
61 - module: cisco.aci.aci_firmware_policy
62 - name: APIC Management Information Model reference
63 description: More information about the internal APIC class B(firmware:FwGrp).
64 link: https://developer.cisco.com/docs/apic-mim-ref/
65 author:
66 - Steven Gerhart (@sgerhart)
67 - Gaspard Micol (@gmicol)
68 """
69
70
71 EXAMPLES = r"""
72 - name: Create a firmware group
73 cisco.aci.aci_firmware_group:
74 host: apic
75 username: admin
76 password: SomeSecretPassword
77 group: fmgroup
78 policy: fmpolicy1
79 state: present
80 delegate_to: localhost
81
82 - name: Delete a firmware group
83 cisco.aci.aci_firmware_group:
84 host: apic
85 username: admin
86 password: SomeSecretPassword
87 group: fmgroup
88 state: absent
89 delegate_to: localhost
90
91 - name: Query all firmware groups
92 cisco.aci.aci_firmware_group:
93 host: apic
94 username: admin
95 password: SomeSecretPassword
96 state: query
97 delegate_to: localhost
98 register: query_result
99
100 - name: Query a specific firmware group
101 cisco.aci.aci_firmware_group:
102 host: apic
103 username: admin
104 password: SomeSecretPassword
105 group: fmgroup
106 state: query
107 delegate_to: localhost
108 register: query_result
109 """
110
111 RETURN = r"""
112 current:
113 description: The existing configuration from the APIC after the module has finished
114 returned: success
115 type: list
116 sample:
117 [
118 {
119 "fvTenant": {
120 "attributes": {
121 "descr": "Production environment",
122 "dn": "uni/tn-production",
123 "name": "production",
124 "nameAlias": "",
125 "ownerKey": "",
126 "ownerTag": ""
127 }
128 }
129 }
130 ]
131 error:
132 description: The error information as returned from the APIC
133 returned: failure
134 type: dict
135 sample:
136 {
137 "code": "122",
138 "text": "unknown managed object class foo"
139 }
140 raw:
141 description: The raw output returned by the APIC REST API (xml or json)
142 returned: parse error
143 type: str
144 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
145 sent:
146 description: The actual/minimal configuration pushed to the APIC
147 returned: info
148 type: list
149 sample:
150 {
151 "fvTenant": {
152 "attributes": {
153 "descr": "Production environment"
154 }
155 }
156 }
157 previous:
158 description: The original configuration from the APIC before the module has started
159 returned: info
160 type: list
161 sample:
162 [
163 {
164 "fvTenant": {
165 "attributes": {
166 "descr": "Production",
167 "dn": "uni/tn-production",
168 "name": "production",
169 "nameAlias": "",
170 "ownerKey": "",
171 "ownerTag": ""
172 }
173 }
174 }
175 ]
176 proposed:
177 description: The assembled configuration from the user-provided parameters
178 returned: info
179 type: dict
180 sample:
181 {
182 "fvTenant": {
183 "attributes": {
184 "descr": "Production environment",
185 "name": "production"
186 }
187 }
188 }
189 filter_string:
190 description: The filter string used for the request
191 returned: failure or debug
192 type: str
193 sample: ?rsp-prop-include=config-only
194 method:
195 description: The HTTP method used for the request to the APIC
196 returned: failure or debug
197 type: str
198 sample: POST
199 response:
200 description: The HTTP response from the APIC
201 returned: failure or debug
202 type: str
203 sample: OK (30 bytes)
204 status:
205 description: The HTTP status from the APIC
206 returned: failure or debug
207 type: int
208 sample: 200
209 url:
210 description: The HTTP url used for the request to the APIC
211 returned: failure or debug
212 type: str
213 sample: https://10.11.12.13/api/mo/uni/tn-production.json
214 """
215
216 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
217 from ansible.module_utils.basic import AnsibleModule
218 from ansible_collections.cisco.aci.plugins.module_utils.constants import MATCH_TYPE_GROUP_MAPPING
219
220
221 def main():
222 argument_spec = aci_argument_spec()
223 argument_spec.update(aci_annotation_spec())
224 argument_spec.update(aci_owner_spec())
225 argument_spec.update(
226 group=dict(type="str"), # Not required for querying all objects
227 policy=dict(type="str", aliases=["firmwarepol"]), # Not required for querying all objects
228 type_group=dict(type="str", choices=list(MATCH_TYPE_GROUP_MAPPING.keys())),
229 description=dict(type="str", aliases=["descr"]),
230 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
231 name_alias=dict(type="str"),
232 )
233
234 module = AnsibleModule(
235 argument_spec=argument_spec,
236 supports_check_mode=True,
237 required_if=[
238 ["state", "absent", ["group"]],
239 ["state", "present", ["group", "policy"]],
240 ],
241 )
242
243 state = module.params.get("state")
244 group = module.params.get("group")
245 policy = module.params.get("policy")
246 type_group = MATCH_TYPE_GROUP_MAPPING.get(module.params.get("type_group"))
247 description = module.params.get("description")
248 name_alias = module.params.get("name_alias")
249
250 aci = ACIModule(module)
251 aci.construct_url(
252 root_class=dict(
253 aci_class="firmwareFwGrp",
254 aci_rn="fabric/fwgrp-{0}".format(group),
255 target_filter={"name": group},
256 module_object=group,
257 ),
258 child_classes=["firmwareRsFwgrpp"],
259 )
260
261 aci.get_existing()
262
263 if state == "present":
264 aci.payload(
265 aci_class="firmwareFwGrp",
266 class_config=dict(
267 name=group,
268 descr=description,
269 type=type_group,
270 nameAlias=name_alias,
271 ),
272 child_configs=[
273 dict(
274 firmwareRsFwgrpp=dict(
275 attributes=dict(
276 tnFirmwareFwPName=policy,
277 ),
278 ),
279 ),
280 ],
281 )
282
283 aci.get_diff(aci_class="firmwareFwGrp")
284
285 aci.post_config()
286
287 elif state == "absent":
288 aci.delete_config()
289
290 aci.exit_json()
291
292
293 if __name__ == "__main__":
294 main()