Merge pull request #357 from bcoca/lxc_container_home_fix

Lxc container home fix
reviewable/pr18780/r1
Brian Coca 10 years ago
commit c5f787e6df

@ -398,7 +398,7 @@ LXC_ANSIBLE_STATES = {
# home directory of the user that was attached to the container and source # home directory of the user that was attached to the container and source
# that users environment variables by default. # that users environment variables by default.
ATTACH_TEMPLATE = """#!/usr/bin/env bash ATTACH_TEMPLATE = """#!/usr/bin/env bash
pushd "$(grep $(whoami) /etc/passwd | awk -F':' '{print $6}')" pushd "$(getent passwd $(whoami)|cut -f6 -d':')"
if [[ -f ".bashrc" ]];then if [[ -f ".bashrc" ]];then
source .bashrc source .bashrc
fi fi

@ -38,27 +38,33 @@ options:
use started/stopped to control it's availability. use started/stopped to control it's availability.
cluster: cluster:
required: false required: false
default: null
description: description:
- List of hosts to use for probing and brick setup - List of hosts to use for probing and brick setup
host: host:
required: false required: false
default: null
description: description:
- Override local hostname (for peer probing purposes) - Override local hostname (for peer probing purposes)
replicas: replicas:
required: false required: false
default: null
description: description:
- Replica count for volume - Replica count for volume
stripes: stripes:
required: false required: false
default: null
description: description:
- Stripe count for volume - Stripe count for volume
transport: transport:
required: false required: false
choices: [ 'tcp', 'rdma', 'tcp,rdma' ] choices: [ 'tcp', 'rdma', 'tcp,rdma' ]
default: 'tcp'
description: description:
- Transport type for volume - Transport type for volume
brick: brick:
required: false required: false
default: null
description: description:
- Brick path on servers - Brick path on servers
start_on_create: start_on_create:
@ -69,22 +75,27 @@ options:
rebalance: rebalance:
choices: [ 'yes', 'no'] choices: [ 'yes', 'no']
required: false required: false
default: 'no'
description: description:
- Controls whether the cluster is rebalanced after changes - Controls whether the cluster is rebalanced after changes
directory: directory:
required: false required: false
default: null
description: description:
- Directory for limit-usage - Directory for limit-usage
options: options:
required: false required: false
default: null
description: description:
- A dictionary/hash with options/settings for the volume - A dictionary/hash with options/settings for the volume
quota: quota:
required: false required: false
default: null
description: description:
- Quota value for limit-usage (be sure to use 10.0MB instead of 10MB, see quota list) - Quota value for limit-usage (be sure to use 10.0MB instead of 10MB, see quota list)
force: force:
required: false required: false
default: null
description: description:
- If brick is being created in the root partition, module will fail. - If brick is being created in the root partition, module will fail.
Set force to true to override this behaviour Set force to true to override this behaviour
@ -119,165 +130,167 @@ import shutil
import time import time
import socket import socket
def main():
def run_gluster(gargs, **kwargs): def run_gluster(gargs, **kwargs):
args = [glusterbin] args = [glusterbin]
args.extend(gargs) args.extend(gargs)
try:
rc, out, err = module.run_command(args, **kwargs) rc, out, err = module.run_command(args, **kwargs)
if rc != 0: if rc != 0:
module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' % (' '.join(args), rc, out if out != '' else err)) module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' % (' '.join(args), rc, out if out != '' else err))
return out except Exception, e:
module.fail_json(msg='error running gluster (%s) command: %s' % (' '.join(args), str(e))
def run_gluster_nofail(gargs, **kwargs): return out
args = [glusterbin]
args.extend(gargs) def run_gluster_nofail(gargs, **kwargs):
rc, out, err = module.run_command(args, **kwargs) args = [glusterbin]
if rc != 0: args.extend(gargs)
return None rc, out, err = module.run_command(args, **kwargs)
return out if rc != 0:
return None
def run_gluster_yes(gargs): return out
args = [glusterbin]
args.extend(gargs) def run_gluster_yes(gargs):
rc, out, err = module.run_command(args, data='y\n') args = [glusterbin]
if rc != 0: args.extend(gargs)
module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' % (' '.join(args), rc, out if out != '' else err)) rc, out, err = module.run_command(args, data='y\n')
return out if rc != 0:
module.fail_json(msg='error running gluster (%s) command (rc=%d): %s' % (' '.join(args), rc, out if out != '' else err))
def get_peers(): return out
out = run_gluster([ 'peer', 'status'])
i = 0 def get_peers():
peers = {} out = run_gluster([ 'peer', 'status'])
hostname = None i = 0
uuid = None peers = {}
state = None hostname = None
for row in out.split('\n'): uuid = None
if ': ' in row: state = None
key, value = row.split(': ') for row in out.split('\n'):
if key.lower() == 'hostname': if ': ' in row:
hostname = value key, value = row.split(': ')
if key.lower() == 'uuid': if key.lower() == 'hostname':
uuid = value hostname = value
if key.lower() == 'state': if key.lower() == 'uuid':
state = value uuid = value
peers[hostname] = [ uuid, state ] if key.lower() == 'state':
return peers state = value
peers[hostname] = [ uuid, state ]
def get_volumes(): return peers
out = run_gluster([ 'volume', 'info' ])
def get_volumes():
volumes = {} out = run_gluster([ 'volume', 'info' ])
volume = {}
for row in out.split('\n'): volumes = {}
if ': ' in row: volume = {}
key, value = row.split(': ') for row in out.split('\n'):
if key.lower() == 'volume name': if ': ' in row:
volume['name'] = value 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:
volume['options'] = {} volume['options'] = {}
volume['quota'] = False volume['options'][key] = value
if key.lower() == 'volume id': if key == 'features.quota' and value == 'on':
volume['id'] = value volume['quota'] = True
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:
volume['options'] = {}
volume['options'][key] = value
if key == 'features.quota' and value == 'on':
volume['quota'] = True
else:
if row.lower() != 'bricks:' and row.lower() != 'options reconfigured:':
if len(volume) > 0:
volumes[volume['name']] = volume
volume = {}
return volumes
def get_quotas(name, nofail):
quotas = {}
if nofail:
out = run_gluster_nofail([ 'volume', 'quota', name, 'list' ])
if not out:
return quotas
else: else:
out = run_gluster([ 'volume', 'quota', name, 'list' ]) if row.lower() != 'bricks:' and row.lower() != 'options reconfigured:':
for row in out.split('\n'): if len(volume) > 0:
if row[:1] == '/': volumes[volume['name']] = volume
q = re.split('\s+', row) volume = {}
quotas[q[0]] = q[1] return volumes
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):
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)
def create_volume(name, stripe, replica, transport, hosts, brick, force):
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)
for host in hosts:
args.append(('%s:%s' % (host, brick)))
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 rebalance(name):
run_gluster(['volume', 'rebalance', name, 'start'])
def enable_quota(name):
run_gluster([ 'volume', 'quota', name, 'enable' ])
def set_quota(name, directory, value):
run_gluster([ 'volume', 'quota', name, 'limit-usage', directory, value ])
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):
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)
def create_volume(name, stripe, replica, transport, hosts, brick, force):
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)
for host in hosts:
args.append(('%s:%s' % (host, brick)))
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):
run_gluster(['volume', 'rebalance', name, 'start'])
def enable_quota(name):
run_gluster([ 'volume', 'quota', name, 'enable' ])
def set_quota(name, directory, value):
run_gluster([ 'volume', 'quota', name, 'limit-usage', directory, value ])
def main():
### MAIN ### ### MAIN ###
module = AnsibleModule( module = AnsibleModule(
@ -403,7 +416,7 @@ def main():
if changed: if changed:
volumes = get_volumes() volumes = get_volumes()
if rebalance: if rebalance:
rebalance(volume_name) do_rebalance(volume_name)
facts = {} facts = {}
facts['glusterfs'] = { 'peers': peers, 'volumes': volumes, 'quotas': quotas } facts['glusterfs'] = { 'peers': peers, 'volumes': volumes, 'quotas': quotas }

Loading…
Cancel
Save