def _cache_image(self, context, instance, image_meta): """Fetch the instance's image from Glance This method pulls the relevant AMI and associated kernel and ramdisk, and the deploy kernel and ramdisk from Glance, and writes them to the appropriate places on local disk. Both sets of kernel and ramdisk are needed for Tilera booting, so these are stored under CONF.baremetal.tftp_root. At present, the AMI is cached and certain files are injected. Debian/ubuntu-specific assumptions are made regarding the injected files. In a future revision, this functionality will be replaced by a more scalable and os-agnostic approach: the deployment ramdisk will fetch from Glance directly, and write its own last-mile configuration. """ fileutils.ensure_tree(get_image_dir_path(instance)) image_path = get_image_file_path(instance) LOG.debug(_("Fetching image %(ami)s for instance %(name)s") % {'ami': image_meta['id'], 'name': instance['name']}) bm_utils.cache_image(context=context, target=image_path, image_id=image_meta['id'], user_id=instance['user_id'], project_id=instance['project_id'] ) return [image_meta['id'], image_path]
def test_cache_image_with_clean(self): self.mox.StubOutWithMock(libvirt_utils, "fetch_image") temp_f, temp_file = tempfile.mkstemp() libvirt_utils.fetch_image(None, temp_file, None, None, None) self.mox.ReplayAll() utils.cache_image(None, temp_file, None, None, None, clean=True) self.mox.VerifyAll() self.assertFalse(os.path.exists(temp_file))
def _cache_tftp_images(self, context, instance, image_info): """Fetch the necessary kernels and ramdisks for the instance.""" fileutils.ensure_tree(os.path.join(CONF.baremetal.tftp_root, instance["uuid"])) LOG.debug(_("Fetching kernel and ramdisk for instance %s") % instance["name"]) for label in image_info.keys(): (uuid, path) = image_info[label] bm_utils.cache_image( context=context, target=path, image_id=uuid, user_id=instance["user_id"], project_id=instance["project_id"], )
def _cache_tftp_images(self, context, instance, image_info): """Fetch the necessary kernels and ramdisks for the instance.""" fileutils.ensure_tree( os.path.join(CONF.baremetal.tftp_root, instance['uuid'])) LOG.debug( _("Fetching kernel and ramdisk for instance %s") % instance['name']) for label in image_info.keys(): (uuid, path) = image_info[label] bm_utils.cache_image( context=context, target=path, image_id=uuid, user_id=instance['user_id'], project_id=instance['project_id'], )