added config changed hooks

This commit is contained in:
yolanda.robla@canonical.com 2013-02-08 11:01:36 +01:00
parent 68a730cec6
commit be44e86e67
5 changed files with 33 additions and 10 deletions

1
hooks/config-changed Symbolic link
View File

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

View File

@ -47,11 +47,11 @@ def render_ceilometer_conf():
if (context and contextdb and os.path.exists(ceilometer_utils.CEILOMETER_CONF)):
context['metering_secret'] = ceilometer_utils.get_shared_secret()
context['service_port'] = utils.config_get('service-port')
context['db_connection'] = "mongodb://"+contextdb["db_host"]+":"+contextdb["db_port"]+"/"+contextdb["db_name"]
with open(ceilometer_utils.CEILOMETER_CONF, "w") as conf:
conf.write(utils.render_template(os.path.basename(ceilometer_utils.CEILOMETER_CONF), context))
def amqp_changed():
render_ceilometer_conf()
utils.restart(*ceilometer_utils.CEILOMETER_SERVICES)
@ -63,11 +63,16 @@ def db_changed():
render_ceilometer_conf()
utils.restart(*ceilometer_utils.CEILOMETER_SERVICES)
def config_changed():
utils.update_ports()
render_ceilometer_conf()
utils.do_hooks({
"install": install,
"amqp-relation-joined": amqp_joined,
"amqp-relation-changed": amqp_changed,
"shared-db-relation-joined": db_joined,
"shared-db-relation-changed": db_changed
"shared-db-relation-changed": db_changed,
"config-changed": config_changed
})
sys.exit(0)

View File

@ -11,7 +11,8 @@ import subprocess
import socket
import sys
import apt_pkg as apt
import re
import ceilometer_utils
def do_hooks(hooks):
hook = os.path.basename(sys.argv[0])
@ -104,6 +105,16 @@ def configure_source():
TCP = 'TCP'
UDP = 'UDP'
def update_ports():
# extract old port from config and close it
ceilometer_config = open(ceilometer_utils.CEILOMETER_CONF).read()
current_api_port = re.search("^#*metering_api_port\s*=\s*(\w+)", ceilometer_config, re.MULTILINE).group(1)
if current_api_port:
unexpose(current_api_port)
port = config_get("service-port")
if port:
expose(port)
def expose(port, protocol='TCP'):
cmd = [
@ -112,6 +123,12 @@ def expose(port, protocol='TCP'):
]
subprocess.check_call(cmd)
def unexpose(port, protocol='TCP'):
cmd = [
'close-port',
'{}/{}'.format(port, protocol)
]
subprocess.check_call(cmd)
def juju_log(severity, message):
cmd = [

View File

@ -1 +1 @@
11
24

View File

@ -3,10 +3,10 @@ debug=True
verbose=True
metering_secret={{ metering_secret }}
control_exchange=ceilometer
metering_api_port=8777
rabbit_host = {{ rabbit_host }}
metering_api_port={{ service_port }}
rabbit_host={{ rabbit_host }}
rabbit_port=5672
rabbit_userid = {{ rabbit_userid }}
rabbit_pasword = {{ rabbit_password }}
rabbit_virtual_host = {{ rabbit_virtual_host }}
database_connection= {{db_connection}}
rabbit_userid={{ rabbit_userid }}
rabbit_pasword={{ rabbit_password }}
rabbit_virtual_host={{ rabbit_virtual_host }}
database_connection={{ db_connection }}