Convert remaining calls to use instance objects
Related to blueprint internal-uuids. This touches get_diagnostics, get_actions, and restore. Change-Id: Ic4b3d9476fb53cb97b4ea75ad2e846374b2b4a41
This commit is contained in:
@@ -42,7 +42,8 @@ class Deferred_delete(extensions.ExtensionDescriptor):
|
||||
"""Restore a previously deleted instance."""
|
||||
|
||||
context = req.environ["nova.context"]
|
||||
self.compute_api.restore(context, instance_id)
|
||||
instance = self.compute_api.get(context, instance_id)
|
||||
self.compute_api.restore(context, instance)
|
||||
return webob.Response(status_int=202)
|
||||
|
||||
def _force_delete(self, input_dict, req, instance_id):
|
||||
|
||||
@@ -646,12 +646,14 @@ class Controller(object):
|
||||
def diagnostics(self, req, id):
|
||||
"""Permit Admins to retrieve server diagnostics."""
|
||||
ctxt = req.environ["nova.context"]
|
||||
return self.compute_api.get_diagnostics(ctxt, id)
|
||||
instance = self._get_server(ctxt, id)
|
||||
return self.compute_api.get_diagnostics(ctxt, instance)
|
||||
|
||||
def actions(self, req, id):
|
||||
"""Permit Admins to retrieve server actions."""
|
||||
ctxt = req.environ["nova.context"]
|
||||
items = self.compute_api.get_actions(ctxt, id)
|
||||
instance = self._get_server(ctxt, id)
|
||||
items = self.compute_api.get_actions(ctxt, instance)
|
||||
actions = []
|
||||
# TODO(jk0): Do not do pre-serialization here once the default
|
||||
# serializer is updated
|
||||
|
||||
+7
-7
@@ -827,9 +827,9 @@ class API(base.Base):
|
||||
self._delete(context, instance)
|
||||
|
||||
@scheduler_api.reroute_compute("restore")
|
||||
def restore(self, context, instance_id):
|
||||
def restore(self, context, instance):
|
||||
"""Restore a previously deleted (but not reclaimed) instance."""
|
||||
instance = self._get_instance(context, instance_id, 'restore')
|
||||
instance_id = instance['id']
|
||||
|
||||
if not _is_queued_delete(instance):
|
||||
return
|
||||
@@ -846,7 +846,7 @@ class API(base.Base):
|
||||
instance_id,
|
||||
task_state=task_states.POWERING_ON)
|
||||
self._cast_compute_message('power_on_instance', context,
|
||||
instance_id, host)
|
||||
instance_id, host)
|
||||
|
||||
@scheduler_api.reroute_compute("force_delete")
|
||||
def force_delete(self, context, instance):
|
||||
@@ -1370,15 +1370,15 @@ class API(base.Base):
|
||||
context, host=host, params={"action": action})
|
||||
|
||||
@scheduler_api.reroute_compute("diagnostics")
|
||||
def get_diagnostics(self, context, instance_id):
|
||||
def get_diagnostics(self, context, instance):
|
||||
"""Retrieve diagnostics for the given instance."""
|
||||
return self._call_compute_message("get_diagnostics",
|
||||
context,
|
||||
instance_id)
|
||||
instance['id'])
|
||||
|
||||
def get_actions(self, context, instance_id):
|
||||
def get_actions(self, context, instance):
|
||||
"""Retrieve actions for the given instance."""
|
||||
return self.db.instance_get_actions(context, instance_id)
|
||||
return self.db.instance_get_actions(context, instance['id'])
|
||||
|
||||
@scheduler_api.reroute_compute("suspend")
|
||||
def suspend(self, context, instance):
|
||||
|
||||
@@ -1112,7 +1112,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
def test_force_delete(self):
|
||||
"""Ensure instance can be soft rebooted"""
|
||||
"""Ensure instance can be deleted after a soft delete"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
||||
@@ -1189,6 +1189,24 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
def test_restore(self):
|
||||
"""Ensure instance can be restored from a soft delete"""
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
|
||||
instance = db.instance_get(self.context, instance_id)
|
||||
self.compute_api.soft_delete(self.context, instance)
|
||||
|
||||
instance = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(instance['task_state'], task_states.POWERING_OFF)
|
||||
|
||||
self.compute_api.restore(self.context, instance)
|
||||
|
||||
instance = db.instance_get(self.context, instance_id)
|
||||
self.assertEqual(instance['task_state'], task_states.POWERING_ON)
|
||||
|
||||
db.instance_destroy(self.context, instance_id)
|
||||
|
||||
def test_rebuild(self):
|
||||
instance_id = self._create_instance()
|
||||
self.compute.run_instance(self.context, instance_id)
|
||||
@@ -1980,6 +1998,7 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
instance = self.compute_api.get(self.context, instance_id)
|
||||
self.compute_api.add_fixed_ip(self.context, instance, '1')
|
||||
self.compute_api.remove_fixed_ip(self.context, instance, '192.168.1.1')
|
||||
self.compute_api.delete(self.context, instance)
|
||||
|
||||
def test_attach_volume_invalid(self):
|
||||
self.assertRaises(exception.ApiError,
|
||||
@@ -2106,6 +2125,18 @@ class ComputeAPITestCase(BaseTestCase):
|
||||
self.compute_api.remove_security_group(self.context,
|
||||
instance,
|
||||
security_group_name)
|
||||
|
||||
def test_get_diagnostics(self):
|
||||
instance_id = self._create_instance()
|
||||
instance = self.compute_api.get(self.context, instance_id)
|
||||
self.compute_api.get_diagnostics(self.context, instance)
|
||||
self.compute_api.delete(self.context, instance)
|
||||
|
||||
def test_get_actions(self):
|
||||
context = self.context.elevated()
|
||||
instance_id = self._create_instance()
|
||||
instance = self.compute_api.get(self.context, instance_id)
|
||||
self.compute_api.get_actions(context, instance)
|
||||
self.compute_api.delete(self.context, instance)
|
||||
|
||||
def test_inject_file(self):
|
||||
|
||||
Reference in New Issue
Block a user