Resync with configure_source supporting proposed

This commit is contained in:
James Page 2013-07-03 12:46:27 +01:00
parent 7d964e8b58
commit 13826f1d07
3 changed files with 26 additions and 8 deletions

View File

@ -1,4 +1,4 @@
branch: lp:charm-helpers
branch: lp:~james-page/charm-helpers/configure_source_proposed
destination: hooks/charmhelpers
include:
- core

View File

@ -48,13 +48,13 @@ def adduser(username, password=None, shell='/bin/bash', system_user=False):
log('creating user {0}'.format(username))
cmd = ['useradd']
if system_user or password is None:
cmd.append('--system')
cmd.append('--system')
else:
cmd.extend([
'--create-home',
'--shell', shell,
'--password', password,
])
cmd.extend([
'--create-home',
'--shell', shell,
'--password', password,
])
cmd.append(username)
subprocess.check_call(cmd)
user_info = pwd.getpwnam(username)
@ -261,3 +261,13 @@ def restart_on_change(restart_map):
service('restart', service_name)
return wrapped_f
return wrap
def lsb_release():
'''Return /etc/lsb-release in a dict'''
d = {}
with open('/etc/lsb-release', 'r') as lsb:
for l in lsb:
k, v = l.split('=')
d[k.strip()] = v.strip()
return d

View File

@ -3,7 +3,8 @@ from yaml import safe_load
from charmhelpers.core.host import (
apt_install,
apt_update,
filter_installed_packages
filter_installed_packages,
lsb_release
)
from urlparse import (
urlparse,
@ -18,6 +19,9 @@ from charmhelpers.core.hookenv import (
CLOUD_ARCHIVE = """# Ubuntu Cloud Archive
deb http://ubuntu-cloud.archive.canonical.com/ubuntu {} main
"""
PROPOSED_POCKET = """# Proposed
deb http://archive.ubuntu.com/ubuntu {}-proposed main universe multiverse restricted
"""
def add_source(source, key=None):
@ -30,6 +34,10 @@ def add_source(source, key=None):
pocket = source.split(':')[-1]
with open('/etc/apt/sources.list.d/cloud-archive.list', 'w') as apt:
apt.write(CLOUD_ARCHIVE.format(pocket))
elif source == 'proposed':
release = lsb_release()['DISTRIB_CODENAME']
with open('/etc/apt/sources.list.d/proposed.list', 'w') as apt:
apt.write(PROPOSED_POCKET.format(release))
if key:
subprocess.check_call(['apt-key', 'import', key])