Added 0mq support

This commit is contained in:
Liam Young 2014-09-09 09:47:14 +00:00
parent b97e87ea20
commit 4e3c0fc4a4
12 changed files with 192 additions and 16 deletions

View File

@ -1,4 +1,4 @@
branch: lp:charm-helpers branch: lp:~openstack-charmers/charm-helpers/0mq
destination: hooks/charmhelpers destination: hooks/charmhelpers
include: include:
- core - core

View File

@ -21,6 +21,7 @@ from charmhelpers.core.hookenv import (
relation_get, relation_get,
relation_ids, relation_ids,
related_units, related_units,
is_relation_made,
relation_set, relation_set,
unit_get, unit_get,
unit_private_ip, unit_private_ip,
@ -787,3 +788,16 @@ class SyslogContext(OSContextGenerator):
'use_syslog': config('use-syslog') 'use_syslog': config('use-syslog')
} }
return ctxt return ctxt
class ZeroMQContext(OSContextGenerator):
interfaces = ['zeromq-configuration']
def __call__(self):
ctxt = {}
if is_relation_made('zeromq-configuration', 'host'):
for rid in relation_ids('zeromq-configuration'):
for unit in related_units(rid):
ctxt['zmq_nonce'] = relation_get('nonce', unit, rid)
ctxt['zmq_host'] = relation_get('host', unit, rid)
return ctxt

View File

@ -70,6 +70,7 @@ SWIFT_CODENAMES = OrderedDict([
('1.13.0', 'icehouse'), ('1.13.0', 'icehouse'),
('1.12.0', 'icehouse'), ('1.12.0', 'icehouse'),
('1.11.0', 'icehouse'), ('1.11.0', 'icehouse'),
('2.0.0', 'juno'),
]) ])
DEFAULT_LOOPBACK_SIZE = '5G' DEFAULT_LOOPBACK_SIZE = '5G'

View File

@ -156,12 +156,15 @@ def hook_name():
class Config(dict): class Config(dict):
"""A Juju charm config dictionary that can write itself to """A dictionary representation of the charm's config.yaml, with some
disk (as json) and track which values have changed since extra features:
the previous hook invocation.
Do not instantiate this object directly - instead call - See which values in the dictionary have changed since the previous hook.
``hookenv.config()`` - For values that have changed, see what the previous value was.
- Store arbitrary data for use in a later hook.
NOTE: Do not instantiate this object directly - instead call
``hookenv.config()``, which will return an instance of :class:`Config`.
Example usage:: Example usage::
@ -170,8 +173,8 @@ class Config(dict):
>>> config = hookenv.config() >>> config = hookenv.config()
>>> config['foo'] >>> config['foo']
'bar' 'bar'
>>> # store a new key/value for later use
>>> config['mykey'] = 'myval' >>> config['mykey'] = 'myval'
>>> config.save()
>>> # user runs `juju set mycharm foo=baz` >>> # user runs `juju set mycharm foo=baz`
@ -188,22 +191,23 @@ class Config(dict):
>>> # keys/values that we add are preserved across hooks >>> # keys/values that we add are preserved across hooks
>>> config['mykey'] >>> config['mykey']
'myval' 'myval'
>>> # don't forget to save at the end of hook!
>>> config.save()
""" """
CONFIG_FILE_NAME = '.juju-persistent-config' CONFIG_FILE_NAME = '.juju-persistent-config'
def __init__(self, *args, **kw): def __init__(self, *args, **kw):
super(Config, self).__init__(*args, **kw) super(Config, self).__init__(*args, **kw)
self.implicit_save = True
self._prev_dict = None self._prev_dict = None
self.path = os.path.join(charm_dir(), Config.CONFIG_FILE_NAME) self.path = os.path.join(charm_dir(), Config.CONFIG_FILE_NAME)
if os.path.exists(self.path): if os.path.exists(self.path):
self.load_previous() self.load_previous()
def load_previous(self, path=None): def load_previous(self, path=None):
"""Load previous copy of config from disk so that current values """Load previous copy of config from disk.
can be compared to previous values.
In normal usage you don't need to call this method directly - it
is called automatically at object initialization.
:param path: :param path:
@ -218,8 +222,8 @@ class Config(dict):
self._prev_dict = json.load(f) self._prev_dict = json.load(f)
def changed(self, key): def changed(self, key):
"""Return true if the value for this key has changed since """Return True if the current value for this key is different from
the last save. the previous value.
""" """
if self._prev_dict is None: if self._prev_dict is None:
@ -228,7 +232,7 @@ class Config(dict):
def previous(self, key): def previous(self, key):
"""Return previous value for this key, or None if there """Return previous value for this key, or None if there
is no "previous" value. is no previous value.
""" """
if self._prev_dict: if self._prev_dict:
@ -238,7 +242,13 @@ class Config(dict):
def save(self): def save(self):
"""Save this config to disk. """Save this config to disk.
Preserves items in _prev_dict that do not exist in self. If the charm is using the :mod:`Services Framework <services.base>`
or :meth:'@hook <Hooks.hook>' decorator, this
is called automatically at the end of successful hook execution.
Otherwise, it should be called directly by user code.
To disable automatic saves, set ``implicit_save=False`` on this
instance.
""" """
if self._prev_dict: if self._prev_dict:
@ -478,6 +488,9 @@ class Hooks(object):
hook_name = os.path.basename(args[0]) hook_name = os.path.basename(args[0])
if hook_name in self._hooks: if hook_name in self._hooks:
self._hooks[hook_name]() self._hooks[hook_name]()
cfg = config()
if cfg.implicit_save:
cfg.save()
else: else:
raise UnregisteredHookError(hook_name) raise UnregisteredHookError(hook_name)

