Revision b705748e snf-cyclades-app/synnefo/logic/servers.py
b/snf-cyclades-app/synnefo/logic/servers.py | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import logging |
31 | 31 |
|
32 |
from datetime import datetime |
|
32 | 33 |
from socket import getfqdn |
33 | 34 |
from functools import wraps |
34 | 35 |
from django import dispatch |
... | ... | |
42 | 43 |
from synnefo.logic import backend, ips, utils |
43 | 44 |
from synnefo.logic.backend_allocator import BackendAllocator |
44 | 45 |
from synnefo.db.models import (NetworkInterface, VirtualMachine, |
45 |
VirtualMachineMetadata, IPAddressLog, Network) |
|
46 |
VirtualMachineMetadata, IPAddressLog, Network, |
|
47 |
pooled_rapi_client) |
|
46 | 48 |
from vncauthproxy.client import request_forwarding as request_vnc_forwarding |
47 | 49 |
from synnefo.logic import rapi |
48 | 50 |
|
... | ... | |
384 | 386 |
""" |
385 | 387 |
log.info("Get console VM %s, type %s", vm, console_type) |
386 | 388 |
|
387 |
# Use RAPI to get VNC console information for this instance |
|
388 | 389 |
if vm.operstate != "STARTED": |
389 | 390 |
raise faults.BadRequest('Server not in ACTIVE state.') |
390 | 391 |
|
391 |
if settings.TEST: |
|
392 |
console_data = {'kind': 'vnc', 'host': 'ganeti_node', 'port': 1000} |
|
393 |
else: |
|
394 |
console_data = backend.get_instance_console(vm) |
|
395 |
|
|
396 |
if console_data['kind'] != 'vnc': |
|
397 |
message = 'got console of kind %s, not "vnc"' % console_data['kind'] |
|
398 |
raise faults.ServiceUnavailable(message) |
|
392 |
# Use RAPI to get VNC console information for this instance |
|
393 |
# RAPI GetInstanceConsole() returns endpoints to the vnc_bind_address, |
|
394 |
# which is a cluster-wide setting, either 0.0.0.0 or 127.0.0.1, and pretty |
|
395 |
# useless (see #783). |
|
396 |
# |
|
397 |
# Until this is fixed on the Ganeti side, construct a console info reply |
|
398 |
# directly. |
|
399 |
# |
|
400 |
# WARNING: This assumes that VNC runs on port network_port on |
|
401 |
# the instance's primary node, and is probably |
|
402 |
# hypervisor-specific. |
|
403 |
def get_console_data(i): |
|
404 |
return {"kind": "vnc", |
|
405 |
"host": i["pnode"], |
|
406 |
"port": i["network_port"]} |
|
407 |
with pooled_rapi_client(vm) as c: |
|
408 |
i = c.GetInstance(vm.backend_vm_id) |
|
409 |
console_data = get_console_data(i) |
|
410 |
|
|
411 |
if vm.backend.hypervisor == "kvm" and i['hvparams']['serial_console']: |
|
412 |
raise Exception("hv parameter serial_console cannot be true") |
|
413 |
|
|
414 |
# Check that the instance is really running |
|
415 |
if not i["oper_state"]: |
|
416 |
log.warning("VM '%s' is marked as '%s' in DB while DOWN in Ganeti", |
|
417 |
vm.id, vm.operstate) |
|
418 |
# Instance is not running. Mock a shutdown job to sync DB |
|
419 |
backend.process_op_status(vm, etime=datetime.now(), jobid=0, |
|
420 |
opcode="OP_INSTANCE_SHUTDOWN", |
|
421 |
status="success", |
|
422 |
logmsg="Reconciliation simulated event") |
|
423 |
raise faults.BadRequest('Server not in ACTIVE state.') |
|
399 | 424 |
|
400 | 425 |
# Let vncauthproxy decide on the source port. |
401 | 426 |
# The alternative: static allocation, e.g. |
... | ... | |
405 | 430 |
dport = console_data['port'] |
406 | 431 |
password = util.random_password() |
407 | 432 |
|
408 |
if settings.TEST: |
|
409 |
fwd = {'source_port': 1234, 'status': 'OK'} |
|
410 |
else: |
|
411 |
vnc_extra_opts = settings.CYCLADES_VNCAUTHPROXY_OPTS |
|
412 |
fwd = request_vnc_forwarding(sport, daddr, dport, password, |
|
413 |
**vnc_extra_opts) |
|
433 |
vnc_extra_opts = settings.CYCLADES_VNCAUTHPROXY_OPTS |
|
434 |
fwd = request_vnc_forwarding(sport, daddr, dport, password, |
|
435 |
**vnc_extra_opts) |
|
414 | 436 |
|
415 | 437 |
if fwd['status'] != "OK": |
416 | 438 |
raise faults.ServiceUnavailable('vncauthproxy returned error status') |
417 | 439 |
|
418 | 440 |
# Verify that the VNC server settings haven't changed |
419 |
if not settings.TEST: |
|
420 |
if console_data != backend.get_instance_console(vm): |
|
421 |
raise faults.ServiceUnavailable('VNC Server settings changed.') |
|
441 |
with pooled_rapi_client(vm) as c: |
|
442 |
i = c.GetInstance(vm.backend_vm_id) |
|
443 |
if get_console_data(i) != console_data: |
|
444 |
raise faults.ServiceUnavailable('VNC Server settings changed.') |
|
422 | 445 |
|
423 | 446 |
console = { |
424 | 447 |
'type': 'vnc', |
Also available in: Unified diff