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 # balance roundrobin
{% for service in haproxy_services %} {% 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 mode http
stats enable stats enable
stats uri /haproxy?stats stats uri /haproxy?stats

View File

@ -72,6 +72,7 @@ resources:
model: x/resources/haproxy_config/ model: x/resources/haproxy_config/
args: args:
servers: {} servers: {}
port: 5000
ports: {} ports: {}
ssh_user: ssh_user:
ssh_key: ssh_key:
@ -112,6 +113,7 @@ resources:
model: x/resources/haproxy_config/ model: x/resources/haproxy_config/
args: args:
servers: {} servers: {}
port: 8774
ports: {} ports: {}
ssh_user: ssh_user:
ssh_key: ssh_key:
@ -120,6 +122,7 @@ resources:
model: x/resources/haproxy/ model: x/resources/haproxy/
args: args:
ip: ip:
listen_ports: {}
configs: {} configs: {}
configs_ports: {} configs_ports: {}
ssh_user: ssh_user:
@ -182,11 +185,13 @@ connections:
- emitter: haproxy_keystone_config - emitter: haproxy_keystone_config
receiver: haproxy-config receiver: haproxy-config
mapping: mapping:
port: listen_ports
ports: configs_ports ports: configs_ports
servers: configs servers: configs
- emitter: haproxy_nova_config - emitter: haproxy_nova_config
receiver: haproxy-config receiver: haproxy-config
mapping: mapping:
port: listen_ports
ports: configs_ports ports: configs_ports
servers: configs servers: configs
@ -194,7 +199,7 @@ connections:
receiver: haproxy receiver: haproxy
mapping: mapping:
ip: ip ip: ip
configs_ports: ports listen_ports: ports
ssh_user: ssh_user ssh_user: ssh_user
ssh_key: ssh_key ssh_key: ssh_key
config_dir: host_binds 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['ip'], haproxy.args['ip'])
self.assertEqual(node5.args['ssh_key'], haproxy.args['ssh_key']) self.assertEqual(node5.args['ssh_key'], haproxy.args['ssh_key'])
self.assertEqual(node5.args['ssh_user'], haproxy.args['ssh_user']) self.assertEqual(node5.args['ssh_user'], haproxy.args['ssh_user'])
self.assertItemsEqual( self.assertDictEqual(
haproxy_config.args['configs'], haproxy_config.args['configs'],
{ {
'haproxy_keystone_config': haproxy_keystone_config.args['servers'], 'haproxy_keystone_config': haproxy_keystone_config.args['servers'],
'haproxy_nova_config': haproxy_nova_config.args['servers'], 'haproxy_nova_config': haproxy_nova_config.args['servers'],
} }
) )
self.assertItemsEqual( self.assertDictEqual(
haproxy_config.args['configs_ports'], haproxy_config.args['configs_ports'],
{ {
'haproxy_keystone_config': haproxy_keystone_config.args['ports'], 'haproxy_keystone_config': haproxy_keystone_config.args['ports'],
'haproxy_nova_config': haproxy_nova_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-config': haproxy_config.args['config_dir'],
}, },
haproxy.args['host_binds'] haproxy.args['host_binds']
) )
self.assertItemsEqual( self.assertDictEqual(
haproxy.args['ports'], haproxy.args['ports'],
haproxy_config.args['configs_ports'], haproxy_config.args['listen_ports'],
) )

View File

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

View File

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

View File

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

View File

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