Esempio n. 1
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        self._ensure_tmp_exists()
        tmp_dir = self.configuration.volume_tmp_dir

        with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp:
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     tmp.name,
                                     self.configuration.volume_dd_blocksize,
                                     size=volume['size'])

            self.delete_volume(volume)

            # keep using the command line import instead of librbd since it
            # detects zeroes to preserve sparseness in the image
            args = [
                'rbd', 'import', '--pool', self.configuration.rbd_pool,
                tmp.name, volume['name']
            ]
            if self._supports_layering():
                args.append('--new-format')
            args.extend(self._ceph_args())
            self._try_execute(*args)
        self._resize(volume)
Esempio n. 2
0
    def test_copy_image_to_volume(self):
        """resize_image common case usage."""
        mox = self._mox
        drv = self._driver

        TEST_IMG_SOURCE = "foo.img"

        volume = {"size": self.TEST_SIZE_IN_GB, "name": TEST_IMG_SOURCE}

        def fake_local_path(volume):
            return volume["name"]

        self.stubs.Set(drv, "local_path", fake_local_path)

        mox.StubOutWithMock(image_utils, "fetch_to_raw")
        image_utils.fetch_to_raw(None, None, None, TEST_IMG_SOURCE, mox_lib.IgnoreArg(), size=self.TEST_SIZE_IN_GB)

        mox.StubOutWithMock(image_utils, "resize_image")
        image_utils.resize_image(TEST_IMG_SOURCE, self.TEST_SIZE_IN_GB)

        mox.StubOutWithMock(image_utils, "qemu_img_info")
        data = mox_lib.MockAnything()
        data.virtual_size = 1 * units.GiB
        image_utils.qemu_img_info(TEST_IMG_SOURCE).AndReturn(data)

        mox.ReplayAll()

        drv.copy_image_to_volume(None, volume, None, None)

        mox.VerifyAll()
Esempio n. 3
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""

        LOG.error('begin time of COPY_IMAGE_TO_VOLUME is %s' %
                  (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
        image_meta = image_service.show(context, image_id)
        container_format = image_meta.get('container_format')
        if container_format in ['fs_vgw_url', 'vcloud_vgw_url', 'aws_vgw_url']:
            image_utils.fetch_from_localfile_to_raw(
                context,
                image_service,
                image_id,
                CONF.vgw.store_file_dir,
                self.local_path(volume),
                self.configuration.volume_dd_blocksize,
                size=volume['size'])
            LOG.error('end time of COPY_IMAGE_TO_VOLUME is %s' %
                      (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
        else:
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     self.local_path(volume),
                                     self.configuration.volume_dd_blocksize,
                                     size=volume['size'])
Esempio n. 4
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     # Copy image to volume.
     # Step1: attach volume to host.
     LOG.debug("Begin to copy image to volume.")
     dsw_manager_ip = self._get_dsware_manage_ip(volume)
     volume_attach_result = self._attach_volume(volume['name'],
                                                dsw_manager_ip)
     volume_attach_path = ''
     if volume_attach_result is not None and int(
             volume_attach_result['ret_code']) == 0:
         volume_attach_path = volume_attach_result['dev_addr']
         LOG.debug("Volume attach path is %s.", volume_attach_path)
     if volume_attach_path == '':
         msg = _("Host attach volume failed!")
         raise exception.VolumeBackendAPIException(data=msg)
         # Step2: fetch the image from image_service and write it to the
         # volume.
     try:
         image_utils.fetch_to_raw(context,
                                  image_service,
                                  image_id,
                                  volume_attach_path,
                                  self.configuration.volume_dd_blocksize)
     finally:
         # Step3: detach volume from host.
         dsw_manager_ip = self._get_dsware_manage_ip(volume)
         volume_detach_result = self._detach_volume(volume['name'],
                                                    dsw_manager_ip)
         if volume_detach_result is not None and int(
                 volume_detach_result['ret_code']) != 0:
             msg = (_("Dsware detach volume from host failed: %s!") %
                    volume_detach_result)
             raise exception.VolumeBackendAPIException(data=msg)
Esempio n. 5
0
    def test_copy_image_to_volume(self):
        """resize_image common case usage."""
        mox = self._mox
        drv = self._driver

        TEST_IMG_SOURCE = 'foo.img'

        volume = {'size': self.TEST_SIZE_IN_GB, 'name': TEST_IMG_SOURCE}

        def fake_local_path(volume):
            return volume['name']

        self.stubs.Set(drv, 'local_path', fake_local_path)

        mox.StubOutWithMock(image_utils, 'fetch_to_raw')
        image_utils.fetch_to_raw(None, None, None, TEST_IMG_SOURCE)

        mox.StubOutWithMock(image_utils, 'resize_image')
        image_utils.resize_image(TEST_IMG_SOURCE, self.TEST_SIZE_IN_GB)

        mox.StubOutWithMock(image_utils, 'qemu_img_info')
        data = mox_lib.MockAnything()
        data.virtual_size = 1024 ** 3
        image_utils.qemu_img_info(TEST_IMG_SOURCE).AndReturn(data)

        mox.ReplayAll()

        drv.copy_image_to_volume(None, volume, None, None)

        mox.VerifyAll()
Esempio n. 6
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     # Copy image to volume
     # step1 attach volume to host
     LOG.debug(_("begin to copy image to volume"))
     dsw_manager_ip = self._get_dsware_manage_ip(volume)
     volume_attach_result = self._attach_volume(volume['name'],
                                                dsw_manager_ip)
     volume_attach_path = ''
     if volume_attach_result is not None and int(
             volume_attach_result['ret_code']) == 0:
         volume_attach_path = volume_attach_result['dev_addr']
         LOG.debug(_("volume_attach_path is %s") % volume_attach_path)
     if volume_attach_path == '':
         msg = _("host attach volume failed")
         raise exception.VolumeBackendAPIException(data=msg % locals())
         # step2 fetch the image from image_service and write it to the
         # volume.
     try:
         image_utils.fetch_to_raw(context, image_service, image_id,
                                  volume_attach_path,
                                  self.configuration.volume_dd_blocksize)
     finally:
         # step3 detach volume from host
         dsw_manager_ip = self._get_dsware_manage_ip(volume)
         volume_detach_result = self._detach_volume(volume['name'],
                                                    dsw_manager_ip)
         if volume_detach_result is not None and int(
                 volume_detach_result['ret_code']) != 0:
             msg = _(
                 "DSware detach volume from host failed: %(volume_detach_result['ret_desc'])s"
             )
             raise exception.VolumeBackendAPIException(data=msg % locals())
Esempio n. 7
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""

        volume['provider_location'] = (
            self.create_export(context, volume, None)['provider_location'])
        connection_data = self.initialize_connection(volume, None)['data']
        target_connector = (
            connector.InitiatorConnector.factory(initiator.NVME,
                                                 utils.get_root_helper()))

        try:
            device_info = target_connector.connect_volume(connection_data)
        except Exception:
            LOG.info('Could not connect SPDK target device')
            return

        connection_data['device_path'] = device_info['path']

        try:
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     device_info['path'],
                                     self.configuration.volume_dd_blocksize,
                                     size=volume['size'])

        finally:
            target_connector.disconnect_volume(connection_data, volume)
Esempio n. 8
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """
        Copy image to volume
        Called on "nova volume-create --image-id ..."
        or "cinder create --image-id"
        Downloads image from glance server into volume

        :param context: Context object
        :param volume: volume reference (sqlalchemy Model)
        :param image_service: image service reference
        :param image_id: id of the image
        """
        volume_name = self.VOLUME_PREFIX + str(volume.id)
        location = self._get_volume_location(volume_name=volume_name)
        image_path = os.path.join('/tmp', image_id)
        if not os.path.exists(image_path):
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     image_path,
                                     '1M',
                                     size=volume['size'])
        self._run_qemu_img('convert', '-n', '-O', 'raw', image_path, location)

        LOG.debug('libovsvolumedriver.ovs_copy_image_to_volume {0} {1}'.format(
            volume.id, image_id))
Esempio n. 9
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):

        tmp_dir = self._image_conversion_dir()

        with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp:
            image_utils.fetch_to_raw(
                context, image_service, image_id, tmp.name, self.configuration.volume_dd_blocksize, size=volume["size"]
            )

            self.delete_volume(volume)

            chunk_size = self.configuration.rbd_store_chunk_size * units.Mi
            order = int(math.log(chunk_size, 2))
            # keep using the command line import instead of librbd since it
            # detects zeroes to preserve sparseness in the image
            args = [
                "rbd",
                "import",
                "--pool",
                self.configuration.rbd_pool,
                "--order",
                order,
                tmp.name,
                volume["name"],
                "--new-format",
            ]
            args.extend(self._ceph_args())
            self._try_execute(*args)
        self._resize(volume)
