From 3bf9bc6f6c0fbf90e3f4eab68a9bd99d85fcc422 Mon Sep 17 00:00:00 2001 From: Rick Harris Date: Thu, 6 Jan 2011 21:37:33 -0600 Subject: Reserving image before uploading --- nova/compute/api.py | 10 +++++++++- nova/compute/manager.py | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) (limited to 'nova/compute') diff --git a/nova/compute/api.py b/nova/compute/api.py index 07c69bd31..5bb6fac91 100644 --- a/nova/compute/api.py +++ b/nova/compute/api.py @@ -263,10 +263,18 @@ class ComputeAPI(base.Base): """Snapshot the given instance.""" instance = self.db.instance_get_by_internal_id(context, instance_id) host = instance['host'] + + image_service = utils.import_object(FLAGS.image_service) + + data = {'name': name, 'is_public': True} + image_meta = image_service.create(context, data) rpc.cast(context, self.db.queue_get_for(context, FLAGS.compute_topic, host), {"method": "snapshot_instance", - "args": {"instance_id": instance['id'], "name": name}}) + "args": {"instance_id": instance['id'], + "image_id": image_meta['id']}}) + + return image_meta def reboot(self, context, instance_id): """Reboot the given instance.""" diff --git a/nova/compute/manager.py b/nova/compute/manager.py index 6e8f34347..27e07ed59 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -225,7 +225,7 @@ class ComputeManager(manager.Manager): self._update_state(context, instance_id) @exception.wrap_exception - def snapshot_instance(self, context, instance_id, name): + def snapshot_instance(self, context, instance_id, image_id): """Snapshot an instance on this server.""" context = context.elevated() instance_ref = self.db.instance_get(context, instance_id) @@ -243,7 +243,7 @@ class ComputeManager(manager.Manager): instance_ref['state'], power_state.RUNNING) - self.driver.snapshot(instance_ref, name) + self.driver.snapshot(instance_ref, image_id) @exception.wrap_exception def rescue_instance(self, context, instance_id): -- cgit