diff --git a/instances/templates/instance.html b/instances/templates/instance.html index 2b73c0a..f6dc355 100644 --- a/instances/templates/instance.html +++ b/instances/templates/instance.html @@ -712,6 +712,27 @@ +

{% trans "To set console listen address, shutdown the instance." %}

+
{% csrf_token %} +
+ +
+ +
+
+ {% ifequal status 5 %} + + {% else %} + + {% endifequal %} +
+
+

{% trans "To create console password, shutdown the instance." %}

{% csrf_token %}
@@ -1273,6 +1294,13 @@ $("#console_select_type option[value='" + console_type + "']").prop('selected', true); } }); + $(document).ready(function () { + // set current console listen address or fall back to default + var console_listen_address = "{{ console_listen_address }}" + if (console_listen_address != '') { + $("#console_select_listen_address option[value='" + console_listen_address + "']").prop('selected', true); + } + }); {% if not request.user.is_superuser %} $('#select_clone_name').on('change', function () { update_clone_disk_name($(this).val()); diff --git a/instances/views.py b/instances/views.py index 0d6dfab..436110f 100644 --- a/instances/views.py +++ b/instances/views.py @@ -22,7 +22,6 @@ from vrtManager.connection import connection_manager from vrtManager.create import wvmCreate from vrtManager.util import randomPasswd from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE -from webvirtcloud.settings import QEMU_KEYMAPS, QEMU_CONSOLE_TYPES from logs.views import addlogmsg from django.conf import settings @@ -186,8 +185,9 @@ def instance(request, compute_id, vname): computes_count = computes.count() users = User.objects.all().order_by('username') publickeys = UserSSHKey.objects.filter(user_id=request.user.id) - keymaps = QEMU_KEYMAPS - console_types = QEMU_CONSOLE_TYPES + keymaps = settings.QEMU_KEYMAPS + console_types = settings.QEMU_CONSOLE_TYPES + console_listen_addresses = settings.QEMU_CONSOLE_LISTEN_ADDRESSES try: userinstace = UserInstance.objects.get(instance__compute_id=compute_id, instance__name=vname, @@ -330,6 +330,7 @@ def instance(request, compute_id, vname): console_type = conn.get_console_type() console_port = conn.get_console_port() console_keymap = conn.get_console_keymap() + console_listen_address = conn.get_console_listen_addr() snapshots = sorted(conn.get_snapshot(), reverse=True) inst_xml = conn._XMLDesc(VIR_DOMAIN_XML_SECURE) has_managed_save_image = conn.get_managed_save_image() @@ -617,6 +618,13 @@ def instance(request, compute_id, vname): msg = _("Set VNC type") addlogmsg(request.user.username, instance.name, msg) return HttpResponseRedirect(request.get_full_path() + '#vncsettings') + + if 'set_console_listen_address' in request.POST: + console_type = request.POST.get('console_listen_address', '') + conn.set_console_listen_addr(console_type) + msg = _("Set VNC listen address") + addlogmsg(request.user.username, instance.name, msg) + return HttpResponseRedirect(request.get_full_path() + '#vncsettings') if request.user.is_superuser: if 'migrate' in request.POST: diff --git a/vrtManager/instance.py b/vrtManager/instance.py index 14feab1..72144e6 100644 --- a/vrtManager/instance.py +++ b/vrtManager/instance.py @@ -455,6 +455,32 @@ class wvmInstance(wvmConnect): return "127.0.0.1" return listen_addr + def set_console_listen_addr(self, listen_addr): + xml = self._XMLDesc(VIR_DOMAIN_XML_SECURE) + root = ElementTree.fromstring(xml) + console_type = self.get_console_type() + try: + graphic = root.find("devices/graphics[@type='%s']" % console_type) + except SyntaxError: + # Little fix for old version ElementTree + graphic = root.find("devices/graphics") + if graphic is None: + return False + listen = graphic.find("listen[@type='address']") + if listen is None: + return False + if listen_addr: + graphic.set("listen", listen_addr) + listen.set("address", listen_addr) + else: + try: + graphic.attrib.pop("listen") + listen.attrib.pop("address") + except: + pass + newxml = ElementTree.tostring(root) + return self._defineXML(newxml) + def get_console_socket(self): socket = util.get_xml_path(self._XMLDesc(0), "/domain/devices/graphics/@socket") diff --git a/webvirtcloud/settings.py.template b/webvirtcloud/settings.py.template index eb77e8b..b7ba1ea 100644 --- a/webvirtcloud/settings.py.template +++ b/webvirtcloud/settings.py.template @@ -106,6 +106,12 @@ QEMU_CONSOLE_TYPES = ['vnc', 'spice'] # default console type QEMU_CONSOLE_DEFAULT_TYPE = 'vnc' +# list of console listen addresses +QEMU_CONSOLE_LISTEN_ADDRESSES = ( + ('127.0.0.1', 'Localhost'), + ('0.0.0.0', 'All interfaces'), +) + # list taken from http://qemu.weilnetz.de/qemu-doc.html#sec_005finvocation QEMU_KEYMAPS = ['ar', 'da', 'de', 'de-ch', 'en-gb', 'en-us', 'es', 'et', 'fi', 'fo', 'fr', 'fr-be', 'fr-ca', 'fr-ch', 'hr', 'hu', 'is', 'it',