View File

@ -118,6 +118,9 @@ class ServiceManager(object):
else: else:
self.provide_data() self.provide_data()
self.reconfigure_services() self.reconfigure_services()
cfg = hookenv.config()
if cfg.implicit_save:
cfg.save()
def provide_data(self): def provide_data(self):
""" """

View File

@ -50,6 +50,7 @@ from nova_compute_utils import (
ceph_config_file, CEPH_SECRET, ceph_config_file, CEPH_SECRET,
enable_shell, disable_shell, enable_shell, disable_shell,
fix_path_ownership, fix_path_ownership,
services,
) )
from nova_compute_context import CEPH_SECRET_UUID from nova_compute_context import CEPH_SECRET_UUID
@ -251,6 +252,20 @@ def nova_ceilometer_relation_changed():
CONFIGS.write_all() CONFIGS.write_all()
@hooks.hook('zeromq-configuration-relation-joined')
def zeromq_configuration_relation_joined(relid=None):
if services:
relation_set(relation_id=relid,
topics=" ".join(services()),
users="nova")
@hooks.hook('zeromq-configuration-relation-changed')
@restart_on_change(restart_map(), stopstart=True)
def zeromq_configuration_relation_changed():
CONFIGS.write(NOVA_CONF)
def main(): def main():
try: try:
hooks.execute(sys.argv) hooks.execute(sys.argv)

View File

@ -79,7 +79,8 @@ BASE_RESOURCE_MAP = {
interface='nova-ceilometer', interface='nova-ceilometer',
service='nova', service='nova',
config_file=NOVA_CONF), config_file=NOVA_CONF),
InstanceConsoleContext(), ], InstanceConsoleContext(),
context.ZeroMQContext()],
}, },
} }

View File

@ -0,0 +1 @@
nova_compute_hooks.py

View File

@ -0,0 +1 @@
nova_compute_hooks.py

View File

@ -30,6 +30,9 @@ requires:
neutron-plugin: neutron-plugin:
interface: neutron-plugin interface: neutron-plugin
scope: container scope: container
zeromq-configuration:
interface: zeromq-configuration
scope: container
peers: peers:
compute-peer: compute-peer:
interface: nova interface: nova

View File

