[hopem,r=]
Adds IPv6 support for ceph osd.
This commit is contained in:
parent
2e92f9df6c
commit
86b1c30ef5
@ -103,3 +103,6 @@ options:
|
|||||||
description: |
|
description: |
|
||||||
The IP address and netmask of the cluster (back-side) network (e.g.,
|
The IP address and netmask of the cluster (back-side) network (e.g.,
|
||||||
192.168.0.0/24)
|
192.168.0.0/24)
|
||||||
|
prefer-ipv6:
|
||||||
|
type: boolean
|
||||||
|
default: False
|
@ -15,14 +15,17 @@ import sys
|
|||||||
import ceph
|
import ceph
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
log,
|
log,
|
||||||
|
WARNING,
|
||||||
ERROR,
|
ERROR,
|
||||||
config,
|
config,
|
||||||
relation_ids,
|
relation_ids,
|
||||||
related_units,
|
related_units,
|
||||||
relation_get,
|
relation_get,
|
||||||
|
relation_set,
|
||||||
Hooks,
|
Hooks,
|
||||||
UnregisteredHookError,
|
UnregisteredHookError,
|
||||||
service_name
|
service_name,
|
||||||
|
unit_get
|
||||||
)
|
)
|
||||||
from charmhelpers.core.host import (
|
from charmhelpers.core.host import (
|
||||||
umount,
|
umount,
|
||||||
@ -38,11 +41,14 @@ from charmhelpers.fetch import (
|
|||||||
|
|
||||||
from utils import (
|
from utils import (
|
||||||
render_template,
|
render_template,
|
||||||
get_host_ip,
|
setup_ipv6
|
||||||
)
|
)
|
||||||
|
|
||||||
from charmhelpers.contrib.openstack.alternatives import install_alternative
|
from charmhelpers.contrib.openstack.alternatives import install_alternative
|
||||||
from charmhelpers.contrib.network.ip import is_ipv6
|
from charmhelpers.contrib.network.ip import (
|
||||||
|
is_ipv6,
|
||||||
|
get_ipv6_addr
|
||||||
|
)
|
||||||
|
|
||||||
hooks = Hooks()
|
hooks = Hooks()
|
||||||
|
|
||||||
@ -58,6 +64,10 @@ def install_upstart_scripts():
|
|||||||
def install():
|
def install():
|
||||||
add_source(config('source'), config('key'))
|
add_source(config('source'), config('key'))
|
||||||
apt_update(fatal=True)
|
apt_update(fatal=True)
|
||||||
|
|
||||||
|
if config('prefer-ipv6'):
|
||||||
|
setup_ipv6()
|
||||||
|
|
||||||
apt_install(packages=ceph.PACKAGES, fatal=True)
|
apt_install(packages=ceph.PACKAGES, fatal=True)
|
||||||
install_upstart_scripts()
|
install_upstart_scripts()
|
||||||
|
|
||||||
@ -76,6 +86,14 @@ def emit_cephconf():
|
|||||||
'ceph_public_network': config('ceph-public-network'),
|
'ceph_public_network': config('ceph-public-network'),
|
||||||
'ceph_cluster_network': config('ceph-cluster-network'),
|
'ceph_cluster_network': config('ceph-cluster-network'),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if config('prefer-ipv6'):
|
||||||
|
host_ip = get_ipv6_addr()
|
||||||
|
if host_ip:
|
||||||
|
cephcontext['host_ip'] = host_ip
|
||||||
|
else:
|
||||||
|
log("Unable to obtain host address", level=WARNING)
|
||||||
|
|
||||||
# Install ceph.conf as an alternative to support
|
# Install ceph.conf as an alternative to support
|
||||||
# co-existence with other charms that write this file
|
# co-existence with other charms that write this file
|
||||||
charm_ceph_conf = "/var/lib/charm/{}/ceph.conf".format(service_name())
|
charm_ceph_conf = "/var/lib/charm/{}/ceph.conf".format(service_name())
|
||||||
@ -95,6 +113,9 @@ def config_changed():
|
|||||||
log('Invalid OSD disk format configuration specified', level=ERROR)
|
log('Invalid OSD disk format configuration specified', level=ERROR)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
if config('prefer-ipv6'):
|
||||||
|
setup_ipv6()
|
||||||
|
|
||||||
e_mountpoint = config('ephemeral-unmount')
|
e_mountpoint = config('ephemeral-unmount')
|
||||||
if (e_mountpoint and ceph.filesystem_mounted(e_mountpoint)):
|
if (e_mountpoint and ceph.filesystem_mounted(e_mountpoint)):
|
||||||
umount(e_mountpoint)
|
umount(e_mountpoint)
|
||||||
@ -120,8 +141,12 @@ def get_mon_hosts():
|
|||||||
hosts = []
|
hosts = []
|
||||||
for relid in relation_ids('mon'):
|
for relid in relation_ids('mon'):
|
||||||
for unit in related_units(relid):
|
for unit in related_units(relid):
|
||||||
addr = relation_get('ceph-public-address', unit, relid) or \
|
if config('prefer-ipv6'):
|
||||||
get_host_ip(relation_get('private-address', unit, relid))
|
addr = relation_get('ceph-public-address', unit, relid) or \
|
||||||
|
get_ipv6_addr()
|
||||||
|
else:
|
||||||
|
addr = relation_get('private-address', unit, relid)
|
||||||
|
|
||||||
if addr is not None:
|
if addr is not None:
|
||||||
if is_ipv6(addr):
|
if is_ipv6(addr):
|
||||||
hosts.append('[{}]:6789'.format(addr))
|
hosts.append('[{}]:6789'.format(addr))
|
||||||
@ -166,6 +191,17 @@ def get_devices():
|
|||||||
@hooks.hook('mon-relation-changed',
|
@hooks.hook('mon-relation-changed',
|
||||||
'mon-relation-departed')
|
'mon-relation-departed')
|
||||||
def mon_relation():
|
def mon_relation():
|
||||||
|
if config('prefer-ipv6'):
|
||||||
|
host = get_ipv6_addr()
|
||||||
|
else:
|
||||||
|
host = unit_get('private-address')
|
||||||
|
|
||||||
|
if host:
|
||||||
|
relation_data = {'private-address': host}
|
||||||
|
relation_set(**relation_data)
|
||||||
|
else:
|
||||||
|
log("Unable to obtain host address", level=WARNING)
|
||||||
|
|
||||||
bootstrap_key = relation_get('osd_bootstrap_key')
|
bootstrap_key = relation_get('osd_bootstrap_key')
|
||||||
if get_fsid() and get_auth() and bootstrap_key:
|
if get_fsid() and get_auth() and bootstrap_key:
|
||||||
log('mon has provided conf- scanning disks')
|
log('mon has provided conf- scanning disks')
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
import socket
|
import socket
|
||||||
import re
|
import re
|
||||||
from charmhelpers.core.hookenv import (
|
from charmhelpers.core.hookenv import (
|
||||||
unit_get,
|
|
||||||
cached
|
cached
|
||||||
)
|
)
|
||||||
from charmhelpers.fetch import (
|
from charmhelpers.fetch import (
|
||||||
@ -18,6 +17,10 @@ from charmhelpers.fetch import (
|
|||||||
filter_installed_packages
|
filter_installed_packages
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from charmhelpers.core.host import (
|
||||||
|
lsb_release
|
||||||
|
)
|
||||||
|
|
||||||
TEMPLATES_DIR = 'templates'
|
TEMPLATES_DIR = 'templates'
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@ -27,13 +30,6 @@ except ImportError:
|
|||||||
fatal=True)
|
fatal=True)
|
||||||
import jinja2
|
import jinja2
|
||||||
|
|
||||||
try:
|
|
||||||
import dns.resolver
|
|
||||||
except ImportError:
|
|
||||||
apt_install(filter_installed_packages(['python-dnspython']),
|
|
||||||
fatal=True)
|
|
||||||
import dns.resolver
|
|
||||||
|
|
||||||
|
|
||||||
def render_template(template_name, context, template_dir=TEMPLATES_DIR):
|
def render_template(template_name, context, template_dir=TEMPLATES_DIR):
|
||||||
templates = jinja2.Environment(
|
templates = jinja2.Environment(
|
||||||
@ -59,16 +55,8 @@ def get_unit_hostname():
|
|||||||
return socket.gethostname()
|
return socket.gethostname()
|
||||||
|
|
||||||
|
|
||||||
@cached
|
def setup_ipv6():
|
||||||
def get_host_ip(hostname=None):
|
ubuntu_rel = float(lsb_release()['DISTRIB_RELEASE'])
|
||||||
hostname = hostname or unit_get('private-address')
|
if ubuntu_rel < 14.04:
|
||||||
try:
|
raise Exception("IPv6 is not supported for Ubuntu "
|
||||||
# Test to see if already an IPv4 address
|
"versions less than Trusty 14.04")
|
||||||
socket.inet_aton(hostname)
|
|
||||||
return hostname
|
|
||||||
except socket.error:
|
|
||||||
# This may throw an NXDOMAIN exception; in which case
|
|
||||||
# things are badly broken so just let it kill the hook
|
|
||||||
answers = dns.resolver.query(hostname, 'A')
|
|
||||||
if answers:
|
|
||||||
return answers[0].address
|
|
||||||
|
@ -32,3 +32,6 @@
|
|||||||
osd journal size = {{ osd_journal_size }}
|
osd journal size = {{ osd_journal_size }}
|
||||||
filestore xattr use omap = true
|
filestore xattr use omap = true
|
||||||
|
|
||||||
|
host = {{ hostname }}
|
||||||
|
public addr = {{ host_ip }}
|
||||||
|
cluster addr = {{ host_ip }}
|
Loading…
Reference in New Issue
Block a user