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

Initial commit for Pure Storage FlashBlade module #32467

Merged
merged 1 commit into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from all 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
49 changes: 47 additions & 2 deletions lib/ansible/module_utils/pure.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,18 @@
except ImportError:
HAS_PURESTORAGE = False

HAS_PURITY_FB = True
try:
from purity_fb import PurityFb, FileSystem, FileSystemSnapshot, SnapshotSuffix, rest
except ImportError:
HAS_PURITY_FB = False

from functools import wraps
from os import environ
from os import path
import platform

VERSION = 1.0
VERSION = 1.1
USER_AGENT_BASE = 'Ansible'


Expand All @@ -60,18 +66,57 @@ def get_system(module):
system = purestorage.FlashArray(environ.get('PUREFA_URL'), api_token=(environ.get('PUREFA_API')), user_agent=user_agent)
else:
module.fail_json(msg="You must set PUREFA_URL and PUREFA_API environment variables or the fa_url and api_token module arguments")

try:
system.get()
except Exception:
module.fail_json(msg="Pure Storage FlashArray authentication failed. Check your credentials")
return system


def get_blade(module):
"""Return System Object or Fail"""
# Note: user_agent not included in FlashBlade API 1.1
# user_agent = '%(base)s %(class)s/%(version)s (%(platform)s)' % {
# 'base': USER_AGENT_BASE,
# 'class': __name__,
# 'version': VERSION,
# 'platform': platform.platform()
# }
blade_name = module.params['fb_url']
api = module.params['api_token']

if blade_name and api:
blade = PurityFb(blade_name)
blade.disable_verify_ssl()
try:
blade.login(api)
except rest.ApiException as e:
module.fail_json(msg="Pure Storage FlashBlade authentication failed. Check your credentials")
elif environ.get('PUREFB_URL') and environ.get('PUREFB_API'):
blade = PurityFb(environ.get('PUREFB_URL'))
blade.disable_verify_ssl()
try:
blade.login(environ.get('PUREFB_API'))
except rest.ApiException as e:
module.fail_json(msg="Pure Storage FlashBlade authentication failed. Check your credentials")
else:
module.fail_json(msg="You must set PUREFB_URL and PUREFB_API environment variables or the fb_url and api_token module arguments")
return blade


def purefa_argument_spec():
"""Return standard base dictionary used for the argument_spec argument in AnsibleModule"""

return dict(
fa_url=dict(),
api_token=dict(no_log=True),
)


def purefb_argument_spec():
"""Return standard base dictionary used for the argument_spec argument in AnsibleModule"""

return dict(
fb_url=dict(),
api_token=dict(no_log=True),
)
2 changes: 1 addition & 1 deletion lib/ansible/modules/storage/purestorage/purefa_hg.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
description:
- List of existing volumes to add to hostgroup.
extends_documentation_fragment:
- purestorage
- purestorage.fa
'''

EXAMPLES = r'''
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/storage/purestorage/purefa_host.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
description:
- Volume name to map to the host.
extends_documentation_fragment:
- purestorage
- purestorage.fa
'''

EXAMPLES = r'''
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/storage/purestorage/purefa_pg.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
type : bool
default: 'yes'
extends_documentation_fragment:
- purestorage
- purestorage.fa
'''

EXAMPLES = r'''
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/storage/purestorage/purefa_pgsnap.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
type: bool
default: 'no'
extends_documentation_fragment:
- purestorage
- purestorage.fa
'''

EXAMPLES = r'''
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/storage/purestorage/purefa_snap.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
type: bool
default: 'no'
extends_documentation_fragment:
- purestorage
- purestorage.fa
'''

EXAMPLES = r'''
Expand Down
2 changes: 1 addition & 1 deletion lib/ansible/modules/storage/purestorage/purefa_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
description:
- Volume size in M, G, T or P units.
extends_documentation_fragment:
- purestorage
- purestorage.fa
'''

EXAMPLES = r'''
Expand Down