[Kimchi-devel] [PATCH v3] [Kimchi 1/8] Rename vnc.py to websocket.py
Jose Ricardo Ziviani
joserz at linux.vnet.ibm.com
Thu Feb 11 13:47:03 UTC 2016
- vnc.py doesn't reflect the source file, which starts the websockify
process and manages its security tokens.
Signed-off-by: Jose Ricardo Ziviani <joserz at linux.vnet.ibm.com>
---
Makefile.am | 4 +--
model/vms.py | 6 ++--
root.py | 6 ++--
vnc.py | 92 ------------------------------------------------------------
websocket.py | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
5 files changed, 100 insertions(+), 100 deletions(-)
delete mode 100644 vnc.py
create mode 100644 websocket.py
diff --git a/Makefile.am b/Makefile.am
index 8ee88f3..a2820b1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -111,7 +111,7 @@ config.py: config.py.in Makefile
install-deb: install
cp -R $(top_srcdir)/contrib/DEBIAN $(DESTDIR)/
mkdir -p $(DESTDIR)/$(localstatedir)/lib/kimchi
- mkdir -p $(DESTDIR)/$(localstatedir)/lib/kimchi/vnc-tokens
+ mkdir -p $(DESTDIR)/$(localstatedir)/lib/kimchi/ws-tokens
mkdir -p $(DESTDIR)/$(localstatedir)/lib/kimchi/screenshots
mkdir -p $(DESTDIR)/$(localstatedir)/lib/kimchi/isos
@@ -160,7 +160,7 @@ install-data-local:
$(MKDIR_P) $(DESTDIR)/$(localstatedir)/lib/kimchi/
$(MKDIR_P) $(DESTDIR)$(kimchidir)
$(INSTALL_DATA) API.json $(DESTDIR)$(kimchidir)/API.json
- mkdir -p $(DESTDIR)/$(localstatedir)/lib/kimchi/vnc-tokens
+ mkdir -p $(DESTDIR)/$(localstatedir)/lib/kimchi/ws-tokens
mkdir -p $(DESTDIR)/$(localstatedir)/lib/kimchi/screenshots
mkdir -p $(DESTDIR)/$(localstatedir)/lib/kimchi/isos
diff --git a/model/vms.py b/model/vms.py
index 593d73b..da341bf 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -45,7 +45,7 @@ from wok.xmlutils.utils import dictize, xpath_get_text, xml_item_insert
from wok.xmlutils.utils import xml_item_remove, xml_item_update
from wok.plugins.kimchi import model
-from wok.plugins.kimchi import vnc
+from wok.plugins.kimchi import websocket
from wok.plugins.kimchi.config import READONLY_POOL_TYPE, get_kimchi_version
from wok.plugins.kimchi.kvmusertests import UserTests
from wok.plugins.kimchi.model.config import CapabilitiesModel
@@ -1301,7 +1301,7 @@ class VMModel(object):
wok_log.error('Error deleting vm information from database: '
'%s', e.message)
- vnc.remove_proxy_token(name)
+ websocket.remove_proxy_token(name)
def start(self, name):
# make sure the ISO file has read permission
@@ -1400,7 +1400,7 @@ class VMModel(object):
# (type, listen, port, passwd, passwdValidTo)
graphics_port = self._vm_get_graphics(name)[2]
if graphics_port is not None:
- vnc.add_proxy_token(name.encode('utf-8'), graphics_port)
+ websocket.add_proxy_token(name.encode('utf-8'), graphics_port)
else:
raise OperationFailed("KCHVM0010E", {'name': name})
diff --git a/root.py b/root.py
index 4b56772..b5aa78b 100644
--- a/root.py
+++ b/root.py
@@ -21,7 +21,7 @@ import json
import os
import cherrypy
-from wok.plugins.kimchi import config, mockmodel, vnc
+from wok.plugins.kimchi import config, mockmodel, websocket
from wok.plugins.kimchi.i18n import messages
from wok.plugins.kimchi.control import sub_nodes
from wok.plugins.kimchi.model import model as kimchiModel
@@ -56,8 +56,8 @@ class Kimchi(WokRoot):
setattr(self, ident, node(self.model))
if isinstance(self.model, kimchiModel.Model):
- vnc_ws_proxy = vnc.new_ws_proxy()
- cherrypy.engine.subscribe('exit', vnc_ws_proxy.terminate)
+ ws_proxy = websocket.new_ws_proxy()
+ cherrypy.engine.subscribe('exit', ws_proxy.terminate)
self.api_schema = json.load(open(os.path.join(os.path.dirname(
os.path.abspath(__file__)), 'API.json')))
diff --git a/vnc.py b/vnc.py
deleted file mode 100644
index 4f94ab2..0000000
--- a/vnc.py
+++ /dev/null
@@ -1,92 +0,0 @@
-#!/usr/bin/env python2
-#
-# Project Kimchi
-#
-# Copyright IBM, Corp. 2013-2016
-#
-# This library is free software; you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation; either
-# version 2.1 of the License, or (at your option) any later version.
-#
-# This library is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-# Lesser General Public License for more details.
-#
-# You should have received a copy of the GNU Lesser General Public
-# License along with this library; if not, write to the Free Software
-# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-
-import base64
-import errno
-import os
-
-from multiprocessing import Process
-from websockify import WebSocketProxy
-
-from wok.config import config, paths, PluginPaths
-
-
-try:
- from websockify.token_plugins import TokenFile
- tokenFile = True
-except ImportError:
- tokenFile = False
-
-
-WS_TOKENS_DIR = os.path.join(PluginPaths('kimchi').state_dir, 'vnc-tokens')
-
-
-def new_ws_proxy():
- try:
- os.makedirs(WS_TOKENS_DIR, mode=0755)
- except OSError as e:
- if e.errno == errno.EEXIST:
- pass
-
- cert = config.get('server', 'ssl_cert')
- key = config.get('server', 'ssl_key')
- if not (cert and key):
- cert = '%s/wok-cert.pem' % paths.conf_dir
- key = '%s/wok-key.pem' % paths.conf_dir
-
- params = {'listen_host': '127.0.0.1',
- 'listen_port': config.get('server', 'websockets_port'),
- 'ssl_only': False}
-
- # old websockify: do not use TokenFile
- if not tokenFile:
- params['target_cfg'] = WS_TOKENS_DIR
-
- # websockify 0.7 and higher: use TokenFile
- else:
- params['token_plugin'] = TokenFile(src=WS_TOKENS_DIR)
-
- def start_proxy():
- server = WebSocketProxy(**params)
- server.start_server()
-
- proc = Process(target=start_proxy)
- proc.start()
- return proc
-
-
-def add_proxy_token(name, port):
- with open(os.path.join(WS_TOKENS_DIR, name), 'w') as f:
- """
- From python documentation base64.urlsafe_b64encode(s)
- substitutes - instead of + and _ instead of / in the
- standard Base64 alphabet, BUT the result can still
- contain = which is not safe in a URL query component.
- So remove it when needed as base64 can work well without it.
- """
- name = base64.urlsafe_b64encode(name).rstrip('=')
- f.write('%s: localhost:%s' % (name.encode('utf-8'), port))
-
-
-def remove_proxy_token(name):
- try:
- os.unlink(os.path.join(WS_TOKENS_DIR, name))
- except OSError:
- pass
diff --git a/websocket.py b/websocket.py
new file mode 100644
index 0000000..5b681af
--- /dev/null
+++ b/websocket.py
@@ -0,0 +1,92 @@
+#!/usr/bin/env python2
+#
+# Project Kimchi
+#
+# Copyright IBM, Corp. 2013-2016
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+import base64
+import errno
+import os
+
+from multiprocessing import Process
+from websockify import WebSocketProxy
+
+from wok.config import config, paths, PluginPaths
+
+
+try:
+ from websockify.token_plugins import TokenFile
+ tokenFile = True
+except ImportError:
+ tokenFile = False
+
+
+WS_TOKENS_DIR = os.path.join(PluginPaths('kimchi').state_dir, 'ws-tokens')
+
+
+def new_ws_proxy():
+ try:
+ os.makedirs(WS_TOKENS_DIR, mode=0755)
+ except OSError as e:
+ if e.errno == errno.EEXIST:
+ pass
+
+ cert = config.get('server', 'ssl_cert')
+ key = config.get('server', 'ssl_key')
+ if not (cert and key):
+ cert = '%s/wok-cert.pem' % paths.conf_dir
+ key = '%s/wok-key.pem' % paths.conf_dir
+
+ params = {'listen_host': '127.0.0.1',
+ 'listen_port': config.get('server', 'websockets_port'),
+ 'ssl_only': False}
+
+ # old websockify: do not use TokenFile
+ if not tokenFile:
+ params['target_cfg'] = WS_TOKENS_DIR
+
+ # websockify 0.7 and higher: use TokenFile
+ else:
+ params['token_plugin'] = TokenFile(src=WS_TOKENS_DIR)
+
+ def start_proxy():
+ server = WebSocketProxy(**params)
+ server.start_server()
+
+ proc = Process(target=start_proxy)
+ proc.start()
+ return proc
+
+
+def add_proxy_token(name, port):
+ with open(os.path.join(WS_TOKENS_DIR, name), 'w') as f:
+ """
+ From python documentation base64.urlsafe_b64encode(s)
+ substitutes - instead of + and _ instead of / in the
+ standard Base64 alphabet, BUT the result can still
+ contain = which is not safe in a URL query component.
+ So remove it when needed as base64 can work well without it.
+ """
+ name = base64.urlsafe_b64encode(name).rstrip('=')
+ f.write('%s: localhost:%s' % (name.encode('utf-8'), port))
+
+
+def remove_proxy_token(name):
+ try:
+ os.unlink(os.path.join(WS_TOKENS_DIR, name))
+ except OSError:
+ pass
--
1.9.1
More information about the Kimchi-devel
mailing list