cluster_changed/haproxy

This commit is contained in:
Andres Rodriguez 2013-07-01 15:01:13 -04:00
parent 430a00f99b
commit 42cad0fb3a
6 changed files with 61 additions and 14 deletions

View File

@ -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

View File

@ -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()

View File

@ -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():

View File

@ -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

View File

@ -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 %}

37
templates/haproxy.cfg Normal file
View File

@ -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 %}