Esempio n. 10
0
File: spdk.py Progetto: mahak/cinder
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""

        volume['provider_location'] = (
            self.create_export(context, volume, None)['provider_location'])
        connection_data = self.initialize_connection(volume, None)['data']
        target_connector = (
            connector.InitiatorConnector.factory(initiator.NVME,
                                                 utils.get_root_helper()))

        try:
            device_info = target_connector.connect_volume(connection_data)
        except Exception:
            LOG.info('Could not connect SPDK target device')
            return

        connection_data['device_path'] = device_info['path']

        try:
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     device_info['path'],
                                     self.configuration.volume_dd_blocksize,
                                     size=volume['size'])

        finally:
            target_connector.disconnect_volume(connection_data, volume)
Esempio n. 11
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     # Copy image to volume.
     # Step1: attach volume to host.
     LOG.debug("Begin to copy image to volume.")
     dsw_manager_ip = self._get_dsware_manage_ip(volume)
     volume_attach_result = self._attach_volume(volume['name'],
                                                dsw_manager_ip)
     volume_attach_path = ''
     if volume_attach_result is not None and int(
             volume_attach_result['ret_code']) == 0:
         volume_attach_path = volume_attach_result['dev_addr']
         LOG.debug("Volume attach path is %s.", volume_attach_path)
     if volume_attach_path == '':
         msg = _("Host attach volume failed!")
         raise exception.VolumeBackendAPIException(data=msg)
         # Step2: fetch the image from image_service and write it to the
         # volume.
     try:
         image_utils.fetch_to_raw(context, image_service, image_id,
                                  volume_attach_path,
                                  self.configuration.volume_dd_blocksize)
     finally:
         # Step3: detach volume from host.
         dsw_manager_ip = self._get_dsware_manage_ip(volume)
         volume_detach_result = self._detach_volume(volume['name'],
                                                    dsw_manager_ip)
         if volume_detach_result is not None and int(
                 volume_detach_result['ret_code']) != 0:
             msg = (_("Dsware detach volume from host failed: %s!") %
                    volume_detach_result)
             raise exception.VolumeBackendAPIException(data=msg)
