From 42cad0fb3ab8e432d9e95bf7c1d1ab578d85f2e3 Mon Sep 17 00:00:00 2001 From: Andres Rodriguez Date: Mon, 1 Jul 2013 15:01:13 -0400 Subject: [PATCH] cluster_changed/haproxy --- hooks/glance_contexts.py | 12 +++++------ hooks/glance_relations.py | 10 +++------ hooks/glance_utils.py | 8 ++++++- templates/essex/glance-api.conf | 4 ++++ templates/folsom/glance-api.conf | 4 ++++ templates/haproxy.cfg | 37 ++++++++++++++++++++++++++++++++ 6 files changed, 61 insertions(+), 14 deletions(-) create mode 100644 templates/haproxy.cfg diff --git a/hooks/glance_contexts.py b/hooks/glance_contexts.py index 65171422..ea74180f 100644 --- a/hooks/glance_contexts.py +++ b/hooks/glance_contexts.py @@ -48,19 +48,19 @@ class ObjectStoreContext(OSContextGenerator): class HAProxyContext(OSContextGenerator): - interfaces = ['ceph'] + interfaces = ['cluster'] def __call__(self): ''' Extends the main charmhelpers HAProxyContext with a port mapping specific to this charm. - Also used to extend cinder.conf context with correct api_listening_port + Also used to extend glance-api.conf context with correct bind_port ''' - haproxy_port = determine_haproxy_port(config('api-listening-port')) - api_port = determine_api_port(config('api-listening-port')) + haproxy_port = determine_haproxy_port('9292') + api_port = determine_api_port('9292') ctxt = { - 'service_ports': {'cinder_api': [haproxy_port, api_port]}, - 'osapi_volume_listen_port': api_port, + 'service_ports': {'glance_api': [haproxy_port, api_port]}, + 'bind_port': api_port, } return ctxt diff --git a/hooks/glance_relations.py b/hooks/glance_relations.py index 1efab210..ccd0d4d1 100755 --- a/hooks/glance_relations.py +++ b/hooks/glance_relations.py @@ -309,16 +309,12 @@ def config_changed(): def cluster_changed(): - if not peer_units(): - juju_log('INFO', '%s: cluster_change() with no peers.' % CHARM) - sys.exit(0) - haproxy_port = determine_haproxy_port('9292') - backend_port = determine_api_port('9292') stop('glance-api') - configure_haproxy("glance_api:%s:%s" % (haproxy_port, backend_port)) - set_or_update(key='bind_port', value=backend_port, file='api') + CONFIGS.write('/etc/glance/glance-api.conf') + CONFIGS.write('/etc/haproxy/haproxy.cfg') start('glance-api') + def upgrade_charm(): cluster_changed() diff --git a/hooks/glance_utils.py b/hooks/glance_utils.py index d952a7a4..a15713a7 100755 --- a/hooks/glance_utils.py +++ b/hooks/glance_utils.py @@ -52,7 +52,8 @@ CONFIG_FILES = OrderedDict([ 'hook_contexts': [context.SharedDBContext(), context.IdentityServiceContext(), glance_contexts.CephContext(), - glance_contexts.ObjectStoreContext()], + glance_contexts.ObjectStoreContext(), + glance_contexts.HAProxyContext()], 'services': ['glance-api'] }), ('/etc/glance/glance-api-paste.ini', { @@ -67,6 +68,11 @@ CONFIG_FILES = OrderedDict([ 'hook_contexts': [context.CephContext()], 'services': [] }), + ('/etc/haproxy/haproxy.cfg', { + 'hook_contexts': [context.HAProxyContext(), + glance_contexts.HAProxyContext()], + 'services': ['haproxy'], + }), ]) def register_configs(): diff --git a/templates/essex/glance-api.conf b/templates/essex/glance-api.conf index af85dff4..de4ae129 100644 --- a/templates/essex/glance-api.conf +++ b/templates/essex/glance-api.conf @@ -9,7 +9,11 @@ default_store = swift default_store = file {% endif %} bind_host = 0.0.0.0 +{% if bind_port %} +bind_port = {{ bind_port }} +{% else %} bind_port = 9292 +{% endif %} log_file = /var/log/glance/api.log backlog = 4096 workers = 0 diff --git a/templates/folsom/glance-api.conf b/templates/folsom/glance-api.conf index 8b3ec148..735d1c56 100644 --- a/templates/folsom/glance-api.conf +++ b/templates/folsom/glance-api.conf @@ -9,7 +9,11 @@ default_store = swift default_store = file {% endif %} bind_host = 0.0.0.0 +{% if bind_port %} +bind_port = {{ bind_port }} +{% else %} bind_port = 9292 +{% endif %} log_file = /var/log/glance/api.log backlog = 4096 {% if database_host %} diff --git a/templates/haproxy.cfg b/templates/haproxy.cfg new file mode 100644 index 00000000..b184cd4a --- /dev/null +++ b/templates/haproxy.cfg @@ -0,0 +1,37 @@ +global + log 127.0.0.1 local0 + log 127.0.0.1 local1 notice + maxconn 20000 + user haproxy + group haproxy + spread-checks 0 + +defaults + log global + mode http + option httplog + option dontlognull + retries 3 + timeout queue 1000 + timeout connect 1000 + timeout client 30000 + timeout server 30000 + +listen stats :8888 + mode http + stats enable + stats hide-version + stats realm Haproxy\ Statistics + stats uri / + stats auth admin:password + +{% if units %} +{% for service, ports in service_ports.iteritems() -%} +listen {{ service }} 0.0.0.0:{{ ports[0] }} + balance roundrobin + option tcplog + {% for unit, address in units.iteritems() -%} + server {{ unit }} {{ address }}:{{ ports[1] }} check + {% endfor %} +{% endfor %} +{% endif %}