Merge lp:~hatch/charms/trusty/juju-gui/custom-port into lp:~juju-gui/charms/trusty/juju-gui/trunk

Proposed by Richard Harding
Status: Merged
Merged at revision: 214
Proposed branch: lp:~hatch/charms/trusty/juju-gui/custom-port
Merge into: lp:~juju-gui/charms/trusty/juju-gui/trunk
Diff against target: 190 lines (+53/-12)
5 files modified
config.yaml (+5/-0)
config/guiserver.conf.template (+3/-0)
hooks/backend.py (+3/-5)
hooks/utils.py (+29/-4)
server/guiserver/manage.py (+13/-3)
To merge this branch: bzr merge lp:~hatch/charms/trusty/juju-gui/custom-port
Reviewer Review Type Date Requested Status
Juju GUI Hackers Pending
Review via email: mp+241716@code.launchpad.net

Description of the change

WIP

To post a comment you must log in.
Revision history for this message
Francesco Banconi (frankban) wrote :

Good start, thank you!
Just added some inline comments.
I'll look again when the branch is complete.

216. By Jeff Pihach

Lint fixes and cleanups from wip review

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'config.yaml'
2--- config.yaml 2014-11-04 01:31:53 +0000
3+++ config.yaml 2014-11-13 19:23:32 +0000
4@@ -49,6 +49,11 @@
5 Whether or not the console should be enabled for the browser.
6 type: boolean
7 default: false
8+ port:
9+ description: |
10+ Supply a different port to host the GUI on besides the default 80 and 443.
11+ type: int
12+ default:
13 command-log-file:
14 description: |
15 The log file where stdout and stderr should be sent for all commands
16
17=== modified file 'config/guiserver.conf.template'
18--- config/guiserver.conf.template 2014-08-29 15:17:01 +0000
19+++ config/guiserver.conf.template 2014-11-13 19:23:32 +0000
20@@ -21,6 +21,9 @@
21 --guiroot="{{gui_root}}" \
22 --sslpath="{{ssl_cert_path}}" \
23 --charmworldurl="{{charmworld_url}}" \
24+ {{if port}}
25+ --port="{{port}}" \
26+ {{endif}}
27 {{if sandbox}}
28 --sandbox \
29 {{else}}
30
31=== modified file 'hooks/backend.py'
32--- hooks/backend.py 2014-02-04 20:07:31 +0000
33+++ hooks/backend.py 2014-11-13 19:23:32 +0000
34@@ -44,7 +44,6 @@
35
36 from charmhelpers import (
37 log,
38- open_port,
39 )
40
41 import utils
42@@ -133,9 +132,7 @@
43 cached_fonts=config['cached-fonts'], ga_key=config['ga-key'],
44 show_get_juju_button=config['show-get-juju-button'],
45 password=config.get('password'))
46- # Expose the service.
47- open_port(80)
48- open_port(443)
49+ utils.modify_open_ports(backend.config, backend.prev_config)
50
51
52 class ServerInstallMixinBase(object):
53@@ -193,12 +190,13 @@
54
55 def start(self, backend):
56 config = backend.config
57+ port = config.get('port')
58 build_dir = utils.compute_build_dir(
59 config['juju-gui-debug'], config['serve-tests'])
60 utils.start_builtin_server(
61 build_dir, config['ssl-cert-path'], config['serve-tests'],
62 config['sandbox'], config['builtin-server-logging'],
63- not config['secure'], config['charmworld-url'])
64+ not config['secure'], config['charmworld-url'], port=port)
65
66 def stop(self, backend):
67 utils.stop_builtin_server()
68
69=== modified file 'hooks/utils.py'
70--- hooks/utils.py 2014-09-29 14:52:52 +0000
71+++ hooks/utils.py 2014-11-13 19:23:32 +0000
72@@ -37,6 +37,7 @@
73 'get_release_file_path',
74 'install_missing_packages',
75 'log_hook',
76+ 'modify_open_ports',
77 'parse_source',
78 'prime_npm_cache',
79 'remove_apache_setup',
80@@ -71,8 +72,10 @@
81 import tempita
82
83 from charmhelpers import (
84+ close_port,
85 get_config,
86 log,
87+ open_port,
88 RESTART,
89 service_control,
90 STOP,
91@@ -413,6 +416,26 @@
92 render_to_file('config.js.template', context, config_js_path)
93
94
95+def modify_open_ports(config, prev_config):
96+ """Open or close ports based on the supplied port config value."""
97+ # If a custom port was previously defined we want to make sure we close it.
98+ if 'port' in prev_config:
99+ log('Closing previously opened user defined port.')
100+ close_port(prev_config['port'])
101+ if 'port' in config:
102+ log('Using user provided port instead of defaults.')
103+ # Make sure that the default ports are closed when setting the custom
104+ # port.
105+ close_port(80)
106+ close_port(443)
107+ # Open the custom defined port.
108+ open_port(config['port'])
109+ else:
110+ log('Using default ports')
111+ open_port(80)
112+ open_port(443)
113+
114+
115 def setup_haproxy_config(ssl_cert_path, secure=True):
116 """Generate the haproxy configuration file."""
117 log('Setting up haproxy Upstart file.')
118@@ -513,7 +536,8 @@
119
120 def write_builtin_server_startup(
121 gui_root, ssl_cert_path, serve_tests=False, sandbox=False,
122- builtin_server_logging='info', insecure=False, charmworld_url=''):
123+ builtin_server_logging='info', insecure=False, charmworld_url='',
124+ port=None):
125 """Generate the builtin server Upstart file."""
126 log('Generating the builtin server Upstart file.')
127 context = {
128@@ -526,7 +550,8 @@
129 'charmworld_url': charmworld_url,
130 'http_proxy': os.environ.get('http_proxy'),
131 'https_proxy': os.environ.get('https_proxy'),
132- 'no_proxy': os.environ.get('no_proxy', os.environ.get('NO_PROXY'))
133+ 'no_proxy': os.environ.get('no_proxy', os.environ.get('NO_PROXY')),
134+ 'port': port,
135 }
136 if not sandbox:
137 api_url = 'wss://{}'.format(get_api_address())
138@@ -542,12 +567,12 @@
139
140 def start_builtin_server(
141 build_dir, ssl_cert_path, serve_tests, sandbox, builtin_server_logging,
142- insecure, charmworld_url):
143+ insecure, charmworld_url, port=None):
144 """Start the builtin server."""
145 write_builtin_server_startup(
146 build_dir, ssl_cert_path, serve_tests=serve_tests, sandbox=sandbox,
147 builtin_server_logging=builtin_server_logging, insecure=insecure,
148- charmworld_url=charmworld_url)
149+ charmworld_url=charmworld_url, port=port)
150 log('Starting the builtin server.')
151 with su('root'):
152 service_control(BUILTIN_SERVER, RESTART)
153
154=== modified file 'server/guiserver/manage.py'
155--- server/guiserver/manage.py 2014-01-24 15:38:37 +0000
156+++ server/guiserver/manage.py 2014-11-13 19:23:32 +0000
157@@ -120,6 +120,11 @@
158 define(
159 'charmworldurl', type=str,
160 help='The URL to use for Charmworld.')
161+ define(
162+ 'port', type=str,
163+ help='User defined port to run the server on. If no port is defined '
164+ 'the server will be started on 80 and 443 as per the default '
165+ 'port options from the charm.')
166
167 # In Tornado, parsing the options also sets up the default logger.
168 parse_command_line()
169@@ -133,13 +138,18 @@
170
171 def run():
172 """Run the server"""
173+ port = options.port
174 if options.insecure:
175 # Run the server over an insecure HTTP connection.
176- server().listen(80)
177+ if not port:
178+ port = 80
179+ server().listen(port)
180 else:
181 # Default configuration: run the server over a secure HTTPS connection.
182- server().listen(443, ssl_options=_get_ssl_options())
183- redirector().listen(80)
184+ if not port:
185+ port = 443
186+ redirector().listen(80)
187+ server().listen(port, ssl_options=_get_ssl_options())
188 version = guiserver.get_version()
189 logging.info('starting Juju GUI server v{}'.format(version))
190 IOLoop.instance().start()

Subscribers

People subscribed via source and target branches

to all changes: