diff options
| author | Tushar Patil <tushar.vitthal.patil@gmail.com> | 2011-08-16 16:18:48 -0700 |
|---|---|---|
| committer | Tushar Patil <tushar.vitthal.patil@gmail.com> | 2011-08-16 16:18:48 -0700 |
| commit | 982427040554d3cfcee25abab981215f73650b3e (patch) | |
| tree | 17fdd26910568059637e6b203f3284d64402579a /nova/compute | |
| parent | 9081e8b62ea01828238ecaebdcf3e627ada3fe9a (diff) | |
| parent | 6dbcc60d5f8d4995a706f0de449756ecea4ebaa0 (diff) | |
| download | nova-982427040554d3cfcee25abab981215f73650b3e.tar.gz nova-982427040554d3cfcee25abab981215f73650b3e.tar.xz nova-982427040554d3cfcee25abab981215f73650b3e.zip | |
Resolved conflicts and merged with trunk
Diffstat (limited to 'nova/compute')
| -rw-r--r-- | nova/compute/manager.py | 64 |
1 files changed, 63 insertions, 1 deletions
diff --git a/nova/compute/manager.py b/nova/compute/manager.py index d9ca31f60..f3260486a 100644 --- a/nova/compute/manager.py +++ b/nova/compute/manager.py @@ -323,11 +323,72 @@ 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. + """ + # NOTE(jk0): image_ref is defined in the DB model, image_href is + # used by the image service. This should be refactored to be + # consistent. + image_href = instance['image_ref'] + image_service, image_id = nova.image.get_image_service(image_href) + image_meta = image_service.show(context, image_id) + + try: + size_bytes = image_meta['size'] + except KeyError: + # Size is not a required field in the image service (yet), so + # we are unable to rely on it being there even though it's in + # glance. + + # TODO(jk0): Should size be required in the image service? + return + + 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'] + + # NOTE(jk0): Since libvirt uses local_gb as a secondary drive, we + # need to handle potential situations where local_gb is 0. This is + # the default for m1.tiny. + if allowed_size_gb == 0: + return + + 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) + requested_networks = kwargs.get('requested_networks', None) + 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 = {} @@ -1317,7 +1378,8 @@ class ComputeManager(manager.SchedulerDependentManager): # This nwfilter is necessary on the destination host. # In addition, this method is creating filtering rule # onto destination host. - self.driver.ensure_filtering_rules_for_instance(instance_ref, network_info) + self.driver.ensure_filtering_rules_for_instance(instance_ref, + network_info) # Preparation for block migration if block_migration: |
