[Kimchi-devel] [PATCH] [Kimchi] Use Websocket facilities from WoK

dhbarboza82 at gmail.com dhbarboza82 at gmail.com
Fri Mar 10 13:21:32 UTC 2017


From: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>

The 'websocket' module was moved from Kimchi to WoK to allow
WoK and all its plug-ins to have websocket capabilities.

This patch removes the existing websocket module inside
Kimchi and updates all the references to use the WoK
module instead.

The initialization of the ws_proxy was also removed from
root.py - this process is also being done by WoK now.

Signed-off-by: Daniel Henrique Barboza <danielhb at linux.vnet.ibm.com>
---
 contrib/DEBIAN/control.in     |   1 -
 contrib/kimchi.spec.fedora.in |   1 -
 contrib/kimchi.spec.suse.in   |   1 -
 docs/fedora-deps.md           |   2 +-
 docs/opensuse-deps.md         |   3 +-
 docs/ubuntu-deps.md           |   2 +-
 model/vms.py                  |   2 +-
 root.py                       |   4 +-
 websocket.py                  | 121 ------------------------------------------
 9 files changed, 5 insertions(+), 132 deletions(-)
 delete mode 100644 websocket.py

diff --git a/contrib/DEBIAN/control.in b/contrib/DEBIAN/control.in
index 6cfd8ee..607b4a5 100644
--- a/contrib/DEBIAN/control.in
+++ b/contrib/DEBIAN/control.in
@@ -7,7 +7,6 @@ Depends: wok (>= 2.1.0),
          ginger-base,
          python-imaging,
          python-configobj,
-         websockify,
          novnc,
          python-jsonschema (>= 1.3.0),
          python-libvirt,
diff --git a/contrib/kimchi.spec.fedora.in b/contrib/kimchi.spec.fedora.in
index 3b33297..3822527 100644
--- a/contrib/kimchi.spec.fedora.in
+++ b/contrib/kimchi.spec.fedora.in
@@ -14,7 +14,6 @@ Requires:	gettext
 Requires:	libvirt
 Requires:	libvirt-python
 Requires:	libvirt-daemon-config-network
-Requires:	python-websockify
 Requires:	python-configobj
 Requires:	novnc
 Requires:	python-pillow
diff --git a/contrib/kimchi.spec.suse.in b/contrib/kimchi.spec.suse.in
index 94dc55e..7a89d6e 100644
--- a/contrib/kimchi.spec.suse.in
+++ b/contrib/kimchi.spec.suse.in
@@ -14,7 +14,6 @@ Requires:	gettext-tools
 Requires:	libvirt
 Requires:	libvirt-python
 Requires:	libvirt-daemon-config-network
-Requires:	python-websockify
 Requires:	python-configobj
 Requires:	novnc
 Requires:	python-Pillow
diff --git a/docs/fedora-deps.md b/docs/fedora-deps.md
index 65ad987..1506aa5 100644
--- a/docs/fedora-deps.md
+++ b/docs/fedora-deps.md
@@ -28,7 +28,7 @@ Runtime Dependencies
     $ sudo yum install libvirt-python libvirt libvirt-daemon-config-network \
                         qemu-kvm python-ethtool sos python-ipaddr nfs-utils \
                         iscsi-initiator-utils pyparted python-libguestfs \
-                        libguestfs-tools python-websockify novnc spice-html5 \
+                        libguestfs-tools novnc spice-html5 \
                         python-configobj python-magic python-paramiko \
                         python-pillow
 
diff --git a/docs/opensuse-deps.md b/docs/opensuse-deps.md
index 1c5fc23..995a842 100644
--- a/docs/opensuse-deps.md
+++ b/docs/opensuse-deps.md
@@ -33,8 +33,7 @@ Runtime Dependencies
                             python-ipaddr libvirt-daemon-config-network \
                             nfs-client open-iscsi python-parted \
                             python-libguestfs python-configobj guestfs-tools \
-                            python-websockify novnc python-magic \
-                            python-paramiko python-Pillow
+                            novnc python-magic python-paramiko python-Pillow
 
 Packages required for UI development
 ------------------------------------
