Rebase on python-redux work.

This commit is contained in:
Adam Gandelman 2013-10-08 17:51:27 -07:00
parent 923b5cf260
commit 0b661186b0
4 changed files with 94 additions and 1 deletions

View File

@ -1,3 +1,4 @@
import json
import os
from base64 import b64decode
@ -21,6 +22,7 @@ from charmhelpers.core.hookenv import (
related_units,
unit_get,
unit_private_ip,
ERROR,
WARNING,
)
@ -431,3 +433,84 @@ class OSConfigFlagContext(OSContextGenerator):
flags[k.strip()] = v
ctxt = {'user_config_flags': flags}
return ctxt
class SubordinateConfigContext(OSContextGenerator):
"""
Responsible for inspecting relations to subordinates that
may be exporting required config via a json blob.
The subordinate interface allows subordinates to export their
configuration requirements to the principle for multiple config
files and multiple serivces. Ie, a subordinate that has interfaces
to both glance and nova may export to following yaml blob as json:
glance:
/etc/glance/glance-api.conf:
sections:
DEFAULT:
- [key1, value1]
/etc/glance/glance-registry.conf:
MYSECTION:
- [key2, value2]
nova:
/etc/nova/nova.conf:
sections:
DEFAULT:
- [key3, value3]
It is then up to the principle charms to subscribe this context to
the service+config file it is interestd in. Configuration data will
be available in the template context, in glance's case, as:
ctxt = {
... other context ...
'subordinate_config': {
'DEFAULT': {
'key1': 'value1',
},
'MYSECTION': {
'key2': 'value2',
},
}
}
"""
def __init__(self, service, config_file, interface):
"""
:param service : Service name key to query in any subordinate
data found
:param config_file : Service's config file to query sections
:param interface : Subordinate interface to inspect
"""
self.service = service
self.config_file = config_file
self.interface = interface
def __call__(self):
ctxt = {}
for rid in relation_ids(self.interface):
sub_config = relation_get('subordinate_config', relaton_id=rid)
if sub_config and sub_config != '':
try:
sub_config = json.loads(sub_config)
except:
log('Could not parse JSON from subordinate_config setting '
'from %s' % rid, level=ERROR)
if self.service not in sub_config:
log('Found subordinate_config on %s but it contained'
'nothing for %s service' % (rid, self.service))
continue
sub_config = sub_config[self.service]
if self.config_file not in sub_config:
log('Found subordinate_config on %s but it contained'
'nothing for %s' % (rid, self.config_file))
continue
sub_config = sub_config[self.config_file]
for k, v in sub_config.iteritems():
ctxt[k] = v
return ctxt

View File

@ -396,6 +396,11 @@ def configure_https():
identity_joined(rid=rid)
@hooks.hook()
def nova_vmware_relation_joined():
relation_set(network_manager=network_manager())
def main():
try:
hooks.execute(sys.argv)

View File

@ -84,6 +84,11 @@ BASE_RESOURCE_MAP = OrderedDict([
context.SharedDBContext(relation_prefix='nova'),
context.ImageServiceContext(),
context.OSConfigFlagContext(),
context.SubordinateConfigContext(
interface='nova-vmware',
service='nova',
config_file=NOVA_CONF,
),
nova_cc_context.HAProxyContext(),
nova_cc_context.IdentityServiceContext(),
nova_cc_context.VolumeServiceContext(),

View File

@ -27,7 +27,7 @@ requires:
ha:
interface: hacluster
scope: container
vmware:
nova-vmware:
interface: nova-vmware
scope: container
peers: