Add listen_port to haproxy_config

This simplifies port rendering logic in docker container
This commit is contained in:
Przemyslaw Kaminski 2015-04-22 10:02:19 +02:00
parent a8ae9cdf26
commit f18971c092
7 changed files with 25 additions and 10 deletions

View File

@ -29,7 +29,7 @@ defaults
# balance roundrobin
{% for service in haproxy_services %}
listen {{ service['name'] }} 0.0.0.0:{{ service['servers'][0]['port'] }}
listen {{ service['name'] }} 0.0.0.0:{{ service['listen_port'] }}
mode http
stats enable
stats uri /haproxy?stats

View File

@ -72,6 +72,7 @@ resources:
model: x/resources/haproxy_config/
args:
servers: {}
port: 5000
ports: {}
ssh_user:
ssh_key:
@ -112,6 +113,7 @@ resources:
model: x/resources/haproxy_config/
args:
servers: {}
port: 8774
ports: {}
ssh_user:
ssh_key:
@ -120,6 +122,7 @@ resources:
model: x/resources/haproxy/
args:
ip:
listen_ports: {}
configs: {}
configs_ports: {}
ssh_user:
@ -182,11 +185,13 @@ connections:
- emitter: haproxy_keystone_config
receiver: haproxy-config
mapping:
port: listen_ports
ports: configs_ports
servers: configs
- emitter: haproxy_nova_config
receiver: haproxy-config
mapping:
port: listen_ports
ports: configs_ports
servers: configs
@ -194,7 +199,7 @@ connections:
receiver: haproxy
mapping:
ip: ip
configs_ports: ports
listen_ports: ports
ssh_user: ssh_user
ssh_key: ssh_key
config_dir: host_binds

View File

@ -72,29 +72,36 @@ class TestHAProxyDeployment(unittest.TestCase):
self.assertEqual(node5.args['ip'], haproxy.args['ip'])
self.assertEqual(node5.args['ssh_key'], haproxy.args['ssh_key'])
self.assertEqual(node5.args['ssh_user'], haproxy.args['ssh_user'])
self.assertItemsEqual(
self.assertDictEqual(
haproxy_config.args['configs'],
{
'haproxy_keystone_config': haproxy_keystone_config.args['servers'],
'haproxy_nova_config': haproxy_nova_config.args['servers'],
}
)
self.assertItemsEqual(
self.assertDictEqual(
haproxy_config.args['configs_ports'],
{
'haproxy_keystone_config': haproxy_keystone_config.args['ports'],
'haproxy_nova_config': haproxy_nova_config.args['ports'],
}
)
self.assertItemsEqual(
self.assertDictEqual(
haproxy_config.args['listen_ports'],
{
'haproxy_keystone_config': haproxy_keystone_config.args['port'],
'haproxy_nova_config': haproxy_nova_config.args['port'],
}
)
self.assertDictEqual(
{
'haproxy-config': haproxy_config.args['config_dir'],
},
haproxy.args['host_binds']
)
self.assertItemsEqual(
self.assertDictEqual(
haproxy.args['ports'],
haproxy_config.args['configs_ports'],
haproxy_config.args['listen_ports'],
)

View File

@ -10,10 +10,9 @@
image: {{ image }}
state: running
ports:
{% for name, ports_dict in ports.items() %}
# TODO: this is ugly
{% for name, port in ports.items() %}
# {{ name }}
- {{ ports_dict.values()[0] }}:{{ ports_dict.values()[0] }}
- {{ port }}:{{ port }}
{% endfor %}
volumes:
# TODO: host_binds might need more work

View File

@ -7,6 +7,7 @@
haproxy_services:
{% for service, servers in configs.items() %}
- name: {{ service }}
listen_port: {{ listen_ports[service] }}
servers:
{% for name, ip in servers.items() %}
- name: {{ name }}

View File

@ -4,10 +4,12 @@ version: 1.0.0
input:
ip:
config_dir: /etc/haproxy
listen_ports:
configs:
configs_ports:
ssh_user:
ssh_key:
input-types:
listen_ports: list
configs: list
configs_ports: list

View File

@ -2,6 +2,7 @@ id: haproxy_config
handler: ansible
version: 1.0.0
input:
port:
ports:
servers:
input-types: