Sync helpers, update accordingly.

This commit is contained in:
Adam Gandelman
2013-09-23 12:01:06 -07:00
parent ecb87dd743
commit df655714eb
8 changed files with 130 additions and 80 deletions

View File

@@ -7,7 +7,7 @@ from subprocess import (
)
from charmhelpers.core.host import (
from charmhelpers.fetch import (
apt_install,
filter_installed_packages,
)
@@ -48,6 +48,13 @@ class OSContextError(Exception):
pass
def ensure_packages(packages):
'''Install but do not upgrade required plugin packages'''
required = filter_installed_packages(packages)
if required:
apt_install(required, fatal=True)
def context_complete(ctxt):
_missing = []
for k, v in ctxt.iteritems():
@@ -103,9 +110,9 @@ class SharedDBContext(OSContextGenerator):
'database_user': self.user,
'database_password': passwd,
}
if not context_complete(ctxt):
return {}
return ctxt
if context_complete(ctxt):
return ctxt
return {}
class IdentityServiceContext(OSContextGenerator):
@@ -134,9 +141,9 @@ class IdentityServiceContext(OSContextGenerator):
'service_protocol': 'http',
'auth_protocol': 'http',
}
if not context_complete(ctxt):
return {}
return ctxt
if context_complete(ctxt):
return ctxt
return {}
class AMQPContext(OSContextGenerator):
@@ -157,20 +164,30 @@ class AMQPContext(OSContextGenerator):
for rid in relation_ids('amqp'):
for unit in related_units(rid):
if relation_get('clustered', rid=rid, unit=unit):
rabbitmq_host = relation_get('vip', rid=rid, unit=unit)
ctxt['clustered'] = True
ctxt['rabbitmq_host'] = relation_get('vip', rid=rid,
unit=unit)
else:
rabbitmq_host = relation_get('private-address',
rid=rid, unit=unit)
ctxt = {
'rabbitmq_host': rabbitmq_host,
ctxt['rabbitmq_host'] = relation_get('private-address',
rid=rid, unit=unit)
ctxt.update({
'rabbitmq_user': username,
'rabbitmq_password': relation_get('password', rid=rid,
unit=unit),
'rabbitmq_virtual_host': vhost,
}
})
if context_complete(ctxt):
# Sufficient information found = break out!
break
# Used for active/active rabbitmq >= grizzly
ctxt['rabbitmq_hosts'] = []
for unit in related_units(rid):
ctxt['rabbitmq_hosts'].append(relation_get('private-address',
rid=rid, unit=unit))
if not context_complete(ctxt):
return {}
return ctxt
else:
return ctxt
class CephContext(OSContextGenerator):
@@ -178,21 +195,33 @@ class CephContext(OSContextGenerator):
def __call__(self):
'''This generates context for /etc/ceph/ceph.conf templates'''
log('Generating tmeplate context for ceph')
if not relation_ids('ceph'):
return {}
log('Generating template context for ceph')
mon_hosts = []
auth = None
key = None
for rid in relation_ids('ceph'):
for unit in related_units(rid):
mon_hosts.append(relation_get('private-address', rid=rid,
unit=unit))
auth = relation_get('auth', rid=rid, unit=unit)
key = relation_get('key', rid=rid, unit=unit)
ctxt = {
'mon_hosts': ' '.join(mon_hosts),
'auth': auth,
'key': key,
}
if not os.path.isdir('/etc/ceph'):
os.mkdir('/etc/ceph')
if not context_complete(ctxt):
return {}
ensure_packages(['ceph-common'])
return ctxt
@@ -341,10 +370,7 @@ class NeutronContext(object):
return None
def _ensure_packages(self):
'''Install but do not upgrade required plugin packages'''
required = filter_installed_packages(self.packages)
if required:
apt_install(required, fatal=True)
ensure_packages(self.packages)
def _save_flag_file(self):
if self.network_manager == 'quantum':