On 01/20/2016 10:24 AM, Ramon Medeiros wrote:
The lastest update of websockify changes how the class instantiate
WebSocketProxy.
Signed-off-by: Ramon Medeiros <ramonn(a)linux.vnet.ibm.com>
---
vnc.py | 27 +++++++++++++++++++++++----
1 file changed, 23 insertions(+), 4 deletions(-)
diff --git a/vnc.py b/vnc.py
index 1a2e59d..00069d5 100644
--- a/vnc.py
+++ b/vnc.py
@@ -21,12 +21,20 @@
import base64
import errno
import os
+
from multiprocessing import Process
from websockify import WebSocketProxy
from wok.config import config, paths, PluginPaths
+websockifyOld = False
+try:
+ from websockify.token_plugins import TokenFile
+except ImportError:
+ websockifyOld = True
+
+
I suggest to name the variable as 'tokenFile'
WS_TOKENS_DIR =
os.path.join(PluginPaths('kimchi').state_dir, 'vnc-tokens')
@@ -43,10 +51,21 @@ def new_ws_proxy():
cert = '%s/wok-cert.pem' % paths.conf_dir
key = '%s/wok-key.pem' % paths.conf_dir
- params = {'web': os.path.join(paths.ui_dir, 'pages/websockify'),
- 'listen_port': config.get('display',
'display_proxy_port'),
- 'target_cfg': WS_TOKENS_DIR,
- 'key': key, 'cert': cert, 'ssl_only': True}
+ # old websockify: do not use TokenFile
+ if websockifyOld:
+ params = {'web': os.path.join(paths.ui_dir,
'pages/websockify'),
+ 'listen_port': config.get('display',
'display_proxy_port'),
+ 'target_cfg': WS_TOKENS_DIR,
+ 'key': key, 'cert': cert, 'ssl_only': True}
+
+ # websockify 0.7 and higher: use TokenFile
+ else:
+ token_plugin = TokenFile(src=WS_TOKENS_DIR)
+
+ params = {'web': os.path.join(paths.ui_dir,
'pages/websockify'),
+ 'listen_port': config.get('display',
'display_proxy_port'),
+ 'token_plugin': token_plugin,
+ 'key': key, 'cert': cert, 'ssl_only': True}
Keep the common configuration in a single place and use the if/else to
only add the specific config according to websockify properties.
That way, we can easily identify the differences between websockify support.
def start_proxy():
server = WebSocketProxy(**params)