From 8d010cacb520786fa12794801bc31eddd23b2af7 Mon Sep 17 00:00:00 2001 From: Anthony Young Date: Thu, 22 Dec 2011 21:39:21 +0000 Subject: Implements blueprint vnc-console-cleanup * Creates a unified way to access vnc consoles for xenserver and libvirt * Now supports both java and websocket clients * Removes nova-vncproxy - a replacement version of this (nova-novncproxy) can be found as described in vncconsole.rst * Adds nova-xvpvncproxy, which supports a java vnc client * Adds api extension to access java and novnc access_urls * Fixes proxy server to close/shutdown sockets more cleanly * Address style feedback * Use new-style extension format * Fix setup.py * utils.gen_uuid must be wrapped like str(utils.gen_uuid()) or it can't be serialized Change-Id: I5e42e2f160e8e3476269bd64b0e8aa77e66c918c --- nova/compute/api.py | 36 ++++++++++++++++++------------------ nova/compute/manager.py | 23 +++++++++++++++++++++-- 2 files changed, 39 insertions(+), 20 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/api.py b/nova/compute/api.py index 23bb4de82..012217584 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -50,7 +50,7 @@ LOG = logging.getLogger('nova.compute.api') FLAGS = flags.FLAGS flags.DECLARE('enable_zone_routing', 'nova.scheduler.api') -flags.DECLARE('vncproxy_topic', 'nova.vnc') +flags.DECLARE('consoleauth_topic', 'nova.consoleauth') flags.DEFINE_integer('find_host_timeout', 30, 'Timeout after NN seconds when looking for a host.') @@ -1571,23 +1571,23 @@ class API(base.Base): output['token'])} @wrap_check_policy - def get_vnc_console(self, context, instance): - """Get a url to a VNC Console.""" - output = self._call_compute_message('get_vnc_console', - context, - instance) - rpc.call(context, '%s' % FLAGS.vncproxy_topic, - {'method': 'authorize_vnc_console', - 'args': {'token': output['token'], - 'host': output['host'], - 'port': output['port']}}) - - # hostignore and portignore are compatibility params for noVNC - return {'url': '%s/vnc_auto.html?token=%s&host=%s&port=%s' % ( - FLAGS.vncproxy_url, - output['token'], - 'hostignore', - 'portignore')} + def get_vnc_console(self, context, instance, console_type): + """Get a url to an instance Console.""" + connect_info = self._call_compute_message('get_vnc_console', + context, + instance, + params={"console_type": console_type}) + + rpc.call(context, '%s' % FLAGS.consoleauth_topic, + {'method': 'authorize_console', + 'args': {'token': connect_info['token'], + 'console_type': console_type, + 'host': connect_info['host'], + 'port': connect_info['port'], + 'internal_access_path':\ + connect_info['internal_access_path']}}) + + return {'url': connect_info['access_url']} @wrap_check_policy def get_console_output(self, context, instance, tail_length=None): diff --git a/nova/compute/manager.py b/nova/compute/manager.py index c0ad9e626..999143153 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -59,6 +59,7 @@ from nova.notifier import api as notifier from nova import rpc from nova import utils from nova.virt import driver +from nova import vnc from nova import volume @@ -1490,12 +1491,30 @@ class ComputeManager(manager.SchedulerDependentManager): @exception.wrap_exception(notifier=notifier, publisher_id=publisher_id()) @wrap_instance_fault - def get_vnc_console(self, context, instance_uuid): + def get_vnc_console(self, context, instance_uuid, console_type): """Return connection information for a vnc console.""" context = context.elevated() LOG.debug(_("instance %s: getting vnc console"), instance_uuid) instance_ref = self.db.instance_get_by_uuid(context, instance_uuid) - return self.driver.get_vnc_console(instance_ref) + + token = str(utils.gen_uuid()) + + if console_type == 'novnc': + # For essex, novncproxy_base_url must include the full path + # including the html file (like http://myhost/vnc_auto.html) + access_url = '%s?token=%s' % (FLAGS.novncproxy_base_url, token) + elif console_type == 'xvpvnc': + access_url = '%s?token=%s' % (FLAGS.xvpvncproxy_base_url, token) + else: + raise exception.ConsoleTypeInvalid(console_type=console_type) + + # Retrieve connect info from driver, and then decorate with our + # access info token + connect_info = self.driver.get_vnc_console(instance_ref) + connect_info['token'] = token + connect_info['access_url'] = access_url + + return connect_info def _attach_volume_boot(self, context, instance, volume, mountpoint): """Attach a volume to an instance at boot time. So actual attach -- cgit