purestorage: Various changes, and one check-mode fix (#28485)

These were the changes I propose twice, a nullified PR edit, and then as
review comments when the PR was being merged.

I made those changes now to all purestorage modules.
pull/25986/merge
Dag Wieers 7 years ago committed by GitHub
parent b150f49187
commit 6d015294c2

@ -2,74 +2,58 @@
# -*- coding: utf-8 -*-
# (c) 2017, Simon Dodsley (simon@purestorage.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/>.
from __future__ import (absolute_import, division, print_function)
# 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
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: purefa_hg
version_added: "2.4"
short_description: Create, Delete and Modify hostgroups on Pure Storage FlashArray
version_added: '2.4'
short_description: Manage hostgroups on Pure Storage FlashArrays
description:
- This module creates, deletes or modifies hostgroups on Pure Storage FlashArray.
author: Simon Dodsley (@sdodsley)
- Create, delete or modifiy hostgroups on Pure Storage FlashArrays.
author:
- Simon Dodsley (@sdodsley)
options:
hostgroup:
description:
- Host Name.
- The name of the hostgroup.
required: true
state:
description:
- Creates or modifies hostgroup.
required: false
- Define whether the hostgroup should exist or not.
default: present
choices: [ "present", "absent" ]
choices: [ absent, present ]
host:
description:
- List of existing hosts to add to hostgroup.
required: false
volume:
description:
- List of existing volumes to add to hostgroup.
required: false
extends_documentation_fragment:
- purestorage
'''
EXAMPLES = '''
EXAMPLES = r'''
- name: Create new hostgroup
purefa_hg:
hostgroup: foo
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
- name: Delete hostgroup - this will disconnect all hosts and volume in the hostgroup
# This will disconnect all hosts and volumes in the hostgroup
- name: Delete hostgroup
purefa_hg:
hostgroup: foo
state: absent
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: absent
- name: Create host group with hosts and volumes
purefa_hg:
@ -84,16 +68,16 @@ EXAMPLES = '''
api_token: e31060a7-21fc-e277-6240-25983c6c4592
'''
RETURN = '''
RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pure import get_system, purefa_argument_spec
HAS_PURESTORAGE = True
try:
from purestorage import purestorage
HAS_PURESTORAGE = True
except ImportError:
HAS_PURESTORAGE = False
@ -143,14 +127,12 @@ def delete_hostgroup(module, array):
def main():
argument_spec = purefa_argument_spec()
argument_spec.update(
dict(
hostgroup=dict(required=True),
state=dict(default='present', choices=['present', 'absent']),
argument_spec.update(dict(
hostgroup=dict(type='str', required=True),
state=dict(type='str', default='present', choices=['absent', 'present']),
host=dict(type='list'),
volume=dict(type='list'),
)
)
))
module = AnsibleModule(argument_spec, supports_check_mode=True)

@ -7,55 +7,49 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: purefa_host
version_added: "2.4"
short_description: Create, Delete and Modify Hosts on Pure Storage FlashArray
version_added: '2.4'
short_description: Manage hosts on Pure Storage FlashArrays
description:
- This module creates, deletes or modifies hosts on Pure Storage FlashArray.
author: Simon Dodsley (@sdodsley)
- Create, delete or modify hosts on Pure Storage FlashArrays.
author:
- Simon Dodsley (@sdodsley)
options:
host:
description:
- Host Name
- The name of the host.
required: true
state:
description:
- Creates host.
- Define whether the host should exist or not.
- When removing host all connected volumes will be disconnected.
required: false
default: present
choices: [ "present", "absent" ]
choices: [ absent, present ]
protocol:
description:
- Defines the host connection protocol for volumes.
required: false
default: iscsi
choices: [ "iscsi", "fc" ]
choices: [ fc, iscsi ]
wwns:
description:
- List of wwns of the host if protocol is fc
required: false
- List of wwns of the host if protocol is fc.
iqn:
description:
- List of IQNs of the host if protocol is iscsi
required: false
- List of IQNs of the host if protocol is iscsi.
volume:
description:
- Volume name to map to the host
required: false
- Volume name to map to the host.
extends_documentation_fragment:
- purestorage
'''
EXAMPLES = '''
EXAMPLES = r'''
- name: Create new new host
purefa_host:
host: foo
@ -65,17 +59,17 @@ EXAMPLES = '''
- name: Delete host
purefa_host:
host: foo
state: absent
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: absent
- name: Make sure host bar is available with wwn ports
purefa_host:
host: bar
protocol: fc
wwns:
- "00:00:00:00:00:00:00"
- "11:11:11:11:11:11:11"
- 00:00:00:00:00:00:00
- 11:11:11:11:11:11:11
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
@ -84,7 +78,7 @@ EXAMPLES = '''
host: bar
protocol: iscsi
iqn:
- "iqn.1994-05.com.redhat:7d366003913"
- iqn.1994-05.com.redhat:7d366003913
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
@ -96,16 +90,16 @@ EXAMPLES = '''
api_token: e31060a7-21fc-e277-6240-25983c6c4592
'''
RETURN = '''
RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pure import get_system, purefa_argument_spec
HAS_PURESTORAGE = True
try:
from purestorage import purestorage
HAS_PURESTORAGE = True
except ImportError:
HAS_PURESTORAGE = False
@ -156,16 +150,14 @@ def delete_host(module, array):
def main():
argument_spec = purefa_argument_spec()
argument_spec.update(
dict(
host=dict(required=True),
state=dict(default='present', choices=['present', 'absent']),
protocol=dict(default='iscsi', choices=['iscsi', 'fc']),
argument_spec.update(dict(
host=dict(type='str', required=True),
state=dict(type='str', default='present', choices=['absent,' 'present']),
protocol=dict(type='str', default='iscsi', choices=['fc', 'iscsi']),
iqn=dict(type='list'),
wwns=dict(type='list'),
volume=dict()
)
)
volume=dict(type='str'),
))
module = AnsibleModule(argument_spec, supports_check_mode=True)

@ -2,73 +2,53 @@
# -*- coding: utf-8 -*-
# (c) 2017, Simon Dodsley (simon@purestorage.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/>.
from __future__ import (absolute_import, division, print_function)
__metaclass__ = type
# 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
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: purefa_pg
version_added: "2.4"
short_description: Create, Delete and Modify Protection Groups on Pure Storage FlashArray
version_added: '2.4'
short_description: Manage protection groups on Pure Storage FlashArrays
description:
- This module creates, deletes or modifies protection groups on Pure Storage FlashArray.
author: Simon Dodsley (@sdodsley)
- Create, delete or modify protection groups on Pure Storage FlashArrays.
author:
- Simon Dodsley (@sdodsley)
options:
pgroup:
description:
- Host Name
- The name of the protection group.
required: true
state:
description:
- Creates or modifies protection group.
required: false
- Define whether the protection group should exist or not.
default: present
choices: [ "present", "absent" ]
choices: [ absent, present ]
volume:
description:
- List of existing volumes to add to protection group.
required: false
host:
description:
- List of existing hosts to add to protection group.
required: false
hostgroup:
description:
- List of existing hostgroups to add to protection group.
required: false
eradicate:
description:
- Define whether to eradicate the protection group on delete and leave in trash.
required: false
type : bool
default: false
default: 'no'
extends_documentation_fragment:
- purestorage
'''
EXAMPLES = '''
EXAMPLES = r'''
- name: Create new protection group
purefa_pg:
pgroup: foo
@ -78,10 +58,10 @@ EXAMPLES = '''
- name: Delete protection group
purefa_pg:
pgroup: foo
state: absent
eradicate: true
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: absent
- name: Create protection group for hostgroups
purefa_pg:
@ -111,16 +91,16 @@ EXAMPLES = '''
api_token: e31060a7-21fc-e277-6240-25983c6c4592
'''
RETURN = '''
RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
from ansible.module_utils.pure import get_system, purefa_argument_spec
HAS_PURESTORAGE = True
try:
from purestorage import purestorage
HAS_PURESTORAGE = True
except ImportError:
HAS_PURESTORAGE = False
@ -169,16 +149,14 @@ def delete_pgroup(module, array):
def main():
argument_spec = purefa_argument_spec()
argument_spec.update(
dict(
pgroup=dict(required=True),
state=dict(default='present', choices=['present', 'absent']),
argument_spec.update(dict(
pgroup=dict(type='str', required=True),
state=dict(type='str', default='present', choices=['absent', 'present']),
volume=dict(type='list'),
host=dict(type='list'),
hostgroup=dict(type='list'),
eradicate=dict(default='false', type='bool'),
)
)
eradicate=dict(type='bool', default=False),
))
module = AnsibleModule(argument_spec, supports_check_mode=True)

@ -1,98 +1,94 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
# (c) 2017, Simon Dodsley (simon@purestorage.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
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: purefa_snap
version_added: 2.4
short_description: Create or Delete volume snapshots on Pure Storage FlashArray
version_added: '2.4'
short_description: Manage volume snapshots on Pure Storage FlashArrays
description:
- This module creates or deletes volume snapshots and creates volumes from snapshots on Pure Storage FlashArray.
author: Simon Dodsley (@sdodsley)
- Create or delete volumes and volume snapshots on Pure Storage FlashArray.
author:
- Simon Dodsley (@sdodsley)
options:
name:
description:
- Source volume name of snapshot
- The name of the source volume.
required: true
suffix:
description:
- Suffix of snapshot name
required: false
- Suffix of snapshot name.
target:
description:
- Name of target volume if creating from snapshot
required: false
- Name of target volume if creating from snapshot.
overwrite:
description:
- Define whether to overwrite existing volume when creating from snapshot
required: false
default: false
- Define whether to overwrite existing volume when creating from snapshot.
type: bool
default: 'no'
state:
description:
- Create or delete volume snapshot
required: false
- Define whether the volume snapshot should exist or not.
choices: [ absent, copy, present ]
default: present
choices: [ "present", "absent", "copy" ]
eradicate:
description:
- Define whether to eradicate the snapshot on delete or leave in trash
required: false
default: false
- Define whether to eradicate the snapshot on delete or leave in trash.
type: bool
default: 'no'
extends_documentation_fragment:
- purestorage
'''
EXAMPLES = '''
EXAMPLES = r'''
- name: Create snapshot foo.ansible
purefa_snap:
name: foo
suffix: ansible
state: present
fa_url: 10.10.10.2
fa_api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: present
- name: Create R/W clone foo_clone from snapshot foo.snap
purefa_snap:
name: foo
suffix: snap
target: foo_clone
state: copy
fa_url: 10.10.10.2
fa_api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: copy
- name: Overwrite existing volume foo_clone with snapshot foo.snap
purefa_snap:
name: foo
suffix: snap
target: foo_clone
state: copy
overwrite: true
fa_url: 10.10.10.2
fa_api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: copy
- name: Delete and eradicate snapshot named foo.snap
purefa_snap:
name: foo
suffix: snap
eradicate: true
state: absent
fa_url: 10.10.10.2
fa_api_token: e31060a7-21fc-e277-6240-25983c6c4592'''
fa_api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: absent
'''
RETURN = '''
RETURN = r'''
'''
from ansible.module_utils.basic import AnsibleModule
@ -100,9 +96,9 @@ from ansible.module_utils.pure import get_system, purefa_argument_spec
from datetime import datetime
HAS_PURESTORAGE = True
try:
from purestorage import purestorage
HAS_PURESTORAGE = True
except ImportError:
HAS_PURESTORAGE = False
@ -144,15 +140,16 @@ def create_snapshot(module, array):
def create_from_snapshot(module, array):
"""Create Volume from Snapshot"""
if not module.check_mode:
source = module.params['name'] + "." + module.params['suffix']
tgt = get_target(module, array)
if tgt is None:
changed = True
if not module.check_mode:
array.copy_volume(source,
module.params['target'])
elif tgt is not None and module.params['overwrite']:
changed = True
if not module.check_mode:
array.copy_volume(source,
module.params['target'],
overwrite=module.params['overwrite'])
@ -179,16 +176,14 @@ def delete_snapshot(module, array):
def main():
argument_spec = purefa_argument_spec()
argument_spec.update(
dict(
name=dict(required=True),
suffix=dict(),
target=dict(),
overwrite=dict(default='false', type='bool'),
eradicate=dict(default='false', type='bool'),
state=dict(default='present', choices=['present', 'absent', 'copy']),
)
)
argument_spec.update(dict(
name=dict(type='str', required=True),
suffix=dict(type='str'),
target=dict(type='str'),
overwrite=dict(type='bool', default=False),
eradicate=dict(type='bool', default=False),
state=dict(type='str', default='present', choices=['absent', 'copy', 'present']),
))
required_if = [('state', 'copy', ['target', 'suffix'])]
@ -202,6 +197,7 @@ def main():
if module.params['suffix'] is None:
suffix = "snap-" + str((datetime.utcnow() - datetime(1970, 1, 1, 0, 0, 0, 0)).total_seconds())
module.params['suffix'] = suffix.replace(".", "")
state = module.params['state']
array = get_system(module)
volume = get_volume(module, array)

@ -7,103 +7,98 @@
from __future__ import absolute_import, division, print_function
__metaclass__ = type
ANSIBLE_METADATA = {'metadata_version': '1.1',
'status': ['preview'],
'supported_by': 'community'}
DOCUMENTATION = '''
DOCUMENTATION = r'''
---
module: purefa_volume
version_added: "2.4"
short_description: Create, Delete, Copy or Extend a volume on Pure Storage FlashArray
version_added: '2.4'
short_description: Manage volumes on Pure Storage FlashArrays
description:
- This module creates, deletes or extends the capacity of a volume on Pure Storage FlashArray.
author: Simon Dodsley (@sdodsley)
- Create, delete or extend the capacity of a volume on Pure Storage FlashArray.
author:
- Simon Dodsley (@sdodsley)
options:
name:
description:
- Volume Name.
- The name of the volume.
required: true
target:
description:
- Target Volume Name if copying.
required: false
- The name of the target volume, if copying.
state:
description:
- Create, delete, copy or extend capacity of a volume.
required: false
- Define whether the volume should exist or not.
default: present
choices: [ "present", "absent" ]
choices: [ absent, present ]
eradicate:
description:
- Define whether to eradicate the volume on delete or leave in trash.
required: false
type: bool
default: false
default: 'no'
overwrite:
description:
- Define whether to overwrite a target volume if it already exisits.
required: false
type: bool
default: false
default: 'no'
size:
description:
- Volume size in M, G, T or P units. See examples.
required: false
- Volume size in M, G, T or P units.
extends_documentation_fragment:
- purestorage
'''
EXAMPLES = '''
EXAMPLES = r'''
- name: Create new volume named foo
purefa_volume:
name: foo
size: 1T
state: present
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: present
- name: Extend the size of an existing volume named foo
purefa_volume:
name: foo
size: 2T
state: present
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: present
- name: Delete and eradicate volume named foo
purefa_volume:
name: foo
eradicate: true
state: absent
eradicate: yes
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: absent
- name: Create clone of volume bar named foo
purefa_volume:
name: foo
target: bar
state: present
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: present
- name: Overwrite volume bar with volume foo
purefa_volume:
name: foo
target: bar
overwrite: true
state: present
overwrite: yes
fa_url: 10.10.10.2
api_token: e31060a7-21fc-e277-6240-25983c6c4592'''
api_token: e31060a7-21fc-e277-6240-25983c6c4592
state: present
'''
RETURN = '''
RETURN = r'''
'''
HAS_PURESTORAGE = True
try:
from purestorage import purestorage
HAS_PURESTORAGE = True
except ImportError:
HAS_PURESTORAGE = False
@ -184,9 +179,9 @@ def copy_from_volume(module, array):
def update_volume(module, array):
"""Update Volume"""
changed = True
if not module.check_mode:
vol = array.get_volume(module.params['name'])
if human_to_bytes(module.params['size']) > vol['size']:
if not module.check_mode:
array.extend_volume(module.params['name'], module.params['size'])
else:
changed = False
@ -204,16 +199,14 @@ def delete_volume(module, array):
def main():
argument_spec = purefa_argument_spec()
argument_spec.update(
dict(
name=dict(required=True),
target=dict(),
overwrite=dict(default=False, type='bool'),
eradicate=dict(default=False, type='bool'),
state=dict(default='present', choices=['present', 'absent']),
size=dict()
)
)
argument_spec.update(dict(
name=dict(type='str', required=True),
target=dict(type='str'),
overwrite=dict(type='bool', default=False),
eradicate=dict(type='bool', default=False),
state=dict(type='str', default='present', choices=['absent', 'present']),
size=dict(type='str'),
))
mutually_exclusive = [['size', 'target']]

Loading…
Cancel
Save