Esempio n. 12
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     # Copy image to volume
     # step1 attach volume to host
     LOG.debug(_("begin to copy image to volume"))
     dsw_manager_ip=self._get_dsware_manage_ip(volume)
     volume_attach_result = self._attach_volume(volume['name'],dsw_manager_ip)
     volume_attach_path = ''
     if volume_attach_result is not None and int(volume_attach_result['ret_code']) == 0:
         volume_attach_path = volume_attach_result['dev_addr']
         LOG.debug(_("volume_attach_path is %s") % volume_attach_path)
     if volume_attach_path == '':
         msg = _("host attach volume failed")
         raise exception.VolumeBackendAPIException(data=msg % locals())
         # step2 fetch the image from image_service and write it to the
         # volume.
     try:     
         image_utils.fetch_to_raw(context,
                              image_service,
                              image_id,
                              volume_attach_path,
                              self.configuration.volume_dd_blocksize)
     finally:  
         # step3 detach volume from host
         dsw_manager_ip=self._get_dsware_manage_ip(volume)
         volume_detach_result = self._detach_volume(volume['name'],dsw_manager_ip)
         if volume_detach_result is not None and int(volume_detach_result['ret_code']) != 0:
             msg = _(
                 "DSware detach volume from host failed: %(volume_detach_result['ret_desc'])s")
             raise exception.VolumeBackendAPIException(data=msg % locals())
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.info("ScaleIO copy_image_to_volume volume: " + str(volume) +
                 " image service: " + str(image_service) + " image id: " +
                 str(image_id))
        properties = utils.brick_get_connector_properties()
        sdc_ip = properties['ip']
        LOG.debug("SDC ip is: {0}".format(sdc_ip))

        cinder_version = version.version_info.version_string()
        #      cinder_version = str(version.version_info)
        LOG.debug("Cinder version is %s " % cinder_version)
        #       check if openstack version ia icehouse
        if (cinder_version.startswith("2014")):
            LOG.info("Cinder version is Icehouse ")
            icehouse = 'True'
        else:
            LOG.info("Cinder version is Havana or older ")
            icehouse = 'False'

        try:
            if (icehouse == 'True'):
                image_utils.fetch_to_raw(context,
                                         image_service,
                                         image_id,
                                         self._attach_volume(volume, sdc_ip),
                                         BLOCK_SIZE,
                                         size=volume['size'])
            else:
                image_utils.fetch_to_raw(context, image_service, image_id,
                                         self._attach_volume(volume, sdc_ip))

        finally:
            self._detach_volume(volume, sdc_ip)
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.info("ScaleIO copy_image_to_volume volume: "+str(volume) + " image service: " + str(image_service) + " image id: " + str(image_id))
        properties = utils.brick_get_connector_properties()
        sdc_ip = properties['ip']
        LOG.debug("SDC ip is: {0}".format(sdc_ip))
        
        cinder_version = version.version_info.version_string()
  #      cinder_version = str(version.version_info) 
        LOG.debug("Cinder version is %s " % cinder_version)
#       check if openstack version ia icehouse  
        if (cinder_version.startswith("2014")):
            LOG.info("Cinder version is Icehouse ")
            icehouse = 'True'
        else:
            LOG.info("Cinder version is Havana or older ")
            icehouse = 'False'
        
        try:
            if (icehouse == 'True'):
                image_utils.fetch_to_raw(context,
                                         image_service,
                                         image_id,
                                         self._attach_volume(volume, sdc_ip),
                                         BLOCK_SIZE,
                                         size=volume['size'])
            else:
                image_utils.fetch_to_raw(context,
                                         image_service,
                                         image_id,
                                         self._attach_volume(volume, sdc_ip))
                
        finally:
            self._detach_volume(volume, sdc_ip)
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """
        Fetch the image from image_service and write it to the volume.
        Called on "nova volume-create --image-id ..." or "cinder create --image-id"
        Downloads image from glance server into volume

        :param context: Context object
        :type context: cinder.context
        :param volume: Volume reference (sqlalchemy Model)
        :type volume: cinder.objects.volume.Volume
        :param image_service: Image service reference
        :type image_service: glance.cmd.replicator.ImageService
        :param image_id: ID of the image
        :type image_id: str
        :return: None
        """
        cleaned_name = OpenvStorageEdgeBaseVD._clean_display_name(name=volume.display_name)
        location = "openvstorage+{0}:{1}:{2}/{3}".format(self._protocol, self._ip, self._port, cleaned_name)
        image_path = os.path.join("/tmp", image_id)
        if not os.path.exists(image_path):
            logger.debug("Downloading image to temporary location {0}".format(image_path))
            image_utils.fetch_to_raw(
                context=context,
                image_service=image_service,
                image_id=image_id,
                dest=image_path,
                blocksize="1M",
                size=volume.size,
            )
        logger.debug("Creating volume from image at location: {0}".format(location))
        OpenvStorageEdgeBaseVD._execute_qemu_command(parameters=["convert", "-n", "-O", "raw", image_path, location])
Esempio n. 16
0
    def test_copy_image_to_volume(self):
        """resize_image common case usage."""
        mox = self._mox
        drv = self._driver

        TEST_IMG_SOURCE = 'foo.img'

        volume = {'size': self.TEST_SIZE_IN_GB, 'name': TEST_IMG_SOURCE}

        def fake_local_path(volume):
            return volume['name']

        self.stubs.Set(drv, 'local_path', fake_local_path)

        mox.StubOutWithMock(image_utils, 'fetch_to_raw')
        image_utils.fetch_to_raw(None, None, None, TEST_IMG_SOURCE)

        mox.StubOutWithMock(image_utils, 'resize_image')
        image_utils.resize_image(TEST_IMG_SOURCE, self.TEST_SIZE_IN_GB)

        mox.StubOutWithMock(image_utils, 'qemu_img_info')
        data = mox_lib.MockAnything()
        data.virtual_size = 1024**3
        image_utils.qemu_img_info(TEST_IMG_SOURCE).AndReturn(data)

        mox.ReplayAll()

        drv.copy_image_to_volume(None, volume, None, None)

        mox.VerifyAll()
