summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlex Meade <alex.meade@rackspace.com>2011-11-10 14:21:57 -0500
committerAlex Meade <alex.meade@rackspace.com>2011-11-10 14:21:57 -0500
commitf2b9f3fa6c8e8e50b23919bad079c86b14b08dee (patch)
tree80fbb096c1d7ca6b36a8f4da500ee931a896845f
parent1a5418b7cbc6f19000ee2847067c681685dd416e (diff)
downloadnova-f2b9f3fa6c8e8e50b23919bad079c86b14b08dee.tar.gz
nova-f2b9f3fa6c8e8e50b23919bad079c86b14b08dee.tar.xz
nova-f2b9f3fa6c8e8e50b23919bad079c86b14b08dee.zip
Converting start and stop to use instance objects
Related to blueprint internal-uuids Change-Id: Ie94bef94e50620419a306eeedcdca756f83f1af6
-rw-r--r--nova/api/ec2/cloud.py10
-rw-r--r--nova/compute/api.py17
-rw-r--r--nova/tests/api/ec2/test_cloud.py29
-rw-r--r--nova/tests/test_compute.py30
4 files changed, 76 insertions, 10 deletions
diff --git a/nova/api/ec2/cloud.py b/nova/api/ec2/cloud.py
index d092d4af0..393df2870 100644
--- a/nova/api/ec2/cloud.py
+++ b/nova/api/ec2/cloud.py
@@ -1471,14 +1471,20 @@ class CloudController(object):
"""Stop each instances in instance_id.
Here instance_id is a list of instance ids"""
LOG.debug(_("Going to stop instances"))
- self._do_instances(self.compute_api.stop, context, instance_id)
+ for ec2_id in instance_id:
+ _instance_id = ec2utils.ec2_id_to_id(ec2_id)
+ instance = self.compute_api.get(context, _instance_id)
+ self.compute_api.stop(context, instance)
return True
def start_instances(self, context, instance_id, **kwargs):
"""Start each instances in instance_id.
Here instance_id is a list of instance ids"""
LOG.debug(_("Going to start instances"))
- self._do_instances(self.compute_api.start, context, instance_id)
+ for ec2_id in instance_id:
+ _instance_id = ec2utils.ec2_id_to_id(ec2_id)
+ instance = self.compute_api.get(context, _instance_id)
+ self.compute_api.start(context, instance)
return True
def rescue_instance(self, context, instance_id, **kwargs):
diff --git a/nova/compute/api.py b/nova/compute/api.py
index 03d5933b0..820a7b9b6 100644
--- a/nova/compute/api.py
+++ b/nova/compute/api.py
@@ -797,7 +797,8 @@ class API(base.Base):
@scheduler_api.reroute_compute("soft_delete")
def soft_delete(self, context, instance):
"""Terminate an instance."""
- LOG.debug(_("Going to try to soft delete %s"), instance["id"])
+ instance_id = instance["id"]
+ LOG.debug(_("Going to try to soft delete %s"), instance_id)
if not _is_able_to_shutdown(instance):
return
@@ -814,11 +815,11 @@ class API(base.Base):
deleted_at=utils.utcnow())
self._cast_compute_message('power_off_instance', context,
- instance['id'], host)
+ instance_id, host)
else:
LOG.warning(_("No host for instance %s, deleting immediately"),
instance["id"])
- self.db.instance_destroy(context, instance["id"])
+ self.db.instance_destroy(context, instance_id)
def _delete(self, context, instance):
host = instance['host']
@@ -875,11 +876,11 @@ class API(base.Base):
self._delete(context, instance)
@scheduler_api.reroute_compute("stop")
- def stop(self, context, instance_id):
+ def stop(self, context, instance):
"""Stop an instance."""
+ instance_id = instance["id"]
LOG.debug(_("Going to try to stop %s"), instance_id)
- instance = self._get_instance(context, instance_id, 'stopping')
if not _is_able_to_shutdown(instance):
return
@@ -895,11 +896,11 @@ class API(base.Base):
self._cast_compute_message('stop_instance', context,
instance_id, host)
- def start(self, context, instance_id):
+ def start(self, context, instance):
"""Start an instance."""
- LOG.debug(_("Going to try to start %s"), instance_id)
- instance = self._get_instance(context, instance_id, 'starting')
vm_state = instance["vm_state"]
+ instance_id = instance["id"]
+ LOG.debug(_("Going to try to start %s"), instance_id)
if vm_state != vm_states.STOPPED:
LOG.warning(_("Instance %(instance_id)s is not "
diff --git a/nova/tests/api/ec2/test_cloud.py b/nova/tests/api/ec2/test_cloud.py
index 57c74ed14..e70f7b832 100644
--- a/nova/tests/api/ec2/test_cloud.py
+++ b/nova/tests/api/ec2/test_cloud.py
@@ -1369,6 +1369,35 @@ class CloudTestCase(test.TestCase):
result = self.cloud.terminate_instances(self.context, [instance_id])
self.assertTrue(result)
+ def test_start_instances(self):
+ kwargs = {'image_id': 'ami-1',
+ 'instance_type': FLAGS.default_instance_type,
+ 'max_count': 1, }
+ instance_id = self._run_instance(**kwargs)
+
+ result = self.cloud.stop_instances(self.context, [instance_id])
+ self.assertTrue(result)
+
+ result = self.cloud.start_instances(self.context, [instance_id])
+ self.assertTrue(result)
+
+ result = self.cloud.terminate_instances(self.context, [instance_id])
+ self.assertTrue(result)
+ self._restart_compute_service()
+
+ def test_stop_instances(self):
+ kwargs = {'image_id': 'ami-1',
+ 'instance_type': FLAGS.default_instance_type,
+ 'max_count': 1, }
+ instance_id = self._run_instance(**kwargs)
+
+ result = self.cloud.stop_instances(self.context, [instance_id])
+ self.assertTrue(result)
+
+ result = self.cloud.terminate_instances(self.context, [instance_id])
+ self.assertTrue(result)
+ self._restart_compute_service()
+
def test_terminate_instances(self):
kwargs = {'image_id': 'ami-1',
'instance_type': FLAGS.default_instance_type,
diff --git a/nova/tests/test_compute.py b/nova/tests/test_compute.py
index 2b124b6fc..0e8d53751 100644
--- a/nova/tests/test_compute.py
+++ b/nova/tests/test_compute.py
@@ -1047,6 +1047,36 @@ class ComputeAPITestCase(BaseTestCase):
finally:
db.instance_destroy(self.context, ref[0]['id'])
+ def test_start(self):
+ instance_id = self._create_instance()
+ self.compute.run_instance(self.context, instance_id)
+
+ self.compute.stop_instance(self.context, instance_id)
+
+ instance = db.instance_get(self.context, instance_id)
+ self.assertEqual(instance['task_state'], None)
+
+ self.compute_api.start(self.context, instance)
+
+ instance = db.instance_get(self.context, instance_id)
+ self.assertEqual(instance['task_state'], task_states.STARTING)
+
+ db.instance_destroy(self.context, instance_id)
+
+ def test_stop(self):
+ instance_id = self._create_instance()
+ self.compute.run_instance(self.context, instance_id)
+
+ instance = db.instance_get(self.context, instance_id)
+ self.assertEqual(instance['task_state'], None)
+
+ self.compute_api.stop(self.context, instance)
+
+ instance = db.instance_get(self.context, instance_id)
+ self.assertEqual(instance['task_state'], task_states.STOPPING)
+
+ db.instance_destroy(self.context, instance_id)
+
def test_delete(self):
instance_id = self._create_instance()
self.compute.run_instance(self.context, instance_id)