Skip to content

Commit

Permalink
Merge branch 'vexata_volume' of github.com:vexata/ansible into vexata…
Browse files Browse the repository at this point in the history
…_volume

 Fix issues from code review
  • Loading branch information
vexata committed Nov 21, 2018
2 parents 180928e + a1481a7 commit 4063f97
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 63 deletions.
59 changes: 21 additions & 38 deletions lib/ansible/module_utils/vexata.py
@@ -1,42 +1,17 @@
# -*- coding: utf-8 -*-

# This code is part of Ansible, but is an independent component.
# This particular file snippet, and this file snippet only, is BSD licensed.
# Modules you write using this snippet, which is embedded dynamically by Ansible
# still belong to the author of the module, and may assign their own license
# to the complete work.
#
# Copyright (c) 2018, Sandeep Kasargod <sandeep@vexata.com>
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
# PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
# USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# Copyright: (c) 2018, Sandeep Kasargod <sandeep@vexata.com>
# Simplified BSD License (see licenses/simplified_bsd.txt or https://opensource.org/licenses/BSD-2-Clause)

from os import environ

HAS_VEXATAPI = True
try:
from vexatapi.vexata_api_proxy import VexataAPIProxy
except ImportError:
HAS_VEXATAPI = False

from ansible.module_utils._text import to_native
from ansible.module_utils.basic import env_fallback

VXOS_VERSION = None

Expand All @@ -62,13 +37,14 @@ def get_array(module):
array = module.params['array']
user = module.params.get('user', None)
password = module.params.get('password', None)
validate = module.params.get('validate_certs')

if not HAS_VEXATAPI:
module.fail_json(msg='vexatapi library is required for this module. '
'To install, use `pip install vexatapi`')

if user and password:
system = VexataAPIProxy(array, user, password, verify_cert=False)
elif environ.get('VEXATA_USER') and environ.get('VEXATA_PASSWORD'):
user = environ.get('VEXATA_USER')
password = environ.get('VEXATA_PASSWORD')
system = VexataAPIProxy(array, user, password, verify_cert=False)
system = VexataAPIProxy(array, user, password, verify_cert=validate)
else:
module.fail_json(msg='The user/password are required to be passed in to '
'the module as arguments or by setting the '
Expand All @@ -80,15 +56,22 @@ def get_array(module):
else:
module.fail_json(msg='Test connection to array failed.')
except Exception as e:
module.fail_json(msg='Vexata API access failed: {0}'.format(str(e)))
module.fail_json(msg='Vexata API access failed: {0}'.format(to_native(e)))


def argument_spec():
"""Return standard base dictionary used for the argument_spec argument in AnsibleModule"""
return dict(
array=dict(type='str', required=True),
user=dict(type='str'),
password=dict(type='str', no_log=True),
array=dict(type='str',
required=True),
user=dict(type='str',
fallback=(env_fallback, ['VEXATA_USER'])),
password=dict(type='str',
no_log=True,
fallback=(env_fallback, ['VEXATA_PASSWORD'])),
validate_certs=dict(type='bool',
required=False,
default=False),
)


Expand Down
16 changes: 7 additions & 9 deletions lib/ansible/modules/storage/vexata/vexata_volume.py
@@ -1,7 +1,7 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-

# (c) 2018, Sandeep Kasargod (sandeep@vexata.com)
# Copyright: (c) 2018, Sandeep Kasargod (sandeep@vexata.com)
# 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
Expand All @@ -17,10 +17,11 @@
---
module: vexata_volume
version_added: 2.8
short_description: Manage volumes on Vexata VX100 storage arrays.
short_description: Manage volumes on Vexata VX100 storage arrays
description:
- Create, deletes or extend volumes on a Vexata VX100 array.
author: Sandeep Kasargod
author:
- Sandeep Kasargod (@vexata)
options:
name:
description:
Expand Down Expand Up @@ -71,8 +72,7 @@

from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.vexata import (
HAS_VEXATAPI, VXOS_VERSION, argument_spec, get_array, required_together,
size_to_MiB)
argument_spec, get_array, required_together, size_to_MiB)


def get_volume(module, array):
Expand Down Expand Up @@ -116,6 +116,8 @@ def create_volume(module, array):
def update_volume(module, array, volume):
"""Expand the volume size."""
changed = False
if not module.params.get('size', False):
module.fail_json(msg='Size is required to update volume')
size = size_to_MiB(module.params['size'])
prev_size = volume['volSize']
if size <= prev_size:
Expand Down Expand Up @@ -171,10 +173,6 @@ def main():
supports_check_mode=True,
required_together=required_together())

if not HAS_VEXATAPI:
module.fail_json(msg='vexatapi library is required for this module. '
'To install, use `pip install vexatapi`')

state = module.params['state']
size = module.params['size']
if size and size_to_MiB(size) < 0:
Expand Down
25 changes: 9 additions & 16 deletions lib/ansible/utils/module_docs_fragments/vexata.py
@@ -1,20 +1,6 @@
#
# (c) 2018, Sandeep Kasargod <sandeep@vexata.com>
#
# This file is part of Ansible
#
# Ansible is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Ansible is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Ansible. If not, see <http://www.gnu.org/licenses/>.
# Copyright: (c) 2018, Sandeep Kasargod <sandeep@vexata.com>
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)


class ModuleDocFragment(object):
Expand Down Expand Up @@ -43,6 +29,13 @@ class ModuleDocFragment(object):
description:
- Vexata API user password.
required: false
validate_certs:
description:
- Allows connection when SSL certificates are not valid. Set to C(false) when certificates are not trusted.
- If set to C(yes), please make sure Python >= 2.7.9 is installed on the given machine.
required: false
type: bool
default: 'no'
requirements:
- Vexata VX100 storage array with VXOS >= v3.5.0 on storage array
Expand Down

0 comments on commit 4063f97

Please sign in to comment.