Add config option netmtu for corosync, refactor code.

This commit is contained in:
Hui Xiang 2014-09-28 09:28:13 +08:00
parent 91fc1c909c
commit f29527cc81
4 changed files with 21 additions and 19 deletions

View File

@ -48,6 +48,10 @@ options:
description: |
Time period between checks of resource health. It consists of a number
and a time factor, e.g. 5s = 5 seconds. 2m = 2 minutes.
netmtu:
type: int
default: 1500
description: MTU size corosync used for communication.
prefer-ipv6:
type: boolean
default: False

View File

@ -14,6 +14,7 @@ import fcntl
import struct
from charmhelpers.fetch import apt_install
from charmhelpers.contrib.network import ip as utils
try:
from netaddr import IPNetwork
@ -90,25 +91,17 @@ def get_ipv6_addr(iface="eth0"):
apt_install('python-netifaces')
import netifaces
iface = str(iface)
iface_addrs = netifaces.ifaddresses(iface)
if netifaces.AF_INET6 not in iface_addrs:
raise Exception("Interface '%s' doesn't have an ipv6 address."
% iface)
ipv6_address = utils.get_ipv6_addr(iface)[0]
ifa_addrs = netifaces.ifaddresses(iface)
addresses = netifaces.ifaddresses(iface)[netifaces.AF_INET6]
ipv6_address = [a for a in addresses
if not a['addr'].startswith('fe80')][0]
if not ipv6_address:
raise Exception("Interface '%s' doesn't have global ipv6 address."
% iface)
ipv6_addr = ipv6_address['addr']
ipv6_netmask = ipv6_address['netmask']
network = "{}/{}".format(ipv6_addr, ipv6_netmask)
ip = IPNetwork(network)
return str(ip.network)
for ifaddr in ifa_addrs[netifaces.AF_INET6]:
if ipv6_address == ifaddr['addr']:
network = "{}/{}".format(ifaddr['addr'],
ifaddr['netmask'])
ip = IPNetwork(network)
return str(ip.network)
except ValueError:
raise Exception("Invalid interface '%s'" % iface)
raise Exception("No valid network found in interface '%s'" % iface)

View File

@ -92,8 +92,9 @@ def get_corosync_conf():
if config('prefer-ipv6'):
local_unit_no = int(local_unit().split('/')[1])
# nodeid can't be 0
# nodeid should not be 0
conf['nodeid'] = local_unit_no + 1
conf['netmtu'] = config('netmtu')
if None not in conf.itervalues():
return conf

View File

@ -40,6 +40,10 @@ totem {
{% if ip_version %}
ip_version: {{ ip_version }}
{% endif %}
{% if netmtu %}
netmtu: {{ netmtu }}
{% endif %}
# This specifies the mode of redundant ring, which may be none, active, or passive.
rrp_mode: none