summaryrefslogtreecommitdiffstats
path: root/nova/compute
diff options
context:
space:
mode:
authorJosh Kearney <josh@jk0.org>2011-08-11 17:10:25 -0500
committerJosh Kearney <josh@jk0.org>2011-08-11 17:10:25 -0500
commitb29bc97d5a69abe71dea5b9ff9dcfc65fcd59cc9 (patch)
tree8f2255023974f23c79edaa272405dbe9cedb1035 /nova/compute
parentfe0bde67193ce76376e72a7263b89240a63722a8 (diff)
downloadnova-b29bc97d5a69abe71dea5b9ff9dcfc65fcd59cc9.tar.gz
nova-b29bc97d5a69abe71dea5b9ff9dcfc65fcd59cc9.tar.xz
nova-b29bc97d5a69abe71dea5b9ff9dcfc65fcd59cc9.zip
Check compressed image size and PEP8 cleanup.
Diffstat (limited to 'nova/compute')
-rw-r--r--nova/compute/manager.py40
1 files changed, 40 insertions, 0 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py
index d38213083..1c3485342 100644
--- a/nova/compute/manager.py
+++ b/nova/compute/manager.py
@@ -321,10 +321,50 @@ class ComputeManager(manager.SchedulerDependentManager):
def _run_instance(self, context, instance_id, **kwargs):
"""Launch a new instance with specified options."""
+ def _check_image_size():
+ """Ensure image is smaller than the maximum size allowed by the
+ instance_type.
+
+ The image stored in Glance is potentially compressed, so we use two
+ checks to ensure that the size isn't exceeded:
+
+ 1) This one - checks compressed size, this a quick check to
+ eliminate any images which are obviously too large
+
+ 2) Check uncompressed size in nova.virt.xenapi.vm_utils. This
+ is a slower check since it requires uncompressing the entire
+ image, but is accurate because it reflects the image's
+ actual size.
+ """
+ image_href = instance['image_ref']
+ image_service, image_id = nova.image.get_image_service(image_href)
+ image_meta = image_service.show(context, image_id)
+ size_bytes = image_meta['size']
+
+ instance_type_id = instance['instance_type_id']
+ instance_type = self.db.instance_type_get(context,
+ instance_type_id)
+ allowed_size_gb = instance_type['local_gb']
+ allowed_size_bytes = allowed_size_gb * 1024 * 1024 * 1024
+
+ LOG.debug(_("image_id=%(image_id)d, image_size_bytes="
+ "%(size_bytes)d, allowed_size_bytes="
+ "%(allowed_size_bytes)d") % locals())
+
+ if size_bytes > allowed_size_bytes:
+ LOG.info(_("Image '%(image_id)d' size %(size_bytes)d exceeded"
+ " instance_type allowed size "
+ "%(allowed_size_bytes)d")
+ % locals())
+ raise exception.ImageTooLarge()
+
context = context.elevated()
instance = self.db.instance_get(context, instance_id)
if instance['name'] in self.driver.list_instances():
raise exception.Error(_("Instance has already been created"))
+
+ _check_image_size()
+
LOG.audit(_("instance %s: starting..."), instance_id,
context=context)
updates = {}