Esempio n. 17
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """
        Fetch the image from image_service and write it to the volume.
        Called on "nova volume-create --image-id ..." or "cinder create --image-id"
        Downloads image from glance server into volume

        :param context: Context object
        :type context: cinder.context
        :param volume: Volume reference (sqlalchemy Model)
        :type volume: cinder.objects.volume.Volume
        :param image_service: Image service reference
        :type image_service: glance.cmd.replicator.ImageService
        :param image_id: ID of the image
        :type image_id: str
        :return: None
        """
        cleaned_name = OpenvStorageEdgeBaseVD._clean_display_name(
            name=volume.display_name)
        location = 'openvstorage+{0}:{1}:{2}/{3}'.format(
            self._protocol, self._ip, self._port, cleaned_name)
        image_path = os.path.join('/tmp', image_id)
        if not os.path.exists(image_path):
            logger.debug('Downloading image to temporary location {0}'.format(
                image_path))
            image_utils.fetch_to_raw(context=context,
                                     image_service=image_service,
                                     image_id=image_id,
                                     dest=image_path,
                                     blocksize='1M',
                                     size=volume.size)
        logger.debug(
            'Creating volume from image at location: {0}'.format(location))
        OpenvStorageEdgeBaseVD._execute_qemu_command(
            parameters=['convert', '-n', '-O', 'raw', image_path, location])
Esempio n. 18
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):

        tmp_dir = self._image_conversion_dir()

        with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp:
            image_utils.fetch_to_raw(context, image_service, image_id,
                                     tmp.name,
                                     self.configuration.volume_dd_blocksize,
                                     size=volume['size'])

            self.delete_volume(volume)

            chunk_size = CONF.rbd_store_chunk_size * units.Mi
            order = int(math.log(chunk_size, 2))
            # keep using the command line import instead of librbd since it
            # detects zeroes to preserve sparseness in the image
            args = ['rbd', 'import',
                    '--pool', self.configuration.rbd_pool,
                    '--order', order,
                    tmp.name, volume['name']]
            if self._supports_layering():
                args.append('--new-format')
            args.extend(self._ceph_args())
            self._try_execute(*args)
        self._resize(volume)
Esempio n. 19
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""

        LOG.debug("copy_image_to_volume volume: %(vol)s "
                  "image service: %(service)s image id: %(id)s.",
                  {'vol': volume,
                   'service': six.text_type(image_service),
                   'id': six.text_type(image_id)})

        path = util.get_image_path(image_id)
        try:
            # Skip image creation if file already exists
            if not os.path.isfile(path):
                image_utils.fetch_to_raw(context,
                                         image_service,
                                         image_id,
                                         path,
                                         BLOCK_SIZE,
                                         size=volume['size'])
            metadata = self._get_volume_metadata(volume)
            hs_img_id = self._get_volume_metadata_value(metadata,
                                                        'hs_image_id')
            util.update_image(path, volume['id'], hs_img_id)

        except (exception.UnableToExecuteHyperScaleCmd,
                exception.UnableToProcessHyperScaleCmdOutput):
            with excutils.save_and_reraise_exception():
                LOG.exception('Failed to copy_image_to_volume')
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     """Fetch the image from image_service and write it to the volume."""
     image_utils.fetch_to_raw(context,
                              image_service,
                              image_id,
                              self.local_path(volume),
                              size=volume['size'])
Esempio n. 21
0
 def copy_image_to_volume(self,
                          context,
                          volume,
                          image_service,
                          image_id,
                          encrypted=False):
     tmp_dir = volume_utils.image_conversion_dir()
     with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp:
         image_utils.fetch_to_raw(context,
                                  image_service,
                                  image_id,
                                  tmp.name,
                                  self.configuration.volume_dd_blocksize,
                                  size=volume.size)
         out_format = ['-O', 'raw']
         if encrypted:
             key_file, opts = self._encrypt_opts(volume, context)
             out_format = ['-O', 'luks', *opts]
         dest_name = utils.convert_str(volume.name)
         self._try_execute(
             'qemu-img', 'convert', '-f', 'raw', tmp.name, *out_format,
             'vitastor:image=' + dest_name.replace(':', '\\:') +
             self._qemu_args())
         if encrypted:
             key_file.close()
Esempio n. 22
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        image_utils.fetch_to_raw(context,
                                 image_service,
                                 image_id,
                                 self.local_path(volume),
                                 self.configuration.volume_dd_blocksize,
                                 size=volume['size'])

        # NOTE (leseb): Set the virtual size of the image
        # the raw conversion overwrote the destination file
        # (which had the correct size)
        # with the fetched glance image size,
        # thus the initial 'size' parameter is not honored
        # this sets the size to the one asked in the first place by the user
        # and then verify the final virtual size
        image_utils.resize_image(self.local_path(volume), volume['size'])

        data = image_utils.qemu_img_info(self.local_path(volume))
        virt_size = data.virtual_size / units.GiB
        if virt_size != volume['size']:
            raise exception.ImageUnacceptable(
                image_id=image_id,
                reason=(_("Expected volume size was %d") % volume['size'])
                + (_(" but size is now %d") % virt_size))
Esempio n. 23
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        image_utils.fetch_to_raw(context,
                                 image_service,
                                 image_id,
                                 self.local_path(volume),
                                 self.configuration.volume_dd_blocksize,
                                 size=volume['size'])

        # NOTE (leseb): Set the virtual size of the image
        # the raw conversion overwrote the destination file
        # (which had the correct size)
        # with the fetched glance image size,
        # thus the initial 'size' parameter is not honored
        # this sets the size to the one asked in the first place by the user
        # and then verify the final virtual size
        image_utils.resize_image(self.local_path(volume), volume['size'])

        data = image_utils.qemu_img_info(self.local_path(volume))
        virt_size = data.virtual_size / units.Gi
        if virt_size != volume['size']:
            raise exception.ImageUnacceptable(
                image_id=image_id,
                reason=(_("Expected volume size was %d") % volume['size'])
                + (_(" but size is now %d") % virt_size))
