Pass Instance object to spice compute rpc api

Update the get_spice_console() method of the compute rpc api to take in
an Instance object instead of a dict.  The object_compat() decorator is
used to maintain backwards compatibility with receiving a dict.

Change-Id: I0bafe18d9c8bffcd0b72629542fbf7aedacdfbb4
This commit is contained in:
Russell Bryant 2013-11-09 11:14:05 +08:00
parent affaf7f19b
commit ea4416324f
8 changed files with 24 additions and 16 deletions

View File

@ -63,7 +63,7 @@ class ConsolesController(wsgi.Controller):
console_type = body['os-getSPICEConsole'].get('type')
try:
instance = self.compute_api.get(context, id)
instance = self.compute_api.get(context, id, want_objects=True)
output = self.compute_api.get_spice_console(context,
instance,
console_type)

View File

@ -66,7 +66,7 @@ class RemoteConsolesController(wsgi.Controller):
console_type = body['get_spice_console'].get('type')
try:
instance = self.compute_api.get(context, id)
instance = self.compute_api.get(context, id, want_objects=True)
output = self.compute_api.get_spice_console(context,
instance,
console_type)

View File

@ -420,7 +420,7 @@ class ComputeVirtAPI(virtapi.VirtAPI):
class ComputeManager(manager.Manager):
"""Manages the running instances from creation to destruction."""
RPC_API_VERSION = '3.0'
RPC_API_VERSION = '3.1'
def __init__(self, compute_driver=None, *args, **kwargs):
"""Load configuration options and connect to the hypervisor."""
@ -3609,15 +3609,13 @@ class ComputeManager(manager.Manager):
exception.InstanceNotReady, exception.InstanceNotFound)
@wrap_exception()
@wrap_instance_fault
@object_compat
def get_spice_console(self, context, console_type, instance):
"""Return connection information for a spice console."""
context = context.elevated()
LOG.debug(_("Getting spice console"), instance=instance)
token = str(uuid.uuid4())
instance = instance_obj.Instance._from_db_object(
context, instance_obj.Instance(), instance)
if not CONF.spice.enabled:
raise exception.ConsoleTypeInvalid(console_type=console_type)

View File

@ -212,6 +212,7 @@ class ComputeAPI(rpcclient.RpcProxy):
... - Remove live_snapshot() that was never actually used
3.0 - Remove 2.x compatibility
3.1 - Update get_spice_console() to take an instance object
'''
#
@ -424,13 +425,16 @@ class ComputeAPI(rpcclient.RpcProxy):
instance=instance_p, console_type=console_type)
def get_spice_console(self, ctxt, instance, console_type):
# NOTE(russellb) Havana compat
version = self._get_compat_version('3.0', '2.24')
instance_p = jsonutils.to_primitive(instance)
if self.can_send_version('3.1'):
version = '3.1'
else:
# NOTE(russellb) Havana compat
version = self._get_compat_version('3.0', '2.24')
instance = jsonutils.to_primitive(instance)
cctxt = self.client.prepare(server=_compute_host(None, instance),
version=version)
return cctxt.call(ctxt, 'get_spice_console',
instance=instance_p, console_type=console_type)
instance=instance, console_type=console_type)
def validate_console_port(self, ctxt, instance, port, console_type):
# NOTE(russellb) Havana compat

View File

@ -56,11 +56,11 @@ def fake_get_spice_console_not_found(self, _context, instance, _console_type):
raise exception.InstanceNotFound(instance_id=instance["uuid"])
def fake_get(self, context, instance_uuid):
def fake_get(self, context, instance_uuid, want_objects=False):
return {'uuid': instance_uuid}
def fake_get_not_found(self, context, instance_uuid):
def fake_get_not_found(self, context, instance_uuid, want_objects=False):
raise exception.InstanceNotFound(instance_id=instance_uuid)

View File

@ -56,11 +56,11 @@ def fake_get_spice_console_not_found(self, _context, instance, _console_type):
raise exception.InstanceNotFound(instance_id=instance["uuid"])
def fake_get(self, context, instance_uuid):
def fake_get(self, context, instance_uuid, want_objects=False):
return {'uuid': instance_uuid}
def fake_get_not_found(self, context, instance_uuid):
def fake_get_not_found(self, context, instance_uuid, want_objects=False):
raise exception.InstanceNotFound(instance_id=instance_uuid)

View File

@ -7700,7 +7700,7 @@ class ComputeAPITestCase(BaseTestCase):
'namespace': None,
'args': {'instance': fake_instance,
'console_type': fake_console_type},
'version': '3.0'}
'version': '3.1'}
rpc_msg2 = {'method': 'authorize_console',
'namespace': None,
'args': fake_connect_info,

View File

@ -291,7 +291,13 @@ class ComputeRpcAPITestCase(test.TestCase):
def test_get_spice_console(self):
self._test_compute_api('get_spice_console', 'call',
instance=self.fake_instance, console_type='type')
instance=self.fake_instance, console_type='type',
version='3.1')
self.flags(compute='3.0', group='upgrade_levels')
self._test_compute_api('get_spice_console', 'call',
instance=self.fake_instance, console_type='type',
version='3.0')
# NOTE(russellb) Havana compat
self.flags(compute='havana', group='upgrade_levels')