[Kimchi-devel] [PATCH WOK 1/2] Move vnc.py to Kimchi plugin

Paulo Ricardo Paz Vital pvital at linux.vnet.ibm.com
Thu Sep 17 19:32:02 UTC 2015


Reviewed-By: Paulo Vital <pvital at linux.vnet.ibm.com>

On Wed, 2015-09-16 at 14:44 -0300, Aline Manera wrote:
> vnc.py is related to noVNC configuration and should not be in wok
> framework.
> 
> Move it to Kimchi and adjust the imports and build process
> accordingly.
> 
> Signed-off-by: Aline Manera <alinefm at linux.vnet.ibm.com>
> ---
>  Makefile.am                                  |  2 -
>  contrib/wok.spec.fedora.in                   |  1 -
>  contrib/wok.spec.suse.in                     |  1 -
>  plugins/kimchi/Makefile.am                   |  4 +-
>  plugins/kimchi/contrib/kimchi.spec.fedora.in |  3 +-
>  plugins/kimchi/contrib/kimchi.spec.suse.in   |  4 +-
>  plugins/kimchi/model/vms.py                  |  2 +-
>  plugins/kimchi/root.py                       |  2 +-
>  plugins/kimchi/vnc.py                        | 77
> ++++++++++++++++++++++++++++
>  src/wok/vnc.py                               | 77 ------------------
> ----------
>  10 files changed, 86 insertions(+), 87 deletions(-)
>  create mode 100644 plugins/kimchi/vnc.py
>  delete mode 100644 src/wok/vnc.py
> 
> diff --git a/Makefile.am b/Makefile.am
> index ab5b7d8..c7914d0 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -69,7 +69,6 @@ all-local:
> 
>  install-deb: install
>  	cp -R $(top_srcdir)/contrib/DEBIAN $(DESTDIR)/
> -	mkdir -p $(DESTDIR)/var/lib/wok/vnc-tokens
>  	touch $(DESTDIR)/var/lib/wok/objectstore
>  	$(MKDIR_P) $(DESTDIR)/etc/init
>  	$(MKDIR_P) $(DESTDIR)/usr/lib/firewalld/services
> @@ -124,7 +123,6 @@ install-data-local:
>  		mkdir -p $(DESTDIR)/usr/lib/firewalld/services/; \
>  		$(INSTALL_DATA) src/firewalld.xml
> $(DESTDIR)/usr/lib/firewalld/services/wokd.xml; \
>  	fi; \
> -	mkdir -p $(DESTDIR)/var/lib/wok/vnc-tokens
>  	touch $(DESTDIR)/var/lib/wok/objectstore
>  	mkdir -p $(DESTDIR)/var/log/wok/
>  	touch $(DESTDIR)/var/log/wok/wok-access.log
> diff --git a/contrib/wok.spec.fedora.in b/contrib/wok.spec.fedora.in
> index 30319a9..037e705 100644
> --- a/contrib/wok.spec.fedora.in
> +++ b/contrib/wok.spec.fedora.in
> @@ -127,7 +127,6 @@ rm -rf $RPM_BUILD_ROOT
> 
>  %if 0%{?with_systemd}
>  %{_sysconfdir}/nginx/conf.d/wok.conf
> -%{_sharedstatedir}/wok/vnc-tokens/
>  %{_sharedstatedir}/wok/
>  %{_localstatedir}/log/wok/*
>  %{_localstatedir}/log/wok/
> diff --git a/contrib/wok.spec.suse.in b/contrib/wok.spec.suse.in
> index 63bdce3..6bff10a 100644
> --- a/contrib/wok.spec.suse.in
> +++ b/contrib/wok.spec.suse.in
> @@ -93,7 +93,6 @@ rm -rf $RPM_BUILD_ROOT
>  %{_sysconfdir}/wok/
>  %{_sysconfdir}/nginx/conf.d/wok.conf.in
>  %{_sysconfdir}/nginx/conf.d/wok.conf
> -%{_var}/lib/wok/vnc-tokens/
>  %{_var}/lib/wok/
>  %{_localstatedir}/log/wok/*
>  %{_localstatedir}/log/wok/
> diff --git a/plugins/kimchi/Makefile.am b/plugins/kimchi/Makefile.am
> index faef341..49c835e 100644
> --- a/plugins/kimchi/Makefile.am
> +++ b/plugins/kimchi/Makefile.am
> @@ -98,6 +98,7 @@ config.py: config.py.in Makefile
> 
>  install-deb: install
>  	cp -R $(top_srcdir)/contrib/DEBIAN $(DESTDIR)/
> +	mkdir -p $(DESTDIR)/var/lib/kimchi/vnc-tokens
>  	mkdir -p $(DESTDIR)/var/lib/kimchi/debugreports
>  	mkdir -p $(DESTDIR)/var/lib/kimchi/screenshots
>  	mkdir -p $(DESTDIR)/var/lib/kimchi/isos
> @@ -138,7 +139,8 @@ ChangeLog:
>  install-data-local:
>  	$(MKDIR_P) $(DESTDIR)$(kimchidir)
>  	$(INSTALL_DATA) API.json $(DESTDIR)$(kimchidir)/API.json
> -	mkdir -p
> $(DESTDIR)/var/lib/kimchi/{debugreports,screenshots,isos}
> +	mkdir -p $(DESTDIR)/var/lib/kimchi/vnc-tokens
> +	mkdir -p
> $(DESTDIR)/var/lib/kimchi/{debugreports,isos,screenshots}
> 
>  uninstall-local:
>  	$(RM) $(DESTDIR)$(kimchidir)/API.json
> diff --git a/plugins/kimchi/contrib/kimchi.spec.fedora.in
> b/plugins/kimchi/contrib/kimchi.spec.fedora.in
> index 7a7a447..fa53980 100644
> --- a/plugins/kimchi/contrib/kimchi.spec.fedora.in
> +++ b/plugins/kimchi/contrib/kimchi.spec.fedora.in
> @@ -102,8 +102,9 @@ rm -rf $RPM_BUILD_ROOT
>  %{_sysconfdir}/kimchi/distros.d/gentoo.json
>  %{_sysconfdir}/kimchi/
>  %{_sharedstatedir}/kimchi/debugreports/
> -%{_sharedstatedir}/kimchi/screenshots/
>  %{_sharedstatedir}/kimchi/isos/
> +%{_sharedstatedir}/kimchi/screenshots/
> +%{_sharedstatedir}/kimchi/vnc-tokens/
>  %{_sharedstatedir}/kimchi/
> 
> 
> diff --git a/plugins/kimchi/contrib/kimchi.spec.suse.in
> b/plugins/kimchi/contrib/kimchi.spec.suse.in
> index 1ab2e5f..9b55c7b 100644
> --- a/plugins/kimchi/contrib/kimchi.spec.suse.in
> +++ b/plugins/kimchi/contrib/kimchi.spec.suse.in
> @@ -89,12 +89,12 @@ rm -rf $RPM_BUILD_ROOT
>  %{_sysconfdir}/kimchi/distros.d/gentoo.json
>  %{_sysconfdir}/kimchi/
>  %{_var}/lib/kimchi/debugreports/
> -%{_var}/lib/kimchi/screenshots/
>  %{_var}/lib/kimchi/isos/
> +%{_var}/lib/kimchi/screenshots/
> +%{_var}/lib/kimchi/vnc-tokens/
>  %{_var}/lib/kimchi/
> 
> 
> -
>  %changelog
>  * Thu Jun 18 2015 Lucio Correia <luciojhc at linux.vnet.ibm.com> 1.6
>  - Run kimchi as a plugin
> diff --git a/plugins/kimchi/model/vms.py
> b/plugins/kimchi/model/vms.py
> index 36e3cd2..f446e80 100644
> --- a/plugins/kimchi/model/vms.py
> +++ b/plugins/kimchi/model/vms.py
> @@ -28,7 +28,6 @@ from lxml import etree, objectify
>  from lxml.builder import E
>  from xml.etree import ElementTree
> 
> -from wok import vnc
>  from wok.config import config
>  from wok.exception import InvalidOperation, InvalidParameter
>  from wok.exception import NotFoundError, OperationFailed
> @@ -39,6 +38,7 @@ from wok.xmlutils.utils import xpath_get_text,
> xml_item_update
>  from wok.xmlutils.utils import dictize
> 
>  from .. import model
> +from .. import vnc
>  from ..config import READONLY_POOL_TYPE
>  from ..kvmusertests import UserTests
>  from ..screenshot import VMScreenshot
> diff --git a/plugins/kimchi/root.py b/plugins/kimchi/root.py
> index fb2f966..1e2bfc7 100644
> --- a/plugins/kimchi/root.py
> +++ b/plugins/kimchi/root.py
> @@ -21,12 +21,12 @@ import json
>  import os
>  import cherrypy
> 
> -from wok import vnc
>  from wok.i18n import messages
>  from wok.root import WokRoot
> 
>  import config
>  import mockmodel
> +import vnc
>  from control import sub_nodes
>  from model import model as kimchiModel
> 
> diff --git a/plugins/kimchi/vnc.py b/plugins/kimchi/vnc.py
> new file mode 100644
> index 0000000..2532449
> --- /dev/null
> +++ b/plugins/kimchi/vnc.py
> @@ -0,0 +1,77 @@
> +#!/usr/bin/env python2
> +#
> +# Project Kimchi
> +#
> +# Copyright IBM, Corp. 2013-2015
> +#
> +# 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
> +
> +
> +WS_TOKENS_DIR = '/var/lib/wok/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 = {'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}
> +
> +    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/src/wok/vnc.py b/src/wok/vnc.py
> deleted file mode 100644
> index 2532449..0000000
> --- a/src/wok/vnc.py
> +++ /dev/null
> @@ -1,77 +0,0 @@
> -#!/usr/bin/env python2
> -#
> -# Project Kimchi
> -#
> -# Copyright IBM, Corp. 2013-2015
> -#
> -# 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
> -
> -
> -WS_TOKENS_DIR = '/var/lib/wok/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 = {'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}
> -
> -    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




More information about the Kimchi-devel mailing list