[jamespage, r=gnuoy] Add suppport for os-data-network
This commit is contained in:
commit
02b115c3b5
17
.project
Normal file
17
.project
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<projectDescription>
|
||||||
|
<name>neutron-openvswitch</name>
|
||||||
|
<comment></comment>
|
||||||
|
<projects>
|
||||||
|
</projects>
|
||||||
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.python.pydev.PyDevBuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
|
</buildSpec>
|
||||||
|
<natures>
|
||||||
|
<nature>org.python.pydev.pythonNature</nature>
|
||||||
|
</natures>
|
||||||
|
</projectDescription>
|
9
.pydevproject
Normal file
9
.pydevproject
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||||
|
<?eclipse-pydev version="1.0"?><pydev_project>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_VERSION">python 2.7</pydev_property>
|
||||||
|
<pydev_property name="org.python.pydev.PYTHON_PROJECT_INTERPRETER">Default</pydev_property>
|
||||||
|
<pydev_pathproperty name="org.python.pydev.PROJECT_SOURCE_PATH">
|
||||||
|
<path>/neutron-openvswitch/hooks</path>
|
||||||
|
<path>/neutron-openvswitch/unit_tests</path>
|
||||||
|
</pydev_pathproperty>
|
||||||
|
</pydev_project>
|
@ -8,3 +8,4 @@ include:
|
|||||||
- contrib.network.ovs
|
- contrib.network.ovs
|
||||||
- contrib.storage.linux
|
- contrib.storage.linux
|
||||||
- payload.execd
|
- payload.execd
|
||||||
|
- contrib.network.ip
|
||||||
|
10
config.yaml
10
config.yaml
@ -26,3 +26,13 @@ options:
|
|||||||
description: |
|
description: |
|
||||||
The data port will be added to br-data and will allow usage of flat or VLAN
|
The data port will be added to br-data and will allow usage of flat or VLAN
|
||||||
network types
|
network types
|
||||||
|
# Network configuration options
|
||||||
|
# by default all access is over 'private-address'
|
||||||
|
os-data-network:
|
||||||
|
type: string
|
||||||
|
description: |
|
||||||
|
The IP address and netmask of the OpenStack Data network (e.g.,
|
||||||
|
192.168.0.0/24)
|
||||||
|
.
|
||||||
|
This network will be used for tenant network traffic in overlay
|
||||||
|
networks.
|
||||||
|
@ -146,12 +146,12 @@ def get_hacluster_config():
|
|||||||
Obtains all relevant configuration from charm configuration required
|
Obtains all relevant configuration from charm configuration required
|
||||||
for initiating a relation to hacluster:
|
for initiating a relation to hacluster:
|
||||||
|
|
||||||
ha-bindiface, ha-mcastport, vip, vip_iface, vip_cidr
|
ha-bindiface, ha-mcastport, vip
|
||||||
|
|
||||||
returns: dict: A dict containing settings keyed by setting name.
|
returns: dict: A dict containing settings keyed by setting name.
|
||||||
raises: HAIncompleteConfig if settings are missing.
|
raises: HAIncompleteConfig if settings are missing.
|
||||||
'''
|
'''
|
||||||
settings = ['ha-bindiface', 'ha-mcastport', 'vip', 'vip_iface', 'vip_cidr']
|
settings = ['ha-bindiface', 'ha-mcastport', 'vip']
|
||||||
conf = {}
|
conf = {}
|
||||||
for setting in settings:
|
for setting in settings:
|
||||||
conf[setting] = config_get(setting)
|
conf[setting] = config_get(setting)
|
||||||
|
156
hooks/charmhelpers/contrib/network/ip.py
Normal file
156
hooks/charmhelpers/contrib/network/ip.py
Normal file
@ -0,0 +1,156 @@
|
|||||||
|
import sys
|
||||||
|
|
||||||
|
from functools import partial
|
||||||
|
|
||||||
|
from charmhelpers.fetch import apt_install
|
||||||
|
from charmhelpers.core.hookenv import (
|
||||||
|
ERROR, log,
|
||||||
|
)
|
||||||
|
|
||||||
|
try:
|
||||||
|
import netifaces
|
||||||
|
except ImportError:
|
||||||
|
apt_install('python-netifaces')
|
||||||
|
import netifaces
|
||||||
|
|
||||||
|
try:
|
||||||
|
import netaddr
|
||||||
|
except ImportError:
|
||||||
|
apt_install('python-netaddr')
|
||||||
|
import netaddr
|
||||||
|
|
||||||
|
|
||||||
|
def _validate_cidr(network):
|
||||||
|
try:
|
||||||
|
netaddr.IPNetwork(network)
|
||||||
|
except (netaddr.core.AddrFormatError, ValueError):
|
||||||
|
raise ValueError("Network (%s) is not in CIDR presentation format" %
|
||||||
|
network)
|
||||||
|
|
||||||
|
|
||||||
|
def get_address_in_network(network, fallback=None, fatal=False):
|
||||||
|
"""
|
||||||
|
Get an IPv4 or IPv6 address within the network from the host.
|
||||||
|
|
||||||
|
:param network (str): CIDR presentation format. For example,
|
||||||
|
'192.168.1.0/24'.
|
||||||
|
:param fallback (str): If no address is found, return fallback.
|
||||||
|
:param fatal (boolean): If no address is found, fallback is not
|
||||||
|
set and fatal is True then exit(1).
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
def not_found_error_out():
|
||||||
|
log("No IP address found in network: %s" % network,
|
||||||
|
level=ERROR)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
|
if network is None:
|
||||||
|
if fallback is not None:
|
||||||
|
return fallback
|
||||||
|
else:
|
||||||
|
if fatal:
|
||||||
|
not_found_error_out()
|
||||||
|
|
||||||
|
_validate_cidr(network)
|
||||||
|
network = netaddr.IPNetwork(network)
|
||||||
|
for iface in netifaces.interfaces():
|
||||||
|
addresses = netifaces.ifaddresses(iface)
|
||||||
|
if network.version == 4 and netifaces.AF_INET in addresses:
|
||||||
|
addr = addresses[netifaces.AF_INET][0]['addr']
|
||||||
|
netmask = addresses[netifaces.AF_INET][0]['netmask']
|
||||||
|
cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask))
|
||||||
|
if cidr in network:
|
||||||
|
return str(cidr.ip)
|
||||||
|
if network.version == 6 and netifaces.AF_INET6 in addresses:
|
||||||
|
for addr in addresses[netifaces.AF_INET6]:
|
||||||
|
if not addr['addr'].startswith('fe80'):
|
||||||
|
cidr = netaddr.IPNetwork("%s/%s" % (addr['addr'],
|
||||||
|
addr['netmask']))
|
||||||
|
if cidr in network:
|
||||||
|
return str(cidr.ip)
|
||||||
|
|
||||||
|
if fallback is not None:
|
||||||
|
return fallback
|
||||||
|
|
||||||
|
if fatal:
|
||||||
|
not_found_error_out()
|
||||||
|
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
def is_ipv6(address):
|
||||||
|
'''Determine whether provided address is IPv6 or not'''
|
||||||
|
try:
|
||||||
|
address = netaddr.IPAddress(address)
|
||||||
|
except netaddr.AddrFormatError:
|
||||||
|
# probably a hostname - so not an address at all!
|
||||||
|
return False
|
||||||
|
else:
|
||||||
|
return address.version == 6
|
||||||
|
|
||||||
|
|
||||||
|
def is_address_in_network(network, address):
|
||||||
|
"""
|
||||||
|
Determine whether the provided address is within a network range.
|
||||||
|
|
||||||
|
:param network (str): CIDR presentation format. For example,
|
||||||
|
'192.168.1.0/24'.
|
||||||
|
:param address: An individual IPv4 or IPv6 address without a net
|
||||||
|
mask or subnet prefix. For example, '192.168.1.1'.
|
||||||
|
:returns boolean: Flag indicating whether address is in network.
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
network = netaddr.IPNetwork(network)
|
||||||
|
except (netaddr.core.AddrFormatError, ValueError):
|
||||||
|
raise ValueError("Network (%s) is not in CIDR presentation format" %
|
||||||
|
network)
|
||||||
|
try:
|
||||||
|
address = netaddr.IPAddress(address)
|
||||||
|
except (netaddr.core.AddrFormatError, ValueError):
|
||||||
|
raise ValueError("Address (%s) is not in correct presentation format" %
|
||||||
|
address)
|
||||||
|
if address in network:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def _get_for_address(address, key):
|
||||||
|
"""Retrieve an attribute of or the physical interface that
|
||||||
|
the IP address provided could be bound to.
|
||||||
|
|
||||||
|
:param address (str): An individual IPv4 or IPv6 address without a net
|
||||||
|
mask or subnet prefix. For example, '192.168.1.1'.
|
||||||
|
:param key: 'iface' for the physical interface name or an attribute
|
||||||
|
of the configured interface, for example 'netmask'.
|
||||||
|
:returns str: Requested attribute or None if address is not bindable.
|
||||||
|
"""
|
||||||
|
address = netaddr.IPAddress(address)
|
||||||
|
for iface in netifaces.interfaces():
|
||||||
|
addresses = netifaces.ifaddresses(iface)
|
||||||
|
if address.version == 4 and netifaces.AF_INET in addresses:
|
||||||
|
addr = addresses[netifaces.AF_INET][0]['addr']
|
||||||
|
netmask = addresses[netifaces.AF_INET][0]['netmask']
|
||||||
|
cidr = netaddr.IPNetwork("%s/%s" % (addr, netmask))
|
||||||
|
if address in cidr:
|
||||||
|
if key == 'iface':
|
||||||
|
return iface
|
||||||
|
else:
|
||||||
|
return addresses[netifaces.AF_INET][0][key]
|
||||||
|
if address.version == 6 and netifaces.AF_INET6 in addresses:
|
||||||
|
for addr in addresses[netifaces.AF_INET6]:
|
||||||
|
if not addr['addr'].startswith('fe80'):
|
||||||
|
cidr = netaddr.IPNetwork("%s/%s" % (addr['addr'],
|
||||||
|
addr['netmask']))
|
||||||
|
if address in cidr:
|
||||||
|
if key == 'iface':
|
||||||
|
return iface
|
||||||
|
else:
|
||||||
|
return addr[key]
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
|
get_iface_for_address = partial(_get_for_address, key='iface')
|
||||||
|
|
||||||
|
get_netmask_for_address = partial(_get_for_address, key='netmask')
|
@ -21,6 +21,7 @@ from charmhelpers.core.hookenv import (
|
|||||||
relation_get,
|
relation_get,
|
||||||
relation_ids,
|
relation_ids,
|
||||||
related_units,
|
related_units,
|
||||||
|
relation_set,
|
||||||
unit_get,
|
unit_get,
|
||||||
unit_private_ip,
|
unit_private_ip,
|
||||||
ERROR,
|
ERROR,
|
||||||
@ -43,6 +44,8 @@ from charmhelpers.contrib.openstack.neutron import (
|
|||||||
neutron_plugin_attribute,
|
neutron_plugin_attribute,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
from charmhelpers.contrib.network.ip import get_address_in_network
|
||||||
|
|
||||||
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
|
CA_CERT_PATH = '/usr/local/share/ca-certificates/keystone_juju_ca_cert.crt'
|
||||||
|
|
||||||
|
|
||||||
@ -135,8 +138,26 @@ class SharedDBContext(OSContextGenerator):
|
|||||||
'Missing required charm config options. '
|
'Missing required charm config options. '
|
||||||
'(database name and user)')
|
'(database name and user)')
|
||||||
raise OSContextError
|
raise OSContextError
|
||||||
|
|
||||||
ctxt = {}
|
ctxt = {}
|
||||||
|
|
||||||
|
# NOTE(jamespage) if mysql charm provides a network upon which
|
||||||
|
# access to the database should be made, reconfigure relation
|
||||||
|
# with the service units local address and defer execution
|
||||||
|
access_network = relation_get('access-network')
|
||||||
|
if access_network is not None:
|
||||||
|
if self.relation_prefix is not None:
|
||||||
|
hostname_key = "{}_hostname".format(self.relation_prefix)
|
||||||
|
else:
|
||||||
|
hostname_key = "hostname"
|
||||||
|
access_hostname = get_address_in_network(access_network,
|
||||||
|
unit_get('private-address'))
|
||||||
|
set_hostname = relation_get(attribute=hostname_key,
|
||||||
|
unit=local_unit())
|
||||||
|
if set_hostname != access_hostname:
|
||||||
|
relation_set(relation_settings={hostname_key: access_hostname})
|
||||||
|
return ctxt # Defer any further hook execution for now....
|
||||||
|
|
||||||
password_setting = 'password'
|
password_setting = 'password'
|
||||||
if self.relation_prefix:
|
if self.relation_prefix:
|
||||||
password_setting = self.relation_prefix + '_password'
|
password_setting = self.relation_prefix + '_password'
|
||||||
@ -341,10 +362,12 @@ class CephContext(OSContextGenerator):
|
|||||||
use_syslog = str(config('use-syslog')).lower()
|
use_syslog = str(config('use-syslog')).lower()
|
||||||
for rid in relation_ids('ceph'):
|
for rid in relation_ids('ceph'):
|
||||||
for unit in related_units(rid):
|
for unit in related_units(rid):
|
||||||
mon_hosts.append(relation_get('private-address', rid=rid,
|
|
||||||
unit=unit))
|
|
||||||
auth = relation_get('auth', rid=rid, unit=unit)
|
auth = relation_get('auth', rid=rid, unit=unit)
|
||||||
key = relation_get('key', rid=rid, unit=unit)
|
key = relation_get('key', rid=rid, unit=unit)
|
||||||
|
ceph_addr = \
|
||||||
|
relation_get('ceph-public-address', rid=rid, unit=unit) or \
|
||||||
|
relation_get('private-address', rid=rid, unit=unit)
|
||||||
|
mon_hosts.append(ceph_addr)
|
||||||
|
|
||||||
ctxt = {
|
ctxt = {
|
||||||
'mon_hosts': ' '.join(mon_hosts),
|
'mon_hosts': ' '.join(mon_hosts),
|
||||||
@ -378,7 +401,9 @@ class HAProxyContext(OSContextGenerator):
|
|||||||
|
|
||||||
cluster_hosts = {}
|
cluster_hosts = {}
|
||||||
l_unit = local_unit().replace('/', '-')
|
l_unit = local_unit().replace('/', '-')
|
||||||
cluster_hosts[l_unit] = unit_get('private-address')
|
cluster_hosts[l_unit] = \
|
||||||
|
get_address_in_network(config('os-internal-network'),
|
||||||
|
unit_get('private-address'))
|
||||||
|
|
||||||
for rid in relation_ids('cluster'):
|
for rid in relation_ids('cluster'):
|
||||||
for unit in related_units(rid):
|
for unit in related_units(rid):
|
||||||
|
75
hooks/charmhelpers/contrib/openstack/ip.py
Normal file
75
hooks/charmhelpers/contrib/openstack/ip.py
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
from charmhelpers.core.hookenv import (
|
||||||
|
config,
|
||||||
|
unit_get,
|
||||||
|
)
|
||||||
|
|
||||||
|
from charmhelpers.contrib.network.ip import (
|
||||||
|
get_address_in_network,
|
||||||
|
is_address_in_network,
|
||||||
|
is_ipv6,
|
||||||
|
)
|
||||||
|
|
||||||
|
from charmhelpers.contrib.hahelpers.cluster import is_clustered
|
||||||
|
|
||||||
|
PUBLIC = 'public'
|
||||||
|
INTERNAL = 'int'
|
||||||
|
ADMIN = 'admin'
|
||||||
|
|
||||||
|
_address_map = {
|
||||||
|
PUBLIC: {
|
||||||
|
'config': 'os-public-network',
|
||||||
|
'fallback': 'public-address'
|
||||||
|
},
|
||||||
|
INTERNAL: {
|
||||||
|
'config': 'os-internal-network',
|
||||||
|
'fallback': 'private-address'
|
||||||
|
},
|
||||||
|
ADMIN: {
|
||||||
|
'config': 'os-admin-network',
|
||||||
|
'fallback': 'private-address'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def canonical_url(configs, endpoint_type=PUBLIC):
|
||||||
|
'''
|
||||||
|
Returns the correct HTTP URL to this host given the state of HTTPS
|
||||||
|
configuration, hacluster and charm configuration.
|
||||||
|
|
||||||
|
:configs OSTemplateRenderer: A config tempating object to inspect for
|
||||||
|
a complete https context.
|
||||||
|
:endpoint_type str: The endpoint type to resolve.
|
||||||
|
|
||||||
|
:returns str: Base URL for services on the current service unit.
|
||||||
|
'''
|
||||||
|
scheme = 'http'
|
||||||
|
if 'https' in configs.complete_contexts():
|
||||||
|
scheme = 'https'
|
||||||
|
address = resolve_address(endpoint_type)
|
||||||
|
if is_ipv6(address):
|
||||||
|
address = "[{}]".format(address)
|
||||||
|
return '%s://%s' % (scheme, address)
|
||||||
|
|
||||||
|
|
||||||
|
def resolve_address(endpoint_type=PUBLIC):
|
||||||
|
resolved_address = None
|
||||||
|
if is_clustered():
|
||||||
|
if config(_address_map[endpoint_type]['config']) is None:
|
||||||
|
# Assume vip is simple and pass back directly
|
||||||
|
resolved_address = config('vip')
|
||||||
|
else:
|
||||||
|
for vip in config('vip').split():
|
||||||
|
if is_address_in_network(
|
||||||
|
config(_address_map[endpoint_type]['config']),
|
||||||
|
vip):
|
||||||
|
resolved_address = vip
|
||||||
|
else:
|
||||||
|
resolved_address = get_address_in_network(
|
||||||
|
config(_address_map[endpoint_type]['config']),
|
||||||
|
unit_get(_address_map[endpoint_type]['fallback'])
|
||||||
|
)
|
||||||
|
if resolved_address is None:
|
||||||
|
raise ValueError('Unable to resolve a suitable IP address'
|
||||||
|
' based on charm state and configuration')
|
||||||
|
else:
|
||||||
|
return resolved_address
|
@ -27,7 +27,12 @@ listen stats :8888
|
|||||||
|
|
||||||
{% if units -%}
|
{% if units -%}
|
||||||
{% for service, ports in service_ports.iteritems() -%}
|
{% for service, ports in service_ports.iteritems() -%}
|
||||||
listen {{ service }} 0.0.0.0:{{ ports[0] }}
|
listen {{ service }}_ipv4 0.0.0.0:{{ ports[0] }}
|
||||||
|
balance roundrobin
|
||||||
|
{% for unit, address in units.iteritems() -%}
|
||||||
|
server {{ unit }} {{ address }}:{{ ports[1] }} check
|
||||||
|
{% endfor %}
|
||||||
|
listen {{ service }}_ipv6 :::{{ ports[0] }}
|
||||||
balance roundrobin
|
balance roundrobin
|
||||||
{% for unit, address in units.iteritems() -%}
|
{% for unit, address in units.iteritems() -%}
|
||||||
server {{ unit }} {{ address }}:{{ ports[1] }} check
|
server {{ unit }} {{ address }}:{{ ports[1] }} check
|
||||||
|
@ -322,6 +322,10 @@ def cmp_pkgrevno(package, revno, pkgcache=None):
|
|||||||
import apt_pkg
|
import apt_pkg
|
||||||
if not pkgcache:
|
if not pkgcache:
|
||||||
apt_pkg.init()
|
apt_pkg.init()
|
||||||
|
# Force Apt to build its cache in memory. That way we avoid race
|
||||||
|
# conditions with other applications building the cache in the same
|
||||||
|
# place.
|
||||||
|
apt_pkg.config.set("Dir::Cache::pkgcache", "")
|
||||||
pkgcache = apt_pkg.Cache()
|
pkgcache = apt_pkg.Cache()
|
||||||
pkg = pkgcache[package]
|
pkg = pkgcache[package]
|
||||||
return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
|
return apt_pkg.version_compare(pkg.current_ver.ver_str, revno)
|
||||||
|
@ -10,6 +10,7 @@ from charmhelpers.contrib.openstack import context
|
|||||||
from charmhelpers.core.host import service_running, service_start
|
from charmhelpers.core.host import service_running, service_start
|
||||||
from charmhelpers.contrib.network.ovs import add_bridge, add_bridge_port
|
from charmhelpers.contrib.network.ovs import add_bridge, add_bridge_port
|
||||||
from charmhelpers.contrib.openstack.utils import get_host_ip
|
from charmhelpers.contrib.openstack.utils import get_host_ip
|
||||||
|
from charmhelpers.contrib.network.ip import get_address_in_network
|
||||||
|
|
||||||
import re
|
import re
|
||||||
|
|
||||||
@ -84,7 +85,9 @@ class OVSPluginContext(context.NeutronContext):
|
|||||||
self._ensure_bridge()
|
self._ensure_bridge()
|
||||||
|
|
||||||
conf = config()
|
conf = config()
|
||||||
ovs_ctxt['local_ip'] = get_host_ip(unit_get('private-address'))
|
ovs_ctxt['local_ip'] = \
|
||||||
|
get_address_in_network(config('os-data-network'),
|
||||||
|
get_host_ip(unit_get('private-address')))
|
||||||
ovs_ctxt['neutron_security_groups'] = self.neutron_security_groups
|
ovs_ctxt['neutron_security_groups'] = self.neutron_security_groups
|
||||||
# TODO: We need to sort out the syslog and debug/verbose options as a
|
# TODO: We need to sort out the syslog and debug/verbose options as a
|
||||||
# general context helper
|
# general context helper
|
||||||
|
Loading…
x
Reference in New Issue
Block a user