Debian Codegraph @

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

raw
1 #!/usr/bin/python
2
3 # (c) 2025, NetApp, Inc
4 # GNU General Public License v3.0+
5 # (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
6
7 from __future__ import absolute_import, division, print_function
8 __metaclass__ = type
9
10 DOCUMENTATION = """
11 module: na_ontap_support_config_backup
12 short_description: NetApp ONTAP support configuration backup
13 extends_documentation_fragment:
14 - netapp.ontap.netapp.na_ontap_rest
15 version_added: 23.0.0
16 author: NetApp Ansible Team (@carchi8py) <[email protected]>
17 description:
18 - Retrieves and modify the cluster configuration backup information.
19
20 options:
21 state:
22 description:
23 - This module supports only system backup configuration modify, hence only present state is supported.
24 choices: ['present']
25 type: str
26 default: present
27
28 url:
29 description:
30 - An external backup location for the cluster configuration.
31 - This is mostly required for single node clusters where node and cluster configuration backups cannot be copied to other nodes in the cluster.
32 type: str
33
34 validate_certificate:
35 description:
36 - Use this parameter with the value "true" to validate the digital certificate of the remote server.
37 - Digital certificate validation is available only when the HTTPS protocol is used in the URL; it is disabled by default.
38 type: bool
39
40 name:
41 description:
42 - Use this parameter to specify the user name to use to log in to the destination system and perform the upload.
43 - The option "name" should be used in parameter instead of "username".
44 type: str
45
46 set_password:
47 description:
48 - Password used to uploads configuration backups.
49 - The option "set_password" should be used in parameter instead of "password".
50 type: str
51 version_added: 23.1.0
52
53 notes:
54 - Only supported with REST and requires ONTAP 9.6 or later.
55 - The option 'validate_certificate' requires ONTAP 9.7 or later.
56
57 """
58
59 EXAMPLES = """
60 - name: Get support config backup
61 netapp.ontap.na_ontap_support_config_backup:
62 state: present
63 hostname: "{{ netapp_hostname }}"
64 username: "{{ netapp_username }}"
65 password: "{{ netapp_password }}"
66 https: true
67 validate_certs: false
68 validate_certificate: false
69 url: "{{ backup_url }}"
70 name: Netappuser
71
72 - name: Modify the support config_backup
73 netapp.ontap.na_ontap_support_config_backup:
74 state: present
75 hostname: "{{ netapp_hostname }}"
76 username: "{{ netapp_username }}"
77 password: "{{ netapp_password }}"
78 https: true
79 validate_certs: false
80 validate_certificate: true
81 url: "{{ backup_url }}"
82 name: ftpuser
83 set_password: "netapp"
84 feature_flags:
85 trace_apis: true
86 """
87
88 RETURN = """
89 """
90
91
92 import traceback
93 from ansible.module_utils.basic import AnsibleModule
94 import ansible_collections.netapp.ontap.plugins.module_utils.netapp as netapp_utils
95 from ansible_collections.netapp.ontap.plugins.module_utils.netapp_module import NetAppModule
96 from ansible_collections.netapp.ontap.plugins.module_utils import rest_generic
97
98
99 class NetAppOntapSupportConfigBackup:
100 """Retriveing and updating the configuration backup settings"""
101 def __init__(self):
102 self.argument_spec = netapp_utils.na_ontap_rest_only_spec()
103 self.argument_spec.update(dict(
104 state=dict(required=False, type='str', choices=['present'], default='present'),
105 url=dict(required=False, type='str'),
106 # destination username should be passed as name
107 name=dict(required=False, type='str'),
108 validate_certificate=dict(required=False, type='bool'),
109 set_password=dict(type='str', no_log=True),
110 ))
111
112 self.module = AnsibleModule(
113 argument_spec=self.argument_spec,
114 supports_check_mode=True
115 )
116 self.na_helper = NetAppModule()
117 self.parameters = self.na_helper.set_parameters(self.module.params)
118 self.rest_api = netapp_utils.OntapRestAPI(self.module)
119 self.use_rest = self.rest_api.is_rest()
120 partially_supported_rest_properties = [['validate_certificate', (9, 7, 0)]]
121 self.use_rest = self.rest_api.is_rest_supported_properties(self.parameters, None, partially_supported_rest_properties)
122 if not self.use_rest:
123 self.module.fail_json(msg='Error: na_ontap_support_config_backup is only supported with REST API')
124
125 def get_support_config_backup(self):
126 # Retrieves the cluster configuration backup information
127 api = 'support/configuration-backup'
128 fields = 'url,username,'
129 if self.rest_api.meets_rest_minimum_version(self.use_rest, 9, 7, 0):
130 fields += 'validate_certificate,'
131 record, error = rest_generic.get_one_record(self.rest_api, api)
132 if error:
133 self.module.fail_json(msg='Error fetching configuration backup settings',
134 exception=traceback.format_exc())
135 if record:
136 return {
137 'url': self.na_helper.safe_get(record, ['url']),
138 'name': self.na_helper.safe_get(record, ['username']),
139 'validate_certificate': self.na_helper.safe_get(record, ['validate_certificate'])
140 }
141 return None
142
143 def modify_support_config_backup(self, modify):
144 # Updates the cluster configuration backup information.
145 api = 'support/configuration-backup'
146 body = {}
147 if 'url' in modify:
148 body['url'] = modify['url']
149 if 'name' in modify:
150 body['username'] = modify['name']
151 if 'validate_certificate' in modify:
152 body['validate_certificate'] = modify['validate_certificate']
153 if 'set_password' in modify:
154 body['password'] = modify['set_password']
155 dummy, error = rest_generic.patch_async(self.rest_api, api, None, body)
156 if error:
157 self.module.fail_json(msg='Error updating the configuration backup settings',
158 exception=traceback.format_exc())
159
160 def apply(self):
161 current = self.get_support_config_backup()
162 cd_action = self.na_helper.get_cd_action(current, self.parameters)
163 modify = self.na_helper.get_modified_attributes(current, self.parameters) if cd_action is None else None
164 password_changed = False
165 if cd_action is None and self.parameters.get('set_password') is not None and self.parameters['state'] == 'present':
166 # if check_mode, don't attempt to change the password, but assume it would be changed
167 if self.module.check_mode:
168 modify['set_password'] = self.parameters.get('set_password')
169 password_changed = True
170 else:
171 modify['set_password'] = self.parameters.get('set_password')
172 password_changed = self.modify_support_config_backup(modify)
173
174 self.na_helper.changed = True
175 self.module.warn('Module is not idempotent when set_password is present.')
176
177 if self.na_helper.changed and not self.module.check_mode:
178 if modify:
179 self.modify_support_config_backup(modify)
180 self.module.exit_json(changed=self.na_helper.changed, current=current, modify=modify, password_changed=password_changed)
181
182
183 def main():
184 config_bkp = NetAppOntapSupportConfigBackup()
185 config_bkp.apply()
186
187
188 if __name__ == '__main__':
189 main()