Merge "Sync charm-helpers"

This commit is contained in:
Zuul 2019-01-09 08:46:27 +00:00 committed by Gerrit Code Review
commit c2dab944ce
2 changed files with 35 additions and 19 deletions

View File

@ -305,7 +305,7 @@ class NRPE(object):
# update-status hooks are configured to firing every 5 minutes by # update-status hooks are configured to firing every 5 minutes by
# default. When nagios-nrpe-server is restarted, the nagios server # default. When nagios-nrpe-server is restarted, the nagios server
# reports checks failing causing unneccessary alerts. Let's not restart # reports checks failing causing unnecessary alerts. Let's not restart
# on update-status hooks. # on update-status hooks.
if not hook_name() == 'update-status': if not hook_name() == 'update-status':
service('restart', 'nagios-nrpe-server') service('restart', 'nagios-nrpe-server')

View File

@ -250,6 +250,27 @@ def update_hacluster_dns_ha(service, relation_data,
raise DNSHAException(msg) raise DNSHAException(msg)
def get_vip_settings(vip):
"""Calculate which nic is on the correct network for the given vip.
If nic or netmask discovery fail then fallback to using charm supplied
config. If fallback is used this is indicated via the fallback variable.
@param vip: VIP to lookup nic and cidr for.
@returns (str, str, bool): eg (iface, netmask, fallback)
"""
iface = get_iface_for_address(vip)
netmask = get_netmask_for_address(vip)
fallback = False
if iface is None:
iface = config('vip_iface')
fallback = True
if netmask is None:
netmask = config('vip_cidr')
fallback = True
return iface, netmask, fallback
def update_hacluster_vip(service, relation_data): def update_hacluster_vip(service, relation_data):
""" Configure VIP resources based on provided configuration """ Configure VIP resources based on provided configuration
@ -267,17 +288,9 @@ def update_hacluster_vip(service, relation_data):
res_vip = 'ocf:heartbeat:IPaddr2' res_vip = 'ocf:heartbeat:IPaddr2'
vip_params = 'ip' vip_params = 'ip'
iface = get_iface_for_address(vip) iface, netmask, fallback = get_vip_settings(vip)
netmask = get_netmask_for_address(vip)
fallback_params = False
if iface is None:
iface = config('vip_iface')
fallback_params = True
if netmask is None:
netmask = config('vip_cidr')
fallback_params = True
vip_monitoring = 'op monitor depth="0" timeout="20s" interval="10s"'
if iface is not None: if iface is not None:
# NOTE(jamespage): Delete old VIP resources # NOTE(jamespage): Delete old VIP resources
# Old style naming encoding iface in name # Old style naming encoding iface in name
@ -296,14 +309,15 @@ def update_hacluster_vip(service, relation_data):
# NOTE(jamespage): # NOTE(jamespage):
# Use option provided vip params if these where used # Use option provided vip params if these where used
# instead of auto-detected values # instead of auto-detected values
if fallback_params: if fallback:
relation_data['resource_params'][vip_key] = ( relation_data['resource_params'][vip_key] = (
'params {ip}="{vip}" cidr_netmask="{netmask}" ' 'params {ip}="{vip}" cidr_netmask="{netmask}" '
'nic="{iface}"'.format(ip=vip_params, 'nic="{iface}" {vip_monitoring}'.format(
vip=vip, ip=vip_params,
iface=iface, vip=vip,
netmask=netmask) iface=iface,
) netmask=netmask,
vip_monitoring=vip_monitoring))
else: else:
# NOTE(jamespage): # NOTE(jamespage):
# let heartbeat figure out which interface and # let heartbeat figure out which interface and
@ -311,8 +325,10 @@ def update_hacluster_vip(service, relation_data):
# when network interface naming is not # when network interface naming is not
# consistent across units. # consistent across units.
relation_data['resource_params'][vip_key] = ( relation_data['resource_params'][vip_key] = (
'params {ip}="{vip}"'.format(ip=vip_params, 'params {ip}="{vip}" {vip_monitoring}'.format(
vip=vip)) ip=vip_params,
vip=vip,
vip_monitoring=vip_monitoring))
vip_group.append(vip_key) vip_group.append(vip_key)