Debian Codegraph @

ansible_collections/netapp_eseries/santricity/plugins/modules/netapp_e_asup.py

raw
1 #!/usr/bin/python
2
3 # (c) 2018, NetApp, Inc
4 # GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
5
6 from __future__ import absolute_import, division, print_function
7
8 __metaclass__ = type
9
10 ANSIBLE_METADATA = {'metadata_version': '1.1',
11 'status': ['deprecated'],
12 'supported_by': 'community'}
13
14 DOCUMENTATION = """
15 ---
16 module: netapp_e_asup
17 short_description: NetApp E-Series manage auto-support settings
18 description:
19 - Allow the auto-support settings to be configured for an individual E-Series storage-system
20 version_added: '2.7.0'
21 author: Michael Price (@lmprice)
22 extends_documentation_fragment:
23 - netapp_eseries.santricity.santricity.netapp.eseries
24 options:
25 state:
26 description:
27 - Enable/disable the E-Series auto-support configuration.
28 - When this option is enabled, configuration, logs, and other support-related information will be relayed
29 to NetApp to help better support your system. No personally identifiable information, passwords, etc, will
30 be collected.
31 default: enabled
32 type: str
33 choices:
34 - enabled
35 - disabled
36 aliases:
37 - asup
38 - auto_support
39 - autosupport
40 active:
41 description:
42 - Enable active/proactive monitoring for ASUP. When a problem is detected by our monitoring systems, it's
43 possible that the bundle did not contain all of the required information at the time of the event.
44 Enabling this option allows NetApp support personnel to manually request transmission or re-transmission
45 of support data in order ot resolve the problem.
46 - Only applicable if I(state=enabled).
47 default: yes
48 type: bool
49 start:
50 description:
51 - A start hour may be specified in a range from 0 to 23 hours.
52 - ASUP bundles will be sent daily between the provided start and end time (UTC).
53 - I(start) must be less than I(end).
54 aliases:
55 - start_time
56 default: 0
57 type: int
58 end:
59 description:
60 - An end hour may be specified in a range from 1 to 24 hours.
61 - ASUP bundles will be sent daily between the provided start and end time (UTC).
62 - I(start) must be less than I(end).
63 aliases:
64 - end_time
65 default: 24
66 type: int
67 days:
68 description:
69 - A list of days of the week that ASUP bundles will be sent. A larger, weekly bundle will be sent on one
70 of the provided days.
71 choices:
72 - monday
73 - tuesday
74 - wednesday
75 - thursday
76 - friday
77 - saturday
78 - sunday
79 required: no
80 type: list
81 elements: str
82 aliases:
83 - days_of_week
84 - schedule_days
85 verbose:
86 description:
87 - Provide the full ASUP configuration in the return.
88 default: no
89 required: no
90 type: bool
91 log_path:
92 description:
93 - A local path to a file to be used for debug logging
94 type: str
95 required: no
96 notes:
97 - Check mode is supported.
98 - Enabling ASUP will allow our support teams to monitor the logs of the storage-system in order to proactively
99 respond to issues with the system. It is recommended that all ASUP-related options be enabled, but they may be
100 disabled if desired.
101 - This API is currently only supported with the Embedded Web Services API v2.0 and higher.
102 """
103
104 EXAMPLES = """
105 - name: Enable ASUP and allow pro-active retrieval of bundles
106 netapp_e_asup:
107 state: enabled
108 active: yes
109 api_url: "10.1.1.1:8443"
110 api_username: "admin"
111 api_password: "myPass"
112
113 - name: Set the ASUP schedule to only send bundles from 12 AM CST to 3 AM CST.
114 netapp_e_asup:
115 start: 17
116 end: 20
117 api_url: "10.1.1.1:8443"
118 api_username: "admin"
119 api_password: "myPass"
120 """
121
122 RETURN = """
123 msg:
124 description: Success message
125 returned: on success
126 type: str
127 sample: The settings have been updated.
128 asup:
129 description:
130 - True if ASUP is enabled.
131 returned: on success
132 sample: True
133 type: bool
134 active:
135 description:
136 - True if the active option has been enabled.
137 returned: on success
138 sample: True
139 type: bool
140 cfg:
141 description:
142 - Provide the full ASUP configuration.
143 returned: on success when I(verbose=true).
144 type: complex
145 contains:
146 asupEnabled:
147 description:
148 - True if ASUP has been enabled.
149 type: bool
150 onDemandEnabled:
151 description:
152 - True if ASUP active monitoring has been enabled.
153 type: bool
154 daysOfWeek:
155 description:
156 - The days of the week that ASUP bundles will be sent.
157 type: list
158 """
159
160 import json
161 import logging
162 from pprint import pformat
163
164 from ansible.module_utils.basic import AnsibleModule
165 from ansible_collections.netapp_eseries.santricity.plugins.module_utils.netapp import request, eseries_host_argument_spec
166 from ansible.module_utils._text import to_native
167
168 HEADERS = {
169 "Content-Type": "application/json",
170 "Accept": "application/json",
171 }
172
173
174 class Asup(object):
175 DAYS_OPTIONS = ['sunday', 'monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday']
176
177 def __init__(self):
178 argument_spec = eseries_host_argument_spec()
179 argument_spec.update(dict(
180 state=dict(type='str', required=False, default='enabled', aliases=['asup', 'auto_support', 'autosupport'],
181 choices=['enabled', 'disabled']),
182 active=dict(type='bool', required=False, default=True, ),
183 days=dict(type='list', elements='str', required=False, aliases=['schedule_days', 'days_of_week'],
184 choices=self.DAYS_OPTIONS),
185 start=dict(type='int', required=False, default=0, aliases=['start_time']),
186 end=dict(type='int', required=False, default=24, aliases=['end_time']),
187 verbose=dict(type='bool', required=False, default=False),
188 log_path=dict(type='str', required=False),
189 ))
190
191 self.module = AnsibleModule(argument_spec=argument_spec, supports_check_mode=True, )
192 args = self.module.params
193 self.asup = args['state'] == 'enabled'
194 self.active = args['active']
195 self.days = args['days']
196 self.start = args['start']
197 self.end = args['end']
198 self.verbose = args['verbose']
199
200 self.ssid = args['ssid']
201 self.url = args['api_url']
202 self.creds = dict(url_password=args['api_password'],
203 validate_certs=args['validate_certs'],
204 url_username=args['api_username'], )
205
206 self.check_mode = self.module.check_mode
207
208 log_path = args['log_path']
209
210 # logging setup
211 self._logger = logging.getLogger(self.__class__.__name__)
212
213 if log_path:
214 logging.basicConfig(
215 level=logging.DEBUG, filename=log_path, filemode='w',
216 format='%(relativeCreated)dms %(levelname)s %(module)s.%(funcName)s:%(lineno)d\n %(message)s')
217
218 if not self.url.endswith('/'):
219 self.url += '/'
220
221 if self.start >= self.end:
222 self.module.fail_json(msg="The value provided for the start time is invalid."
223 " It must be less than the end time.")
224 if self.start < 0 or self.start > 23:
225 self.module.fail_json(msg="The value provided for the start time is invalid. It must be between 0 and 23.")
226 else:
227 self.start = self.start * 60
228 if self.end < 1 or self.end > 24:
229 self.module.fail_json(msg="The value provided for the end time is invalid. It must be between 1 and 24.")
230 else:
231 self.end = min(self.end * 60, 1439)
232
233 if not self.days:
234 self.days = self.DAYS_OPTIONS
235
236 def get_configuration(self):
237 try:
238 (rc, result) = request(self.url + 'device-asup', headers=HEADERS, **self.creds)
239
240 if not (result['asupCapable'] and result['onDemandCapable']):
241 self.module.fail_json(msg="ASUP is not supported on this device. Array Id [%s]." % (self.ssid))
242 return result
243
244 except Exception as err:
245 self.module.fail_json(msg="Failed to retrieve ASUP configuration! Array Id [%s]. Error [%s]."
246 % (self.ssid, to_native(err)))
247
248 def update_configuration(self):
249 config = self.get_configuration()
250 update = False
251 body = dict()
252
253 if self.asup:
254 body = dict(asupEnabled=True)
255 if not config['asupEnabled']:
256 update = True
257
258 if (config['onDemandEnabled'] and config['remoteDiagsEnabled']) != self.active:
259 update = True
260 body.update(dict(onDemandEnabled=self.active,
261 remoteDiagsEnabled=self.active))
262 self.days.sort()
263 config['schedule']['daysOfWeek'].sort()
264
265 body['schedule'] = dict(daysOfWeek=self.days,
266 dailyMinTime=self.start,
267 dailyMaxTime=self.end,
268 weeklyMinTime=self.start,
269 weeklyMaxTime=self.end)
270
271 if self.days != config['schedule']['daysOfWeek']:
272 update = True
273 if self.start != config['schedule']['dailyMinTime'] or self.start != config['schedule']['weeklyMinTime']:
274 update = True
275 elif self.end != config['schedule']['dailyMaxTime'] or self.end != config['schedule']['weeklyMaxTime']:
276 update = True
277
278 elif config['asupEnabled']:
279 body = dict(asupEnabled=False)
280 update = True
281
282 self._logger.info(pformat(body))
283
284 if update and not self.check_mode:
285 try:
286 (rc, result) = request(self.url + 'device-asup', method='POST',
287 data=json.dumps(body), headers=HEADERS, **self.creds)
288 # This is going to catch cases like a connection failure
289 except Exception as err:
290 self.module.fail_json(msg="We failed to set the storage-system name! Array Id [%s]. Error [%s]."
291 % (self.ssid, to_native(err)))
292
293 return update
294
295 def update(self):
296 update = self.update_configuration()
297 cfg = self.get_configuration()
298 if self.verbose:
299 self.module.exit_json(msg="The ASUP settings have been updated.", changed=update,
300 asup=cfg['asupEnabled'], active=cfg['onDemandEnabled'], cfg=cfg)
301 else:
302 self.module.exit_json(msg="The ASUP settings have been updated.", changed=update,
303 asup=cfg['asupEnabled'], active=cfg['onDemandEnabled'])
304
305 def __call__(self, *args, **kwargs):
306 self.update()
307
308
309 def main():
310 settings = Asup()
311 settings()
312
313
314 if __name__ == '__main__':
315 main()