summaryrefslogtreecommitdiffstats
path: root/nova
diff options
context:
space:
mode:
authorBrian Waldon <brian.waldon@rackspace.com>2011-11-10 23:36:17 -0500
committerBrian Waldon <brian.waldon@rackspace.com>2011-11-16 13:03:12 -0800
commit1dba0cdc332e54162dc1d880e80deca968dbff4e (patch)
treec479c43014bbd5ca876152279867130168c206d6 /nova
parent3278f4d72f369403395b745987d7e80330817e6a (diff)
downloadnova-1dba0cdc332e54162dc1d880e80deca968dbff4e.tar.gz
nova-1dba0cdc332e54162dc1d880e80deca968dbff4e.tar.xz
nova-1dba0cdc332e54162dc1d880e80deca968dbff4e.zip
Convert remaining calls to use instance objects
Related to blueprint internal-uuids. This touches get_diagnostics, get_actions, and restore. Change-Id: Ic4b3d9476fb53cb97b4ea75ad2e846374b2b4a41
Diffstat (limited to 'nova')
-rw-r--r--nova/api/openstack/contrib/deferred_delete.py3
-rw-r--r--nova/api/openstack/servers.py6
-rw-r--r--nova/compute/api.py14
-rw-r--r--nova/tests/test_compute.py33
4 files changed, 45 insertions, 11 deletions
diff --git a/nova/api/openstack/contrib/deferred_delete.py b/nova/api/openstack/contrib/deferred_delete.py
index 013acbbea..8415ca4b3 100644
--- a/nova/api/openstack/contrib/deferred_delete.py
+++ b/nova/api/openstack/contrib/deferred_delete.py
@@ -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):
diff --git a/nova/api/openstack/servers.py b/nova/api/openstack/servers.py
index 1e9089560..677635354 100644
--- a/nova/api/openstack/servers.py
+++ b/nova/api/openstack/servers.py
@@ -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
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 2a0685fc2..ffd2efd29 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -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):
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 69b998d68..4d0832e2a 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -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):