Debian Codegraph @

ansible_collections/netapp/ontap/plugins/modules/na_ontap_autoupdate_support.py

raw
1 #!/usr/bin/python
2 """
3 create auto-update module to enable automatic software update
4 """
5
6 # (c) 2025, NetApp, Inc
7 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
8 from __future__ import absolute_import, division, print_function
9 __metaclass__ = type
10
11
12 DOCUMENTATION = '''
13 module: na_ontap_autoupdate_support
14 short_description: NetApp ONTAP enable auto update status.
15 extends_documentation_fragment:
16 - netapp.ontap.netapp.na_ontap_rest
17 version_added: '23.1.0'
18 author: NetApp Ansible Team (@carchi8py) <[email protected]>
19 description:
20 - Enable automatic software update.
21 options:
22 enabled:
23 description:
24 - Flag indicating feature state.
25 type: bool
26 force:
27 description:
28 - Set the force flag to true to enable the automatic update feature regardless of how AutoSupport is configured.
29 - Without this flag set to true, an attempt to enable the automatic update feature fails unless AutoSupport is enabled,
30 its transport is HTTPS, and the AutoSupport OnDemand feature is enabled.
31 type: bool
32 '''
33
34 EXAMPLES = """
35 - name: Modify status to enable automatic update
36 netapp.ontap.na_ontap_autoupdate_support:
37 enabled: true
38 force: true
39 hostname: "{{ netapp_hostname }}"
40 username: "{{ netapp_username }}"
41 password: "{{ netapp_password }}"
42 """
43
44 RETURN = """
45 """
46 from ansible.module_utils.basic import AnsibleModule
47 import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils
48 from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule
49 from ansible_collections.netapp.ontap.plugins.module_utils import rest_generic
50
51
52 class NetAppONTAPAutoUpdateSupport:
53 """Class with auto update methods"""
54
55 def __init__(self):
56 self.use_rest = False
57 self.argument_spec = netapp_utils.na_ontap_rest_only_spec()
58 self.argument_spec.update(dict(
59 enabled=dict(required=False, type='bool'),
60 force=dict(required=False, type='bool'),
61 ))
62 self.module = AnsibleModule(
63 argument_spec=self.argument_spec,
64 supports_check_mode=True
65 )
66 self.na_helper = NetAppModule()
67 self.parameters = self.na_helper.set_parameters(self.module.params)
68 self.rest_api = netapp_utils.OntapRestAPI(self.module)
69 self.rest_api.fail_if_not_rest_minimum_version('na_ontap_autoupdate_support', 9, 10, 1)
70 partially_supported_rest_properties = [['force', (9, 16, 1)]]
71 self.use_rest = self.rest_api.is_rest_supported_properties(self.parameters, None, partially_supported_rest_properties)
72
73 def get_auto_update_status(self):
74 """
75 Retrieves the current status of the automatic update feature
76 """
77 query = {'fields': 'enabled'}
78 api = 'support/auto-update'
79 record, error = rest_generic.get_one_record(self.rest_api, api, query)
80 if error:
81 self.module.fail_json(msg="Error retrieving the current status of the automatic update feature info: %s" % error)
82 return record
83
84 def modify_auto_update_status(self, modify):
85 """
86 Updates the current enabled status of the automatic update feature
87 """
88 params = {}
89 query = {}
90 api = 'support/auto-update'
91 if 'enabled' in modify:
92 params['enabled'] = self.parameters.get('enabled')
93 if 'force' in self.parameters:
94 query['force'] = self.parameters.get('force')
95 dummy, error = rest_generic.patch_async(self.rest_api, api, None, params, query)
96 if error:
97 self.module.fail_json(msg="Error on modifying the current status of the automatic update feature: %s" % error)
98
99 def apply(self):
100 """
101 Apply action to enable auto update support
102 """
103 current = self.get_auto_update_status()
104 cd_action = self.na_helper.get_cd_action(current, self.parameters)
105 modify = self.na_helper.get_modified_attributes(current, self.parameters) if cd_action is None else None
106 if self.na_helper.changed and not self.module.check_mode:
107 if modify:
108 self.modify_auto_update_status(modify)
109 result = netapp_utils.generate_result(self.na_helper.changed, cd_action, modify)
110 self.module.exit_json(**result)
111
112
113 def main():
114 """Execute action"""
115 community_obj = NetAppONTAPAutoUpdateSupport()
116 community_obj.apply()
117
118
119 if __name__ == '__main__':
120 main()