18
from charmhelpers.core.host import (
22
from charmhelpers.fetch import (
20
from charmhelpers.contrib.storage.linux.lvm import (
21
deactivate_lvm_volume_group,
22
is_lvm_physical_volume,
23
remove_lvm_physical_volume,
26
from charmhelpers.core.host import lsb_release, mounts, umount
27
from charmhelpers.fetch import apt_install
28
from charmhelpers.contrib.storage.linux.utils import is_block_device, zap_disk
29
from charmhelpers.contrib.storage.linux.loopback import ensure_loopback_device
26
31
CLOUD_ARCHIVE_URL = "http://ubuntu-cloud.archive.canonical.com/ubuntu"
27
32
CLOUD_ARCHIVE_KEY_ID = '5EDB1B62EC4926EA'
34
DISTRO_PROPOSED = ('deb http://archive.ubuntu.com/ubuntu/ %s-proposed '
35
'restricted main multiverse universe')
29
38
UBUNTU_OPENSTACK_RELEASE = OrderedDict([
30
39
('oneiric', 'diablo'),
31
40
('precise', 'essex'),
67
78
'''Derive OpenStack release codename from a given installation source.'''
68
79
ubuntu_rel = lsb_release()['DISTRIB_CODENAME']
81
if src in ['distro', 'distro-proposed']:
72
83
rel = UBUNTU_OPENSTACK_RELEASE[ubuntu_rel]
202
213
'''Configure apt installation source.'''
203
214
if rel == 'distro':
216
elif rel == 'distro-proposed':
217
ubuntu_rel = lsb_release()['DISTRIB_CODENAME']
218
with open('/etc/apt/sources.list.d/juju_deb.list', 'w') as f:
219
f.write(DISTRO_PROPOSED % ubuntu_rel)
205
220
elif rel[:4] == "ppa:":
207
222
subprocess.check_call(["add-apt-repository", "-y", src])
299
314
return apt.version_compare(available_vers, cur_vers) == 1
317
def ensure_block_device(block_device):
319
Confirm block_device, create as loopback if necessary.
321
:param block_device: str: Full path of block device to ensure.
323
:returns: str: Full path of ensured block device.
325
_none = ['None', 'none', None]
326
if (block_device in _none):
327
error_out('prepare_storage(): Missing required input: '
328
'block_device=%s.' % block_device, level=ERROR)
330
if block_device.startswith('/dev/'):
332
elif block_device.startswith('/'):
333
_bd = block_device.split('|')
338
size = DEFAULT_LOOPBACK_SIZE
339
bdev = ensure_loopback_device(bdev, size)
341
bdev = '/dev/%s' % block_device
343
if not is_block_device(bdev):
344
error_out('Failed to locate valid block device at %s' % bdev,
350
def clean_storage(block_device):
352
Ensures a block device is clean. That is:
354
- any lvm volume groups are deactivated
355
- any lvm physical device signatures removed
356
- partition table wiped
358
:param block_device: str: Full path to block device to clean.
360
for mp, d in mounts():
361
if d == block_device:
362
juju_log('clean_storage(): %s is mounted @ %s, unmounting.' %
364
umount(mp, persist=True)
366
if is_lvm_physical_volume(block_device):
367
deactivate_lvm_volume_group(block_device)
368
remove_lvm_physical_volume(block_device)
370
zap_disk(block_device)
302
373
def is_ip(address):
304
375
Returns True if address is a valid IP address.