Add 0mq support
This commit is contained in:
parent
2cc8ced26e
commit
ffdc2f4aa4
@ -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
|
||||||
|
@ -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
|
@ -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'
|
||||||
|
@ -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)
|
||||||
|
|
||||||
|
@ -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):
|
||||||
"""
|
"""
|
||||||
|
@ -41,6 +41,7 @@ from quantum_utils import (
|
|||||||
get_packages,
|
get_packages,
|
||||||
get_early_packages,
|
get_early_packages,
|
||||||
get_common_package,
|
get_common_package,
|
||||||
|
get_topics,
|
||||||
valid_plugin,
|
valid_plugin,
|
||||||
configure_ovs,
|
configure_ovs,
|
||||||
reassign_agent_resources,
|
reassign_agent_resources,
|
||||||
@ -85,6 +86,8 @@ def config_changed():
|
|||||||
amqp_joined(relation_id=r_id)
|
amqp_joined(relation_id=r_id)
|
||||||
for r_id in relation_ids('amqp-nova'):
|
for r_id in relation_ids('amqp-nova'):
|
||||||
amqp_nova_joined(relation_id=r_id)
|
amqp_nova_joined(relation_id=r_id)
|
||||||
|
for rid in relation_ids('zeromq-configuration'):
|
||||||
|
zeromq_configuration_relation_joined(rid)
|
||||||
if valid_plugin():
|
if valid_plugin():
|
||||||
CONFIGS.write_all()
|
CONFIGS.write_all()
|
||||||
configure_ovs()
|
configure_ovs()
|
||||||
@ -195,6 +198,20 @@ def cluster_departed():
|
|||||||
def stop():
|
def stop():
|
||||||
stop_services()
|
stop_services()
|
||||||
|
|
||||||
|
|
||||||
|
@hooks.hook('zeromq-configuration-relation-joined')
|
||||||
|
def zeromq_configuration_relation_joined(relid=None):
|
||||||
|
relation_set(relation_id=relid,
|
||||||
|
topics=" ".join(get_topics()),
|
||||||
|
users="neutron")
|
||||||
|
|
||||||
|
|
||||||
|
@hooks.hook('zeromq-configuration-relation-changed')
|
||||||
|
@restart_on_change(restart_map(), stopstart=True)
|
||||||
|
def zeromq_configuration_relation_changed():
|
||||||
|
CONFIGS.write_all()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
hooks.execute(sys.argv)
|
hooks.execute(sys.argv)
|
||||||
|
@ -227,7 +227,8 @@ QUANTUM_OVS_CONFIG_FILES = {
|
|||||||
QUANTUM_CONF: {
|
QUANTUM_CONF: {
|
||||||
'hook_contexts': [context.AMQPContext(ssl_dir=QUANTUM_CONF_DIR),
|
'hook_contexts': [context.AMQPContext(ssl_dir=QUANTUM_CONF_DIR),
|
||||||
QuantumGatewayContext(),
|
QuantumGatewayContext(),
|
||||||
SyslogContext()],
|
SyslogContext(),
|
||||||
|
context.ZeroMQContext()],
|
||||||
'services': ['quantum-l3-agent',
|
'services': ['quantum-l3-agent',
|
||||||
'quantum-dhcp-agent',
|
'quantum-dhcp-agent',
|
||||||
'quantum-metadata-agent',
|
'quantum-metadata-agent',
|
||||||
@ -532,3 +533,17 @@ def configure_ovs():
|
|||||||
ext_port_ctx = ExternalPortContext()()
|
ext_port_ctx = ExternalPortContext()()
|
||||||
if ext_port_ctx is not None and ext_port_ctx['ext_port']:
|
if ext_port_ctx is not None and ext_port_ctx['ext_port']:
|
||||||
add_bridge_port(EXT_BRIDGE, ext_port_ctx['ext_port'])
|
add_bridge_port(EXT_BRIDGE, ext_port_ctx['ext_port'])
|
||||||
|
|
||||||
|
|
||||||
|
def get_topics():
|
||||||
|
# metering_agent
|
||||||
|
topics = []
|
||||||
|
if 'neutron-l3-agent' in services():
|
||||||
|
topics.append('l3_agent')
|
||||||
|
if 'neutron-dhcp-agent' in services():
|
||||||
|
topics.append('dhcp_agent')
|
||||||
|
if 'neutron-metering-agent' in services():
|
||||||
|
topics.append('metering_agent')
|
||||||
|
if 'neutron-lbaas-agent' in services():
|
||||||
|
topics.append('n-lbaas_agent')
|
||||||
|
return topics
|
||||||
|
1
hooks/zeromq-configuration-relation-changed
Symbolic link
1
hooks/zeromq-configuration-relation-changed
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
quantum_hooks.py
|
1
hooks/zeromq-configuration-relation-joined
Symbolic link
1
hooks/zeromq-configuration-relation-joined
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
quantum_hooks.py
|
@ -27,6 +27,9 @@ requires:
|
|||||||
interface: rabbitmq
|
interface: rabbitmq
|
||||||
amqp-nova:
|
amqp-nova:
|
||||||
interface: rabbitmq
|
interface: rabbitmq
|
||||||
|
zeromq-configuration:
|
||||||
|
interface: zeromq-configuration
|
||||||
|
scope: container
|
||||||
peers:
|
peers:
|
||||||
cluster:
|
cluster:
|
||||||
interface: quantum-gateway-ha
|
interface: quantum-gateway-ha
|
||||||
|
@ -8,8 +8,9 @@ debug = {{ debug }}
|
|||||||
lock_path = /var/lock/neutron
|
lock_path = /var/lock/neutron
|
||||||
core_plugin = {{ core_plugin }}
|
core_plugin = {{ core_plugin }}
|
||||||
{% include "parts/rabbitmq" %}
|
{% include "parts/rabbitmq" %}
|
||||||
|
{% include "parts/zeromq" %}
|
||||||
control_exchange = neutron
|
control_exchange = neutron
|
||||||
notification_driver = neutron.openstack.common.notifier.list_notifier
|
notification_driver = neutron.openstack.common.notifier.list_notifier
|
||||||
list_notifier_drivers = neutron.openstack.common.notifier.rabbit_notifier
|
list_notifier_drivers = neutron.openstack.common.notifier.rabbit_notifier
|
||||||
[agent]
|
[agent]
|
||||||
root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf
|
root_helper = sudo /usr/bin/neutron-rootwrap /etc/neutron/rootwrap.conf
|
||||||
|
6
templates/parts/zeromq
Normal file
6
templates/parts/zeromq
Normal 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 -%}
|
Loading…
Reference in New Issue
Block a user