From nobody Thu Mar 28 12:30:12 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of ovirt.org designates 66.187.230.42 as permitted sender) client-ip=66.187.230.42; envelope-from=kimchi-devel-bounces@ovirt.org; helo=lists.ovirt.org; Authentication-Results: mx.zoho.com; spf=pass (zoho.com: domain of ovirt.org designates 66.187.230.42 as permitted sender) smtp.mailfrom=kimchi-devel-bounces@ovirt.org; Return-Path: Received: from lists.ovirt.org (lists.phx.ovirt.org [66.187.230.42]) by mx.zohomail.com with SMTPS id 1487943978572847.2627089427489; Fri, 24 Feb 2017 05:46:18 -0800 (PST) Received: from lists.phx.ovirt.org (localhost [127.0.0.1]) by lists.ovirt.org (Postfix) with ESMTP id 5290882051B; Fri, 24 Feb 2017 13:46:17 +0000 (UTC) Received: from mail-qk0-f194.google.com (mail-qk0-f194.google.com [209.85.220.194]) by lists.ovirt.org (Postfix) with ESMTPS id AFED982051B for ; Fri, 24 Feb 2017 13:45:53 +0000 (UTC) Received: by mail-qk0-f194.google.com with SMTP id s186so2847656qkb.1 for ; Fri, 24 Feb 2017 05:45:53 -0800 (PST) Received: from arthas.ltc.br.ibm.com ([187.113.151.243]) by smtp.gmail.com with ESMTPSA id g66sm4789032qkb.55.2017.02.24.05.45.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 24 Feb 2017 05:45:52 -0800 (PST) X-Original-To: kimchi-devel@ovirt.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=ovz+sEhDVlqlbDj4jCrYsqeUecYvUa9sINEu4JPL/ps=; b=lTVIazjywUTE/ERrv2IW/gQKfLFZaFAAw3X+5h9hY8j7a8kWkgV5pqKfs8f1+koXf2 xlMK+kzNP9K7ji4L5i6TWl0WjaXSQIO+TcqgaeQskj8YsRb94MPQ2zdxj3t0kGB7CA0r K+PDq+unq4ZNaPf5YFDLtMMsUIM6uBrK2F4Y06vhZz1DXxlkWm3na3jeb8AiLJQQ3xJ9 +77huR59rj8YVZ5ViLtGnSLdiu3O2J3cW3KbC3ByEoA6KAaA/R2zAO7XM383zFDeV/ZB 8sqTbrTLRvHm5ulMPyC97+7uwOMb/TZ/c6i5OoS0ipsNT2FzSPQsidmEqL36sIxJgDJn 7/Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=ovz+sEhDVlqlbDj4jCrYsqeUecYvUa9sINEu4JPL/ps=; b=sR1MQE6JKH0dtd1zEOvV859XSr07rBjmUUdOJy6s01NJJp8TsZkzeGTph1eeqckdt+ iQsm4PEEyOThXedVq8lDIiTCOIS8iu3/QJ4vE/nRwkaOYJgwVZbbOPjEk3kAxdn5fsI9 Q46telo9ZeCJKp6cZka+wtlA18YUR2xa8Q/CtVr6KNqpvOqiJzMF8Ym6UVAhkNZ0uJ3y H9beFTJXDtsKiNObiRsn+v5XKf6poZeuV5PeJaBmVP2/NglaWgWs3dFoLV6zctdacGXF lmSefZ0Wurz6twD8Oj8s6uNWfjxp6KYa4pjy0MbAat2VKbCfd/8IWHJjZOb9dHAMA0CM wbjA== X-Gm-Message-State: AMke39mPuGKREZ5xiUSw3r4pyviV9p8WTc4JA1LqkZBW6S7lnBh2Fzo5yyy9XQQkm0ngZg== X-Received: by 10.55.159.71 with SMTP id i68mr2468863qke.134.1487943952739; Fri, 24 Feb 2017 05:45:52 -0800 (PST) From: To: Kimchi Devel Date: Fri, 24 Feb 2017 10:45:34 -0300 Message-Id: <20170224134534.8285-2-dhbarboza82@gmail.com> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170224134534.8285-1-dhbarboza82@gmail.com> References: <20170224134534.8285-1-dhbarboza82@gmail.com> Subject: [Kimchi-devel] [PATCH] [Kimchi] Use Websocket facilities from WoK X-BeenThere: kimchi-devel@ovirt.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Sender: kimchi-devel-bounces@ovirt.org Errors-To: kimchi-devel-bounces@ovirt.org X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" From: Daniel Henrique Barboza 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 --- model/vms.py | 2 +- root.py | 4 +- websocket.py | 121 -------------------------------------------------------= ---- 3 files changed, 2 insertions(+), 125 deletions(-) delete mode 100644 websocket.py 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 =20 +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, x= ml_item_insert from wok.xmlutils.utils import xml_item_remove, xml_item_update =20 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_versi= on 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 =20 -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 =3D kimchiModel.Model() - ws_proxy =3D websocket.new_ws_proxy() - cherrypy.engine.subscribe('exit', ws_proxy.terminate) =20 dev_env =3D wok_options.environment !=3D '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-130= 1 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 =3D True -except ImportError: - tokenFile =3D False - -try: - from websockify import ProxyRequestHandler as request_proxy -except: - from websockify import WebSocketProxy as request_proxy - - -WS_TOKENS_DIR =3D 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 =3D super(CustomHandler, self).get_target(target_plugin, - path) - else: - target =3D request_proxy.get_target(self, target_plugin, path) - - if target[0] =3D=3D 'unix_socket': - try: - self.server.unix_target =3D target[1] - except: - self.unix_target =3D target[1] - else: - try: - self.server.unix_target =3D None - except: - self.unix_target =3D None - return target - - -def new_ws_proxy(): - try: - os.makedirs(WS_TOKENS_DIR, mode=3D0755) - except OSError as e: - if e.errno =3D=3D errno.EEXIST: - pass - - params =3D {'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'] =3D WS_TOKENS_DIR - - # websockify 0.7 and higher: use TokenFile - else: - params['token_plugin'] =3D TokenFile(src=3DWS_TOKENS_DIR) - - def start_proxy(): - try: - server =3D WebSocketProxy(RequestHandlerClass=3DCustomHandler, - **params) - except TypeError: - server =3D CustomHandler(**params) - - server.start_server() - - proc =3D Process(target=3Dstart_proxy) - proc.start() - return proc - - -def add_proxy_token(name, port, is_unix_socket=3DFalse): - 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 =3D which is not safe in a URL query component. - So remove it when needed as base64 can work well without it. - """ - name =3D base64.urlsafe_b64encode(name).rstrip('=3D') - 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 --=20 2.9.3 _______________________________________________ Kimchi-devel mailing list Kimchi-devel@ovirt.org http://lists.ovirt.org/mailman/listinfo/kimchi-devel