Merge lp:~gnuoy/charms/precise/haproxy/return-servicename-specfic-config into lp:charms/haproxy

Proposed by Liam Young
Status: Merged
Approved by: Juan L. Negron
Approved revision: 59
Merge reported by: Juan L. Negron
Merged at revision: not available
Proposed branch: lp:~gnuoy/charms/precise/haproxy/return-servicename-specfic-config
Merge into: lp:charms/haproxy
Diff against target: 67 lines (+34/-8)
1 file modified
hooks/hooks.py (+34/-8)
To merge this branch: bzr merge lp:~gnuoy/charms/precise/haproxy/return-servicename-specfic-config
Reviewer Review Type Date Requested Status
Juan L. Negron (community) Approve
Review via email: mp+124731@code.launchpad.net

Description of the change

Currently the haproxy charm allows for multiple stanzas to be defined on different IP and ports but when a charm joins the website relationship it is always given hostname:80 so doesn't have access to any of the additional configs. I've added code so that if a specfic service has been asked for when the website relationship is called then return the ip:port for that service, else pass back the default.

I've also added a change to expose a variable (all_services) which contains a yaml list of all available services in case the joining charm want to use more than one

To post a comment you must log in.
Revision history for this message
Juan L. Negron (negronjl) wrote :

Reviewing this now.

-Juan

Revision history for this message
Juan L. Negron (negronjl) wrote :

Liam:

Thanks for your continuing contributions to the haproxy charm ( among your many other contributions ).

This looks good to me.

Approved.

-Juan

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'hooks/hooks.py'
2--- hooks/hooks.py 2012-09-10 05:16:58 +0000
3+++ hooks/hooks.py 2012-09-17 16:02:22 +0000
4@@ -307,6 +307,16 @@
5 services_list = yaml.load(config_data['services'])
6 return(services_list)
7
8+#------------------------------------------------------------------------------
9+# get_config_service: Convenience function that returns a dictionary
10+# of the configuration of a given services configuration
11+#------------------------------------------------------------------------------
12+def get_config_service(service_name=None):
13+ services_list = get_config_services()
14+ for service_item in services_list:
15+ if service_item['service_name'] == service_name:
16+ return(service_item)
17+ return(None)
18
19 #------------------------------------------------------------------------------
20 # create_services: Function that will create the services configuration
21@@ -545,22 +555,38 @@
22 def website_interface(hook_name=None):
23 if hook_name is None:
24 return(None)
25- my_host = socket.getfqdn(socket.gethostname())
26+ default_port = 80
27+ relation_data = relation_get()
28+ config_data = config_get()
29+
30+ # If a specfic service has been asked for then return the ip:port for
31+ # that service, else pass back the default
32+ if 'service_name' in relation_data:
33+ service_name = relation_data['service_name']
34+ requestedservice = get_config_service(service_name)
35+ my_host = requestedservice['service_host']
36+ my_port = requestedservice['service_port']
37+ else:
38+ my_host = socket.getfqdn(socket.gethostname())
39+ my_port = default_port
40+
41+ # If the listen ip has been set to 0.0.0.0 then pass back the hostname
42+ if my_host == "0.0.0.0":
43+ my_host = socket.getfqdn(socket.gethostname())
44+
45+ # If the fqdn lookup has returned localhost (lxc setups) then return
46+ # hostname
47 if my_host == "localhost":
48 my_host = socket.gethostname()
49- default_port = 80
50- relation_data = relation_get()
51- if hook_name == "joined":
52- subprocess.call(['relation-set', 'port=%d' % \
53- default_port, 'hostname=%s' % my_host])
54- elif hook_name == "changed":
55+ subprocess.call(['relation-set', 'port=%d' % \
56+ my_port, 'hostname=%s' % my_host, 'all_services=%s' % config_data['services']])
57+ if hook_name == "changed":
58 if 'is-proxy' in relation_data:
59 service_name = "%s__%d" % \
60 (relation_data['hostname'], relation_data['port'])
61 open("%s/%s.is.proxy" % \
62 (default_haproxy_service_config_dir, service_name), 'a').close()
63
64-
65 ###############################################################################
66 # Main section
67 ###############################################################################

Subscribers

People subscribed via source and target branches