Support etcd-peer-relation

This commit is contained in:
Cory Benfield 2015-04-16 11:42:32 +01:00
parent 459ccf5db5
commit af1b04bcd2
8 changed files with 63 additions and 4 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -143,3 +143,28 @@ class HAProxyContext(context.HAProxyContext):
# for haproxy.conf
ctxt['service_ports'] = port_mapping
return ctxt
class EtcdContext(context.OSContextGenerator):
interfaces = ['etcd-peer']
def __call__(self):
ctxt = {
'peers': [],
'cluster_token': '',
}
if not config('neutron-plugin') == 'Calico':
return ctxt
for rid in relation_ids('etcd-peer'):
for unit in related_units(rid):
rdata = relation_get(rid=rid, unit=unit)
ctxt['cluster_token'] = rdata.get('initial_cluster_token')
ctxt['peers'].append({
'ip': rdata.get('ip'),
'port': rdata.get('port'),
'name': rdata.get('name'),
})
return ctxt

View File

@ -44,11 +44,13 @@ from neutron_api_utils import (
restart_map,
services,
setup_ipv6,
additional_install_locations
additional_install_locations,
force_etcd_restart,
)
from neutron_api_context import (
get_l2population,
get_overlay_network_type,
EtcdContext,
)
from charmhelpers.contrib.hahelpers.cluster import (
@ -403,6 +405,18 @@ def calico_network_api_joined(rid=None):
relation_set(relation_id=rid, **relation_data)
@hooks.hook('etcd-peer-relation-joined')
@hooks.hook('etcd-peer-relation-changed')
def etcd_peer_force_restart(relation_id=None):
# note(cory.benfield): Mostly etcd does not require active management,
# but occasionally it does require a full config nuking. This does not
# play well with the standard neutron-api config management, so we
# treat etcd like the special snowflake it insists on being.
CONFIGS.register('/etc/init/etcd.conf', [EtcdContext()])
CONFIGS.write('/etc/init/etcd.conf')
force_etcd_restart()
def main():
try:
hooks.execute(sys.argv)

View File

@ -1,6 +1,8 @@
from collections import OrderedDict
from copy import deepcopy
import os
import shutil
import glob
from base64 import b64encode
from charmhelpers.contrib.openstack import context, templating
from charmhelpers.contrib.openstack.neutron import (
@ -26,7 +28,9 @@ from charmhelpers.fetch import (
)
from charmhelpers.core.host import (
lsb_release
lsb_release,
service_stop,
service_start,
)
import neutron_api_context
@ -125,6 +129,18 @@ def additional_install_locations(plugin):
apt_upgrade()
def force_etcd_restart():
'''
If etcd has been reconfigured we need to force it to fully restart.
This is necessary because etcd has some config flags that it ignores
after the first time it starts, so we need to make it forget them.
'''
service_stop('etcd')
for directory in glob.glob('/var/lib/etcd/*'):
shutil.rmtree(directory)
service_start('etcd')
def determine_packages(source=None):
# currently all packages match service names
packages = [] + BASE_PACKAGES

View File

@ -22,8 +22,6 @@ provides:
interface: neutron-api
neutron-plugin-api:
interface: neutron-plugin-api
calico-network-api:
interface: calico-network-api
requires:
shared-db:
interface: mysql-shared
@ -36,6 +34,8 @@ requires:
ha:
interface: hacluster
scope: container
etcd-peer:
interface: http
peers:
cluster:
interface: neutron-api-ha