@ -0,0 +1,118 @@
# icehouse
###############################################################################
# [ WARNING ]
# Configuration file maintained by Juju. Local changes may be overwritten.
{% if restart_trigger -%}
# restart trigger: {{ restart_trigger }}
{% endif -%}
###############################################################################
[DEFAULT]
dhcpbridge_flagfile=/etc/nova/nova.conf
dhcpbridge=/usr/bin/nova-dhcpbridge
logdir=/var/log/nova
state_path=/var/lib/nova
lock_path=/var/lock/nova
force_dhcp_release=True
libvirt_use_virtio_for_bridges=True
verbose=True
use_syslog = {{ use_syslog }}
ec2_private_dns_show_ip=True
api_paste_config=/etc/nova/api-paste.ini
enabled_apis=ec2,osapi_compute,metadata
auth_strategy=keystone
compute_driver=libvirt.LibvirtDriver
{% include "parts/database" %}
{% include "parts/rabbitmq" %}
{% include "parts/zeromq" %}
{% if glance_api_servers -%}
glance_api_servers = {{ glance_api_servers }}
{% endif -%}
{% if rbd_pool -%}
rbd_pool = {{ rbd_pool }}
rbd_user = {{ rbd_user }}
rbd_secret_uuid = {{ rbd_secret_uuid }}
{% endif -%}
{% if console_vnc_type -%}
vnc_enabled = True
novnc_enabled = True
vnc_keymap = {{ console_keymap }}
vncserver_listen = 0.0.0.0
vncserver_proxyclient_address = {{ console_listen_addr }}
{% if console_access_protocol == 'novnc' or console_access_protocol == 'vnc' -%}
novncproxy_base_url = {{ novnc_proxy_address }}
{% endif -%}
{% if console_access_protocol == 'xvpvnc' or console_access_protocol == 'vnc' -%}
xvpvncproxy_port = {{ xvpvnc_proxy_port }}
xvpvncproxy_host = {{ xvpvnc_proxy_host }}
xvpvncproxy_base_url = {{ xvpvnc_proxy_address }}
{% endif -%}
{% else -%}
vnc_enabled = False
novnc_enabled = False
{% endif -%}
{% if neutron_plugin and neutron_plugin == 'ovs' -%}
libvirt_vif_driver = nova.virt.libvirt.vif.LibvirtGenericVIFDriver
{% if neutron_security_groups -%}
security_group_api = neutron
firewall_driver = nova.virt.firewall.NoopFirewallDriver
{% endif -%}
{% endif -%}
{% if neutron_plugin and (neutron_plugin == 'nvp' or neutron_plugin == 'nsx') -%}
libvirt_vif_driver = nova.virt.libvirt.vif.LibvirtOpenVswitchVirtualPortDriver
security_group_api = neutron
firewall_driver = nova.virt.firewall.NoopFirewallDriver
{% endif -%}
{% if network_manager_config -%}
{% for key, value in network_manager_config.iteritems() -%}
{{ key }} = {{ value }}
{% endfor -%}
{% endif -%}
{% if network_manager == 'neutron' -%}
network_api_class = nova.network.neutronv2.api.API
{% else -%}
network_manager = nova.network.manager.FlatDHCPManager
{% endif -%}
{% if volume_service -%}
volume_api_class = nova.volume.cinder.API
{% endif -%}
{% if user_config_flags -%}
{% for key, value in user_config_flags.iteritems() -%}
{{ key }} = {{ value }}
{% endfor -%}
{% endif -%}
{% if live_migration_uri -%}
live_migration_uri = {{ live_migration_uri }}
{% endif -%}
{% if instances_path -%}
instances_path = {{ instances_path }}
{% endif -%}
{% if sections and 'DEFAULT' in sections -%}
{% for key, value in sections['DEFAULT'] -%}
{{ key }} = {{ value }}
{% endfor -%}
{% endif -%}
{% if console_access_protocol == 'spice' -%}
[spice]
agent_enabled = True
enabled = True
html5proxy_base_url = {{ spice_proxy_address }}
keymap = {{ console_keymap }}
server_listen = 0.0.0.0
server_proxyclient_address = {{ console_listen_addr }}
{% endif -%}

6
templates/parts/zeromq Normal file
View File

@ -0,0 +1,6 @@
{% if zmq_host -%}
# ZeroMQ configuration (restart-nonce: {{ zmq_nonce }})
rpc_backend = zmq
rpc_zmq_matchmaker = oslo.messaging._drivers.matchmaker_ring.MatchMakerRing
rpc_zmq_host = {{ zmq_host }}
{% endif -%}