From e30f3f7b3c8b6f4f5d11c816d104dd7aaffa6a3e Mon Sep 17 00:00:00 2001 From: James Page Date: Mon, 12 Nov 2012 09:36:03 +0000 Subject: [PATCH] Add full support for cloud archive use; add early check for device presens in osdize. --- config.yaml | 4 ++-- hooks/hooks.py | 8 ++++++-- hooks/utils.py | 42 +++++++++++++++++++++++++++++++----------- revision | 2 +- 4 files changed, 40 insertions(+), 16 deletions(-) diff --git a/config.yaml b/config.yaml index 93de8291..e4ae50f5 100644 --- a/config.yaml +++ b/config.yaml @@ -22,7 +22,7 @@ options: Optional configuration to support use of additional sources such as: . - ppa:myteam/ppa - - cloud:folsom-proposed + - cloud:precise-proposed/folsom - http://my.archive.com/ubuntu main . The last option should be used in conjunction with the key configuration @@ -30,7 +30,7 @@ options: . Note that a minimum ceph version of 0.48.2 is required for use with this charm which is NOT provided by the packages in the main Ubuntu archive - for precise. + for precise but is provided in the Ubuntu cloud archive. key: type: string description: | diff --git a/hooks/hooks.py b/hooks/hooks.py index 1421284e..42d59f01 100755 --- a/hooks/hooks.py +++ b/hooks/hooks.py @@ -90,6 +90,11 @@ def get_conf(name): def osdize(dev): + if not os.path.exists(dev): + utils.juju_log('INFO', + 'Path {} does not exist - bailing'.format(dev)) + return + e_mountpoint = utils.config_get('ephemeral-unmount') if e_mountpoint != "": subprocess.call(['umount', e_mountpoint]) @@ -105,8 +110,7 @@ def osdize(dev): 'Looks like {} is in use, skipping.'.format(dev)) return - if os.path.exists(dev): - subprocess.call(['ceph-disk-prepare', dev]) + subprocess.call(['ceph-disk-prepare', dev]) def mon_relation(): diff --git a/hooks/utils.py b/hooks/utils.py index 64c578e1..5ae96bc0 100644 --- a/hooks/utils.py +++ b/hooks/utils.py @@ -50,24 +50,38 @@ 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 = config_get('source') - if (source.startswith('ppa:') or - source.startswith('cloud:') or - source.startswith('http:')): + source = str(config_get('source')) + if not source: + return + if source.startswith('ppa:'): cmd = [ 'add-apt-repository', source ] subprocess.check_call(cmd) + if source.startswith('cloud:'): + install('ubuntu-cloud-keyring') + 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/quantum.list', 'w') as apt: + apt.write("deb " + source + "\n") key = config_get('key') - cmd = [ - 'apt-key', - 'import', - key - ] - subprocess.check_call(cmd) + if key: + cmd = [ + 'apt-key', + 'adv', '--keyserver keyserver.ubuntu.com', + '--recv-keys', key + ] + subprocess.check_call(cmd) cmd = [ 'apt-get', 'update' @@ -129,8 +143,14 @@ def relation_set(**kwargs): cmd = [ 'relation-set' ] + args = [] for k, v in kwargs.items(): - cmd.append('{}={}'.format(k, v)) + if k == 'rid': + cmd.append('-r') + cmd.append(v) + else: + args.append('{}={}'.format(k, v)) + cmd += args subprocess.check_call(cmd) diff --git a/revision b/revision index b8626c4c..7ed6ff82 100644 --- a/revision +++ b/revision @@ -1 +1 @@ -4 +5