Esempio n. 24
0
    def test_fetch_to_raw(self):
        TEST_RET = "image: qemu.qcow2\n"\
                   "file_format: qcow2 \n"\
                   "virtual_size: 50M (52428800 bytes)\n"\
                   "cluster_size: 65536\n"\
                   "disk_size: 196K (200704 bytes)"
        TEST_RETURN_RAW = "image: qemu.raw\n"\
                          "file_format: raw\n"\
                          "virtual_size: 50M (52428800 bytes)\n"\
                          "cluster_size: 65536\n"\
                          "disk_size: 196K (200704 bytes)\n"\

        fake_image_service = FakeImageService()
        mox = self._mox

        mox.StubOutWithMock(image_utils, 'create_temporary_file')
        mox.StubOutWithMock(utils, 'execute')
        mox.StubOutWithMock(image_utils, 'fetch')

        image_utils.create_temporary_file().AndReturn(self.TEST_DEV_PATH)
        image_utils.fetch(context, fake_image_service, self.TEST_IMAGE_ID,
                          self.TEST_DEV_PATH, None, None)

        utils.execute('env',
                      'LC_ALL=C',
                      'LANG=C',
                      'qemu-img',
                      'info',
                      self.TEST_DEV_PATH,
                      run_as_root=True).AndReturn((TEST_RET, 'ignored'))

        utils.execute('env',
                      'LC_ALL=C',
                      'LANG=C',
                      'qemu-img',
                      'info',
                      self.TEST_DEV_PATH,
                      run_as_root=True).AndReturn((TEST_RET, 'ignored'))

        utils.execute('qemu-img',
                      'convert',
                      '-O',
                      'raw',
                      self.TEST_DEV_PATH,
                      self.TEST_DEV_PATH,
                      run_as_root=True)

        utils.execute('env',
                      'LC_ALL=C',
                      'LANG=C',
                      'qemu-img',
                      'info',
                      self.TEST_DEV_PATH,
                      run_as_root=True).AndReturn((TEST_RETURN_RAW, 'ignored'))

        mox.ReplayAll()

        image_utils.fetch_to_raw(context, fake_image_service,
                                 self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
        mox.VerifyAll()
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Copy image to volume
        Called on "nova volume-create --image-id ..."
        or "cinder create --image-id"
        Downloads image from glance server into local .raw
        :param volume: volume reference (sqlalchemy Model)
        """
        _debug_vol_info("CP_IMG_TO_VOL", volume)
        LOG.info("CP_IMG_TO_VOL %s %s" % (image_service, image_id))

        name = volume.display_name
        if not name:
            name = volume.name
            volume.display_name = volume.name

        # downloading from an existing image
        destination_path = volume.provider_location
        if destination_path:
            try:
                LOG.info("CP_IMG_TO_VOL Deleting existing empty raw file %s " % destination_path)
                VDiskController.delete_volume(location=destination_path)
                LOG.info("CP_IMG_TO_VOL Downloading image to %s" % destination_path)
                image_utils.fetch_to_raw(context, image_service, image_id, destination_path, "1M", size=volume["size"])
                LOG.info("CP_IMG_TO_VOL Resizing volume to size %s" % volume["size"])
                self.extend_volume(volume=volume, size_gb=volume["size"])
            except Exception as ex:
                LOG.error("CP_IMG_TO_VOL Internal error %s " % unicode(ex))
                self.delete_volume(volume)
                raise
            ovs_disk = self._find_ovs_model_disk_by_location(volume.provider_location, str(volume.host))
            ovs_disk.name = name
            ovs_disk.save()
Esempio n. 26
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):

        tmp_dir = self._image_conversion_dir()

        with tempfile.NamedTemporaryFile(dir=tmp_dir) as tmp:
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     tmp.name,
                                     self.configuration.volume_dd_blocksize,
                                     size=volume['size'])

            self.delete_volume(volume)

            chunk_size = self.configuration.rbd_store_chunk_size * units.Mi
            order = int(math.log(chunk_size, 2))
            # keep using the command line import instead of librbd since it
            # detects zeroes to preserve sparseness in the image
            args = [
                'rbd', 'import', '--pool', self.configuration.rbd_pool,
                '--order', order, tmp.name, volume['name'], '--new-format'
            ]
            args.extend(self._ceph_args())
            self._try_execute(*args)
        self._resize(volume)
Esempio n. 27
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""

        LOG.debug("copy_image_to_volume volume: %(vol)s "
                  "image service: %(service)s image id: %(id)s.",
                  {'vol': volume,
                   'service': six.text_type(image_service),
                   'id': six.text_type(image_id)})

        path = util.get_image_path(image_id)
        try:
            # Skip image creation if file already exists
            if not os.path.isfile(path):
                image_utils.fetch_to_raw(context,
                                         image_service,
                                         image_id,
                                         path,
                                         BLOCK_SIZE,
                                         size=volume['size'])
            metadata = self._get_volume_metadata(volume)
            hs_img_id = self._get_volume_metadata_value(metadata,
                                                        'hs_image_id')
            util.update_image(path, volume['id'], hs_img_id)

        except (v_exception.UnableToExecuteHyperScaleCmd,
                v_exception.UnableToProcessHyperScaleCmdOutput):
            with excutils.save_and_reraise_exception():
                LOG.exception('Failed to copy_image_to_volume')
Esempio n. 28
0
    def _create_image_volume(self, context, image_meta, image_service, image_id):
        # NOTE(jdg): It's callers responsibility to ensure that
        # the optional properties.virtual_size is set on the image
        # before we get here
        virt_size = int(image_meta["properties"].get("virtual_size"))
        min_sz_in_bytes = math.ceil(virt_size / float(units.Gi)) * float(units.Gi)
        min_sz_in_gig = math.ceil(min_sz_in_bytes / float(units.Gi))

        attributes = {}
        attributes["image_info"] = {}
        attributes["image_info"]["image_updated_at"] = image_meta["updated_at"].isoformat()
        attributes["image_info"]["image_name"] = image_meta["name"]
        attributes["image_info"]["image_created_at"] = image_meta["created_at"].isoformat()
        attributes["image_info"]["image_id"] = image_meta["id"]
        params = {
            "name": "OpenStackIMG-%s" % image_id,
            "accountID": self.template_account_id,
            "sliceCount": 1,
            "totalSize": int(min_sz_in_bytes),
            "enable512e": self.configuration.sf_emulate_512,
            "attributes": attributes,
            "qos": {},
        }

        sf_account = self._issue_api_request("GetAccountByID", {"accountID": self.template_account_id})

        template_vol = self._do_volume_create(sf_account, params)
        tvol = {}
        tvol["id"] = image_id
        tvol["provider_location"] = template_vol["provider_location"]
        tvol["provider_auth"] = template_vol["provider_auth"]

        connector = "na"
        conn = self.initialize_connection(tvol, connector)
        attach_info = super(SolidFireDriver, self)._connect_device(conn)
        properties = "na"

        try:
            image_utils.fetch_to_raw(
                context,
                image_service,
                image_id,
                attach_info["device"]["path"],
                self.configuration.volume_dd_blocksize,
                size=min_sz_in_gig,
            )
        except Exception as exc:
            params["volumeID"] = template_vol["volumeID"]
            LOG.error(_LE("Failed image conversion during cache creation: %s"), exc)
            LOG.debug("Removing SolidFire Cache Volume (SF ID): %s", template_vol["volumeID"])

            self._detach_volume(context, attach_info, tvol, properties)
            self._issue_api_request("DeleteVolume", params)
            return

        self._detach_volume(context, attach_info, tvol, properties)
        sf_vol = self._get_sf_volume(image_id, params)
        LOG.debug("Successfully created SolidFire Image Template " "for image-id: %s", image_id)
        return sf_vol
Esempio n. 29
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     """Fetch the image from image_service and write it to the volume."""
     image_utils.fetch_to_raw(context,
                              image_service,
                              image_id,
                              self.local_path(volume),
                              self.configuration.volume_dd_blocksize,
                              size=volume.size)
Esempio n. 30
0
 def _use_image_utils_to_pipe_bytes_to_volume(self, context, volume,
                                              image_service, image_id):
     sr_uuid, vdi_uuid = volume['provider_location'].split('/')
     with self.nfs_ops.volume_attached_here(FLAGS.xenapi_nfs_server,
                                            FLAGS.xenapi_nfs_serverpath,
                                            sr_uuid, vdi_uuid,
                                            False) as device:
         image_utils.fetch_to_raw(context, image_service, image_id, device)
Esempio n. 31
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     LOG.debug('Copy image to volume')
     image_utils.fetch_to_raw(context,
                              image_service,
                              image_id,
                              self.local_path(volume),
                              self.configuration.volume_dd_blocksize,
                              size=volume['size'])
Esempio n. 32
0
File: nbd.py Progetto: Jchuan/cinder
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     LOG.debug('Copy image to volume')
     image_utils.fetch_to_raw(context,
                              image_service,
                              image_id,
                              self.local_path(volume),
                              self.configuration.volume_dd_blocksize,
                              size=volume['size'])
Esempio n. 33
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     """Fetch the image from image_service and write it to the volume."""
     image_utils.fetch_to_raw(context,
                              image_service,
                              image_id,
                              self.local_path(volume),
                              self.configuration.volume_dd_blocksize,
                              size=volume.size)
Esempio n. 34
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     """Fetch the image from image_service and write it to the volume."""
     LOG.debug(_("FuseVolumeDriver::copy_image_to_volume() v:%s"), volume)
     image_utils.fetch_to_raw(context,
                              image_service,
                              image_id,
                              self.local_path(volume),
                              self.configuration.volume_dd_blocksize,
                              size=volume['size'])
Esempio n. 35
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     with image_utils.temporary_file() as tmp:
         image_utils.fetch_verify_image(context, image_service, image_id,
                                        tmp)
     image_utils.fetch_to_raw(context,
                              image_service,
                              image_id,
                              tmp,
                              self.configuration.volume_dd_blocksize,
                              size=volume['size'])
Esempio n. 36
0
 def copy_image_to_volume(self, context, volume, image_service, image_id):
     with image_utils.temporary_file() as tmp:
         image_utils.fetch_verify_image(context, image_service,
                                        image_id, tmp)
     image_utils.fetch_to_raw(context,
                              image_service,
                              image_id,
                              tmp,
                              self.configuration.volume_dd_blocksize,
                              size=volume['size'])
Esempio n. 37
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug(_("copy_image_to_volume %s.") % volume["name"])
        connector = {"initiator": self._get_iscsi_initiator(), "host": socket.gethostname()}

        iscsi_properties, volume_path = self._attach_volume(context, volume, connector)

        try:
            image_utils.fetch_to_raw(context, image_service, image_id, volume_path)
        finally:
            self.terminate_connection(volume, connector)
Esempio n. 38
0
 def _use_image_utils_to_pipe_bytes_to_volume(self, context, volume,
                                              image_service, image_id):
     sr_uuid, vdi_uuid = volume['provider_location'].split('/')
     with self.nfs_ops.volume_attached_here(CONF.xenapi_nfs_server,
                                            CONF.xenapi_nfs_serverpath,
                                            sr_uuid, vdi_uuid,
                                            False) as device:
         image_utils.fetch_to_raw(context,
                                  image_service,
                                  image_id,
                                  device)
Esempio n. 39
0
 def test_copy_image_to_volume(self):
     TEST_VOLUME = {'provider_location': '1 2 3 /dev/loop1'}
     TEST_IMAGE_SERVICE = "image_service"
     TEST_IMAGE_ID = "image_id"
     self.mox.StubOutWithMock(image_utils, 'fetch_to_raw')
     self.mox.StubOutWithMock(self.drv, 'local_path')
     self.drv.local_path(TEST_VOLUME).AndReturn('/dev/loop1')
     image_utils.fetch_to_raw(context, TEST_IMAGE_SERVICE, TEST_IMAGE_ID,
                              '/dev/loop1')
     self.mox.ReplayAll()
     self.drv.copy_image_to_volume(context, TEST_VOLUME, TEST_IMAGE_SERVICE,
                                   TEST_IMAGE_ID)
Esempio n. 40
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug(_("copy_image_to_volume %s.") % volume["name"])

        properties = initiator.get_connector_properties()
        attach_info = self._attach_volume(context, volume, properties)

        try:
            image_utils.fetch_to_raw(context, image_service, image_id, attach_info["device"]["path"])
        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Esempio n. 41
0
 def test_copy_image_to_volume(self):
     TEST_VOLUME = {'provider_location': '1 2 3 /dev/loop1'}
     TEST_IMAGE_SERVICE = "image_service"
     TEST_IMAGE_ID = "image_id"
     self.mox.StubOutWithMock(image_utils, 'fetch_to_raw')
     self.mox.StubOutWithMock(self.drv, 'local_path')
     self.drv.local_path(TEST_VOLUME).AndReturn('/dev/loop1')
     image_utils.fetch_to_raw(context, TEST_IMAGE_SERVICE,
                              TEST_IMAGE_ID, '/dev/loop1')
     self.mox.ReplayAll()
     self.drv.copy_image_to_volume(context, TEST_VOLUME, TEST_IMAGE_SERVICE,
                                   TEST_IMAGE_ID)
Esempio n. 42
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        # self.create_volume(volume) already called by Cinder, and works
        full_rsc_name = self._drbd_resource_name_from_cinder_volume(volume)

        # This creates a LINSTOR volume from the source image
        image_utils.fetch_to_raw(context,
                                 image_service,
                                 image_id,
                                 str(self._get_rsc_path(full_rsc_name)),
                                 self.default_blocksize,
                                 size=volume['size'])
        return {}
Esempio n. 43
0
    def test_copy_image_to_volume(self):
        """Expected behaviour for copy_image_to_volume."""
        self.mox.StubOutWithMock(image_utils, 'fetch_to_raw')

        image_utils.fetch_to_raw(context, self.TEST_IMAGE_SERVICE,
                                 self.TEST_IMAGE_ID, self.TEST_VOLPATH)

        self.mox.ReplayAll()

        self._driver.copy_image_to_volume(context, self.TEST_VOLUME,
                                          self.TEST_IMAGE_SERVICE,
                                          self.TEST_IMAGE_ID)
Esempio n. 44
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug(_('copy_image_to_volume %s.') % volume['name'])

        properties = utils.brick_get_connector_properties()
        attach_info = self._attach_volume(context, volume, properties)

        try:
            image_utils.fetch_to_raw(context, image_service, image_id,
                                     attach_info['device']['path'])
        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Esempio n. 45
0
 def _use_image_utils_to_pipe_bytes_to_volume(self, context, volume,
                                              image_service, image_id):
     sr_uuid, vdi_uuid = volume['provider_location'].split('/')
     with self.nfs_ops.volume_attached_here(CONF.xenapi_nfs_server,
                                            CONF.xenapi_nfs_serverpath,
                                            sr_uuid, vdi_uuid,
                                            False) as device:
         image_utils.fetch_to_raw(context,
                                  image_service,
                                  image_id,
                                  device,
                                  self.configuration.volume_dd_blocksize,
                                  size=volume['size'])
Esempio n. 46
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        # self.create_volume(volume) already called by Cinder, and works.
        # Need to check return values
        full_rsc_name = self._drbd_resource_name_from_cinder_volume(volume)

        # This creates a LINSTOR volume at the original size.
        image_utils.fetch_to_raw(context,
                                 image_service,
                                 image_id,
                                 str(self._get_rsc_path(full_rsc_name)),
                                 self.default_blocksize,
                                 size=volume['size'])
        return {}
Esempio n. 47
0
    def test_copy_image_to_volume(self):
        fake_image_service = 'fake-image-service'
        fake_image_id = 'fake-image-id;'

        self.mox.StubOutWithMock(image_utils, 'fetch_to_raw')
        image_utils.fetch_to_raw({}, fake_image_service, fake_image_id,
                                 self.fake_dev_path)

        self.mox.ReplayAll()

        self.driver.copy_image_to_volume({}, fake_volume, fake_image_service,
                                         fake_image_id)

        self.mox.VerifyAll()
Esempio n. 48
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug("Enter in copy image to volume for disco.")

        try:
            device_info = self._attach_volume(volume)
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     device_info['path'],
                                     self.configuration.volume_dd_blocksize,
                                     size=volume['size'])
        finally:
            self._detach_volume(volume)
Esempio n. 49
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug("Enter in copy image to volume for disco.")

        try:
            device_info = self._attach_volume(volume)
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     device_info['path'],
                                     self.configuration.volume_dd_blocksize,
                                     size=volume['size'])
        finally:
            self._detach_volume(volume)
Esempio n. 50
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume.

        Note that cinder.volume.flows.create_volume will attempt to use
        clone_image to efficiently create volume from image when both
        source and target are backed by gpfs storage.  If that is not the
        case, this function is invoked and uses fetch_to_raw to create the
        volume.
        """
        LOG.debug('Copy image to vol %s using image_utils fetch_to_raw' %
                  volume['id'])
        image_utils.fetch_to_raw(context, image_service, image_id,
                                 self.local_path(volume))
        image_utils.resize_image(self.local_path(volume), volume['size'])
Esempio n. 51
0
    def test_copy_image_to_volume(self):
        fake_image_service = "fake-image-service"
        fake_image_id = "fake-image-id;"

        self.mox.StubOutWithMock(image_utils, "fetch_to_raw")
        image_utils.fetch_to_raw(
            {}, fake_image_service, fake_image_id, self.fake_dev_path, mox.IgnoreArg(), size=fake_volume_size
        )

        self.mox.ReplayAll()

        self.driver.copy_image_to_volume({}, fake_volume, fake_image_service, fake_image_id)

        self.mox.VerifyAll()
Esempio n. 52
0
    def test_fetch_to_raw(self):
        TEST_RET = "image: qemu.qcow2\n"\
                   "file_format: qcow2 \n"\
                   "virtual_size: 50M (52428800 bytes)\n"\
                   "cluster_size: 65536\n"\
                   "disk_size: 196K (200704 bytes)"
        TEST_RETURN_RAW = "image: qemu.raw\n"\
                          "file_format: raw\n"\
                          "virtual_size: 50M (52428800 bytes)\n"\
                          "cluster_size: 65536\n"\
                          "disk_size: 196K (200704 bytes)\n"\

        fake_image_service = FakeImageService()
        mox = self._mox

        mox.StubOutWithMock(image_utils, 'create_temporary_file')
        mox.StubOutWithMock(utils, 'execute')
        mox.StubOutWithMock(image_utils, 'fetch')

        image_utils.create_temporary_file().AndReturn(self.TEST_DEV_PATH)
        image_utils.fetch(context, fake_image_service,
                          self.TEST_IMAGE_ID, self.TEST_DEV_PATH, None, None)

        utils.execute(
            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
                (TEST_RET, 'ignored')
            )

        utils.execute(
            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
                (TEST_RET, 'ignored')
            )

        utils.execute('qemu-img', 'convert', '-O', 'raw',
                      self.TEST_DEV_PATH, self.TEST_DEV_PATH, run_as_root=True)

        utils.execute(
            'env', 'LC_ALL=C', 'LANG=C', 'qemu-img', 'info',
            self.TEST_DEV_PATH, run_as_root=True).AndReturn(
                (TEST_RETURN_RAW, 'ignored')
            )

        mox.ReplayAll()

        image_utils.fetch_to_raw(context, fake_image_service,
                                 self.TEST_IMAGE_ID, self.TEST_DEV_PATH)
        mox.VerifyAll()
Esempio n. 53
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume.

        Note that cinder.volume.flows.create_volume will attempt to use
        clone_image to efficiently create volume from image when both
        source and target are backed by gpfs storage.  If that is not the
        case, this function is invoked and uses fetch_to_raw to create the
        volume.
        """
        # Check if GPFS is mounted
        self._verify_gpfs_path_state(self.configuration.gpfs_mount_point_base)

        LOG.debug("Copy image to vol %s using image_utils fetch_to_raw" % volume["id"])
        image_utils.fetch_to_raw(context, image_service, image_id, self.local_path(volume), size=volume["size"])
        image_utils.resize_image(self.local_path(volume), volume["size"])
Esempio n. 54
0
    def test_copy_image_to_volume(self):
        """Expected behaviour for copy_image_to_volume."""
        self.mox.StubOutWithMock(image_utils, 'fetch_to_raw')

        image_utils.fetch_to_raw(context,
                                 self.TEST_IMAGE_SERVICE,
                                 self.TEST_IMAGE_ID,
                                 self.TEST_VOLPATH)

        self.mox.ReplayAll()

        self._driver.copy_image_to_volume(context,
                                          self.TEST_VOLUME,
                                          self.TEST_IMAGE_SERVICE,
                                          self.TEST_IMAGE_ID)
Esempio n. 55
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug(_('copy_image_to_volume %s.') % volume['name'])

        properties = utils.brick_get_connector_properties()
        attach_info = self._attach_volume(context, volume, properties)

        try:
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     attach_info['device']['path'])
        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
Esempio n. 56
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug(_('copy_image_to_volume %s.') % volume['name'])
        connector = {'initiator': self._get_iscsi_initiator(),
                     'host': socket.gethostname()}

        iscsi_properties, volume_path = self._attach_volume(
            context, volume, connector)

        try:
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     volume_path)
        finally:
            self.terminate_connection(volume, connector)
Esempio n. 57
0
    def test_copy_image_to_volume(self):
        """Expected behaviour for copy_image_to_volume."""
        self.mox.StubOutWithMock(image_utils, "fetch_to_raw")

        image_utils.fetch_to_raw(
            context,
            self.TEST_IMAGE_SERVICE,
            self.TEST_IMAGE_ID,
            self.TEST_VOLPATH,
            mox_lib.IgnoreArg(),
            size=self.TEST_VOLSIZE,
        )

        self.mox.ReplayAll()

        self._driver.copy_image_to_volume(context, self.TEST_VOLUME, self.TEST_IMAGE_SERVICE, self.TEST_IMAGE_ID)
Esempio n. 58
0
    def copy_image_to_volume(self, context, volume, image_service, image_id):
        """Fetch the image from image_service and write it to the volume."""
        LOG.debug(_('copy_image_to_volume %s.') % volume['name'])

        properties = utils.brick_get_connector_properties()
        attach_info = self._attach_volume(context, volume, properties)

        try:
            image_utils.fetch_to_raw(context,
                                     image_service,
                                     image_id,
                                     attach_info['device']['path'],
                                     self.configuration.volume_dd_blocksize,
                                     size=volume['size'])
        finally:
            self._detach_volume(context, attach_info, volume, properties)