Add templating for db_changed
This commit is contained in:
parent
42eb308656
commit
4f610e4718
@ -9,6 +9,11 @@ from glance_common import (
|
||||
set_or_update,
|
||||
)
|
||||
|
||||
from glance_utils import (
|
||||
register_configs,
|
||||
migrate_database,
|
||||
)
|
||||
|
||||
from charmhelpers.contrib.hahelpers.cluster_utils import (
|
||||
https,
|
||||
peer_units,
|
||||
@ -54,6 +59,11 @@ from subprocess import (
|
||||
check_call,
|
||||
)
|
||||
|
||||
CLUSTER_RES = "res_glance_vip"
|
||||
|
||||
CONFIGS = register_configs()
|
||||
|
||||
|
||||
PACKAGES = [
|
||||
"glance", "python-mysqldb", "python-swift",
|
||||
"python-keystone", "uuid", "haproxy",
|
||||
@ -98,34 +108,21 @@ def db_joined():
|
||||
|
||||
|
||||
def db_changed(rid=None):
|
||||
relation_data = relation_get_dict(relation_id=rid)
|
||||
if ('password' not in relation_data or
|
||||
'db_host' not in relation_data):
|
||||
juju_log('INFO',
|
||||
'db_host or password not set. Peer not ready, exit 0')
|
||||
sys.exit(0)
|
||||
|
||||
db_host = relation_data["db_host"]
|
||||
db_password = relation_data["password"]
|
||||
glance_db = config["glance-db"]
|
||||
db_user = config["db-user"]
|
||||
rel = get_os_codename_package("glance-common")
|
||||
|
||||
value = "mysql://%s:%s@%s/%s" % (db_user, db_password, db_host, glance_db)
|
||||
set_or_update(key='sql_connection', value=value, file='registry')
|
||||
|
||||
CONFIGS.write('/etc/glance/glance-registry.conf')
|
||||
if rel != "essex":
|
||||
value = "mysql://%s:%s@%s/%s" % (db_user, db_password, db_host, glance_db)
|
||||
set_or_update(key='sql_connection', value=value, file='api')
|
||||
CONFIGS.write('/etc/glance/glance-api.conf')
|
||||
|
||||
if eligible_leader("res_glance_vip"):
|
||||
if eligible_leader(CLUSTER_RES):
|
||||
if rel == "essex":
|
||||
if not check_output(['glance-manage', 'db_version']):
|
||||
juju_log("INFO", "Setting flance database version to 0")
|
||||
try:
|
||||
check_call(['glance-manage', 'db_version'])
|
||||
except:
|
||||
check_call(["glance-manage", "version_control", "0"])
|
||||
|
||||
juju_log("INFO", "%s - db_changed: Running database migrations for %s." % (CHARM, rel))
|
||||
check_call(["glance-manage", "db_sync"])
|
||||
juju_log('Cluster leader, performing db sync')
|
||||
migrate_database()
|
||||
|
||||
restart(*SERVICES)
|
||||
|
||||
|
51
hooks/glance_utils.py
Executable file
51
hooks/glance_utils.py
Executable file
@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
|
||||
from charmhelpers.contrib.openstack import (
|
||||
templating,
|
||||
context,
|
||||
)
|
||||
|
||||
import subprocess
|
||||
|
||||
CHARM = "glance"
|
||||
|
||||
SERVICES = "glance-api glance-registry"
|
||||
PACKAGES = "glance python-mysqldb python-swift python-keystone uuid haproxy"
|
||||
|
||||
GLANCE_REGISTRY_CONF = "/etc/glance/glance-registry.conf"
|
||||
GLANCE_REGISTRY_PASTE_INI = "/etc/glance/glance-registry-paste.ini"
|
||||
GLANCE_API_CONF = "/etc/glance/glance-api.conf"
|
||||
GLANCE_API_PASTE_INI = "/etc/glance/glance-api-paste.ini"
|
||||
CONF_DIR = "/etc/glance"
|
||||
|
||||
# Flag used to track config changes.
|
||||
CONFIG_CHANGED = False
|
||||
|
||||
TEMPLATES = 'templates/'
|
||||
|
||||
CONFIG_FILES = {
|
||||
'/etc/glance/glance-registry.conf': {
|
||||
'hook_contexts': [context.shared_db],
|
||||
'services': ['glance-registry']
|
||||
}
|
||||
}
|
||||
|
||||
def register_configs():
|
||||
# Register config files with their respective contexts.
|
||||
# Regstration of some configs may not be required depending on
|
||||
# existing of certain relations.
|
||||
configs = templating.OSConfigRenderer(templates_dir=TEMPLATES,
|
||||
openstack_release='grizzly')
|
||||
|
||||
confs = ['/etc/glance/glance-registry.conf']
|
||||
|
||||
for conf in confs:
|
||||
configs.register(conf, CONFIG_FILES[conf]['hook_contexts'])
|
||||
|
||||
return configs
|
||||
|
||||
|
||||
def migrate_database():
|
||||
'''Runs glance-manage to initialize a new database or migrate existing'''
|
||||
cmd = ['glance-manage', 'db_sync']
|
||||
subprocess.check_call(cmd)
|
14
templates/glance-registry.conf
Normal file
14
templates/glance-registry.conf
Normal file
@ -0,0 +1,14 @@
|
||||
[DEFAULT]
|
||||
verbose = True
|
||||
debug = True
|
||||
bind_host = 0.0.0.0
|
||||
bind_port = 9191
|
||||
log_file = /var/log/glance/registry.log
|
||||
backlog = 4096
|
||||
{% if database_host %}
|
||||
sql_connection = mysql://{{ database_user }}:{{ database_password }}@{{ database_host }}/{{ database }}
|
||||
{% endif %}
|
||||
sql_idle_timeout = 3600
|
||||
api_limit_max = 1000
|
||||
limit_param_default = 25
|
||||
use_syslog = False
|
Loading…
x
Reference in New Issue
Block a user