mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-22 21:00:22 -07:00
New Options for Autosupport (#50773)
* new option * spelling * fix minor issue * Fix Doc line * Add update netapp_module * fix issue with autosupport * Fix docuemntation
This commit is contained in:
parent
8c08d03989
commit
890f4eb5c4
3 changed files with 449 additions and 92 deletions
|
@ -3,7 +3,7 @@
|
|||
create Autosupport module to enable, disable or modify
|
||||
"""
|
||||
|
||||
# (c) 2018, NetApp, Inc
|
||||
# (c) 2018-2019, NetApp, Inc
|
||||
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
from __future__ import absolute_import, division, print_function
|
||||
__metaclass__ = type
|
||||
|
@ -24,58 +24,79 @@ module: na_ontap_autosupport
|
|||
options:
|
||||
state:
|
||||
description:
|
||||
- Specifies whether the AutoSupport daemon is present or absent.
|
||||
- When this setting is absent, delivery of all AutoSupport messages is turned off.
|
||||
- Specifies whether the AutoSupport daemon is present or absent.
|
||||
- When this setting is absent, delivery of all AutoSupport messages is turned off.
|
||||
choices: ['present', 'absent']
|
||||
default: present
|
||||
node_name:
|
||||
description:
|
||||
- The name fo the filer that owns the AutoSupport Configuration.
|
||||
- The name of the filer that owns the AutoSupport Configuration.
|
||||
required: true
|
||||
transport:
|
||||
description:
|
||||
- The name of the transport protocol used to deliver AutoSupport messages
|
||||
- The name of the transport protocol used to deliver AutoSupport messages
|
||||
choices: ['http', 'https', 'smtp']
|
||||
noteto:
|
||||
description:
|
||||
- Specifies up to five recipients of full AutoSupport e-mail messages.
|
||||
- Specifies up to five recipients of short AutoSupport e-mail messages.
|
||||
post_url:
|
||||
description:
|
||||
- The URL used to deliver AutoSupport messages via HTTP POST
|
||||
- The URL used to deliver AutoSupport messages via HTTP POST
|
||||
mail_hosts:
|
||||
description:
|
||||
- List of mail server(s) used to deliver AutoSupport messages via SMTP.
|
||||
- Both host names and IP addresses may be used as valid input.
|
||||
- List of mail server(s) used to deliver AutoSupport messages via SMTP.
|
||||
- Both host names and IP addresses may be used as valid input.
|
||||
support:
|
||||
description:
|
||||
- Specifies whether AutoSupport notification to technical support is enabled.
|
||||
- Specifies whether AutoSupport notification to technical support is enabled.
|
||||
type: bool
|
||||
short_description: "NetApp ONTAP manage Autosupport"
|
||||
from_address:
|
||||
description:
|
||||
- specify the e-mail address from which the node sends AutoSupport messages
|
||||
version_added: 2.8
|
||||
partner_addresses:
|
||||
description:
|
||||
- Specifies up to five partner vendor recipients of full AutoSupport e-mail messages.
|
||||
version_added: 2.8
|
||||
to_addresses:
|
||||
description:
|
||||
- Specifies up to five recipients of full AutoSupport e-mail messages.
|
||||
version_added: 2.8
|
||||
proxy_url:
|
||||
description:
|
||||
- specify an HTTP or HTTPS proxy if the 'transport' parameter is set to HTTP or HTTPS and your organization uses a proxy
|
||||
version_added: 2.8
|
||||
hostname_in_subject:
|
||||
description:
|
||||
- Specify whether the hostname of the node is included in the subject line of the AutoSupport message.
|
||||
type: bool
|
||||
version_added: 2.8
|
||||
short_description: NetApp ONTAP Autosupport
|
||||
version_added: "2.7"
|
||||
|
||||
"""
|
||||
|
||||
EXAMPLES = """
|
||||
- name: Enable autosupport
|
||||
na_ontap_autosupport:
|
||||
hostname: "{{ hostname }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
state: present
|
||||
node_name: test
|
||||
transport: https
|
||||
noteto: abc@def.com,def@ghi.com
|
||||
mail_hosts: 1.2.3.4,5.6.7.8
|
||||
support: False
|
||||
post_url: url/1.0/post
|
||||
- name: Enable autosupport
|
||||
na_ontap_autosupport:
|
||||
hostname: "{{ hostname }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
state: present
|
||||
node_name: test
|
||||
transport: https
|
||||
noteto: abc@def.com,def@ghi.com
|
||||
mail_hosts: 1.2.3.4,5.6.7.8
|
||||
support: False
|
||||
post_url: url/1.0/post
|
||||
|
||||
- name: Disable autosupport
|
||||
na_ontap_autosupport:
|
||||
hostname: "{{ hostname }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
state: absent
|
||||
node_name: test
|
||||
- name: Disable autosupport
|
||||
na_ontap_autosupport:
|
||||
hostname: "{{ hostname }}"
|
||||
username: "{{ username }}"
|
||||
password: "{{ password }}"
|
||||
state: absent
|
||||
node_name: test
|
||||
|
||||
"""
|
||||
|
||||
|
@ -104,7 +125,12 @@ class NetAppONTAPasup(object):
|
|||
noteto=dict(required=False, type='list'),
|
||||
post_url=dict(reuired=False, type='str'),
|
||||
support=dict(required=False, type='bool'),
|
||||
mail_hosts=dict(required=False, type='list')
|
||||
mail_hosts=dict(required=False, type='list'),
|
||||
from_address=dict(required=False, type='str'),
|
||||
partner_addresses=dict(required=False, type='list'),
|
||||
to_addresses=dict(required=False, type='list'),
|
||||
proxy_url=dict(required=False, type='str'),
|
||||
hostname_in_subject=dict(required=False, type='bool'),
|
||||
))
|
||||
|
||||
self.module = AnsibleModule(
|
||||
|
@ -116,16 +142,36 @@ class NetAppONTAPasup(object):
|
|||
self.parameters = self.na_helper.set_parameters(self.module.params)
|
||||
# present or absent requires modifying state to enabled or disabled
|
||||
self.parameters['service_state'] = 'started' if self.parameters['state'] == 'present' else 'stopped'
|
||||
self.set_playbook_zapi_key_map()
|
||||
|
||||
if HAS_NETAPP_LIB is False:
|
||||
self.module.fail_json(msg="the python NetApp-Lib module is required")
|
||||
else:
|
||||
self.server = netapp_utils.setup_ontap_zapi(module=self.module)
|
||||
|
||||
def set_playbook_zapi_key_map(self):
|
||||
self.na_helper.zapi_string_keys = {
|
||||
'node_name': 'node-name',
|
||||
'transport': 'transport',
|
||||
'post_url': 'post-url',
|
||||
'from_address': 'from',
|
||||
'proxy_url': 'proxy-url'
|
||||
}
|
||||
self.na_helper.zapi_list_keys = {
|
||||
'noteto': ('noteto', 'mail-address'),
|
||||
'mail_hosts': ('mail-hosts', 'string'),
|
||||
'partner_addresses': ('partner-address', 'mail-address'),
|
||||
'to_addresses': ('to', 'mail-address'),
|
||||
}
|
||||
self.na_helper.zapi_bool_keys = {
|
||||
'support': 'is-support-enabled',
|
||||
'hostname_in_subject': 'is-node-in-subject'
|
||||
}
|
||||
|
||||
def get_autosupport_config(self):
|
||||
"""
|
||||
Invoke zapi - get current autosupport status
|
||||
@return: 'true' or 'false' / FAILURE with an error_message
|
||||
Invoke zapi - get current autosupport details
|
||||
:return: dict()
|
||||
"""
|
||||
asup_details = netapp_utils.zapi.NaElement('autosupport-config-get')
|
||||
asup_details.add_new_child('node-name', self.parameters['node_name'])
|
||||
|
@ -137,26 +183,17 @@ class NetAppONTAPasup(object):
|
|||
exception=traceback.format_exc())
|
||||
# zapi invoke successful
|
||||
asup_attr_info = result.get_child_by_name('attributes').get_child_by_name('autosupport-config-info')
|
||||
current_state = asup_attr_info.get_child_content('is-enabled')
|
||||
if current_state == 'true':
|
||||
asup_info['service_state'] = 'started'
|
||||
elif current_state == 'false':
|
||||
asup_info['service_state'] = 'stopped'
|
||||
current_support = asup_attr_info.get_child_content('is-support-enabled')
|
||||
if current_support == 'true':
|
||||
asup_info['support'] = True
|
||||
elif current_support == 'false':
|
||||
asup_info['support'] = False
|
||||
asup_info['transport'] = asup_attr_info.get_child_content('transport')
|
||||
asup_info['post_url'] = asup_attr_info.get_child_content('post-url')
|
||||
mail_hosts = asup_attr_info.get_child_by_name('mail-hosts')
|
||||
# mail hosts has one valid entry always
|
||||
if mail_hosts is not None:
|
||||
# get list of mail hosts
|
||||
asup_info['mail_hosts'] = [mail.get_content() for mail in mail_hosts.get_children()]
|
||||
email_list = asup_attr_info.get_child_by_name('noteto')
|
||||
# if email_list is empty, noteto is also empty
|
||||
asup_info['noteto'] = [] if email_list is None else [email.get_content() for email in email_list.get_children()]
|
||||
asup_info['service_state'] = 'started' if asup_attr_info['is-enabled'] == 'true' else 'stopped'
|
||||
for item_key, zapi_key in self.na_helper.zapi_string_keys.items():
|
||||
asup_info[item_key] = asup_attr_info[zapi_key]
|
||||
for item_key, zapi_key in self.na_helper.zapi_bool_keys.items():
|
||||
asup_info[item_key] = self.na_helper.get_value_for_bool(from_zapi=True,
|
||||
value=asup_attr_info[zapi_key])
|
||||
for item_key, zapi_key in self.na_helper.zapi_list_keys.items():
|
||||
parent, dummy = zapi_key
|
||||
asup_info[item_key] = self.na_helper.get_value_for_list(from_zapi=True,
|
||||
zapi_parent=asup_attr_info.get_child_by_name(parent)
|
||||
)
|
||||
return asup_info
|
||||
|
||||
def modify_autosupport_config(self, modify):
|
||||
|
@ -164,55 +201,46 @@ class NetAppONTAPasup(object):
|
|||
Invoke zapi - modify autosupport config
|
||||
@return: NaElement object / FAILURE with an error_message
|
||||
"""
|
||||
asup_details = netapp_utils.zapi.NaElement('autosupport-config-modify')
|
||||
asup_details.add_new_child('node-name', self.parameters['node_name'])
|
||||
asup_details = {'node-name': self.parameters['node_name']}
|
||||
if modify.get('service_state'):
|
||||
if modify.get('service_state') == 'started':
|
||||
asup_details.add_new_child('is-enabled', 'true')
|
||||
elif modify.get('service_state') == 'stopped':
|
||||
asup_details.add_new_child('is-enabled', 'false')
|
||||
if modify.get('support') is not None:
|
||||
if modify.get('support') is True:
|
||||
asup_details.add_new_child('is-support-enabled', 'true')
|
||||
elif modify.get('support') is False:
|
||||
asup_details.add_new_child('is-support-enabled', 'false')
|
||||
if modify.get('transport'):
|
||||
asup_details.add_new_child('transport', modify['transport'])
|
||||
if modify.get('post_url'):
|
||||
asup_details.add_new_child('post-url', modify['post_url'])
|
||||
if modify.get('noteto'):
|
||||
asup_email = netapp_utils.zapi.NaElement('noteto')
|
||||
asup_details.add_child_elem(asup_email)
|
||||
for email in modify.get('noteto'):
|
||||
asup_email.add_new_child('mail-address', email)
|
||||
if modify.get('mail_hosts'):
|
||||
asup_mail_hosts = netapp_utils.zapi.NaElement('mail-hosts')
|
||||
asup_details.add_child_elem(asup_mail_hosts)
|
||||
for mail in modify.get('mail_hosts'):
|
||||
asup_mail_hosts.add_new_child('string', mail)
|
||||
asup_details['is-enabled'] = 'true' if modify.get('service_state') == 'started' else 'false'
|
||||
asup_config = netapp_utils.zapi.NaElement('autosupport-config-modify')
|
||||
for item_key in modify:
|
||||
if item_key in self.na_helper.zapi_string_keys:
|
||||
zapi_key = self.na_helper.zapi_string_keys.get(item_key)
|
||||
asup_details[zapi_key] = modify[item_key]
|
||||
elif item_key in self.na_helper.zapi_bool_keys:
|
||||
zapi_key = self.na_helper.zapi_bool_keys.get(item_key)
|
||||
asup_details[zapi_key] = self.na_helper.get_value_for_bool(from_zapi=False,
|
||||
value=modify[item_key])
|
||||
elif item_key in self.na_helper.zapi_list_keys:
|
||||
parent_key, child_key = self.na_helper.zapi_list_keys.get(item_key)
|
||||
asup_config.add_child_elem(self.na_helper.get_value_for_list(from_zapi=False,
|
||||
zapi_parent=parent_key,
|
||||
zapi_child=child_key,
|
||||
data=modify.get(item_key)))
|
||||
asup_config.translate_struct(asup_details)
|
||||
try:
|
||||
result = self.server.invoke_successfully(asup_details, enable_tunneling=True)
|
||||
return result
|
||||
return self.server.invoke_successfully(asup_config, enable_tunneling=True)
|
||||
except netapp_utils.zapi.NaApiError as error:
|
||||
self.module.fail_json(msg='%s' % to_native(error),
|
||||
exception=traceback.format_exc())
|
||||
self.module.fail_json(msg='%s' % to_native(error), exception=traceback.format_exc())
|
||||
|
||||
def autosupport_log(self):
|
||||
results = netapp_utils.get_cserver(self.server)
|
||||
cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
|
||||
netapp_utils.ems_log_event("na_ontap_autosupport", cserver)
|
||||
|
||||
def apply(self):
|
||||
"""
|
||||
Apply action to autosupport
|
||||
"""
|
||||
results = netapp_utils.get_cserver(self.server)
|
||||
cserver = netapp_utils.setup_na_ontap_zapi(module=self.module, vserver=results)
|
||||
netapp_utils.ems_log_event("na_ontap_autosupport", cserver)
|
||||
|
||||
current = self.get_autosupport_config()
|
||||
modify = self.na_helper.get_modified_attributes(current, self.parameters)
|
||||
if self.na_helper.changed:
|
||||
if self.module.check_mode:
|
||||
pass
|
||||
else:
|
||||
if modify:
|
||||
self.modify_autosupport_config(modify)
|
||||
self.modify_autosupport_config(modify)
|
||||
self.module.exit_json(changed=self.na_helper.changed)
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue