added postgresql support
This commit is contained in:
parent
70e61d50fd
commit
499930bcd8
@ -152,6 +152,35 @@ class SharedDBContext(OSContextGenerator):
|
||||
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):
|
||||
interfaces = ['identity-service']
|
||||
|
||||
|
@ -22,4 +22,5 @@ def zap_disk(block_device):
|
||||
|
||||
: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])
|
||||
|
@ -135,6 +135,10 @@ def apt_hold(packages, fatal=False):
|
||||
|
||||
|
||||
def add_source(source, key=None):
|
||||
if source is None:
|
||||
log('Source is not present. Skipping')
|
||||
return
|
||||
|
||||
if (source.startswith('ppa:') or
|
||||
source.startswith('http') or
|
||||
source.startswith('deb ') or
|
||||
|
@ -174,3 +174,9 @@ class SharedDBContext(context.SharedDBContext):
|
||||
ctxt['database_type'] = 'mysql'
|
||||
return ctxt
|
||||
|
||||
class NovaPostgresqlDBContext(context.PostgresqlDBContext):
|
||||
interfaces = ['pgsql-nova-db']
|
||||
|
||||
|
||||
class NeutronPostgresqlDBContext(context.PostgresqlDBContext):
|
||||
interfaces = ['pgsql-neutron-db']
|
||||
|
@ -13,6 +13,7 @@ from charmhelpers.core.hookenv import (
|
||||
UnregisteredHookError,
|
||||
config,
|
||||
charm_dir,
|
||||
is_relation_made,
|
||||
log,
|
||||
relation_get,
|
||||
relation_ids,
|
||||
@ -29,6 +30,8 @@ from charmhelpers.fetch import (
|
||||
apt_install, apt_update
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.openstack import context
|
||||
|
||||
from charmhelpers.contrib.openstack.utils import (
|
||||
configure_installation_source,
|
||||
openstack_upgrade_available,
|
||||
@ -124,6 +127,12 @@ def amqp_changed():
|
||||
|
||||
@hooks.hook('shared-db-relation-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'),
|
||||
nova_username=config('database-user'),
|
||||
nova_hostname=unit_get('private-address'))
|
||||
@ -134,6 +143,28 @@ def db_joined():
|
||||
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')
|
||||
@restart_on_change(restart_map())
|
||||
def db_changed():
|
||||
@ -154,6 +185,28 @@ def db_changed():
|
||||
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')
|
||||
@restart_on_change(restart_map())
|
||||
def image_service_changed():
|
||||
@ -385,7 +438,9 @@ def ha_changed():
|
||||
'identity-service-relation-broken',
|
||||
'image-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')
|
||||
def relation_broken():
|
||||
CONFIGS.write_all()
|
||||
|
@ -85,6 +85,8 @@ BASE_RESOURCE_MAP = OrderedDict([
|
||||
'services': BASE_SERVICES,
|
||||
'contexts': [context.AMQPContext(),
|
||||
nova_cc_context.SharedDBContext(relation_prefix='nova'),
|
||||
nova_cc_context.NovaPostgresqlDBContext(),
|
||||
nova_cc_context.NeutronPostgresqlDBContext(),
|
||||
context.ImageServiceContext(),
|
||||
context.OSConfigFlagContext(),
|
||||
context.SubordinateConfigContext(
|
||||
|
1
hooks/pgsql-neutron-db-relation-broken
Symbolic link
1
hooks/pgsql-neutron-db-relation-broken
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-neutron-db-relation-changed
Symbolic link
1
hooks/pgsql-neutron-db-relation-changed
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-neutron-db-relation-joined
Symbolic link
1
hooks/pgsql-neutron-db-relation-joined
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-nova-db-relation-broken
Symbolic link
1
hooks/pgsql-nova-db-relation-broken
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-nova-db-relation-changed
Symbolic link
1
hooks/pgsql-nova-db-relation-changed
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
1
hooks/pgsql-nova-db-relation-joined
Symbolic link
1
hooks/pgsql-nova-db-relation-joined
Symbolic link
@ -0,0 +1 @@
|
||||
nova_cc_hooks.py
|
@ -12,6 +12,10 @@ provides:
|
||||
requires:
|
||||
shared-db:
|
||||
interface: mysql-shared
|
||||
pgsql-nova-db:
|
||||
interface: pgsql
|
||||
pgsql-neutron-db:
|
||||
interface: pgsql
|
||||
amqp:
|
||||
interface: rabbitmq
|
||||
image-service:
|
||||
|
Loading…
Reference in New Issue
Block a user