Move to using new storage charmhelpers

This commit is contained in:
James Page 2013-06-25 12:03:02 +01:00
parent b0bf0e6632
commit d6e7d2031a
8 changed files with 37 additions and 47 deletions

View File

@ -3,3 +3,5 @@ destination: hooks/charmhelpers
include:
- core
- fetch
- contrib.storage.linux:
- utils

View File

@ -17,6 +17,10 @@ from charmhelpers.core.host import (
service_restart,
log
)
from charmhelpers.contrib.storage.linux.utils import (
zap_disk,
is_block_device
)
from utils import (
get_unit_hostname
)
@ -125,11 +129,6 @@ def rescan_osd_devices():
subprocess.call(cmd)
def zap_disk(dev):
cmd = ['sgdisk', '--zap-all', dev]
subprocess.check_call(cmd)
_bootstrap_keyring = "/var/lib/ceph/bootstrap-osd/ceph.keyring"
@ -297,6 +296,10 @@ def osdize(dev, osd_format, osd_journal, reformat_osd=False):
log('Path {} does not exist - bailing'.format(dev))
return
if not is_block_device(dev):
log('Path {} is not a block device - bailing'.format(dev))
return
if (is_osd_disk(dev) and not reformat_osd):
log('Looks like {} is already an OSD, skipping.'.format(dev))
return

View File

View File

@ -0,0 +1,25 @@
from os import stat
from stat import S_ISBLK
from subprocess import (
check_call
)
def is_block_device(path):
'''
Confirm device at path is a valid block device node.
:returns: boolean: True if path is a block device, False if not.
'''
return S_ISBLK(stat(path).st_mode)
def zap_disk(block_device):
'''
Clear a block device of partition table. Relies on sgdisk, which is
installed as pat of the 'gdisk' package in Ubuntu.
:param block_device: str: Full path of block device to clean.
'''
check_call(['sgdisk', '--zap-all', block_device])

View File

@ -14,18 +14,15 @@ import shutil
import sys
import ceph
#import utils
from charmhelpers.core.hookenv import (
log,
ERROR,
log, ERROR,
config,
relation_ids,
related_units,
relation_get,
relation_set,
remote_unit,
Hooks,
UnregisteredHookError
Hooks, UnregisteredHookError
)
from charmhelpers.core.host import (
apt_install,

View File

@ -7,17 +7,14 @@
# Paul Collins <paul.collins@canonical.com>
#
import subprocess
import socket
import re
from charmhelpers.core.hookenv import (
config,
unit_get,
cached
)
from charmhelpers.core.host import (
apt_install,
apt_update,
filter_installed_packages
)
@ -45,40 +42,6 @@ def render_template(template_name, context, template_dir=TEMPLATES_DIR):
return template.render(context)
CLOUD_ARCHIVE = """ # Ubuntu Cloud Archive
deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main
"""
def configure_source(source=None):
if not source:
return
if source.startswith('ppa:'):
cmd = [
'add-apt-repository',
source
]
subprocess.check_call(cmd)
if source.startswith('cloud:'):
apt_install(filter_installed_packages(['ubuntu-cloud-keyring']),
fatal=True)
pocket = source.split(':')[-1]
with open('/etc/apt/sources.list.d/cloud-archive.list', 'w') as apt:
apt.write(CLOUD_ARCHIVE.format(pocket))
if source.startswith('http:'):
with open('/etc/apt/sources.list.d/ceph.list', 'w') as apt:
apt.write("deb " + source + "\n")
key = config('key')
if key:
cmd = [
'apt-key',
'adv', '--keyserver keyserver.ubuntu.com',
'--recv-keys', key
]
subprocess.check_call(cmd)
apt_update(fatal=True)
def enable_pocket(pocket):
apt_sources = "/etc/apt/sources.list"
with open(apt_sources, "r") as sources: