[PATCH v3 1/4] Move configuration parsing to config.py

The configruation is also needed for other code except starting kimchi server. So it should be moved to a separate module, config.py. Then the configuration can be accessed directly by importing config module. Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com> --- src/kimchi/config.py.in | 24 ++++++++++++++++++++++++ src/kimchid.in | 20 +------------------- 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index f3c408a..72308ff 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -27,6 +27,7 @@ import os import platform +from ConfigParser import SafeConfigParser from glob import iglob @@ -166,5 +167,28 @@ def get_plugin_tab_xml(name): return os.path.join(_get_plugin_ui_dir(name), 'config/tab-ext.xml') +def _get_config(): + config = SafeConfigParser() + config.add_section("server") + config.set("server", "host", "0.0.0.0") + config.set("server", "port", "8000") + config.set("server", "ssl_port", "8001") + config.set("server", "ssl_cert", "") + config.set("server", "ssl_key", "") + config.set("server", "environment", "development") + config.add_section("logging") + config.set("logging", "log_dir", get_default_log_dir()) + config.set("logging", "log_level", DEFAULT_LOG_LEVEL) + + if os.path.exists(CONFIG_FILE): + config.read(CONFIG_FILE) + return config + + +CONFIG_FILE = "%s/kimchi.conf" % get_config_dir() +DEFAULT_LOG_LEVEL = "debug" +config = _get_config() + + if __name__ == '__main__': print get_prefix() diff --git a/src/kimchid.in b/src/kimchid.in index 7865713..548fa52 100644 --- a/src/kimchid.in +++ b/src/kimchid.in @@ -33,31 +33,13 @@ import kimchi.config if kimchi.config.without_installation(): sys.path.append(kimchi.config.get_prefix()) -from ConfigParser import SafeConfigParser +from kimchi.config import config from optparse import OptionParser ACCESS_LOG = "kimchi-access.log" ERROR_LOG = "kimchi-error.log" -CONFIG_FILE = "%s/kimchi.conf" % kimchi.config.get_config_dir() -DEFAULT_LOG_DIR = kimchi.config.get_default_log_dir() -DEFAULT_LOG_LEVEL = "debug" def main(options): - config = SafeConfigParser() - config.add_section("server") - config.set("server", "host", "0.0.0.0") - config.set("server", "port", "8000") - config.set("server", "ssl_port", "8001") - config.set("server", "ssl_cert", "") - config.set("server", "ssl_key", "") - config.set("server", "environment", "development") - config.add_section("logging") - config.set("logging", "log_dir", DEFAULT_LOG_DIR) - config.set("logging", "log_level", DEFAULT_LOG_LEVEL) - - if os.path.exists(CONFIG_FILE): - config.read(CONFIG_FILE) - host = config.get("server", "host") port = config.get("server", "port") ssl_port = config.get("server", "ssl_port") -- 1.8.4.2

We are going to use one proxy instance to forward all vm's vnc traffics. The proxy instance listens on a fixed port instead of a random one. This patch makes the port configurable and exported to client by adding it to the response of '/config'. Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi.conf.in | 4 ++++ src/kimchi/config.py.in | 2 ++ src/kimchi/control/config.py | 4 +++- 4 files changed, 10 insertions(+), 1 deletion(-) diff --git a/docs/API.md b/docs/API.md index 0013e86..4d7bdff 100644 --- a/docs/API.md +++ b/docs/API.md @@ -432,6 +432,7 @@ Contains information about the application environment and configuration. * **GET**: Retrieve configuration information * http_port: The port number on which the server is listening + * vnc_proxy_port: Port for vnc's websocket proxy to listen on * **POST**: *See Configuration Actions* **Actions (POST):** diff --git a/src/kimchi.conf.in b/src/kimchi.conf.in index bf26c26..ac5a1f5 100644 --- a/src/kimchi.conf.in +++ b/src/kimchi.conf.in @@ -29,3 +29,7 @@ # Logging level: debug, info, warning, error or critical #log_level = debug + +[novnc] +# Port for vnc's websocket proxy to listen on +#vnc_proxy_port = 64667 diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index 72308ff..e1319e3 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -179,6 +179,8 @@ def _get_config(): config.add_section("logging") config.set("logging", "log_dir", get_default_log_dir()) config.set("logging", "log_level", DEFAULT_LOG_LEVEL) + config.add_section("novnc") + config.set("novnc", "vnc_proxy_port", "64667") if os.path.exists(CONFIG_FILE): config.read(CONFIG_FILE) diff --git a/src/kimchi/control/config.py b/src/kimchi/control/config.py index 3630172..5186ddd 100644 --- a/src/kimchi/control/config.py +++ b/src/kimchi/control/config.py @@ -25,6 +25,7 @@ import cherrypy +from kimchi.config import config from kimchi.control.base import Collection, Resource @@ -38,7 +39,8 @@ class Config(Resource): @property def data(self): - return {'http_port': cherrypy.server.socket_port} + return {'http_port': cherrypy.server.socket_port, + 'vnc_proxy_port': config.get('novnc', 'vnc_proxy_port')} class Capabilities(Resource): -- 1.8.4.2

