mirror of
https://github.com/retspen/webvirtcloud
synced 2026-11-11 12:46:49 +00:00
refactor(instances): one way to reach a VM, its console and its devices
The .vv console file is built from the VM found by its UUID, with the console page's getters, instead of looking the VM up by name five times; a console without a listen address or password now gives 127.0.0.1 and an empty password instead of "None". Removed methods nothing calls: the by-name getters and power methods of wvmInstances, managed save, the vCPU mode getter (it read the wrong attribute), the old NIC editor and its bridge lookup. CD-ROM media and NIC hotplug use _definitions() like the other device edits, the disk editor takes the bus prefix from util.vol_dev_type, and an unreadable disk is logged, not printed.
This commit is contained in:
parent
0ea5f0ff18
commit
f1e83455e4
5 changed files with 31 additions and 201 deletions
|
|
@ -52,17 +52,20 @@ class CanOpenConsoleTestCase(TestCase):
|
|||
|
||||
def test_owner_can_download_vv_file(self):
|
||||
self.client.force_login(self.owner)
|
||||
with patch("instances.views.wvmInstances") as mock_conn_cls, patch("instances.models.wvmInstance") as wvm:
|
||||
wvm.return_value.instance.name.return_value = "cons-vm"
|
||||
conn = mock_conn_cls.return_value
|
||||
conn.graphics_type.return_value = "vnc"
|
||||
conn.graphics_listen.return_value = "127.0.0.1"
|
||||
conn.graphics_port.return_value = "5900"
|
||||
conn.domain_name.return_value = "cons-vm"
|
||||
conn.graphics_passwd.return_value = "secret"
|
||||
with patch("instances.models.wvmInstance") as wvm:
|
||||
proxy = wvm.return_value.cached_reads.return_value.__enter__.return_value
|
||||
proxy.instance.name.return_value = "cons-vm"
|
||||
proxy.host = "192.0.2.7"
|
||||
proxy.get_console_type.return_value = "vnc"
|
||||
proxy.get_console_listener_addr.return_value = "0.0.0.0"
|
||||
proxy.get_console_port.return_value = "5900"
|
||||
proxy.get_console_passwd.return_value = "secret"
|
||||
res = self.client.get(reverse("instances:getvvfile", args=[self.instance.id]))
|
||||
self.assertEqual(res.status_code, 200)
|
||||
self.assertIn(b"[virt-viewer]", res.content)
|
||||
# the VM found by its UUID; a console on all addresses is reached through the host
|
||||
for line in (b"type=vnc", b"host=192.0.2.7", b"port=5900", b"title=cons-vm", b"password=secret"):
|
||||
self.assertIn(line + b"\n", res.content)
|
||||
|
||||
def test_owner_can_get_vdi_url(self):
|
||||
self.client.force_login(self.owner)
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ from logs.views import addlogmsg
|
|||
from webvirtcloud.middleware import error_text
|
||||
from vrtManager import util
|
||||
from vrtManager.create import wvmCreate
|
||||
from vrtManager.instance import USAGE_MAX_WINDOW, wvmInstances
|
||||
from vrtManager.instance import USAGE_MAX_WINDOW
|
||||
from vrtManager.interface import wvmInterface
|
||||
from vrtManager.storage import wvmStorage
|
||||
from vrtManager.util import randomPasswd
|
||||
|
|
@ -2046,15 +2046,6 @@ def getvvfile(request, pk):
|
|||
# The .vv file contains the VNC password: same rule as the console.
|
||||
if not utils.can_open_console(request.user, instance):
|
||||
raise PermissionDenied
|
||||
conn = wvmInstances(
|
||||
instance.compute.hostname,
|
||||
instance.compute.login,
|
||||
instance.compute.password,
|
||||
instance.compute.type,
|
||||
)
|
||||
|
||||
# The host's current name for this UUID; the stored name may be stale.
|
||||
name = instance.proxy.instance.name()
|
||||
msg = _("Send console.vv file")
|
||||
addlogmsg(request.user.username, instance.compute.name, instance.name, msg)
|
||||
response = HttpResponse(
|
||||
|
|
@ -2064,15 +2055,15 @@ def getvvfile(request, pk):
|
|||
reason=None,
|
||||
charset="utf-8",
|
||||
)
|
||||
response.writelines("[virt-viewer]\n")
|
||||
response.writelines("type=" + conn.graphics_type(name) + "\n")
|
||||
if conn.graphics_listen(name) == "0.0.0.0":
|
||||
response.writelines("host=" + conn.host + "\n")
|
||||
else:
|
||||
response.writelines("host=" + conn.graphics_listen(name) + "\n")
|
||||
response.writelines("port=" + conn.graphics_port(name) + "\n")
|
||||
response.writelines("title=" + conn.domain_name(name) + "\n")
|
||||
response.writelines("password=" + conn.graphics_passwd(name) + "\n")
|
||||
# the VM found by its UUID; the stored name may be stale
|
||||
with instance.proxy.cached_reads() as proxy:
|
||||
listen = proxy.get_console_listener_addr()
|
||||
response.writelines("[virt-viewer]\n")
|
||||
response.writelines(f"type={proxy.get_console_type()}\n")
|
||||
response.writelines(f"host={proxy.host if listen == '0.0.0.0' else listen}\n")
|
||||
response.writelines(f"port={proxy.get_console_port()}\n")
|
||||
response.writelines(f"title={proxy.instance.name()}\n")
|
||||
response.writelines(f"password={proxy.get_console_passwd() or ''}\n")
|
||||
response.writelines("enable-usbredir=1\n")
|
||||
response.writelines("disable-effects=all\n")
|
||||
response.writelines("secure-attention=ctrl+alt+ins\n")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue