2
# Copyright 2014 Canonical Ltd.
5
# Chuck Short <zulcss@ubuntu.com>
10
from subprocess import (
16
from charmhelpers.core.hookenv import (
27
from charmhelpers.core.host import (
37
from charmhelpers.fetch import (
46
'ppa:zulcss/flex-testing'
52
log('Configuring flex')
54
# This can be removed once in the archive
58
flex_block_device = config('flex-block-device')
59
flex_mount_point = config('flex-mount-point')
61
instance_path = '/var/lib/nova/instances'
62
if config('instances-path') is not None:
63
instance_path = config('instances-path')
65
# configure the btrfs block device
66
apt_install('btrfs-tools', fatal=True)
67
if filesystem_mounted(flex_mount_point):
68
umount(flex_mount_point)
70
make_filesystem(flex_block_device)
71
mount(flex_block_device, instance_path, persist=True)
72
cmd = ['chown', 'nova:nova', instance_path]
76
cmd = ['chmod', '+x', instance_path]
78
service_start('nova-compute')
80
def configure_flex_user():
81
cmd = ['usermod', '--add-subuids', '100000-165536', 'nova']
83
cmd = ['usermod', '--add-subgids', '100000-165536', 'nova']
86
def filesystem_mounted(fs):
87
return fs in [f for f, m in mounts()]
89
def make_filesystem(blk_device, timeout=10):
91
e_noent = os.errno.ENOENT
92
while not os.path.exists(blk_device):
94
log('gave up waiting on block device %s' % blk_device,
96
raise IOError(e_noent, os.strerror(e_noent), blk_device)
97
log('waiting for block device %s to appear' % blk_device,
102
log('Formatting block device %s.' % blk_device, level=INFO)
103
check_call(['mkfs.btrfs', '-f', blk_device])