Add webapp port and listen_address configuration
This change adds a webapp settings to nodepool.yaml to enable custom setting for port and listen_address. Change-Id: I0f41a0b131bc2a09c47a448c65471e052c0a9e88
This commit is contained in:
parent
c132780c02
commit
a0159428d7
|
@ -19,6 +19,19 @@ and ``providers`` sections::
|
|||
The following sections are available. All are required unless
|
||||
otherwise indicated.
|
||||
|
||||
.. _webapp-conf:
|
||||
|
||||
webapp
|
||||
------
|
||||
|
||||
Define the webapp endpoint port and listen address.
|
||||
|
||||
Example::
|
||||
|
||||
webapp:
|
||||
port: 8005
|
||||
listen_address: '0.0.0.0'
|
||||
|
||||
.. _elements-dir:
|
||||
|
||||
elements-dir
|
||||
|
|
|
@ -103,7 +103,13 @@ class ConfigValidator:
|
|||
'env-vars': {str: str},
|
||||
}
|
||||
|
||||
webapp = {
|
||||
'port': int,
|
||||
'listen_address': str,
|
||||
}
|
||||
|
||||
top_level = {
|
||||
'webapp': webapp,
|
||||
'elements-dir': str,
|
||||
'images-dir': str,
|
||||
'zookeeper-servers': [{
|
||||
|
|
|
@ -54,7 +54,9 @@ class NodePoolLauncherApp(nodepool.cmd.NodepoolDaemonApp):
|
|||
self.pool = nodepool.launcher.NodePool(self.args.secure,
|
||||
self.args.config)
|
||||
if not self.args.no_webapp:
|
||||
self.webapp = nodepool.webapp.WebApp(self.pool)
|
||||
config = self.pool.loadConfig()
|
||||
self.webapp = nodepool.webapp.WebApp(self.pool,
|
||||
**config.webapp)
|
||||
|
||||
signal.signal(signal.SIGINT, self.exit_handler)
|
||||
# For back compatibility:
|
||||
|
|
|
@ -150,6 +150,11 @@ def loadConfig(config_path):
|
|||
|
||||
newconfig = Config()
|
||||
newconfig.db = None
|
||||
newconfig.webapp = {
|
||||
'port': config.get('webapp', {}).get('port', 8005),
|
||||
'listen_address': config.get('webapp', {}).get('listen_address',
|
||||
'0.0.0.0')
|
||||
}
|
||||
newconfig.providers = {}
|
||||
newconfig.labels = {}
|
||||
newconfig.elementsdir = config.get('elements-dir')
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
elements-dir: /etc/nodepool/elements
|
||||
images-dir: /opt/nodepool_dib
|
||||
|
||||
webapp:
|
||||
port: 8005
|
||||
listen_address: '0.0.0.0'
|
||||
|
||||
zookeeper-servers:
|
||||
- host: zk1.openstack.org
|
||||
port: 2181
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
webapp:
|
||||
port: 8080
|
||||
listen_address: '127.0.0.1'
|
|
@ -15,6 +15,7 @@
|
|||
|
||||
import json
|
||||
import logging
|
||||
import yaml
|
||||
from six.moves.urllib import request
|
||||
|
||||
from nodepool import tests
|
||||
|
@ -67,3 +68,9 @@ class TestWebApp(tests.DBTestCase):
|
|||
self.assertDictContainsSubset({'id': 'fake-image-0000000001',
|
||||
'formats': ['qcow2'],
|
||||
'state': 'ready'}, objs[0])
|
||||
|
||||
def test_webapp_config(self):
|
||||
configfile = self.setup_config('webapp.yaml')
|
||||
config = yaml.safe_load(open(configfile))
|
||||
self.assertEqual(config['webapp']['port'], 8080)
|
||||
self.assertEqual(config['webapp']['listen_address'], '127.0.0.1')
|
||||
|
|
|
@ -54,14 +54,17 @@ class Cache(object):
|
|||
class WebApp(threading.Thread):
|
||||
log = logging.getLogger("nodepool.WebApp")
|
||||
|
||||
def __init__(self, nodepool, port=8005, cache_expiry=1):
|
||||
def __init__(self, nodepool, port=8005, listen_address='0.0.0.0',
|
||||
cache_expiry=1):
|
||||
threading.Thread.__init__(self)
|
||||
self.nodepool = nodepool
|
||||
self.port = port
|
||||
self.listen_address = listen_address
|
||||
self.cache = Cache(cache_expiry)
|
||||
self.cache_expiry = cache_expiry
|
||||
self.daemon = True
|
||||
self.server = httpserver.serve(dec.wsgify(self.app), host='0.0.0.0',
|
||||
self.server = httpserver.serve(dec.wsgify(self.app),
|
||||
host=self.listen_address,
|
||||
port=self.port, start_loop=False)
|
||||
|
||||
def run(self):
|
||||
|
|
Loading…
Reference in New Issue