Resync helpers for mysql changes

This commit is contained in:
James Page 2014-07-02 09:07:17 +01:00
parent d0b42f999c
commit 730b876845
5 changed files with 54 additions and 12 deletions

View File

@ -6,11 +6,15 @@ lint:
@charm proof
test:
@echo Starting tests...
@$(PYTHON) /usr/bin/nosetests --nologcapture unit_tests
@$(PYTHON) /usr/bin/nosetests --nologcapture --with-coverage unit_tests
sync:
@charm-helper-sync -c charm-helpers.yaml
bin/charm_helpers_sync.py:
@mkdir -p bin
@bzr cat lp:charm-helpers/tools/charm_helpers_sync/charm_helpers_sync.py \
> bin/charm_helpers_sync.py
sync: bin/charm_helpers_sync.py
@$(PYTHON) bin/charm_helpers_sync.py -c charm-helpers.yaml
publish: lint test
bzr push lp:charms/cinder

View File

@ -165,9 +165,4 @@ options:
192.168.0.0/24)
.
This network will be used for public endpoints.
database-network:
type: string
description: |
The IP address and netmask of the Database access network (e.g.,
192.168.0.0/24)

View File

@ -67,3 +67,29 @@ def get_address_in_network(network, fallback=None, fatal=False):
not_found_error_out()
return None
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

View File

@ -21,6 +21,7 @@ from charmhelpers.core.hookenv import (
relation_get,
relation_ids,
related_units,
relation_set,
unit_get,
unit_private_ip,
ERROR,
@ -42,6 +43,8 @@ from charmhelpers.contrib.openstack.neutron import (
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'
@ -134,8 +137,22 @@ class SharedDBContext(OSContextGenerator):
'Missing required charm config options. '
'(database name and user)')
raise OSContextError
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:
access_hostname = get_address_in_network(access_network,
unit_get('private-address'))
set_hostname = relation_get(attribute='hostname',
unit=local_unit())
if set_hostname != access_hostname:
relation_set(hostname=access_hostname)
return ctxt # Defer any further hook execution for now....
password_setting = 'password'
if self.relation_prefix:
password_setting = self.relation_prefix + '_password'

View File

@ -34,7 +34,8 @@ from charmhelpers.core.hookenv import (
service_name,
unit_get,
log,
ERROR
ERROR,
local_unit,
)
from charmhelpers.fetch import apt_install, apt_update
@ -106,8 +107,7 @@ def db_joined():
conf = config()
relation_set(database=conf['database'], username=conf['database-user'],
hostname=get_address_in_network(conf.get('database-network'),
unit_get('private-address')))
hostname=unit_get('private-address'))
@hooks.hook('pgsql-db-relation-joined')