diff --git a/docs/ubuntu-deps.md b/docs/ubuntu-deps.md
index f88eb51..687a9f9 100644
--- a/docs/ubuntu-deps.md
+++ b/docs/ubuntu-deps.md
@@ -15,7 +15,7 @@ Build Dependencies
 Runtime Dependencies
 --------------------
 
-    $ sudo apt-get install python-configobj websockify novnc python-libvirt \
+    $ sudo apt-get install python-configobj novnc python-libvirt \
                             libvirt-bin nfs-common qemu-kvm python-parted \
                             python-ethtool sosreport python-ipaddr \
                             python-lxml open-iscsi python-guestfs \
diff --git a/model/vms.py b/model/vms.py
index e7ed7c2..6da4f3b 100644
--- a/model/vms.py
+++ b/model/vms.py
@@ -36,6 +36,7 @@ from lxml import etree, objectify
 from lxml.builder import E
 from xml.etree import ElementTree
 
+from wok import websocket
 from wok.asynctask import AsyncTask
 from wok.config import config
 from wok.exception import InvalidOperation, InvalidParameter
@@ -48,7 +49,6 @@ 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 websocket
 from wok.plugins.kimchi import serialconsole
 from wok.plugins.kimchi.config import READONLY_POOL_TYPE, get_kimchi_version
 from wok.plugins.kimchi.kvmusertests import UserTests
diff --git a/root.py b/root.py
index 5ba4f68..4f131e7 100644
--- a/root.py
+++ b/root.py
@@ -22,7 +22,7 @@ import json
 import os
 import tempfile
 
-from wok.plugins.kimchi import config, mockmodel, websocket
+from wok.plugins.kimchi import config, mockmodel
 from wok.plugins.kimchi.i18n import messages
 from wok.plugins.kimchi.control import sub_nodes
 from wok.plugins.kimchi.model import model as kimchiModel
@@ -59,8 +59,6 @@ class Kimchi(WokRoot):
             cherrypy.engine.subscribe('exit', remove_objectstore)
         else:
             self.model = kimchiModel.Model()
-            ws_proxy = websocket.new_ws_proxy()
-            cherrypy.engine.subscribe('exit', ws_proxy.terminate)
 
         dev_env = wok_options.environment != 'production'
         super(Kimchi, self).__init__(self.model, dev_env)
diff --git a/websocket.py b/websocket.py
deleted file mode 100644
index 6268c8a..0000000
--- a/websocket.py
+++ /dev/null
@@ -1,121 +0,0 @@
-#!/usr/bin/env python2
-#
-# Project Kimchi
-#
-# Copyright IBM Corp, 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, PluginPaths
-
-
-try:
-    from websockify.token_plugins import TokenFile
-    tokenFile = True
-except ImportError:
-    tokenFile = False
-
-try:
-    from websockify import ProxyRequestHandler as request_proxy
-except:
-    from websockify import WebSocketProxy as request_proxy
-
-
-WS_TOKENS_DIR = os.path.join(PluginPaths('kimchi').state_dir, 'ws-tokens')
-
-
-class CustomHandler(request_proxy):
-
-    def get_target(self, target_plugin, path):
-        if issubclass(CustomHandler, object):
-            target = super(CustomHandler, self).get_target(target_plugin,
-                                                           path)
-        else:
-            target = request_proxy.get_target(self, target_plugin, path)
-
-        if target[0] == 'unix_socket':
-            try:
-                self.server.unix_target = target[1]
-            except:
-                self.unix_target = target[1]
-        else:
-            try:
-                self.server.unix_target = None
-            except:
-                self.unix_target = None
-        return target
-
-
-def new_ws_proxy():
-    try:
-        os.makedirs(WS_TOKENS_DIR, mode=0755)
-    except OSError as e:
-        if e.errno == errno.EEXIST:
-            pass
-
-    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():
-        try:
-            server = WebSocketProxy(RequestHandlerClass=CustomHandler,
-                                    **params)
-        except TypeError:
-            server = CustomHandler(**params)
-
-        server.start_server()
-
-    proc = Process(target=start_proxy)
-    proc.start()
-    return proc
-
-
-def add_proxy_token(name, port, is_unix_socket=False):
-    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('=')
-        if is_unix_socket:
-            f.write('%s: unix_socket:%s' % (name.encode('utf-8'), port))
-        else:
-            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
-- 
2.9.3



More information about the Kimchi-devel mailing list