Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

na_ontap_volume - added qos policy module options #56026

Merged
merged 5 commits into from May 21, 2019
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 48 additions & 4 deletions lib/ansible/modules/storage/netapp/na_ontap_volume.py
Expand Up @@ -222,6 +222,17 @@
- zh_tw.big5 Traditional Chinese Big 5
- To use UTF-8 as the NFS character set, append '.UTF-8' to the language code
version_added: '2.8'

qos_policy_group:
description:
- Allows a QoS policy group to be set on volume creation.
vicmunoz marked this conversation as resolved.
Show resolved Hide resolved
version_added: '2.9'

qos_adaptive_policy_group:
vicmunoz marked this conversation as resolved.
Show resolved Hide resolved
description:
- Allows a QoS adaptive policy group to be set on volume creation.
version_added: '2.9'

'''

EXAMPLES = """
Expand Down Expand Up @@ -371,7 +382,9 @@ def __init__(self):
auto_provision_as=dict(choices=['flexgroup'], required=False, type='str'),
wait_for_completion=dict(required=False, type='bool', default=False),
time_out=dict(required=False, type='int', default=180),
language=dict(type='str', required=False)
language=dict(type='str', required=False),
qos_policy_group=dict(required=False, type='str'),
qos_adaptive_policy_group=dict(required=False, type='str')
))
self.module = AnsibleModule(
argument_spec=self.argument_spec,
Expand Down Expand Up @@ -482,6 +495,20 @@ def get_volume(self, vol_name=None):
return_value['atime_update'] = volume_performance_attributes['is-atime-update-enabled']
else:
return_value['atime_update'] = None
if volume_attributes.get_child_by_name('volume-qos-attributes'):
volume_qos_attributes = volume_attributes['volume-qos-attributes']
if volume_qos_attributes.get_child_by_name('policy-group-name'):
return_value['qos_policy_group'] = volume_qos_attributes['policy-group-name']
else:
return_value['qos_policy_group'] = None
if volume_qos_attributes.get_child_by_name('adaptive-policy-group-name'):
vol_qos_adaptive = volume_qos_attributes['adaptive-policy-group-name']
vicmunoz marked this conversation as resolved.
Show resolved Hide resolved
return_value['qos_adaptive_policy_group'] = vol_qos_adaptive
else:
return_value['qos_adaptive_policy_group'] = None
else:
return_value['qos_policy_group'] = None
return_value['qos_adaptive_policy_group'] = None

return return_value

Expand Down Expand Up @@ -537,6 +564,7 @@ def create_volume_async(self):
self.assign_efficiency_policy_async()

def create_volume_options(self):
'''Set volume options for create operation'''
options = {}
if self.volume_style == 'flexGroup':
options['volume-name'] = self.parameters['name']
Expand Down Expand Up @@ -574,6 +602,10 @@ def create_volume_options(self):
options['percentage-snapshot-reserve'] = self.parameters['percent_snapshot_space']
if self.parameters.get('language'):
options['language-code'] = self.parameters['language']
if self.parameters.get('qos_policy_group'):
options['qos-policy-group-name'] = self.parameters['qos_policy_group']
if self.parameters.get('qos_adaptive_policy_group'):
options['qos-adaptive-policy-group-name'] = self.parameters['qos_adaptive_policy_group']
return options

def delete_volume(self):
Expand Down Expand Up @@ -688,7 +720,8 @@ def change_volume_state(self):

def volume_modify_attributes(self):
"""
modify volume parameter 'policy','unix_permissions','snapshot_policy','space_guarantee','percent_snapshot_space'
modify volume parameter 'policy','unix_permissions','snapshot_policy','space_guarantee', 'percent_snapshot_space',
'qos_policy_group', 'qos_adaptive_policy_group'
"""
# TODO: refactor this method
vol_mod_iter = None
Expand Down Expand Up @@ -731,6 +764,13 @@ def volume_modify_attributes(self):
vol_performance_attributes = netapp_utils.zapi.NaElement('volume-performance-attributes')
vol_performance_attributes.add_new_child('is-atime-update-enabled', self.parameters.get('atime_update'))
vol_mod_attributes.add_child_elem(vol_performance_attributes)
if self.parameters.get('qos_policy_group') or self.parameters.get('qos_adaptive_policy_group'):
vol_qos_attributes = netapp_utils.zapi.NaElement('volumes-qos-attributes')
if self.parameters.get('qos_policy_group'):
vol_qos_attributes.add_new_child('policy-group-name', self.parameters['qos_policy_group'])
if self.parameters.get('qos_adaptive_policy_group'):
vol_qos_attributes.add_new_child('adaptive-policy-group-name', self.parameters['qos_adaptive_policy_group'])
vol_mod_attributes.add_child_elem(vol_qos_attributes)
attributes.add_child_elem(vol_mod_attributes)
query = netapp_utils.zapi.NaElement('query')
vol_query_attributes = netapp_utils.zapi.NaElement('volume-attributes')
Expand Down Expand Up @@ -809,15 +849,16 @@ def volume_unmount(self):
% (self.parameters['name'], to_native(error)), exception=traceback.format_exc())

def modify_volume(self, modify):
'''Modify volume action'''
for attribute in modify.keys():
if attribute == 'size':
self.resize_volume()
if attribute == 'is_online':
self.change_volume_state()
if attribute == 'aggregate_name':
self.move_volume()
if attribute in ['space_guarantee', 'policy', 'unix_permissions',
'snapshot_policy', 'percent_snapshot_space', 'snapdir_access', 'atime_update']:
if attribute in ['space_guarantee', 'policy', 'unix_permissions', 'snapshot_policy', 'percent_snapshot_space',
'snapdir_access', 'atime_update', 'qos_policy_group', 'qos_adaptive_policy_group']:
self.volume_modify_attributes()
if attribute == 'junction_path':
if modify.get('junction_path') == '':
Expand Down Expand Up @@ -865,6 +906,7 @@ def char_to_octal(self, chars):
return total

def get_volume_style(self, current):
'''Get volume style, infinite or standard flexvol'''
if current is None:
if self.parameters.get('aggr_list') or self.parameters.get('aggr_list_multiplier') or self.parameters.get('auto_provision_as'):
return 'flexGroup'
Expand Down Expand Up @@ -965,6 +1007,7 @@ def check_invoke_result(self, result, action):
self.module.fail_json(msg='Operation failed when %s volume.' % action)

def assign_efficiency_policy(self):
'''Set efficiency policy'''
options = {'path': '/vol/' + self.parameters['name']}
efficiency_enable = netapp_utils.zapi.NaElement.create_node_with_children('sis-enable', **options)
try:
Expand All @@ -984,6 +1027,7 @@ def assign_efficiency_policy(self):
exception=traceback.format_exc())

def assign_efficiency_policy_async(self):
'''Set efficiency policy in asynchronous mode'''
options = {'volume-name': self.parameters['name']}
efficiency_enable = netapp_utils.zapi.NaElement.create_node_with_children('sis-enable-async', **options)
try:
Expand Down