Add ha support
This commit is contained in:
parent
895d91474a
commit
d072f4e544
25
config.yaml
25
config.yaml
@ -59,4 +59,27 @@ options:
|
|||||||
ovs - OpenvSwitch Plugin
|
ovs - OpenvSwitch Plugin
|
||||||
nvp - Nicira Network Virtualization Platform
|
nvp - Nicira Network Virtualization Platform
|
||||||
.
|
.
|
||||||
|
# HA configuration settings
|
||||||
|
vip:
|
||||||
|
type: string
|
||||||
|
description: "Virtual IP to use to front API services in ha configuration"
|
||||||
|
vip_iface:
|
||||||
|
type: string
|
||||||
|
default: eth0
|
||||||
|
description: "Network Interface where to place the Virtual IP"
|
||||||
|
vip_cidr:
|
||||||
|
type: int
|
||||||
|
default: 24
|
||||||
|
description: "Netmask that will be used for the Virtual IP"
|
||||||
|
ha-bindiface:
|
||||||
|
type: string
|
||||||
|
default: eth0
|
||||||
|
description: |
|
||||||
|
Default network interface on which HA cluster will bind to communication
|
||||||
|
with the other members of the HA Cluster.
|
||||||
|
ha-mcastport:
|
||||||
|
type: int
|
||||||
|
default: 5404
|
||||||
|
description: |
|
||||||
|
Default multicast port number that will be used to communicate between
|
||||||
|
HA Cluster nodes.
|
||||||
|
@ -28,11 +28,19 @@ class HAIncompleteConfig(Exception):
|
|||||||
|
|
||||||
|
|
||||||
def is_clustered():
|
def is_clustered():
|
||||||
|
log('** LY ** In is_clustered')
|
||||||
|
if relation_ids('ha'):
|
||||||
|
log('** LY ** In is_clustered len(relation_ids(ha)):' + str(len(relation_ids('ha'))))
|
||||||
|
else:
|
||||||
|
log('** LY ** relation_ids(ha) is false')
|
||||||
for r_id in (relation_ids('ha') or []):
|
for r_id in (relation_ids('ha') or []):
|
||||||
|
log('** LY ** r_id: ' + str(r_id))
|
||||||
for unit in (relation_list(r_id) or []):
|
for unit in (relation_list(r_id) or []):
|
||||||
|
log('** LY ** unit: ' + str(unit))
|
||||||
clustered = relation_get('clustered',
|
clustered = relation_get('clustered',
|
||||||
rid=r_id,
|
rid=r_id,
|
||||||
unit=unit)
|
unit=unit)
|
||||||
|
log('** LY ** clustered: ' + str(clustered))
|
||||||
if clustered:
|
if clustered:
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
@ -56,18 +64,27 @@ def is_leader(resource):
|
|||||||
|
|
||||||
def peer_units():
|
def peer_units():
|
||||||
peers = []
|
peers = []
|
||||||
|
log('** LY ** In peer_units')
|
||||||
for r_id in (relation_ids('cluster') or []):
|
for r_id in (relation_ids('cluster') or []):
|
||||||
|
log('** LY ** In peer_units r_id:' + str(r_id))
|
||||||
for unit in (relation_list(r_id) or []):
|
for unit in (relation_list(r_id) or []):
|
||||||
|
log('** LY ** In peer_units unit:' + str(unit))
|
||||||
peers.append(unit)
|
peers.append(unit)
|
||||||
return peers
|
return peers
|
||||||
|
|
||||||
|
|
||||||
def oldest_peer(peers):
|
def oldest_peer(peers):
|
||||||
|
log('** LY ** In oldest_peer')
|
||||||
local_unit_no = int(os.getenv('JUJU_UNIT_NAME').split('/')[1])
|
local_unit_no = int(os.getenv('JUJU_UNIT_NAME').split('/')[1])
|
||||||
|
log('** LY ** In oldest_peer local_unit_no:' + str(local_unit_no))
|
||||||
for peer in peers:
|
for peer in peers:
|
||||||
remote_unit_no = int(peer.split('/')[1])
|
remote_unit_no = int(peer.split('/')[1])
|
||||||
|
log('** LY ** In oldest_peer remote_unit_no:' + str(remote_unit_no))
|
||||||
if remote_unit_no < local_unit_no:
|
if remote_unit_no < local_unit_no:
|
||||||
|
log('** LY ** In oldest_peer %s < %s:' % (str(remote_unit_no), str(local_unit_no)))
|
||||||
return False
|
return False
|
||||||
|
else:
|
||||||
|
log('** LY ** In oldest_peer %s >= %s:' % (str(remote_unit_no), str(local_unit_no)))
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
@ -173,11 +190,14 @@ def canonical_url(configs, vip_setting='vip'):
|
|||||||
:vip_setting: str: Setting in charm config that specifies
|
:vip_setting: str: Setting in charm config that specifies
|
||||||
VIP address.
|
VIP address.
|
||||||
'''
|
'''
|
||||||
|
log('** LY ** In canonical_url')
|
||||||
scheme = 'http'
|
scheme = 'http'
|
||||||
if 'https' in configs.complete_contexts():
|
if 'https' in configs.complete_contexts():
|
||||||
scheme = 'https'
|
scheme = 'https'
|
||||||
if is_clustered():
|
if is_clustered():
|
||||||
|
log('** LY ** is_clustered is true, returning vip')
|
||||||
addr = config_get(vip_setting)
|
addr = config_get(vip_setting)
|
||||||
else:
|
else:
|
||||||
|
log('** LY ** is_clustered is false, returning private-address')
|
||||||
addr = unit_get('private-address')
|
addr = unit_get('private-address')
|
||||||
return '%s://%s' % (scheme, addr)
|
return '%s://%s' % (scheme, addr)
|
||||||
|
1
hooks/cluster-relation-changed
Symbolic link
1
hooks/cluster-relation-changed
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
neutron_api_hooks.py
|
1
hooks/cluster-relation-departed
Symbolic link
1
hooks/cluster-relation-departed
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
neutron_api_hooks.py
|
1
hooks/ha-relation-changed
Symbolic link
1
hooks/ha-relation-changed
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
neutron_api_hooks.py
|
1
hooks/ha-relation-joined
Symbolic link
1
hooks/ha-relation-joined
Symbolic link
@ -0,0 +1 @@
|
|||||||
|
neutron_api_hooks.py
|
@ -44,10 +44,14 @@ from neutron_api_utils import (
|
|||||||
api_port,
|
api_port,
|
||||||
auth_token_config,
|
auth_token_config,
|
||||||
keystone_ca_cert_b64,
|
keystone_ca_cert_b64,
|
||||||
|
CLUSTER_RES,
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.contrib.hahelpers.cluster import (
|
from charmhelpers.contrib.hahelpers.cluster import (
|
||||||
canonical_url,
|
canonical_url,
|
||||||
|
eligible_leader,
|
||||||
|
get_hacluster_config,
|
||||||
|
is_leader,
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.payload.execd import execd_preinstall
|
from charmhelpers.payload.execd import execd_preinstall
|
||||||
@ -70,6 +74,8 @@ def install():
|
|||||||
def config_changed():
|
def config_changed():
|
||||||
global CONFIGS
|
global CONFIGS
|
||||||
CONFIGS.write_all()
|
CONFIGS.write_all()
|
||||||
|
for r_id in relation_ids('neutron-api'):
|
||||||
|
neutron_api_relation_joined(rid=r_id)
|
||||||
|
|
||||||
|
|
||||||
@hooks.hook('amqp-relation-joined')
|
@hooks.hook('amqp-relation-joined')
|
||||||
@ -203,9 +209,12 @@ def _get_keystone_info():
|
|||||||
|
|
||||||
@hooks.hook('neutron-api-relation-joined')
|
@hooks.hook('neutron-api-relation-joined')
|
||||||
def neutron_api_relation_joined(rid=None):
|
def neutron_api_relation_joined(rid=None):
|
||||||
|
log('** LY ** neutron_api_relation_joined')
|
||||||
manager = network_manager()
|
manager = network_manager()
|
||||||
base_url = canonical_url(CONFIGS)
|
base_url = canonical_url(CONFIGS)
|
||||||
|
log('** LY ** neutron_api_relation_joined base_url:' + base_url)
|
||||||
neutron_url = '%s:%s' % (base_url, api_port('neutron-server'))
|
neutron_url = '%s:%s' % (base_url, api_port('neutron-server'))
|
||||||
|
log('** LY ** neutron_api_relation_joined neutron_url:' + neutron_url)
|
||||||
relation_data = {
|
relation_data = {
|
||||||
'network_manager': manager,
|
'network_manager': manager,
|
||||||
'default_floating_pool': config('neutron-external-network'),
|
'default_floating_pool': config('neutron-external-network'),
|
||||||
@ -214,6 +223,7 @@ def neutron_api_relation_joined(rid=None):
|
|||||||
manager + '_url': neutron_url,
|
manager + '_url': neutron_url,
|
||||||
manager + '_security_groups': config('neutron-security-groups')
|
manager + '_security_groups': config('neutron-security-groups')
|
||||||
}
|
}
|
||||||
|
log('** LY ** neutron_api_relation_joined neutron_url (from relation_data):' + relation_data['neutron_url'])
|
||||||
keystone_info = _get_keystone_info()
|
keystone_info = _get_keystone_info()
|
||||||
if is_relation_made('identity-service') and keystone_info:
|
if is_relation_made('identity-service') and keystone_info:
|
||||||
relation_data.update({
|
relation_data.update({
|
||||||
@ -233,6 +243,59 @@ def neutron_api_relation_joined(rid=None):
|
|||||||
def neutron_api_relation_changed():
|
def neutron_api_relation_changed():
|
||||||
CONFIGS.write(NEUTRON_CONF)
|
CONFIGS.write(NEUTRON_CONF)
|
||||||
|
|
||||||
|
@hooks.hook('cluster-relation-changed',
|
||||||
|
'cluster-relation-departed')
|
||||||
|
@restart_on_change(restart_map(), stopstart=True)
|
||||||
|
def cluster_changed():
|
||||||
|
CONFIGS.write_all()
|
||||||
|
|
||||||
|
|
||||||
|
@hooks.hook('ha-relation-joined')
|
||||||
|
def ha_joined():
|
||||||
|
log('** LY ** IN HA JOINED')
|
||||||
|
config = get_hacluster_config()
|
||||||
|
resources = {
|
||||||
|
'res_neutron_vip': 'ocf:heartbeat:IPaddr2',
|
||||||
|
'res_neutron_haproxy': 'lsb:haproxy',
|
||||||
|
}
|
||||||
|
vip_params = 'params ip="%s" cidr_netmask="%s" nic="%s"' % \
|
||||||
|
(config['vip'], config['vip_cidr'], config['vip_iface'])
|
||||||
|
resource_params = {
|
||||||
|
'res_neutron_vip': vip_params,
|
||||||
|
'res_neutron_haproxy': 'op monitor interval="5s"'
|
||||||
|
}
|
||||||
|
init_services = {
|
||||||
|
'res_neutron_haproxy': 'haproxy'
|
||||||
|
}
|
||||||
|
clones = {
|
||||||
|
'cl_nova_haproxy': 'res_neutron_haproxy'
|
||||||
|
}
|
||||||
|
log('** LY ** HA JOINED ha-bindiface: '+ str(config['ha-bindiface']))
|
||||||
|
log('** LY ** HA JOINED ha-mcastport: '+ str(config['ha-mcastport']))
|
||||||
|
relation_set(init_services=init_services,
|
||||||
|
corosync_bindiface=config['ha-bindiface'],
|
||||||
|
corosync_mcastport=config['ha-mcastport'],
|
||||||
|
resources=resources,
|
||||||
|
resource_params=resource_params,
|
||||||
|
clones=clones)
|
||||||
|
|
||||||
|
|
||||||
|
@hooks.hook('ha-relation-changed')
|
||||||
|
def ha_changed():
|
||||||
|
clustered = relation_get('clustered')
|
||||||
|
if not clustered or clustered in [None, 'None', '']:
|
||||||
|
log('ha_changed: hacluster subordinate not fully clustered.')
|
||||||
|
return
|
||||||
|
if not is_leader(CLUSTER_RES):
|
||||||
|
log('ha_changed: hacluster complete but we are not leader.')
|
||||||
|
return
|
||||||
|
log('Cluster configured, notifying other services and updating '
|
||||||
|
'keystone endpoint configuration')
|
||||||
|
for rid in relation_ids('identity-service'):
|
||||||
|
identity_joined(rid=rid)
|
||||||
|
for rid in relation_ids('neutron-api'):
|
||||||
|
neutron_api_relation_joined(rid=rid)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
try:
|
try:
|
||||||
hooks.execute(sys.argv)
|
hooks.execute(sys.argv)
|
||||||
|
@ -19,7 +19,7 @@ import neutron_api_context
|
|||||||
|
|
||||||
TEMPLATES = 'templates/'
|
TEMPLATES = 'templates/'
|
||||||
|
|
||||||
CLUSTER_RES = 'res_nova_vip'
|
CLUSTER_RES = 'res_neutron_vip'
|
||||||
|
|
||||||
# removed from original: charm-helper-sh
|
# removed from original: charm-helper-sh
|
||||||
BASE_PACKAGES = [
|
BASE_PACKAGES = [
|
||||||
|
@ -21,3 +21,9 @@ requires:
|
|||||||
interface: rabbitmq
|
interface: rabbitmq
|
||||||
identity-service:
|
identity-service:
|
||||||
interface: keystone
|
interface: keystone
|
||||||
|
ha:
|
||||||
|
interface: hacluster
|
||||||
|
scope: container
|
||||||
|
peers:
|
||||||
|
cluster:
|
||||||
|
interface: neutron-api-ha
|
||||||
|
Loading…
Reference in New Issue
Block a user