Make get_console_output() use objects
This changes the get_console_output() method in compute manager to take objects. Related to blueprint compute-manager-objects-juno Change-Id: Ia8cb2168313903d5255fa2c9616ee2a56aebdb68
This commit is contained in:
@@ -771,7 +771,8 @@ class CloudController(object):
|
||||
ec2_id = instance_id
|
||||
validate_ec2_id(ec2_id)
|
||||
instance_uuid = ec2utils.ec2_inst_id_to_uuid(context, ec2_id)
|
||||
instance = self.compute_api.get(context, instance_uuid)
|
||||
instance = self.compute_api.get(context, instance_uuid,
|
||||
want_objects=True)
|
||||
output = self.compute_api.get_console_output(context, instance)
|
||||
now = timeutils.utcnow()
|
||||
return {"InstanceId": ec2_id,
|
||||
|
||||
@@ -39,7 +39,8 @@ class ConsoleOutputController(wsgi.Controller):
|
||||
authorize(context)
|
||||
|
||||
try:
|
||||
instance = self.compute_api.get(context, id)
|
||||
instance = self.compute_api.get(context, id,
|
||||
want_objects=True)
|
||||
except exception.NotFound:
|
||||
msg = _('Instance not found')
|
||||
raise webob.exc.HTTPNotFound(explanation=msg)
|
||||
|
||||
@@ -42,7 +42,8 @@ class ConsoleOutputController(wsgi.Controller):
|
||||
context = req.environ['nova.context']
|
||||
authorize(context)
|
||||
|
||||
instance = common.get_instance(self.compute_api, context, id)
|
||||
instance = common.get_instance(self.compute_api, context, id,
|
||||
want_objects=True)
|
||||
length = body['get_console_output'].get('length')
|
||||
if length is not None and int(length) == -1:
|
||||
# NOTE: -1 means an unlimited length. So here translates it to None
|
||||
|
||||
@@ -562,7 +562,7 @@ class ComputeVirtAPI(virtapi.VirtAPI):
|
||||
class ComputeManager(manager.Manager):
|
||||
"""Manages the running instances from creation to destruction."""
|
||||
|
||||
target = messaging.Target(version='3.27')
|
||||
target = messaging.Target(version='3.28')
|
||||
|
||||
def __init__(self, compute_driver=None, *args, **kwargs):
|
||||
"""Load configuration options and connect to the hypervisor."""
|
||||
@@ -3968,14 +3968,13 @@ class ComputeManager(manager.Manager):
|
||||
network_info = self._get_instance_nw_info(context, instance)
|
||||
self._inject_network_info(context, instance, network_info)
|
||||
|
||||
@object_compat
|
||||
@messaging.expected_exceptions(NotImplementedError,
|
||||
exception.InstanceNotFound)
|
||||
@wrap_exception()
|
||||
@wrap_instance_fault
|
||||
def get_console_output(self, context, instance, tail_length):
|
||||
"""Send the console output for the given instance."""
|
||||
instance = objects.Instance._from_db_object(
|
||||
context, objects.Instance(), instance)
|
||||
context = context.elevated()
|
||||
LOG.audit(_("Get console output"), context=context,
|
||||
instance=instance)
|
||||
|
||||
@@ -254,6 +254,7 @@ class ComputeAPI(object):
|
||||
rollback_live_migration_at_destination() take an object
|
||||
... - Removed run_instance()
|
||||
3.27 - Make run_instance() accept a new-world object
|
||||
3.28 - Update get_console_output() to take an object
|
||||
'''
|
||||
|
||||
VERSION_ALIASES = {
|
||||
@@ -446,13 +447,16 @@ class ComputeAPI(object):
|
||||
reservations=reservations)
|
||||
|
||||
def get_console_output(self, ctxt, instance, tail_length):
|
||||
# NOTE(russellb) Havana compat
|
||||
version = self._get_compat_version('3.0', '2.0')
|
||||
instance_p = jsonutils.to_primitive(instance)
|
||||
if self.client.can_send_version('3.28'):
|
||||
version = '3.28'
|
||||
else:
|
||||
# NOTE(russellb) Havana compat
|
||||
version = self._get_compat_version('3.0', '2.0')
|
||||
instance = jsonutils.to_primitive(instance)
|
||||
cctxt = self.client.prepare(server=_compute_host(None, instance),
|
||||
version=version)
|
||||
return cctxt.call(ctxt, 'get_console_output',
|
||||
instance=instance_p, tail_length=tail_length)
|
||||
instance=instance, tail_length=tail_length)
|
||||
|
||||
def get_console_pool_info(self, ctxt, console_type, host):
|
||||
# NOTE(russellb) Havana compat
|
||||
|
||||
@@ -21,6 +21,7 @@ from nova import exception
|
||||
from nova.openstack.common import jsonutils
|
||||
from nova import test
|
||||
from nova.tests.api.openstack import fakes
|
||||
from nova.tests import fake_instance
|
||||
|
||||
|
||||
def fake_get_console_output(self, _context, _instance, tail_length):
|
||||
@@ -44,8 +45,8 @@ def fake_get_console_output_all_characters(self, _ctx, _instance, _tail_len):
|
||||
return string.printable
|
||||
|
||||
|
||||
def fake_get(self, context, instance_uuid):
|
||||
return {'uuid': instance_uuid}
|
||||
def fake_get(self, context, instance_uuid, want_objects=False):
|
||||
return fake_instance.fake_instance_obj(context, **{'uuid': instance_uuid})
|
||||
|
||||
|
||||
def fake_get_not_found(*args, **kwargs):
|
||||
|
||||
@@ -249,7 +249,8 @@ class ComputeRpcAPITestCase(test.TestCase):
|
||||
|
||||
def test_get_console_output(self):
|
||||
self._test_compute_api('get_console_output', 'call',
|
||||
instance=self.fake_instance, tail_length='tl')
|
||||
instance=self.fake_instance, tail_length='tl',
|
||||
version='3.28')
|
||||
|
||||
# NOTE(russellb) Havana compat
|
||||
self.flags(compute='havana', group='upgrade_levels')
|
||||
|
||||
Reference in New Issue
Block a user