Please ignore this patch too. On 01/07/2014 04:54 PM, Mark Wu wrote:
We are going to use one proxy instance to forward all vm's vnc traffics. The proxy instance listens on a fixed port instead of a random one. This patch makes the port configurable and exported to client by adding it to the response of '/config'.
Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com> --- docs/API.md | 1 + src/kimchi.conf.in | 4 ++++ src/kimchi/config.py.in | 2 ++ src/kimchi/control/config.py | 4 +++- 4 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/docs/API.md b/docs/API.md index 0013e86..4d7bdff 100644 --- a/docs/API.md +++ b/docs/API.md @@ -432,6 +432,7 @@ Contains information about the application environment and configuration.
* **GET**: Retrieve configuration information * http_port: The port number on which the server is listening + * vnc_proxy_port: Port for vnc's websocket proxy to listen on * **POST**: *See Configuration Actions*
**Actions (POST):** diff --git a/src/kimchi.conf.in b/src/kimchi.conf.in index bf26c26..ac5a1f5 100644 --- a/src/kimchi.conf.in +++ b/src/kimchi.conf.in @@ -29,3 +29,7 @@
# Logging level: debug, info, warning, error or critical #log_level = debug + +[novnc] +# Port for vnc's websocket proxy to listen on +#vnc_proxy_port = 64667 diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index 72308ff..e1319e3 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -179,6 +179,8 @@ def _get_config(): config.add_section("logging") config.set("logging", "log_dir", get_default_log_dir()) config.set("logging", "log_level", DEFAULT_LOG_LEVEL) + config.add_section("novnc") + config.set("novnc", "vnc_proxy_port", "64667")
if os.path.exists(CONFIG_FILE): config.read(CONFIG_FILE) diff --git a/src/kimchi/control/config.py b/src/kimchi/control/config.py index 3630172..5186ddd 100644 --- a/src/kimchi/control/config.py +++ b/src/kimchi/control/config.py @@ -25,6 +25,7 @@ import cherrypy
+from kimchi.config import config from kimchi.control.base import Collection, Resource
@@ -38,7 +39,8 @@ class Config(Resource):
@property def data(self): - return {'http_port': cherrypy.server.socket_port} + return {'http_port': cherrypy.server.socket_port, + 'vnc_proxy_port': config.get('novnc', 'vnc_proxy_port')}
class Capabilities(Resource):

Please ignore this patch since the typo in commit message is not fixed. On 01/07/2014 04:54 PM, Mark Wu wrote:
The configruation is also needed for other code except starting kimchi server. So it should be moved to a separate module, config.py. Then the configuration can be accessed directly by importing config module.
Signed-off-by: Mark Wu <wudxw@linux.vnet.ibm.com> --- src/kimchi/config.py.in | 24 ++++++++++++++++++++++++ src/kimchid.in | 20 +------------------- 2 files changed, 25 insertions(+), 19 deletions(-)
diff --git a/src/kimchi/config.py.in b/src/kimchi/config.py.in index f3c408a..72308ff 100644 --- a/src/kimchi/config.py.in +++ b/src/kimchi/config.py.in @@ -27,6 +27,7 @@ import os import platform
+from ConfigParser import SafeConfigParser from glob import iglob
@@ -166,5 +167,28 @@ def get_plugin_tab_xml(name): return os.path.join(_get_plugin_ui_dir(name), 'config/tab-ext.xml')
+def _get_config(): + config = SafeConfigParser() + config.add_section("server") + config.set("server", "host", "0.0.0.0") + config.set("server", "port", "8000") + config.set("server", "ssl_port", "8001") + config.set("server", "ssl_cert", "") + config.set("server", "ssl_key", "") + config.set("server", "environment", "development") + config.add_section("logging") + config.set("logging", "log_dir", get_default_log_dir()) + config.set("logging", "log_level", DEFAULT_LOG_LEVEL) + + if os.path.exists(CONFIG_FILE): + config.read(CONFIG_FILE) + return config + + +CONFIG_FILE = "%s/kimchi.conf" % get_config_dir() +DEFAULT_LOG_LEVEL = "debug" +config = _get_config() + + if __name__ == '__main__': print get_prefix() diff --git a/src/kimchid.in b/src/kimchid.in index 7865713..548fa52 100644 --- a/src/kimchid.in +++ b/src/kimchid.in @@ -33,31 +33,13 @@ import kimchi.config if kimchi.config.without_installation(): sys.path.append(kimchi.config.get_prefix())
-from ConfigParser import SafeConfigParser +from kimchi.config import config from optparse import OptionParser
ACCESS_LOG = "kimchi-access.log" ERROR_LOG = "kimchi-error.log" -CONFIG_FILE = "%s/kimchi.conf" % kimchi.config.get_config_dir() -DEFAULT_LOG_DIR = kimchi.config.get_default_log_dir() -DEFAULT_LOG_LEVEL = "debug"
def main(options): - config = SafeConfigParser() - config.add_section("server") - config.set("server", "host", "0.0.0.0") - config.set("server", "port", "8000") - config.set("server", "ssl_port", "8001") - config.set("server", "ssl_cert", "") - config.set("server", "ssl_key", "") - config.set("server", "environment", "development") - config.add_section("logging") - config.set("logging", "log_dir", DEFAULT_LOG_DIR) - config.set("logging", "log_level", DEFAULT_LOG_LEVEL) - - if os.path.exists(CONFIG_FILE): - config.read(CONFIG_FILE) - host = config.get("server", "host") port = config.get("server", "port") ssl_port = config.get("server", "ssl_port")
participants (1)
-
Mark Wu