Debian Codegraph @

ansible_collections/cisco/aci/plugins/modules/aci_firmware_policy.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
12 ANSIBLE_METADATA = {"metadata_version": "1.1", "status": ["preview"], "supported_by": "community"}
13
14 DOCUMENTATION = r"""
15 ---
16 module: aci_firmware_policy
17 short_description: Manage firmware policies (firmware:FwP)
18 description:
19 - This module creates a firmware policy for firmware groups.
20 - The compatibility check can be explicitly ignored while assigning the firmware.
21 options:
22 name:
23 description:
24 - The name of the firmware policy
25 type: str
26 effective_on_reboot:
27 description:
28 - A property that indicates if the selected firmware version will be active after reboot.
29 - The firmware must be effective on an unplanned reboot before the scheduled maintenance operation.
30 type: bool
31 ignore_compat:
32 description:
33 - Check if compatibility checks should be ignored
34 type: bool
35 aliases: [ ignoreCompat ]
36 sr_upgrade:
37 description:
38 - The SR firware upgrade.
39 type: bool
40 sr_version:
41 description:
42 - The SR version of the firmware associated with this policy.
43 type: str
44 version:
45 description:
46 - The version of the firmware associated with this policy.
47 - The syntax for this field is n9000-xx.x.
48 - if the Full Version is 13.1(1i), the value for this field would be n9000-13.1(1i).
49 type: str
50 version_check_override:
51 description:
52 - The version check override.
53 - This is a directive to ignore the version check for the next install.
54 - The version check, which occurs during a maintenance window, checks to see if the desired version matches the running version.
55 - If the versions do not match, the install is performed. If the versions do match, the install is not performed.
56 - The version check override is a one-time override that performs the install whether or not the versions match.
57 - The APIC defaults to C(untriggered) when unset during creation.
58 type: str
59 choices: [ trigger, trigger_immediate, triggered, untriggered ]
60 description:
61 description:
62 - Description for the firmware policy.
63 type: str
64 aliases: [ descr ]
65 state:
66 description:
67 - Use C(present) or C(absent) for adding or removing.
68 - Use C(query) for listing an object or multiple objects.
69 type: str
70 choices: [absent, present, query]
71 default: present
72 name_alias:
73 description:
74 - The alias for the current object. This relates to the nameAlias field in ACI.
75 type: str
76 extends_documentation_fragment:
77 - cisco.aci.aci
78 - cisco.aci.annotation
79 - cisco.aci.owner
80
81 seealso:
82 - name: APIC Management Information Model reference
83 description: More information about the internal APIC class B(firmware:FwP).
84 link: https://developer.cisco.com/docs/apic-mim-ref/
85 author:
86 - Steven Gerhart (@sgerhart)
87 - Gaspard Micol (@gmicol)
88 """
89
90 EXAMPLES = r"""
91 - name: Create a firmware policy
92 cisco.aci.aci_firmware_policy:
93 host: apic
94 username: admin
95 password: SomeSecretPassword
96 name: my_firmware_policy
97 version: n9000-13.2(1m)
98 ignore_compat: false
99 state: present
100 delegate_to: localhost
101
102 - name: Delete a firmware policy
103 cisco.aci.aci_firmware_policy:
104 host: apic
105 username: admin
106 password: SomeSecretPassword
107 name: my_firmware_policy
108 state: absent
109 delegate_to: localhost
110
111 - name: Query all maintenance policies
112 cisco.aci.aci_firmware_policy:
113 host: apic
114 username: admin
115 password: SomeSecretPassword
116 state: query
117 delegate_to: localhost
118 register: query_result
119
120 - name: Query a specific firmware policy
121 cisco.aci.aci_firmware_policy:
122 host: apic
123 username: admin
124 password: SomeSecretPassword
125 name: my_firmware_policy
126 state: query
127 delegate_to: localhost
128 register: query_result
129 """
130
131 RETURN = r"""
132 current:
133 description: The existing configuration from the APIC after the module has finished
134 returned: success
135 type: list
136 sample:
137 [
138 {
139 "fvTenant": {
140 "attributes": {
141 "descr": "Production environment",
142 "dn": "uni/tn-production",
143 "name": "production",
144 "nameAlias": "",
145 "ownerKey": "",
146 "ownerTag": ""
147 }
148 }
149 }
150 ]
151 error:
152 description: The error information as returned from the APIC
153 returned: failure
154 type: dict
155 sample:
156 {
157 "code": "122",
158 "text": "unknown managed object class foo"
159 }
160 raw:
161 description: The raw output returned by the APIC REST API (xml or json)
162 returned: parse error
163 type: str
164 sample: '<?xml version="1.0" encoding="UTF-8"?><imdata totalCount="1"><error code="122" text="unknown managed object class foo"/></imdata>'
165 sent:
166 description: The actual/minimal configuration pushed to the APIC
167 returned: info
168 type: list
169 sample:
170 {
171 "fvTenant": {
172 "attributes": {
173 "descr": "Production environment"
174 }
175 }
176 }
177 previous:
178 description: The original configuration from the APIC before the module has started
179 returned: info
180 type: list
181 sample:
182 [
183 {
184 "fvTenant": {
185 "attributes": {
186 "descr": "Production",
187 "dn": "uni/tn-production",
188 "name": "production",
189 "nameAlias": "",
190 "ownerKey": "",
191 "ownerTag": ""
192 }
193 }
194 }
195 ]
196 proposed:
197 description: The assembled configuration from the user-provided parameters
198 returned: info
199 type: dict
200 sample:
201 {
202 "fvTenant": {
203 "attributes": {
204 "descr": "Production environment",
205 "name": "production"
206 }
207 }
208 }
209 filter_string:
210 description: The filter string used for the request
211 returned: failure or debug
212 type: str
213 sample: ?rsp-prop-include=config-only
214 method:
215 description: The HTTP method used for the request to the APIC
216 returned: failure or debug
217 type: str
218 sample: POST
219 response:
220 description: The HTTP response from the APIC
221 returned: failure or debug
222 type: str
223 sample: OK (30 bytes)
224 status:
225 description: The HTTP status from the APIC
226 returned: failure or debug
227 type: int
228 sample: 200
229 url:
230 description: The HTTP url used for the request to the APIC
231 returned: failure or debug
232 type: str
233 sample: https://10.11.12.13/api/mo/uni/tn-production.json
234 """
235
236
237 from ansible_collections.cisco.aci.plugins.module_utils.aci import ACIModule, aci_argument_spec, aci_annotation_spec, aci_owner_spec
238 from ansible.module_utils.basic import AnsibleModule
239 from ansible_collections.cisco.aci.plugins.module_utils.constants import MATCH_TRIGGER_MAPPING
240
241
242 def main():
243 argument_spec = aci_argument_spec()
244 argument_spec.update(aci_annotation_spec())
245 argument_spec.update(aci_owner_spec())
246 argument_spec.update(
247 name=dict(type="str"), # Not required for querying all objects
248 description=dict(type="str", aliases=["descr"]),
249 version=dict(type="str"),
250 effective_on_reboot=dict(type="bool"),
251 ignore_compat=dict(type="bool", aliases=["ignoreCompat"]),
252 sr_upgrade=dict(type="bool"),
253 sr_version=dict(type="str"),
254 version_check_override=dict(type="str", choices=list(MATCH_TRIGGER_MAPPING.keys())),
255 state=dict(type="str", default="present", choices=["absent", "present", "query"]),
256 name_alias=dict(type="str"),
257 )
258
259 module = AnsibleModule(
260 argument_spec=argument_spec,
261 supports_check_mode=True,
262 required_if=[
263 ["state", "absent", ["name"]],
264 ["state", "present", ["name", "version"]],
265 ],
266 )
267 aci = ACIModule(module)
268
269 state = module.params.get("state")
270 name = module.params.get("name")
271 description = module.params.get("description")
272 version = module.params.get("version")
273 effective_on_reboot = aci.boolean(module.params.get("effective_on_reboot"), "yes", "no")
274 ignore_compat = aci.boolean(module.params.get("ignore_compat"), "yes", "no")
275 sr_version = module.params.get("sr_version")
276 sr_upgrade = aci.boolean(module.params.get("sr_upgrade"), "yes", "no")
277 version_check_override = MATCH_TRIGGER_MAPPING.get(module.params.get("version_check_override"))
278 name_alias = module.params.get("name_alias")
279
280 aci.construct_url(
281 root_class=dict(
282 aci_class="firmwareFwP",
283 aci_rn="fabric/fwpol-{0}".format(name),
284 target_filter={"name": name},
285 module_object=name,
286 ),
287 )
288
289 aci.get_existing()
290
291 if state == "present":
292 aci.payload(
293 aci_class="firmwareFwP",
294 class_config=dict(
295 name=name,
296 descr=description,
297 version=version,
298 effectiveOnReboot=effective_on_reboot,
299 ignoreCompat=ignore_compat,
300 srUpgrade=sr_upgrade,
301 srVersion=sr_version,
302 versionCheckOverride=version_check_override,
303 nameAlias=name_alias,
304 ),
305 )
306
307 aci.get_diff(aci_class="firmwareFwP")
308
309 aci.post_config()
310
311 elif state == "absent":
312 aci.delete_config()
313
314 aci.exit_json()
315
316
317 if __name__ == "__main__":
318 main()