Пример #1
0
    def _get_or_upload_image(self, context, image_meta):
        """Return a cached image name

        Attempt to find a cached copy of the image. If there is no cached copy
        of the image, create one.

        :param context: nova context used to retrieve image from glance
        :param nova.objects.ImageMeta image_meta:
            The metadata of the image of the instance.
        :return: The name of the virtual disk containing the image
        """

        # Check for cached image
        with lockutils.lock(image_meta.id):
            vg_wrap = self._get_vg_wrap()
            cache_name = self.get_name_by_uuid(disk_dvr.DiskType.IMAGE,
                                               image_meta.id, short=True)
            image = [disk for disk in vg_wrap.virtual_disks
                     if disk.name == cache_name]
            if len(image) == 1:
                return image[0].udid

            image = tsk_stg.upload_new_vdisk(
                self.adapter, self._vios_uuid, self.vg_uuid,
                disk_dvr.IterableToFileAdapter(
                    IMAGE_API.download(context, image_meta.id)), cache_name,
                image_meta.size, d_size=image_meta.size,
                upload_type=tsk_stg.UploadType.IO_STREAM,
                file_format=image_meta.disk_format)[0]
            return image.udid
Пример #2
0
    def _create_disk_from_image(self, context, instance, image_meta,
                                image_type=disk_drv.DiskType.BOOT):
        """Creates a disk and copies the specified image to it.

        If the specified image has not already been uploaded, an Image LU is
        created for it.  A Disk LU is then created for the instance and linked
        to the Image LU.

        :param context: nova context used to retrieve image from glance
        :param instance: instance to create the disk for.
        :param nova.objects.ImageMeta image_meta:
            The metadata of the image of the instance.
        :param image_type: The image type. See disk_drv.DiskType.
        :return: The backing pypowervm LU storage object that was created.
        """
        LOG.info('SSP: Create %(image_type)s disk from image %(image_id)s.',
                 dict(image_type=image_type, image_id=image_meta.id),
                 instance=instance)

        image_lu = tsk_cs.get_or_upload_image_lu(
            self._tier, self._get_image_name(image_meta),
            self._any_vios_uuid(), disk_drv.IterableToFileAdapter(
                IMAGE_API.download(context, image_meta.id)),
            image_meta.size, upload_type=tsk_stg.UploadType.IO_STREAM)

        boot_lu_name = self._get_disk_name(image_type, instance)
        LOG.info('SSP: Disk name is %s', boot_lu_name, instance=instance)

        return tsk_stg.crt_lu(
            self._tier, boot_lu_name, instance.flavor.root_gb,
            typ=pvm_stg.LUType.DISK, clone=image_lu)[1]