1
0
Fork 0
mirror of https://github.com/retspen/webvirtcloud synced 2024-12-25 15:45:23 +00:00

add views/instance/settings/vnc listen addresses

configures console listen addresses for instance

update webvirtcloud/settings.py QEMU_CONSOLE_LISTEN_ADDRESSES according to template, before use

instances/views.py remove include webvirtcloud.settings (duplicate)
This commit is contained in:
Ing. Jan KRCMAR 2018-06-15 14:13:50 +02:00
parent 6b444075b6
commit 22d03da60f
4 changed files with 71 additions and 3 deletions

View file

@ -712,6 +712,27 @@
</div> </div>
</div> </div>
</form> </form>
<p>{% trans "To set console listen address, shutdown the instance." %}</p>
<form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group" id="console_listen_address_selection">
<label for="console_select_listen_address" class="col-sm-2 control-label">{% trans "Listen on" %}</label>
<div class="col-sm-6">
<select id="console_select_listen_address" class="form-control" name="console_listen_address">
<option value="" style="font-weight: bold">{% trans "please choose" %}</option>
{% for address, label in console_listen_addresses %}
<option value="{{ address }}">{{ label }}</option>
{% endfor %}
</select>
</div>
<div class="col-sm-3">
{% ifequal status 5 %}
<button type="submit" class="btn btn-success " name="set_console_listen_address">{% trans "Set" %}</button>
{% else %}
<button class="btn btn-success disabled" name="set_console_listen_address">{% trans "Set" %}</button>
{% endifequal %}
</div>
</div>
</form>
<p>{% trans "To create console password, shutdown the instance." %}</p> <p>{% trans "To create console password, shutdown the instance." %}</p>
<form class="form-horizontal" method="post" role="form">{% csrf_token %} <form class="form-horizontal" method="post" role="form">{% csrf_token %}
<div class="form-group"> <div class="form-group">
@ -1273,6 +1294,13 @@
$("#console_select_type option[value='" + console_type + "']").prop('selected', true); $("#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 %} {% if not request.user.is_superuser %}
$('#select_clone_name').on('change', function () { $('#select_clone_name').on('change', function () {
update_clone_disk_name($(this).val()); update_clone_disk_name($(this).val());

View file

@ -22,7 +22,6 @@ from vrtManager.connection import connection_manager
from vrtManager.create import wvmCreate from vrtManager.create import wvmCreate
from vrtManager.util import randomPasswd from vrtManager.util import randomPasswd
from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE from libvirt import libvirtError, VIR_DOMAIN_XML_SECURE
from webvirtcloud.settings import QEMU_KEYMAPS, QEMU_CONSOLE_TYPES
from logs.views import addlogmsg from logs.views import addlogmsg
from django.conf import settings from django.conf import settings
@ -186,8 +185,9 @@ def instance(request, compute_id, vname):
computes_count = computes.count() computes_count = computes.count()
users = User.objects.all().order_by('username') users = User.objects.all().order_by('username')
publickeys = UserSSHKey.objects.filter(user_id=request.user.id) publickeys = UserSSHKey.objects.filter(user_id=request.user.id)
keymaps = QEMU_KEYMAPS keymaps = settings.QEMU_KEYMAPS
console_types = QEMU_CONSOLE_TYPES console_types = settings.QEMU_CONSOLE_TYPES
console_listen_addresses = settings.QEMU_CONSOLE_LISTEN_ADDRESSES
try: try:
userinstace = UserInstance.objects.get(instance__compute_id=compute_id, userinstace = UserInstance.objects.get(instance__compute_id=compute_id,
instance__name=vname, instance__name=vname,
@ -330,6 +330,7 @@ def instance(request, compute_id, vname):
console_type = conn.get_console_type() console_type = conn.get_console_type()
console_port = conn.get_console_port() console_port = conn.get_console_port()
console_keymap = conn.get_console_keymap() console_keymap = conn.get_console_keymap()
console_listen_address = conn.get_console_listen_addr()
snapshots = sorted(conn.get_snapshot(), reverse=True) snapshots = sorted(conn.get_snapshot(), reverse=True)
inst_xml = conn._XMLDesc(VIR_DOMAIN_XML_SECURE) inst_xml = conn._XMLDesc(VIR_DOMAIN_XML_SECURE)
has_managed_save_image = conn.get_managed_save_image() has_managed_save_image = conn.get_managed_save_image()
@ -618,6 +619,13 @@ def instance(request, compute_id, vname):
addlogmsg(request.user.username, instance.name, msg) addlogmsg(request.user.username, instance.name, msg)
return HttpResponseRedirect(request.get_full_path() + '#vncsettings') 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 request.user.is_superuser:
if 'migrate' in request.POST: if 'migrate' in request.POST:
compute_id = request.POST.get('compute_id', '') compute_id = request.POST.get('compute_id', '')

View file

@ -455,6 +455,32 @@ class wvmInstance(wvmConnect):
return "127.0.0.1" return "127.0.0.1"
return listen_addr 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): def get_console_socket(self):
socket = util.get_xml_path(self._XMLDesc(0), socket = util.get_xml_path(self._XMLDesc(0),
"/domain/devices/graphics/@socket") "/domain/devices/graphics/@socket")

View file

@ -106,6 +106,12 @@ QEMU_CONSOLE_TYPES = ['vnc', 'spice']
# default console type # default console type
QEMU_CONSOLE_DEFAULT_TYPE = 'vnc' 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 # 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', 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', 'fo', 'fr', 'fr-be', 'fr-ca', 'fr-ch', 'hr', 'hu', 'is', 'it',