2017-08-02 14:20:58 +00:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# (c) 2017, Simon Dodsley (simon@purestorage.com)
|
2017-08-22 00:25:13 +00:00
|
|
|
# GNU General Public License v3.0+ (see COPYING or https://www.gnu.org/licenses/gpl-3.0.txt)
|
2017-08-02 14:20:58 +00:00
|
|
|
|
2017-08-22 00:25:13 +00:00
|
|
|
from __future__ import absolute_import, division, print_function
|
|
|
|
__metaclass__ = type
|
2017-08-02 14:20:58 +00:00
|
|
|
|
2017-08-16 03:16:38 +00:00
|
|
|
ANSIBLE_METADATA = {'metadata_version': '1.1',
|
2017-08-02 14:20:58 +00:00
|
|
|
'status': ['preview'],
|
|
|
|
'supported_by': 'community'}
|
|
|
|
|
2017-08-22 00:25:13 +00:00
|
|
|
DOCUMENTATION = r'''
|
2017-08-02 14:20:58 +00:00
|
|
|
---
|
|
|
|
module: purefa_pg
|
2017-08-22 00:25:13 +00:00
|
|
|
version_added: '2.4'
|
|
|
|
short_description: Manage protection groups on Pure Storage FlashArrays
|
2017-08-02 14:20:58 +00:00
|
|
|
description:
|
2017-08-22 00:25:13 +00:00
|
|
|
- Create, delete or modify protection groups on Pure Storage FlashArrays.
|
|
|
|
author:
|
|
|
|
- Simon Dodsley (@sdodsley)
|
2017-08-02 14:20:58 +00:00
|
|
|
options:
|
|
|
|
pgroup:
|
|
|
|
description:
|
2017-08-22 00:25:13 +00:00
|
|
|
- The name of the protection group.
|
2017-08-02 14:20:58 +00:00
|
|
|
required: true
|
|
|
|
state:
|
|
|
|
description:
|
2017-08-22 00:25:13 +00:00
|
|
|
- Define whether the protection group should exist or not.
|
2017-08-02 14:20:58 +00:00
|
|
|
default: present
|
2017-08-22 00:25:13 +00:00
|
|
|
choices: [ absent, present ]
|
2017-08-02 14:20:58 +00:00
|
|
|
volume:
|
|
|
|
description:
|
2017-08-22 00:25:13 +00:00
|
|
|
- List of existing volumes to add to protection group.
|
2017-08-02 14:20:58 +00:00
|
|
|
host:
|
|
|
|
description:
|
2017-08-22 00:25:13 +00:00
|
|
|
- List of existing hosts to add to protection group.
|
2017-08-02 14:20:58 +00:00
|
|
|
hostgroup:
|
|
|
|
description:
|
2017-08-22 00:25:13 +00:00
|
|
|
- List of existing hostgroups to add to protection group.
|
2017-08-02 14:20:58 +00:00
|
|
|
eradicate:
|
|
|
|
description:
|
2017-08-22 00:25:13 +00:00
|
|
|
- Define whether to eradicate the protection group on delete and leave in trash.
|
2017-08-02 14:20:58 +00:00
|
|
|
type : bool
|
2017-08-22 00:25:13 +00:00
|
|
|
default: 'no'
|
2017-08-24 15:48:01 +00:00
|
|
|
enabled:
|
|
|
|
description:
|
|
|
|
- Define whether to enabled snapshots for the protection group.
|
|
|
|
type : bool
|
|
|
|
default: 'yes'
|
2017-08-02 14:20:58 +00:00
|
|
|
extends_documentation_fragment:
|
2018-02-22 20:33:48 +00:00
|
|
|
- purestorage.fa
|
2017-08-02 14:20:58 +00:00
|
|
|
'''
|
|
|
|
|
2017-08-22 00:25:13 +00:00
|
|
|
EXAMPLES = r'''
|
2017-08-02 14:20:58 +00:00
|
|
|
- name: Create new protection group
|
|
|
|
purefa_pg:
|
|
|
|
pgroup: foo
|
|
|
|
fa_url: 10.10.10.2
|
|
|
|
api_token: e31060a7-21fc-e277-6240-25983c6c4592
|
|
|
|
|
2017-08-24 15:48:01 +00:00
|
|
|
- name: Create new protection group with snapshots disabled
|
|
|
|
purefa_pg:
|
|
|
|
pgroup: foo
|
|
|
|
enabled: false
|
|
|
|
fa_url: 10.10.10.2
|
|
|
|
api_token: e31060a7-21fc-e277-6240-25983c6c4592
|
|
|
|
|
2017-08-02 14:20:58 +00:00
|
|
|
- name: Delete protection group
|
|
|
|
purefa_pg:
|
|
|
|
pgroup: foo
|
|
|
|
eradicate: true
|
|
|
|
fa_url: 10.10.10.2
|
|
|
|
api_token: e31060a7-21fc-e277-6240-25983c6c4592
|
2017-08-22 00:25:13 +00:00
|
|
|
state: absent
|
2017-08-02 14:20:58 +00:00
|
|
|
|
|
|
|
- name: Create protection group for hostgroups
|
|
|
|
purefa_pg:
|
|
|
|
pgroup: bar
|
|
|
|
hostgroup:
|
|
|
|
- hg1
|
|
|
|
- hg2
|
|
|
|
fa_url: 10.10.10.2
|
|
|
|
api_token: e31060a7-21fc-e277-6240-25983c6c4592
|
|
|
|
|
|
|
|
- name: Create protection group for hosts
|
|
|
|
purefa_pg:
|
|
|
|
pgroup: bar
|
|
|
|
host:
|
|
|
|
- host1
|
|
|
|
- host2
|
|
|
|
fa_url: 10.10.10.2
|
|
|
|
api_token: e31060a7-21fc-e277-6240-25983c6c4592
|
|
|
|
|
|
|
|
- name: Create protection group for volumes
|
|
|
|
purefa_pg:
|
|
|
|
pgroup: bar
|
|
|
|
volume:
|
|
|
|
- vol1
|
|
|
|
- vol2
|
|
|
|
fa_url: 10.10.10.2
|
|
|
|
api_token: e31060a7-21fc-e277-6240-25983c6c4592
|
|
|
|
'''
|
|
|
|
|
2017-08-22 00:25:13 +00:00
|
|
|
RETURN = r'''
|
2017-08-02 14:20:58 +00:00
|
|
|
'''
|
|
|
|
|
|
|
|
from ansible.module_utils.basic import AnsibleModule
|
|
|
|
from ansible.module_utils.pure import get_system, purefa_argument_spec
|
|
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
from purestorage import purestorage
|
2017-08-22 00:25:13 +00:00
|
|
|
HAS_PURESTORAGE = True
|
2017-08-02 14:20:58 +00:00
|
|
|
except ImportError:
|
|
|
|
HAS_PURESTORAGE = False
|
|
|
|
|
|
|
|
|
|
|
|
def get_pgroup(module, array):
|
|
|
|
|
|
|
|
pgroup = None
|
|
|
|
|
|
|
|
for h in array.list_pgroups():
|
|
|
|
if h["name"] == module.params['pgroup']:
|
|
|
|
pgroup = h
|
|
|
|
break
|
|
|
|
|
|
|
|
return pgroup
|
|
|
|
|
|
|
|
|
|
|
|
def make_pgroup(module, array):
|
|
|
|
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
if not module.check_mode:
|
|
|
|
host = array.create_pgroup(module.params['pgroup'])
|
2017-08-24 15:48:01 +00:00
|
|
|
array.set_pgroup(module.params['pgroup'], snap_enabled=module.params['enabled'])
|
2017-08-02 14:20:58 +00:00
|
|
|
if module.params['volume']:
|
|
|
|
array.set_pgroup(module.params['pgroup'], vollist=module.params['volume'])
|
|
|
|
if module.params['host']:
|
|
|
|
array.set_pgroup(module.params['pgroup'], hostlist=module.params['host'])
|
|
|
|
if module.params['hostgroup']:
|
|
|
|
array.set_pgroup(module.params['pgroup'], hgrouplist=module.params['hostgroup'])
|
|
|
|
module.exit_json(changed=changed)
|
|
|
|
|
|
|
|
|
|
|
|
def update_pgroup(module, array):
|
|
|
|
changed = False
|
|
|
|
pgroup = module.params['pgroup']
|
|
|
|
module.exit_json(changed=changed)
|
|
|
|
|
|
|
|
|
|
|
|
def delete_pgroup(module, array):
|
|
|
|
changed = True
|
|
|
|
if not module.check_mode:
|
|
|
|
array.destroy_pgroup(module.params['pgroup'])
|
2017-08-17 17:35:52 +00:00
|
|
|
if module.params['eradicate']:
|
2017-08-02 14:20:58 +00:00
|
|
|
array.eradicate_pgroup(module.params['pgroup'])
|
|
|
|
module.exit_json(changed=changed)
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
argument_spec = purefa_argument_spec()
|
2017-08-22 00:25:13 +00:00
|
|
|
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(type='bool', default=False),
|
2017-08-24 15:48:01 +00:00
|
|
|
enabled=dict(type='bool', default=True),
|
2017-08-22 00:25:13 +00:00
|
|
|
))
|
2017-08-02 14:20:58 +00:00
|
|
|
|
|
|
|
module = AnsibleModule(argument_spec, supports_check_mode=True)
|
|
|
|
|
|
|
|
if not HAS_PURESTORAGE:
|
|
|
|
module.fail_json(msg='purestorage sdk is required for this module in host')
|
|
|
|
|
|
|
|
state = module.params['state']
|
|
|
|
array = get_system(module)
|
|
|
|
pgroup = get_pgroup(module, array)
|
|
|
|
|
|
|
|
if module.params['host']:
|
|
|
|
try:
|
|
|
|
for h in module.params['host']:
|
|
|
|
array.get_host(h)
|
|
|
|
except:
|
|
|
|
module.fail_json(msg='Host {} not found'.format(h))
|
|
|
|
|
|
|
|
if module.params['hostgroup']:
|
|
|
|
try:
|
|
|
|
for hg in module.params['hostgroup']:
|
|
|
|
array.get_hgroup(hg)
|
|
|
|
except:
|
|
|
|
module.fail_json(msg='Hostgroup {} not found'.format(hg))
|
|
|
|
|
|
|
|
if pgroup and state == 'present':
|
|
|
|
update_pgroup(module, array)
|
|
|
|
elif pgroup and state == 'absent':
|
|
|
|
delete_pgroup(module, array)
|
|
|
|
elif pgroup is None and state == 'absent':
|
|
|
|
module.exit_json(changed=False)
|
|
|
|
else:
|
|
|
|
make_pgroup(module, array)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|