added postgresql support

This commit is contained in:
yolanda.robla@canonical.com 2014-03-20 11:18:23 +01:00
parent 70e61d50fd
commit 499930bcd8
14 changed files with 110 additions and 3 deletions

View File

@ -152,6 +152,35 @@ class SharedDBContext(OSContextGenerator):
return {} return {}
class PostgresqlDBContext(OSContextGenerator):
interfaces = ['pgsql-db']
def __init__(self, database=None):
self.database = database
def __call__(self):
self.database = self.database or config('database')
if self.database is None:
log('Could not generate shared_db context. '
'Missing required charm config options. '
'(database name)')
raise OSContextError
ctxt = {}
for rid in relation_ids(self.interfaces[0]):
for unit in related_units(rid):
ctxt = {
'database_host': relation_get('host', rid=rid, unit=unit),
'database': self.database,
'database_user': relation_get('user', rid=rid, unit=unit),
'database_password': relation_get('password', rid=rid, unit=unit),
'database_type': 'postgresql',
}
if context_complete(ctxt):
return ctxt
return {}
class IdentityServiceContext(OSContextGenerator): class IdentityServiceContext(OSContextGenerator):
interfaces = ['identity-service'] interfaces = ['identity-service']

View File

@ -22,4 +22,5 @@ def zap_disk(block_device):
:param block_device: str: Full path of block device to clean. :param block_device: str: Full path of block device to clean.
''' '''
check_call(['sgdisk', '--zap-all', '--mbrtogpt', block_device]) check_call(['sgdisk', '--zap-all', '--clear',
'--mbrtogpt', block_device])

View File

@ -135,6 +135,10 @@ def apt_hold(packages, fatal=False):
def add_source(source, key=None): def add_source(source, key=None):
if source is None:
log('Source is not present. Skipping')
return
if (source.startswith('ppa:') or if (source.startswith('ppa:') or
source.startswith('http') or source.startswith('http') or
source.startswith('deb ') or source.startswith('deb ') or

View File

@ -174,3 +174,9 @@ class SharedDBContext(context.SharedDBContext):
ctxt['database_type'] = 'mysql' ctxt['database_type'] = 'mysql'
return ctxt return ctxt
class NovaPostgresqlDBContext(context.PostgresqlDBContext):
interfaces = ['pgsql-nova-db']
class NeutronPostgresqlDBContext(context.PostgresqlDBContext):
interfaces = ['pgsql-neutron-db']

View File

@ -13,6 +13,7 @@ from charmhelpers.core.hookenv import (
UnregisteredHookError, UnregisteredHookError,
config, config,
charm_dir, charm_dir,
is_relation_made,
log, log,
relation_get, relation_get,
relation_ids, relation_ids,
@ -29,6 +30,8 @@ from charmhelpers.fetch import (
apt_install, apt_update apt_install, apt_update
) )
from charmhelpers.contrib.openstack import context
from charmhelpers.contrib.openstack.utils import ( from charmhelpers.contrib.openstack.utils import (
configure_installation_source, configure_installation_source,
openstack_upgrade_available, openstack_upgrade_available,
@ -124,6 +127,12 @@ def amqp_changed():
@hooks.hook('shared-db-relation-joined') @hooks.hook('shared-db-relation-joined')
def db_joined(): def db_joined():
if is_relation_made('pgsql-nova-db') or is_relation_made('pgsql-neutron-db'):
# error, postgresql is used
e = ('Attempting to associate a mysql database when there is already '
'associated a postgresql one')
raise context.OSContextError(e)
relation_set(nova_database=config('database'), relation_set(nova_database=config('database'),
nova_username=config('database-user'), nova_username=config('database-user'),
nova_hostname=unit_get('private-address')) nova_hostname=unit_get('private-address'))
@ -134,6 +143,28 @@ def db_joined():
neutron_hostname=unit_get('private-address')) neutron_hostname=unit_get('private-address'))
@hooks.hook('pgsql-nova-db-relation-joined')
def pgsql_nova_db_joined():
if is_relation_made('shared-db'):
# raise error
e = ('Attempting to associate a postgresql database when there is already '
'associated a mysql one')
raise context.OSContextError(e)
relation_set(database=config('database')),
@hooks.hook('pgsql-neutron-db-relation-joined')
def pgsql_neutron_db_joined():
if is_relation_made('shared-db'):
# raise error
e = ('Attempting to associate a postgresql database when there is already '
'associated a mysql one')
raise context.OSContextError(e)
relation_set(database=config('neutron-database')),
@hooks.hook('shared-db-relation-changed') @hooks.hook('shared-db-relation-changed')
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def db_changed(): def db_changed():
@ -154,6 +185,28 @@ def db_changed():
for rid in relation_ids('cloud-compute')] for rid in relation_ids('cloud-compute')]
@hooks.hook('pgsql-nova-db-relation-changed')
@hooks.hook('pgsql-neutron-db-relation-changed')
@restart_on_change(restart_map())
def db_changed():
if 'pgsql-nova-db' not in CONFIGS.complete_contexts() or \
'pgsql-neutron-db' not in CONFIGS.complete_contexts():
log('pgsql-*-db relation incomplete. Peer not ready?')
return
CONFIGS.write(NOVA_CONF)
if network_manager() in ['neutron', 'quantum']:
plugin = neutron_plugin()
# DB config might have been moved to main neutron.conf in H?
CONFIGS.write(neutron_plugin_attribute(plugin, 'config'))
if eligible_leader(CLUSTER_RES):
migrate_database()
log('Triggering remote cloud-compute restarts.')
[compute_joined(rid=rid, remote_restart=True)
for rid in relation_ids('cloud-compute')]
@hooks.hook('image-service-relation-changed') @hooks.hook('image-service-relation-changed')
@restart_on_change(restart_map()) @restart_on_change(restart_map())
def image_service_changed(): def image_service_changed():
@ -385,7 +438,9 @@ def ha_changed():
'identity-service-relation-broken', 'identity-service-relation-broken',
'image-service-relation-broken', 'image-service-relation-broken',
'nova-volume-service-relation-broken', 'nova-volume-service-relation-broken',
'shared-db-relation-broken' 'shared-db-relation-broken',
'pgsql-nova-db-relation-broken',
'pgsql-neutron-db-relation-broken',
'quantum-network-service-relation-broken') 'quantum-network-service-relation-broken')
def relation_broken(): def relation_broken():
CONFIGS.write_all() CONFIGS.write_all()

View File

@ -85,6 +85,8 @@ BASE_RESOURCE_MAP = OrderedDict([
'services': BASE_SERVICES, 'services': BASE_SERVICES,
'contexts': [context.AMQPContext(), 'contexts': [context.AMQPContext(),
nova_cc_context.SharedDBContext(relation_prefix='nova'), nova_cc_context.SharedDBContext(relation_prefix='nova'),
nova_cc_context.NovaPostgresqlDBContext(),
nova_cc_context.NeutronPostgresqlDBContext(),
context.ImageServiceContext(), context.ImageServiceContext(),
context.OSConfigFlagContext(), context.OSConfigFlagContext(),
context.SubordinateConfigContext( context.SubordinateConfigContext(

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -0,0 +1 @@
nova_cc_hooks.py

View File

@ -12,6 +12,10 @@ provides:
requires: requires:
shared-db: shared-db:
interface: mysql-shared interface: mysql-shared
pgsql-nova-db:
interface: pgsql
pgsql-neutron-db:
interface: pgsql
amqp: amqp:
interface: rabbitmq interface: rabbitmq
image-service: image-service:

View File

@ -1 +1 @@
314 315