2014-10-03 09:25:42 +02:00
|
|
|
#!/usr/bin/python
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
# (c) 2014, Taneli Leppä <taneli@crasman.fi>
|
|
|
|
#
|
|
|
|
# This file is part of Ansible (sort of)
|
|
|
|
#
|
|
|
|
# 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/>.
|
|
|
|
|
|
|
|
|
|
|
|
DOCUMENTATION = """
|
2014-12-06 23:54:38 +01:00
|
|
|
module: gluster_volume
|
2014-12-31 01:53:59 +01:00
|
|
|
short_description: Manage GlusterFS volumes
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
2014-12-06 23:54:38 +01:00
|
|
|
- Create, remove, start, stop and tune GlusterFS volumes
|
2015-01-05 17:40:57 +01:00
|
|
|
version_added: "1.9"
|
2014-10-03 09:25:42 +02:00
|
|
|
options:
|
|
|
|
name:
|
|
|
|
required: true
|
|
|
|
description:
|
|
|
|
- The volume name
|
2014-12-06 23:54:38 +01:00
|
|
|
state:
|
|
|
|
required: true
|
|
|
|
choices: [ 'present', 'absent', 'started', 'stopped' ]
|
|
|
|
description:
|
2014-12-31 01:53:59 +01:00
|
|
|
- Use present/absent ensure if a volume exists or not,
|
2015-01-05 17:40:57 +01:00
|
|
|
use started/stopped to control it's availability.
|
2014-12-06 23:54:38 +01:00
|
|
|
cluster:
|
2014-10-03 09:25:42 +02:00
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: null
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
|
|
|
- List of hosts to use for probing and brick setup
|
|
|
|
host:
|
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: null
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
|
|
|
- Override local hostname (for peer probing purposes)
|
2014-12-06 23:54:38 +01:00
|
|
|
replicas:
|
2014-10-03 09:25:42 +02:00
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: null
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
|
|
|
- Replica count for volume
|
2014-12-06 23:54:38 +01:00
|
|
|
stripes:
|
2014-10-03 09:25:42 +02:00
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: null
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
|
|
|
- Stripe count for volume
|
|
|
|
transport:
|
|
|
|
required: false
|
|
|
|
choices: [ 'tcp', 'rdma', 'tcp,rdma' ]
|
2015-03-31 02:15:40 +02:00
|
|
|
default: 'tcp'
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
|
|
|
- Transport type for volume
|
2015-04-20 16:13:52 +02:00
|
|
|
bricks:
|
2014-10-03 09:25:42 +02:00
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: null
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
2015-04-20 16:13:52 +02:00
|
|
|
- Brick paths on servers. Multiple brick paths can be separated by commas
|
2015-04-20 16:20:50 +02:00
|
|
|
aliases: ['brick']
|
2014-12-06 23:54:38 +01:00
|
|
|
start_on_create:
|
|
|
|
choices: [ 'yes', 'no']
|
2014-10-03 09:25:42 +02:00
|
|
|
required: false
|
|
|
|
description:
|
2014-12-06 23:54:38 +01:00
|
|
|
- Controls whether the volume is started after creation or not, defaults to yes
|
2014-10-03 09:25:42 +02:00
|
|
|
rebalance:
|
2014-12-06 23:54:38 +01:00
|
|
|
choices: [ 'yes', 'no']
|
2014-10-03 09:25:42 +02:00
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: 'no'
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
2014-12-06 23:54:38 +01:00
|
|
|
- Controls whether the cluster is rebalanced after changes
|
2014-10-03 09:25:42 +02:00
|
|
|
directory:
|
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: null
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
|
|
|
- Directory for limit-usage
|
2014-12-06 23:54:38 +01:00
|
|
|
options:
|
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: null
|
2014-12-06 23:54:38 +01:00
|
|
|
description:
|
|
|
|
- A dictionary/hash with options/settings for the volume
|
|
|
|
quota:
|
2014-10-03 09:25:42 +02:00
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: null
|
2014-10-03 09:25:42 +02:00
|
|
|
description:
|
|
|
|
- Quota value for limit-usage (be sure to use 10.0MB instead of 10MB, see quota list)
|
2015-03-11 08:54:13 +01:00
|
|
|
force:
|
|
|
|
required: false
|
2015-03-31 02:15:40 +02:00
|
|
|
default: null
|
2015-03-11 08:54:13 +01:00
|
|
|
description:
|
|
|
|
- If brick is being created in the root partition, module will fail.
|
|
|
|
Set force to true to override this behaviour
|
2014-10-03 09:25:42 +02:00
|
|
|
notes:
|
|
|
|
- "Requires cli tools for GlusterFS on servers"
|
|
|
|
- "Will add new bricks, but not remove them"
|
|
|
|
author: Taneli Leppä
|
|
|
|
"""
|
|
|
|
|
|
|
|
EXAMPLES = """
|
|
|
|
- name: create gluster volume
|
2015-04-20 16:13:52 +02:00
|
|
|
gluster_volume: state=present name=test1 bricks=/bricks/brick1/g1 rebalance=yes cluster:"{{ play_hosts }}"
|
2014-10-03 09:25:42 +02:00
|
|
|
run_once: true
|
|
|
|
|
|
|
|
- name: tune
|
2014-12-06 23:54:38 +01:00
|
|
|
gluster_volume: state=present name=test1 options='{performance.cache-size: 256MB}'
|
2014-10-03 09:25:42 +02:00
|
|
|
|
|
|
|
- name: start gluster volume
|
2014-12-06 23:54:38 +01:00
|
|
|
gluster_volume: status=started name=test1
|
2014-10-03 09:25:42 +02:00
|
|
|
|
|
|
|
- name: limit usage
|
2014-12-06 23:54:38 +01:00
|
|
|
gluster_volume: state=present name=test1 directory=/foo quota=20.0MB
|
2014-10-03 09:25:42 +02:00
|
|
|
|
|
|
|
- name: stop gluster volume
|
2014-12-06 23:54:38 +01:00
|
|
|
gluster_volume: state=stopped name=test1
|
|
|
|
|
|
|
|
- name: remove gluster volume
|
|
|
|
gluster_volume: state=absent name=test1
|
2015-04-20 16:13:52 +02:00
|
|
|
|
|
|
|
- name: create gluster volume with multiple bricks
|
|
|
|
gluster_volume: state=present name=test2 bricks="/bricks/brick1/g2,/bricks/brick2/g2" cluster:"{{ play_hosts }}"
|
|
|
|
run_once: true
|
2014-10-03 09:25:42 +02:00
|
|
|
"""
|
|
|
|
|
|
|
|
import shutil
|
|
|
|
import time
|
|
|
|
import socket
|
|
|
|
|
2015-03-31 20:29:38 +02:00
|
|
|
glusterbin = ''
|
2014-10-03 09:25:42 +02:00
|
|
|
|
2015-03-31 02:15:40 +02:00
|
|
|
def run_gluster(gargs, **kwargs):
|
2015-03-31 20:29:38 +02:00
|
|
|
global glusterbin
|
2015-04-14 19:02:32 +02:00
|
|
|
global module
|
2015-03-31 02:15:40 +02:00
|
|
|
args = [glusterbin]
|
|
|
|
args.extend(gargs)
|
|
|
|
try:
|
2014-10-03 09:25:42 +02:00
|
|
|
rc, out, err = module.run_command(args, **kwargs)
|
|
|
|
if rc != 0:
|
|
|
|
module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' % (' '.join(args), rc, out if out != '' else err))
|
2015-03-31 02:15:40 +02:00
|
|
|
except Exception, e:
|
2015-03-31 04:30:58 +02:00
|
|
|
module.fail_json(msg='error running gluster (%s) command: %s' % (' '.join(args), str(e)))
|
2015-03-31 02:15:40 +02:00
|
|
|
return out
|
|
|
|
|
|
|
|
def run_gluster_nofail(gargs, **kwargs):
|
2015-03-31 20:29:38 +02:00
|
|
|
global glusterbin
|
2015-04-14 19:02:32 +02:00
|
|
|
global module
|
2015-03-31 02:15:40 +02:00
|
|
|
args = [glusterbin]
|
|
|
|
args.extend(gargs)
|
|
|
|
rc, out, err = module.run_command(args, **kwargs)
|
|
|
|
if rc != 0:
|
|
|
|
return None
|
|
|
|
return out
|
|
|
|
|
|
|
|
def run_gluster_yes(gargs):
|
2015-03-31 20:29:38 +02:00
|
|
|
global glusterbin
|
2015-04-14 19:02:32 +02:00
|
|
|
global module
|
2015-03-31 02:15:40 +02:00
|
|
|
args = [glusterbin]
|
|
|
|
args.extend(gargs)
|
|
|
|
rc, out, err = module.run_command(args, data='y\n')
|
|
|
|
if rc != 0:
|
|
|
|
module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' % (' '.join(args), rc, out if out != '' else err))
|
|
|
|
return out
|
|
|
|
|
|
|
|
def get_peers():
|
|
|
|
out = run_gluster([ 'peer', 'status'])
|
|
|
|
i = 0
|
|
|
|
peers = {}
|
|
|
|
hostname = None
|
|
|
|
uuid = None
|
|
|
|
state = None
|
|
|
|
for row in out.split('\n'):
|
|
|
|
if ': ' in row:
|
|
|
|
key, value = row.split(': ')
|
|
|
|
if key.lower() == 'hostname':
|
|
|
|
hostname = value
|
|
|
|
if key.lower() == 'uuid':
|
|
|
|
uuid = value
|
|
|
|
if key.lower() == 'state':
|
|
|
|
state = value
|
|
|
|
peers[hostname] = [ uuid, state ]
|
|
|
|
return peers
|
|
|
|
|
|
|
|
def get_volumes():
|
|
|
|
out = run_gluster([ 'volume', 'info' ])
|
|
|
|
|
|
|
|
volumes = {}
|
|
|
|
volume = {}
|
|
|
|
for row in out.split('\n'):
|
|
|
|
if ': ' in row:
|
|
|
|
key, value = row.split(': ')
|
|
|
|
if key.lower() == 'volume name':
|
|
|
|
volume['name'] = value
|
|
|
|
volume['options'] = {}
|
|
|
|
volume['quota'] = False
|
|
|
|
if key.lower() == 'volume id':
|
|
|
|
volume['id'] = value
|
|
|
|
if key.lower() == 'status':
|
|
|
|
volume['status'] = value
|
|
|
|
if key.lower() == 'transport-type':
|
|
|
|
volume['transport'] = value
|
|
|
|
if key.lower() != 'bricks' and key.lower()[:5] == 'brick':
|
|
|
|
if not 'bricks' in volume:
|
|
|
|
volume['bricks'] = []
|
|
|
|
volume['bricks'].append(value)
|
|
|
|
# Volume options
|
|
|
|
if '.' in key:
|
|
|
|
if not 'options' in volume:
|
2014-10-03 09:25:42 +02:00
|
|
|
volume['options'] = {}
|
2015-03-31 02:15:40 +02:00
|
|
|
volume['options'][key] = value
|
|
|
|
if key == 'features.quota' and value == 'on':
|
|
|
|
volume['quota'] = True
|
2014-10-03 09:25:42 +02:00
|
|
|
else:
|
2015-03-31 02:15:40 +02:00
|
|
|
if row.lower() != 'bricks:' and row.lower() != 'options reconfigured:':
|
|
|
|
if len(volume) > 0:
|
|
|
|
volumes[volume['name']] = volume
|
|
|
|
volume = {}
|
|
|
|
return volumes
|
2014-12-06 23:54:38 +01:00
|
|
|
|
2015-03-31 02:15:40 +02:00
|
|
|
def get_quotas(name, nofail):
|
|
|
|
quotas = {}
|
|
|
|
if nofail:
|
|
|
|
out = run_gluster_nofail([ 'volume', 'quota', name, 'list' ])
|
|
|
|
if not out:
|
|
|
|
return quotas
|
|
|
|
else:
|
|
|
|
out = run_gluster([ 'volume', 'quota', name, 'list' ])
|
|
|
|
for row in out.split('\n'):
|
|
|
|
if row[:1] == '/':
|
|
|
|
q = re.split('\s+', row)
|
|
|
|
quotas[q[0]] = q[1]
|
|
|
|
return quotas
|
|
|
|
|
|
|
|
def wait_for_peer(host):
|
|
|
|
for x in range(0, 4):
|
|
|
|
peers = get_peers()
|
|
|
|
if host in peers and peers[host][1].lower().find('peer in cluster') != -1:
|
|
|
|
return True
|
|
|
|
time.sleep(1)
|
|
|
|
return False
|
|
|
|
|
|
|
|
def probe(host):
|
2015-04-14 19:02:32 +02:00
|
|
|
global module
|
2015-03-31 02:15:40 +02:00
|
|
|
run_gluster([ 'peer', 'probe', host ])
|
|
|
|
if not wait_for_peer(host):
|
|
|
|
module.fail_json(msg='failed to probe peer %s' % host)
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
def probe_all_peers(hosts, peers, myhostname):
|
|
|
|
for host in hosts:
|
|
|
|
if host not in peers:
|
|
|
|
# dont probe ourselves
|
|
|
|
if myhostname != host:
|
|
|
|
probe(host)
|
|
|
|
|
2015-04-17 21:48:53 +02:00
|
|
|
def create_volume(name, stripe, replica, transport, hosts, bricks, force):
|
2015-03-31 02:15:40 +02:00
|
|
|
args = [ 'volume', 'create' ]
|
|
|
|
args.append(name)
|
|
|
|
if stripe:
|
|
|
|
args.append('stripe')
|
|
|
|
args.append(str(stripe))
|
|
|
|
if replica:
|
|
|
|
args.append('replica')
|
|
|
|
args.append(str(replica))
|
|
|
|
args.append('transport')
|
|
|
|
args.append(transport)
|
2015-04-17 21:48:53 +02:00
|
|
|
for brick in bricks:
|
|
|
|
for host in hosts:
|
|
|
|
args.append(('%s:%s' % (host, brick)))
|
2015-03-31 02:15:40 +02:00
|
|
|
if force:
|
|
|
|
args.append('force')
|
|
|
|
run_gluster(args)
|
|
|
|
|
|
|
|
def start_volume(name):
|
|
|
|
run_gluster([ 'volume', 'start', name ])
|
|
|
|
|
|
|
|
def stop_volume(name):
|
|
|
|
run_gluster_yes([ 'volume', 'stop', name ])
|
|
|
|
|
|
|
|
def set_volume_option(name, option, parameter):
|
|
|
|
run_gluster([ 'volume', 'set', name, option, parameter ])
|
|
|
|
|
|
|
|
def add_brick(name, brick, force):
|
|
|
|
args = [ 'volume', 'add-brick', name, brick ]
|
|
|
|
if force:
|
|
|
|
args.append('force')
|
|
|
|
run_gluster(args)
|
|
|
|
|
|
|
|
def do_rebalance(name):
|
2015-04-14 19:02:32 +02:00
|
|
|
run_gluster([ 'volume', 'rebalance', name, 'start' ])
|
2015-03-31 02:15:40 +02:00
|
|
|
|
|
|
|
def enable_quota(name):
|
|
|
|
run_gluster([ 'volume', 'quota', name, 'enable' ])
|
|
|
|
|
|
|
|
def set_quota(name, directory, value):
|
2015-04-14 19:02:32 +02:00
|
|
|
run_gluster([ 'volume', 'quota', name, 'limit-usage', directory, value ])
|
2014-10-03 09:25:42 +02:00
|
|
|
|
2015-03-31 02:15:40 +02:00
|
|
|
|
|
|
|
def main():
|
2014-12-06 23:54:38 +01:00
|
|
|
### MAIN ###
|
|
|
|
|
2015-04-14 19:02:32 +02:00
|
|
|
global module
|
2014-12-06 23:54:38 +01:00
|
|
|
module = AnsibleModule(
|
|
|
|
argument_spec=dict(
|
|
|
|
name=dict(required=True, default=None, aliases=['volume']),
|
|
|
|
state=dict(required=True, choices=[ 'present', 'absent', 'started', 'stopped', 'rebalanced' ]),
|
|
|
|
cluster=dict(required=False, default=None, type='list'),
|
|
|
|
host=dict(required=False, default=None),
|
|
|
|
stripes=dict(required=False, default=None, type='int'),
|
|
|
|
replicas=dict(required=False, default=None, type='int'),
|
|
|
|
transport=dict(required=False, default='tcp', choices=[ 'tcp', 'rdma', 'tcp,rdma' ]),
|
2015-04-20 16:13:52 +02:00
|
|
|
bricks=dict(required=False, default=None, aliases=['brick']),
|
2014-12-06 23:54:38 +01:00
|
|
|
start_on_create=dict(required=False, default=True, type='bool'),
|
2015-03-11 08:54:13 +01:00
|
|
|
rebalance=dict(required=False, default=False, type='bool'),
|
2015-03-11 15:22:38 +01:00
|
|
|
options=dict(required=False, default={}, type='dict'),
|
2014-12-06 23:54:38 +01:00
|
|
|
quota=dict(required=False),
|
|
|
|
directory=dict(required=False, default=None),
|
2015-03-11 08:54:13 +01:00
|
|
|
force=dict(required=False, default=False, type='bool'),
|
2014-12-06 23:54:38 +01:00
|
|
|
)
|
|
|
|
)
|
|
|
|
|
2015-03-31 20:29:38 +02:00
|
|
|
global glusterbin
|
2014-12-06 23:54:38 +01:00
|
|
|
glusterbin = module.get_bin_path('gluster', True)
|
|
|
|
|
|
|
|
changed = False
|
|
|
|
|
|
|
|
action = module.params['state']
|
|
|
|
volume_name = module.params['name']
|
|
|
|
cluster= module.params['cluster']
|
2015-04-17 21:48:53 +02:00
|
|
|
brick_paths = module.params['brick']
|
2014-12-06 23:54:38 +01:00
|
|
|
stripes = module.params['stripes']
|
|
|
|
replicas = module.params['replicas']
|
|
|
|
transport = module.params['transport']
|
|
|
|
myhostname = module.params['host']
|
2015-03-11 08:54:13 +01:00
|
|
|
start_on_create = module.boolean(module.params['start_on_create'])
|
2014-12-06 23:54:38 +01:00
|
|
|
rebalance = module.boolean(module.params['rebalance'])
|
2015-03-11 08:54:13 +01:00
|
|
|
force = module.boolean(module.params['force'])
|
2014-12-06 23:54:38 +01:00
|
|
|
|
|
|
|
if not myhostname:
|
|
|
|
myhostname = socket.gethostname()
|
|
|
|
|
2015-04-17 21:48:53 +02:00
|
|
|
if brick_paths != None and "," in brick_paths:
|
|
|
|
brick_paths = brick_paths.split(",")
|
|
|
|
else:
|
|
|
|
brick_paths = [brick_paths]
|
|
|
|
|
2015-03-11 15:22:38 +01:00
|
|
|
options = module.params['options']
|
2014-12-06 23:54:38 +01:00
|
|
|
quota = module.params['quota']
|
|
|
|
directory = module.params['directory']
|
|
|
|
|
|
|
|
|
|
|
|
# get current state info
|
2014-10-03 09:25:42 +02:00
|
|
|
peers = get_peers()
|
|
|
|
volumes = get_volumes()
|
|
|
|
quotas = {}
|
|
|
|
if volume_name in volumes and volumes[volume_name]['quota'] and volumes[volume_name]['status'].lower() == 'started':
|
|
|
|
quotas = get_quotas(volume_name, True)
|
2014-12-06 23:54:38 +01:00
|
|
|
|
|
|
|
# do the work!
|
|
|
|
if action == 'absent':
|
|
|
|
if volume_name in volumes:
|
2015-04-19 21:29:30 +02:00
|
|
|
if volumes[volume_name]['status'].lower() != 'stopped':
|
|
|
|
stop_volume(volume_name)
|
|
|
|
run_gluster_yes([ 'volume', 'delete', volume_name ])
|
2014-12-06 23:54:38 +01:00
|
|
|
changed = True
|
|
|
|
|
|
|
|
if action == 'present':
|
|
|
|
probe_all_peers(cluster, peers, myhostname)
|
|
|
|
|
|
|
|
# create if it doesn't exist
|
2014-10-03 09:25:42 +02:00
|
|
|
if volume_name not in volumes:
|
2015-04-17 21:48:53 +02:00
|
|
|
create_volume(volume_name, stripes, replicas, transport, cluster, brick_paths, force)
|
2015-03-11 08:54:13 +01:00
|
|
|
volumes = get_volumes()
|
2014-10-03 09:25:42 +02:00
|
|
|
changed = True
|
2014-12-06 23:54:38 +01:00
|
|
|
|
2014-10-03 09:25:42 +02:00
|
|
|
if volume_name in volumes:
|
2015-03-11 08:54:13 +01:00
|
|
|
if volumes[volume_name]['status'].lower() != 'started' and start_on_create:
|
2014-10-03 09:25:42 +02:00
|
|
|
start_volume(volume_name)
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
# switch bricks
|
|
|
|
new_bricks = []
|
|
|
|
removed_bricks = []
|
|
|
|
all_bricks = []
|
2014-12-06 23:54:38 +01:00
|
|
|
for node in cluster:
|
2015-04-17 21:48:53 +02:00
|
|
|
for brick_path in brick_paths:
|
|
|
|
brick = '%s:%s' % (node, brick_path)
|
|
|
|
all_bricks.append(brick)
|
|
|
|
if brick not in volumes[volume_name]['bricks']:
|
|
|
|
new_bricks.append(brick)
|
2014-10-03 09:25:42 +02:00
|
|
|
|
|
|
|
# this module does not yet remove bricks, but we check those anyways
|
|
|
|
for brick in volumes[volume_name]['bricks']:
|
|
|
|
if brick not in all_bricks:
|
|
|
|
removed_bricks.append(brick)
|
2014-12-06 23:54:38 +01:00
|
|
|
|
2014-10-03 09:25:42 +02:00
|
|
|
for brick in new_bricks:
|
2015-03-11 14:40:22 +01:00
|
|
|
add_brick(volume_name, brick, force)
|
2014-10-03 09:25:42 +02:00
|
|
|
changed = True
|
|
|
|
|
2014-12-06 23:54:38 +01:00
|
|
|
# handle quotas
|
|
|
|
if quota:
|
|
|
|
if not volumes[volume_name]['quota']:
|
|
|
|
enable_quota(volume_name)
|
|
|
|
quotas = get_quotas(volume_name, False)
|
|
|
|
if directory not in quotas or quotas[directory] != quota:
|
|
|
|
set_quota(volume_name, directory, quota)
|
|
|
|
changed = True
|
|
|
|
|
|
|
|
# set options
|
|
|
|
for option in options.keys():
|
|
|
|
if option not in volumes[volume_name]['options'] or volumes[volume_name]['options'][option] != options[option]:
|
|
|
|
set_volume_option(volume_name, option, options[option])
|
|
|
|
changed = True
|
|
|
|
|
2014-10-03 09:25:42 +02:00
|
|
|
else:
|
|
|
|
module.fail_json(msg='failed to create volume %s' % volume_name)
|
2014-12-06 23:54:38 +01:00
|
|
|
|
|
|
|
if volume_name not in volumes:
|
|
|
|
module.fail_json(msg='volume not found %s' % volume_name)
|
|
|
|
|
|
|
|
if action == 'started':
|
2014-10-03 09:25:42 +02:00
|
|
|
if volumes[volume_name]['status'].lower() != 'started':
|
|
|
|
start_volume(volume_name)
|
|
|
|
changed = True
|
2014-12-06 23:54:38 +01:00
|
|
|
|
|
|
|
if action == 'stopped':
|
2014-10-03 09:25:42 +02:00
|
|
|
if volumes[volume_name]['status'].lower() != 'stopped':
|
|
|
|
stop_volume(volume_name)
|
|
|
|
changed = True
|
|
|
|
|
2014-12-06 23:54:38 +01:00
|
|
|
if changed:
|
|
|
|
volumes = get_volumes()
|
|
|
|
if rebalance:
|
2015-03-31 02:15:40 +02:00
|
|
|
do_rebalance(volume_name)
|
2014-12-06 23:54:38 +01:00
|
|
|
|
2014-10-03 09:25:42 +02:00
|
|
|
facts = {}
|
|
|
|
facts['glusterfs'] = { 'peers': peers, 'volumes': volumes, 'quotas': quotas }
|
|
|
|
|
|
|
|
module.exit_json(changed=changed, ansible_facts=facts)
|
|
|
|
|
|
|
|
# import module snippets
|
|
|
|
from ansible.module_utils.basic import *
|
|
|
|
main()
|