예제 #1
0
    def test_copy_volume_to_image(self):
        drv = self._driver

        vol = db_fakes.get_fake_volume_info()

        image_meta = db_fakes.get_fake_image_meta()

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

        self.mox.StubOutWithMock(image_utils, 'upload_volume')

        temp_vhd_path = os.path.join(CONF.image_conversion_dir,
                                     str(image_meta['id']) + ".vhd")

        image_utils.upload_volume(None, None, image_meta, temp_vhd_path, 'vpc')

        self.mox.StubOutWithMock(windows_utils.WindowsUtils,
                                 'copy_vhd_disk')

        windows_utils.WindowsUtils.copy_vhd_disk(self.fake_local_path(vol),
                                                 temp_vhd_path)

        self.mox.ReplayAll()

        drv.copy_volume_to_image(None, vol, None, image_meta)
예제 #2
0
파일: remotefs.py 프로젝트: luisfdez/cinder
    def _copy_volume_to_image(self, context, volume, image_service,
                              image_meta):
        """Copy the volume to the specified image."""

        # If snapshots exist, flatten to a temporary image, and upload it

        active_file = self.get_active_image_from_info(volume)
        active_file_path = os.path.join(self._local_volume_dir(volume),
                                        active_file)
        info = self._qemu_img_info(active_file_path)
        backing_file = info.backing_file

        root_file_fmt = info.file_format

        tmp_params = {
            'prefix': '%s.temp_image.%s' % (volume['id'], image_meta['id']),
            'suffix': '.img'
        }
        with image_utils.temporary_file(**tmp_params) as temp_path:
            if backing_file or (root_file_fmt != 'raw'):
                # Convert due to snapshots
                # or volume data not being stored in raw format
                #  (upload_volume assumes raw format input)
                image_utils.convert_image(active_file_path, temp_path, 'raw')
                upload_path = temp_path
            else:
                upload_path = active_file_path

            image_utils.upload_volume(context, image_service, image_meta,
                                      upload_path)
예제 #3
0
    def test_upload_volume_with_bps_limit(self, mock_stat):
        bps_limit = 1048576
        image_meta = {"id": 1, "disk_format": "qcow2"}
        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)"
        )

        self.override_config("volume_copy_bps_limit", bps_limit)
        prefix = ("cgexec", "-g", "blkio:test")

        cmd = prefix + ("qemu-img", "convert", "-O", "qcow2", mox.IgnoreArg(), mox.IgnoreArg())

        m = self._mox
        m.StubOutWithMock(utils, "execute")
        m.StubOutWithMock(volume_utils, "setup_blkio_cgroup")
        m.StubOutWithMock(volume_utils, "check_for_odirect_support")

        volume_utils.setup_blkio_cgroup(mox.IgnoreArg(), mox.IgnoreArg(), bps_limit).AndReturn(prefix)
        utils.execute(*cmd, run_as_root=True)
        utils.execute("env", "LC_ALL=C", "qemu-img", "info", mox.IgnoreArg(), run_as_root=True).AndReturn(
            (TEST_RET, "ignored")
        )

        m.ReplayAll()
        image_utils.upload_volume(context, FakeImageService(), image_meta, "/dev/loop1")
        m.VerifyAll()
예제 #4
0
파일: srb.py 프로젝트: yangkf1985/cinder
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy the volume to the specified image."""
     with temp_lvm_device(self, volume):
         image_utils.upload_volume(context,
                                   image_service,
                                   image_meta,
                                   self._mapper_path(volume))
예제 #5
0
def upload_volume(context,
                  image_service,
                  image_meta,
                  volume_path,
                  volume,
                  volume_format='raw',
                  run_as_root=True,
                  compress=True):
    # retrieve store information from extra-specs
    store_id = volume.volume_type.extra_specs.get('image_service:store_id')

    # This fetches the image_id from volume glance metadata and pass
    # it to the driver calling it during upload volume to image operation
    base_image_ref = None
    if volume.glance_metadata:
        base_image_ref = volume.glance_metadata.get('image_id')
    image_utils.upload_volume(context,
                              image_service,
                              image_meta,
                              volume_path,
                              volume_format=volume_format,
                              run_as_root=run_as_root,
                              compress=compress,
                              store_id=store_id,
                              base_image_ref=base_image_ref)
예제 #6
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""

        # If snapshots exist, flatten to a temporary image, and upload it

        active_file = self.get_active_image_from_info(volume)
        active_file_path = os.path.join(self._local_volume_dir(volume),
                                        active_file)
        backing_file = self._vhdutils.get_vhd_parent_path(active_file_path)
        root_file_fmt = self.get_volume_format(volume)

        temp_path = None

        try:
            if backing_file:
                temp_file_name = '%s.temp_image.%s.%s' % (
                    volume.id, image_meta['id'], root_file_fmt)
                temp_path = os.path.join(self._local_volume_dir(volume),
                                         temp_file_name)

                self._vhdutils.convert_vhd(active_file_path, temp_path)
                upload_path = temp_path
            else:
                upload_path = active_file_path

            image_utils.upload_volume(context, image_service, image_meta,
                                      upload_path, root_file_fmt)
        finally:
            if temp_path:
                self._delete(temp_path)
예제 #7
0
    def test_upload_volume(self, bps_limit=0):
        image_meta = {'id': 1, 'disk_format': 'qcow2'}
        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)"
        if bps_limit:
            CONF.set_override('volume_copy_bps_limit', bps_limit)
            prefix = ('cgexec', '-g', 'blkio:test')
            postfix = ('-t', 'none')
        else:
            prefix = postfix = ()
        cmd = prefix + ('qemu-img', 'convert', '-O', 'qcow2',
                        mox.IgnoreArg(), mox.IgnoreArg()) + postfix

        m = self._mox
        m.StubOutWithMock(utils, 'execute')
        m.StubOutWithMock(volume_utils, 'setup_blkio_cgroup')

        volume_utils.setup_blkio_cgroup(mox.IgnoreArg(), mox.IgnoreArg(),
                                        bps_limit).AndReturn(prefix)
        utils.execute(*cmd, run_as_root=True)
        utils.execute(
            'env', 'LC_ALL=C', 'qemu-img', 'info',
            mox.IgnoreArg(), run_as_root=True).AndReturn(
                (TEST_RET, 'ignored')
            )

        m.ReplayAll()

        image_utils.upload_volume(context, FakeImageService(),
                                  image_meta, '/dev/loop1')
        m.VerifyAll()
예제 #8
0
    def test_copy_volume_to_image(self):
        mox = self._mox
        drv = self._driver

        vol = db_fakes.get_fake_volume_info()

        image_meta = db_fakes.get_fake_image_meta()

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

        mox.StubOutWithMock(image_utils, 'upload_volume')

        temp_vhd_path = os.path.join(CONF.image_conversion_dir,
                                     str(image_meta['id']) + ".vhd")

        image_utils.upload_volume(None, None, image_meta, temp_vhd_path, 'vpc')

        self._mox.StubOutWithMock(windows_utils.WindowsUtils,
                                  'copy_vhd_disk')

        windows_utils.WindowsUtils.copy_vhd_disk(self.fake_local_path(vol),
                                                 temp_vhd_path)

        mox.ReplayAll()

        drv.copy_volume_to_image(None, vol, None, image_meta)

        mox.VerifyAll()
예제 #9
0
파일: lvm.py 프로젝트: kevin-zhangsen/badam
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.error('begin time of COPY_VOLUME_TO_IMAGE is %s' %
                  (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
        container_format = image_meta.get('container_format')
        file_name = image_meta.get('id')
        full_url = None
        if container_format in ['fs_vgw_url', 'vcloud_vgw_url', 'aws_vgw_url']:
            LOG.debug('get the vgw url')
            vgw_url = CONF.vgw.vgw_url.get(container_format)
            if vgw_url:
                full_url = vgw_url + '/' + file_name

            image_utils.upload_volume_to_vgw(context,
                                             image_service, image_meta,
                                             self.local_path(volume), volume,
                                             full_url)
            #create a empty file to glance
            with image_utils.temporary_file() as tmp:
                image_utils.upload_volume(context, image_service, image_meta,
                                          tmp)
            fileutils.delete_if_exists(tmp)
            LOG.error('end time of COPY_VOLUME_TO_IMAGE is %s' %
                      (time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
        else:
            image_utils.upload_volume(context, image_service, image_meta,
                                      self.local_path(volume))
예제 #10
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        if not os.path.exists(
                self.configuration.provider_image_conversion_dir):
            fileutils.ensure_tree(
                self.configuration.provider_image_conversion_dir)
        provider_volume_id = self._get_provider_volumeid_from_volume(volume)
        task_ret = self.adpter.export_volume(
            provider_volume_id,
            self.configuration.provider_image_conversion_dir,
            str(image_meta['id']),
            cgw_host_id=self.configuration.cgw_host_id,
            cgw_host_ip=self.configuration.cgw_host_ip,
            cgw_username=self.configuration.cgw_username,
            cgw_certificate=self.configuration.cgw_certificate,
            transfer_station=self.configuration.storage_tmp_dir)
        if not task_ret:
            raise exception_ex.ProviderExportVolumeError
        temp_path = os.path.join(
            self.configuration.provider_image_conversion_dir,
            str(image_meta['id']))
        upload_image = temp_path

        try:
            image_utils.upload_volume(context, image_service, image_meta,
                                      upload_image)
        finally:
            fileutils.delete_if_exists(upload_image)
예제 #11
0
    def test_upload_volume_with_bps_limit(self, mock_stat):
        bps_limit = 1048576
        image_meta = {'id': 1, 'disk_format': 'qcow2'}
        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)"

        self.override_config('volume_copy_bps_limit', bps_limit)
        prefix = ('cgexec', '-g', 'blkio:test')

        cmd = prefix + ('qemu-img', 'convert', '-O', 'qcow2', mox.IgnoreArg(),
                        mox.IgnoreArg())

        m = self._mox
        m.StubOutWithMock(utils, 'execute')
        m.StubOutWithMock(volume_utils, 'setup_blkio_cgroup')
        m.StubOutWithMock(volume_utils, 'check_for_odirect_support')

        volume_utils.setup_blkio_cgroup(mox.IgnoreArg(), mox.IgnoreArg(),
                                        bps_limit).AndReturn(prefix)
        utils.execute(*cmd, run_as_root=True)
        utils.execute('env',
                      'LC_ALL=C',
                      'qemu-img',
                      'info',
                      mox.IgnoreArg(),
                      run_as_root=True).AndReturn((TEST_RET, 'ignored'))

        m.ReplayAll()
        image_utils.upload_volume(context, FakeImageService(), image_meta,
                                  '/dev/loop1')
        m.VerifyAll()
예제 #12
0
파일: smbfs.py 프로젝트: mahak/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""

        # If snapshots exist, flatten to a temporary image, and upload it

        active_file = self.get_active_image_from_info(volume)
        active_file_path = os.path.join(self._local_volume_dir(volume),
                                        active_file)
        backing_file = self._vhdutils.get_vhd_parent_path(active_file_path)
        root_file_fmt = self.get_volume_format(volume)

        temp_path = None

        try:
            if backing_file:
                temp_file_name = '%s.temp_image.%s.%s' % (
                    volume.id,
                    image_meta['id'],
                    root_file_fmt)
                temp_path = os.path.join(self._local_volume_dir(volume),
                                         temp_file_name)

                self._vhdutils.convert_vhd(active_file_path, temp_path)
                upload_path = temp_path
            else:
                upload_path = active_file_path

            image_utils.upload_volume(context,
                                      image_service,
                                      image_meta,
                                      upload_path,
                                      root_file_fmt)
        finally:
            if temp_path:
                self._delete(temp_path)
예제 #13
0
파일: srb.py 프로젝트: kaitlin-farr/cinder
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy the volume to the specified image."""
     with temp_lvm_device(self, volume):
         image_utils.upload_volume(context,
                                   image_service,
                                   image_meta,
                                   self._mapper_path(volume))
예제 #14
0
    def test_upload_volume(self):
        image_meta = {'id': 1, 'disk_format': 'qcow2'}
        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)"

        m = self._mox
        m.StubOutWithMock(utils, 'execute')

        utils.execute('qemu-img',
                      'convert',
                      '-O',
                      'qcow2',
                      mox.IgnoreArg(),
                      mox.IgnoreArg(),
                      run_as_root=True)
        utils.execute('env',
                      'LC_ALL=C',
                      'LANG=C',
                      'qemu-img',
                      'info',
                      mox.IgnoreArg(),
                      run_as_root=True).AndReturn((TEST_RET, 'ignored'))

        m.ReplayAll()

        image_utils.upload_volume(context, FakeImageService(), image_meta,
                                  '/dev/loop1')
        m.VerifyAll()
예제 #15
0
파일: spdk.py 프로젝트: mahak/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""

        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.upload_volume(context,
                                      image_service,
                                      image_meta,
                                      device_info['path'])

        finally:
            target_connector.disconnect_volume(connection_data, volume)
예제 #16
0
파일: glusterfs.py 프로젝트: jcru/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""

        # If snapshots exist, flatten to a temporary image, and upload it

        active_file = self.get_active_image_from_info(volume)
        active_file_path = "%s/%s" % (self._local_volume_dir(volume), active_file)
        backing_file = self._get_backing_file_for_path(active_file_path)
        if backing_file is not None:
            snapshots_exist = True
        else:
            snapshots_exist = False

        root_file_fmt = self._get_file_format_for_path(self._local_path_volume(volume))

        temp_path = None

        try:
            if snapshots_exist or (root_file_fmt != "raw"):
                # Convert due to snapshots
                # or volume data not being stored in raw format
                #  (upload_volume assumes raw format input)
                temp_path = "%s/%s.temp_image.%s" % (self._local_volume_dir(volume), volume["id"], image_meta["id"])

                image_utils.convert_image(active_file_path, temp_path, "raw")
                upload_path = temp_path
            else:
                upload_path = active_file_path

            image_utils.upload_volume(context, image_service, image_meta, upload_path)
        finally:
            if temp_path is not None:
                self._execute("rm", "-f", temp_path)
예제 #17
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        # retrieve store information from extra-specs
        store_id = volume.volume_type.extra_specs.get('image_service:store_id')
        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.upload_volume(context,
                                      image_service,
                                      image_meta,
                                      device_info['path'],
                                      store_id=store_id)

        finally:
            target_connector.disconnect_volume(connection_data, volume)
예제 #18
0
파일: glusterfs.py 프로젝트: licyh/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""

        # If snapshots exist, flatten to a temporary image, and upload it

        active_file = self.get_active_image_from_info(volume)
        active_file_path = '%s/%s' % (self._local_volume_dir(volume),
                                      active_file)
        info = self._qemu_img_info(active_file_path)
        backing_file = info.backing_file
        if backing_file:
            snapshots_exist = True
        else:
            snapshots_exist = False

        root_file_fmt = info.file_format

        tmp_params = {
            'prefix': '%s.temp_image.%s' % (volume['id'], image_meta['id']),
            'suffix': '.img'
        }
        with image_utils.temporary_file(**tmp_params) as temp_path:
            if snapshots_exist or (root_file_fmt != 'raw'):
                # Convert due to snapshots
                # or volume data not being stored in raw format
                #  (upload_volume assumes raw format input)
                image_utils.convert_image(active_file_path, temp_path, 'raw')
                upload_path = temp_path
            else:
                upload_path = active_file_path

            image_utils.upload_volume(context,
                                      image_service,
                                      image_meta,
                                      upload_path)
예제 #19
0
파일: lvm.py 프로젝트: kevin-zhangsen/badam
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy the volume to the specified image."""
     LOG.error('begin time of COPY_VOLUME_TO_IMAGE is %s' %(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
     container_format=image_meta.get('container_format')
     file_name=image_meta.get('id')
     full_url=None
     if container_format in ['fs_vgw_url','vcloud_vgw_url','aws_vgw_url']:
         LOG.debug('get the vgw url')
         vgw_url = CONF.vgw.vgw_url.get(container_format)
         if  vgw_url:
             full_url=vgw_url+'/'+file_name
          
         image_utils.upload_volume_to_vgw(context, image_service, image_meta, self.local_path(volume), volume, full_url)
         #create a empty file to glance
         with image_utils.temporary_file() as tmp:
             image_utils.upload_volume(context,
                                       image_service,
                                       image_meta,
                                       tmp)
         fileutils.delete_if_exists(tmp)
         LOG.error('end time of COPY_VOLUME_TO_IMAGE is %s' %(time.strftime("%Y-%m-%d %H:%M:%S", time.localtime())))
     else:    
         image_utils.upload_volume(context,
                                   image_service,
                                   image_meta,
                                   self.local_path(volume))
예제 #20
0
            def _unused():
                # todo(wangfeng)
                # pdb.set_trace()
                # 1. get the vmdk file.

                volume_id = volume['id']
                if volume['attach_status'] == 'attached':
                    # nova_client = nova.novaclient(context)
                    # node_name = nova_client.servers.get(instance_id)._
                    # info['OS-EXT-SRV-ATTR:hypervisor_hostname']
                    the_vapp = self._get_vcloud_vapp(volume['instance_uuid'])
                    vmdk_url = self._query_vmdk_url(the_vapp)
                    local_file_name = '%s/%s.vmdk' % (
                        CONF.vcloud.vcloud_conversion_dir, volume_id)
                    self._download_vmdk_from_vcloud(context, vmdk_url,
                                                    local_file_name)

                    # volume_id = volume['id']
                    # create_info = {'snapshot_id':volume['snapshot_id'],
                    #              'type':'qcow2',
                    #             'new_file':'snapshot_file'}

                    # self._nova_api.create_volume_snapshot(context,volume_id,create_info)
                    # local_file_name = '%s/%s.vmdk' % (CONVERT_DIR, volume_id)
                else:
                    local_file_name = '%s/%s.vmdk' % (
                        CONF.vcloud.vcloud_volumes_dir, volume_id)
                    if not os.path.exists(local_file_name):
                        LOG.error('volume file %s do not exist' %
                                  local_file_name)
                        return

                # 1. the file is vmdk, convert it to qcow2
                # converted_file_name = '%s/converted-file.qcow2' %
                # CONF.vcloud.vcloud_conversion_dir
                # convert_commond = "qemu-img convert -f %s -O %s %s %s" % \
                #                      ('vmdk',
                #                     'qcow2',
                #                    local_file_name,
                #                   converted_file_name)
                # convert_result = subprocess.call([convert_commond],shell=True)
                # if convert_result != 0:
                # do something, change metadata
                # LOG.error('converting file failed')

                # 2. upload to glance

                # file_size = os.path.getsize(converted_file_name)

                # The properties and other fields that we need to set for the image.
                # image_meta['disk_format'] = 'qcow2'
                # image_meta['status'] = 'active'
                # image_meta['size'] = file_size
                # image_meta['properties'] = {'owner_id': volume['project_id']}

                # image_utils.upload_volume(context,image_service,image_meta,converted_file_name,'qcow2')

                image_utils.upload_volume(context, image_service, image_meta,
                                          local_file_name, 'vmdk')
예제 #21
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""

        # Copy the volume to the image conversion dir
        temp_vhd_path = os.path.join(self.configuration.image_conversion_dir,
                                     str(image_meta['id']) + ".vhd")
        self.utils.copy_vhd_disk(self.local_path(volume), temp_vhd_path)
        image_utils.upload_volume(context, image_service, image_meta,
                                  temp_vhd_path, 'vpc')
예제 #22
0
 def _use_image_utils_to_upload_volume(self, context, volume, image_service,
                                       image_meta):
     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,
                                            True) as device:
         image_utils.upload_volume(context, image_service, image_meta,
                                   device)
예제 #23
0
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy a  volume to a new image."""
     LOG.debug("Enter in copy image to volume for disco.")
     try:
         device_info = self._attach_volume(volume)
         image_utils.upload_volume(context, image_service, image_meta,
                                   device_info['path'])
     finally:
         self._detach_volume(volume)
예제 #24
0
    def test_copy_volume_to_image(self):
        """Expected behaviour for copy_volume_to_image."""
        self.mox.StubOutWithMock(image_utils, "upload_volume")

        image_utils.upload_volume(context, self.TEST_IMAGE_SERVICE, self.TEST_IMAGE_META, self.TEST_VOLPATH)

        self.mox.ReplayAll()

        self._driver.copy_volume_to_image(context, self.TEST_VOLUME, self.TEST_IMAGE_SERVICE, self.TEST_IMAGE_META)
예제 #25
0
파일: windows.py 프로젝트: chadlung/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""

        # Copy the volume to the image conversion dir
        temp_vhd_path = os.path.join(self.configuration.image_conversion_dir,
                                     str(image_meta['id']) + ".vhd")
        self.utils.copy_vhd_disk(self.local_path(volume), temp_vhd_path)
        image_utils.upload_volume(context, image_service, image_meta,
                                  temp_vhd_path, 'vpc')
예제 #26
0
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     tmp_dir = self._image_conversion_dir()
     tmp_file = os.path.join(tmp_dir, volume["name"] + "-" + image_meta["id"])
     with fileutils.remove_path_on_error(tmp_file):
         args = ["rbd", "export", "--pool", self.configuration.rbd_pool, volume["name"], tmp_file]
         args.extend(self._ceph_args())
         self._try_execute(*args)
         image_utils.upload_volume(context, image_service, image_meta, tmp_file)
     os.unlink(tmp_file)
예제 #27
0
파일: lvm.py 프로젝트: yongwc09/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        # retrieve store information from extra-specs
        store_id = volume.volume_type.extra_specs.get('image_service:store_id')

        image_utils.upload_volume(context,
                                  image_service,
                                  image_meta,
                                  self.local_path(volume),
                                  store_id=store_id)
예제 #28
0
    def test_copy_volume_to_image(self):
        fake_image_service = "fake-image-service"
        fake_image_meta = "fake-image-meta"

        self.mox.StubOutWithMock(image_utils, "upload_volume")
        image_utils.upload_volume({}, fake_image_service, fake_image_meta, self.fake_dev_path)

        self.mox.ReplayAll()
        self.driver.copy_volume_to_image({}, fake_volume, fake_image_service, fake_image_meta)

        self.mox.VerifyAll()
예제 #29
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.debug(_("copy_volume_to_image %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.upload_volume(context, image_service, image_meta, volume_path)
        finally:
            self.terminate_connection(volume, connector)
예제 #30
0
파일: driver.py 프로젝트: resker/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.debug(("copy_volume_to_image %s.") % volume["name"])

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

        try:
            image_utils.upload_volume(context, image_service, image_meta, attach_info["device"]["path"])
        finally:
            self._detach_volume(context, attach_info, volume, properties)
예제 #31
0
파일: disco.py 프로젝트: NetApp/cinder
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy a  volume to a new image."""
     LOG.debug("Enter in copy image to volume for disco.")
     try:
         device_info = self._attach_volume(volume)
         image_utils.upload_volume(context,
                                   image_service,
                                   image_meta,
                                   device_info['path'])
     finally:
         self._detach_volume(volume)
예제 #32
0
파일: sm.py 프로젝트: chadlung/cinder
 def _use_image_utils_to_upload_volume(self, context, volume, image_service,
                                       image_meta):
     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,
                                            True) as device:
         image_utils.upload_volume(context,
                                   image_service,
                                   image_meta,
                                   device)
예제 #33
0
    def test_upload_volume_with_raw_image(self):
        image_meta = {"id": 1, "disk_format": "raw"}
        mox = self._mox

        mox.StubOutWithMock(image_utils, "convert_image")

        mox.ReplayAll()

        with tempfile.NamedTemporaryFile() as f:
            image_utils.upload_volume(context, FakeImageService(), image_meta, f.name)
        mox.VerifyAll()
예제 #34
0
파일: driver.py 프로젝트: liulongzhu/badam
            def _unused():
                # todo(wangfeng)
                # pdb.set_trace()
                # 1. get the vmdk file.

                volume_id = volume['id']
                if volume['attach_status']=='attached':
                    # nova_client = nova.novaclient(context)
                    # node_name = nova_client.servers.get(instance_id)._
                    # info['OS-EXT-SRV-ATTR:hypervisor_hostname']
                    the_vapp = self._get_vcloud_vapp(volume['instance_uuid'])
                    vmdk_url = self._query_vmdk_url(the_vapp)
                    local_file_name = '%s/%s.vmdk' % (CONF.vcloud.vcloud_conversion_dir, volume_id)
                    self._download_vmdk_from_vcloud(context, vmdk_url,local_file_name)

                    # volume_id = volume['id']
                    # create_info = {'snapshot_id':volume['snapshot_id'],
                    #              'type':'qcow2',
                    #             'new_file':'snapshot_file'}

                    # self._nova_api.create_volume_snapshot(context,volume_id,create_info)
                    # local_file_name = '%s/%s.vmdk' % (CONVERT_DIR, volume_id)
                else:
                    local_file_name = '%s/%s.vmdk' % (CONF.vcloud.vcloud_volumes_dir, volume_id)
                    if not os.path.exists(local_file_name):
                        LOG.error('volume file %s do not exist' % local_file_name)
                        return

                # 1. the file is vmdk, convert it to qcow2
                # converted_file_name = '%s/converted-file.qcow2' %
                # CONF.vcloud.vcloud_conversion_dir
                # convert_commond = "qemu-img convert -f %s -O %s %s %s" % \
                #                      ('vmdk',
                #                     'qcow2',
                #                    local_file_name,
                #                   converted_file_name)
                # convert_result = subprocess.call([convert_commond],shell=True)
                # if convert_result != 0:
                # do something, change metadata
                # LOG.error('converting file failed')

                # 2. upload to glance

                # file_size = os.path.getsize(converted_file_name)

                # The properties and other fields that we need to set for the image.
                # image_meta['disk_format'] = 'qcow2'
                # image_meta['status'] = 'active'
                # image_meta['size'] = file_size
                # image_meta['properties'] = {'owner_id': volume['project_id']}

                # image_utils.upload_volume(context,image_service,image_meta,converted_file_name,'qcow2')

                image_utils.upload_volume(context,image_service,image_meta,local_file_name,'vmdk')
예제 #35
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""

        LOG.debug(_('copy_volume_to_image %s.') % volume['name'])
        (properties, attach_info) = self._attach_volume_syc(context, volume)

        try:
            image_utils.upload_volume(context, image_service, image_meta,
                                      attach_info['device']['path'])
        finally:
            self._detach_and_terminate_syc(context, attach_info, volume,
                                           properties)
예제 #36
0
 def test_copy_volume_to_image(self):
     TEST_VOLUME = {'provider_location': '1 2 3 /dev/loop1'}
     TEST_IMAGE_SERVICE = "image_service"
     TEST_IMAGE_META = "image_meta"
     self.mox.StubOutWithMock(image_utils, 'upload_volume')
     self.mox.StubOutWithMock(self.drv, 'local_path')
     self.drv.local_path(TEST_VOLUME).AndReturn('/dev/loop1')
     image_utils.upload_volume(context, TEST_IMAGE_SERVICE, TEST_IMAGE_META,
                               '/dev/loop1')
     self.mox.ReplayAll()
     self.drv.copy_volume_to_image(context, TEST_VOLUME, TEST_IMAGE_SERVICE,
                                   TEST_IMAGE_META)
예제 #37
0
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy a  volume to a new image."""
     LOG.debug("Enter in copy image to volume for disco.")
     try:
         attach_detach_volume = (
             disco_attach_detach.AttachDetachDiscoVolume(
                 self.configuration))
         device_info = attach_detach_volume._attach_volume(volume)
         image_utils.upload_volume(context, image_service, image_meta,
                                   device_info['path'])
     finally:
         attach_detach_volume._detach_volume(volume)
예제 #38
0
 def test_copy_volume_to_image(self):
     TEST_VOLUME = {'provider_location': '1 2 3 /dev/loop1'}
     TEST_IMAGE_SERVICE = "image_service"
     TEST_IMAGE_META = "image_meta"
     self.mox.StubOutWithMock(image_utils, 'upload_volume')
     self.mox.StubOutWithMock(self.drv, 'local_path')
     self.drv.local_path(TEST_VOLUME).AndReturn('/dev/loop1')
     image_utils.upload_volume(context, TEST_IMAGE_SERVICE,
                               TEST_IMAGE_META, '/dev/loop1')
     self.mox.ReplayAll()
     self.drv.copy_volume_to_image(context, TEST_VOLUME, TEST_IMAGE_SERVICE,
                                   TEST_IMAGE_META)
예제 #39
0
    def test_copy_volume_to_image(self):
        """Expected behaviour for copy_volume_to_image."""
        self.mox.StubOutWithMock(image_utils, 'upload_volume')

        image_utils.upload_volume(context, self.TEST_IMAGE_SERVICE,
                                  self.TEST_IMAGE_META, self.TEST_VOLPATH)

        self.mox.ReplayAll()

        self._driver.copy_volume_to_image(context, self.TEST_VOLUME,
                                          self.TEST_IMAGE_SERVICE,
                                          self.TEST_IMAGE_META)
예제 #40
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.debug(_('copy_volume_to_image %s.') % volume['name'])

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

        try:
            image_utils.upload_volume(context, image_service, image_meta,
                                      attach_info['device']['path'])
        finally:
            self._detach_volume(context, attach_info, volume, properties)
예제 #41
0
    def test_upload_volume_with_raw_image(self):
        image_meta = {'id': 1, 'disk_format': 'raw'}
        mox = self._mox

        mox.StubOutWithMock(image_utils, 'convert_image')

        mox.ReplayAll()

        with tempfile.NamedTemporaryFile() as f:
            image_utils.upload_volume(context, FakeImageService(), image_meta,
                                      f.name)
        mox.VerifyAll()
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy the volume to the specified image."""
     LOG.info("ScaleIO copy_volume_to_image volume: "+str(volume) + " image service: " + str(image_service) + " image meta: " + str(image_meta))
     properties = utils.brick_get_connector_properties()
     sdc_ip = properties['ip']
     LOG.debug("SDC ip is: {0}".format(sdc_ip))
     try:
         image_utils.upload_volume(context,
                               image_service,
                               image_meta,
                               self._attach_volume (volume, sdc_ip))
     finally:
         self._detach_volume(volume, sdc_ip)
예제 #43
0
    def test_copy_volume_to_image(self):
        fake_image_service = 'fake-image-service'
        fake_image_meta = 'fake-image-meta'

        self.mox.StubOutWithMock(image_utils, 'upload_volume')
        image_utils.upload_volume({}, fake_image_service, fake_image_meta,
                                  self.fake_dev_path)

        self.mox.ReplayAll()
        self.driver.copy_volume_to_image({}, fake_volume, fake_image_service,
                                         fake_image_meta)

        self.mox.VerifyAll()
예제 #44
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
       
        LOG.debug(_('copy_volume_to_image %s.') % volume['name'])
        (properties,attach_info) = self._attach_volume_syc(context, volume)

        try:
            image_utils.upload_volume(context,
                                      image_service,
                                      image_meta,
                                      attach_info['device']['path'])
        finally:
            self._detach_and_terminate_syc(context,attach_info,volume,properties)
예제 #45
0
파일: rbd.py 프로젝트: rahul4-jain/cinder
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     tmp_dir = self._image_conversion_dir()
     tmp_file = os.path.join(tmp_dir,
                             volume['name'] + '-' + image_meta['id'])
     with fileutils.remove_path_on_error(tmp_file):
         args = ['rbd', 'export',
                 '--pool', self.configuration.rbd_pool,
                 volume['name'], tmp_file]
         args.extend(self._ceph_args())
         self._try_execute(*args)
         image_utils.upload_volume(context, image_service,
                                   image_meta, tmp_file)
     os.unlink(tmp_file)
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy the volume to the specified image."""
     LOG.info("ScaleIO copy_volume_to_image volume: " + str(volume) +
              " image service: " + str(image_service) + " image meta: " +
              str(image_meta))
     properties = utils.brick_get_connector_properties()
     sdc_ip = properties['ip']
     LOG.debug("SDC ip is: {0}".format(sdc_ip))
     try:
         image_utils.upload_volume(context, image_service, image_meta,
                                   self._attach_volume(volume, sdc_ip))
     finally:
         self._detach_volume(volume, sdc_ip)
예제 #47
0
파일: rbd.py 프로젝트: Jchuan/cinder
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     tmp_dir = self._image_conversion_dir()
     tmp_file = os.path.join(tmp_dir, volume.name + '-' + image_meta['id'])
     with fileutils.remove_path_on_error(tmp_file):
         args = [
             'rbd', 'export', '--pool', self.configuration.rbd_pool,
             volume.name, tmp_file
         ]
         args.extend(self._ceph_args())
         self._try_execute(*args)
         image_utils.upload_volume(context, image_service, image_meta,
                                   tmp_file)
     os.unlink(tmp_file)
예제 #48
0
파일: rbd.py 프로젝트: twigs/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        self._ensure_tmp_exists()

        tmp_dir = self.configuration.volume_tmp_dir or '/tmp'
        tmp_file = os.path.join(tmp_dir,
                                volume['name'] + '-' + image_meta['id'])
        with utils.remove_path_on_error(tmp_file):
            self._try_execute('rbd', 'export',
                              '--pool', self.configuration.rbd_pool,
                              volume['name'], tmp_file)
            image_utils.upload_volume(context, image_service,
                                      image_meta, tmp_file)
        os.unlink(tmp_file)
예제 #49
0
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy the volume to the specified image."""
     LOG.info(
         _LI("ScaleIO copy_volume_to_image volume: %(vol)s image service: "
             "%(service)s image meta: %(meta)s."), {
                 'vol': volume,
                 'service': six.text_type(image_service),
                 'meta': six.text_type(image_meta)
             })
     try:
         image_utils.upload_volume(context, image_service, image_meta,
                                   self._sio_attach_volume(volume))
     finally:
         self._sio_detach_volume(volume)
예제 #50
0
파일: disco.py 프로젝트: j-griffith/cinder
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy a  volume to a new image."""
     LOG.debug("Enter in copy image to volume for disco.")
     try:
         attach_detach_volume = (
             disco_attach_detach.AttachDetachDiscoVolume(
                 self.configuration))
         device_info = attach_detach_volume._attach_volume(volume)
         image_utils.upload_volume(context,
                                   image_service,
                                   image_meta,
                                   device_info['path'])
     finally:
         attach_detach_volume._detach_volume(volume)
예제 #51
0
파일: driver.py 프로젝트: niuzhenguo/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.debug(_('copy_volume_to_image %s.') % volume['name'])

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

        try:
            image_utils.upload_volume(context,
                                      image_service,
                                      image_meta,
                                      attach_info['device']['path'])
        finally:
            self._detach_volume(attach_info)
            self.terminate_connection(volume, properties)
예제 #52
0
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy the volume to the specified image."""
     LOG.info(_LI(
         "ScaleIO copy_volume_to_image volume: %(vol)s image service: "
         "%(service)s image meta: %(meta)s."),
         {'vol': volume,
          'service': six.text_type(image_service),
          'meta': six.text_type(image_meta)})
     try:
         image_utils.upload_volume(context,
                                   image_service,
                                   image_meta,
                                   self._sio_attach_volume(volume))
     finally:
         self._sio_detach_volume(volume)
예제 #53
0
파일: windows.py 프로젝트: NetApp/cinder
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        disk_format = self._tgt_utils.get_supported_disk_format()
        temp_vhd_path = os.path.join(CONF.image_conversion_dir,
                                     str(image_meta['id']) + '.' + disk_format)

        try:
            with self._temporary_snapshot(volume['name']) as tmp_snap_name:
                # qemu-img cannot access VSS snapshots, for which reason it
                # must be exported first.
                self._tgt_utils.export_snapshot(tmp_snap_name, temp_vhd_path)
                image_utils.upload_volume(context, image_service, image_meta,
                                          temp_vhd_path, 'vhd')
        finally:
            fileutils.delete_if_exists(temp_vhd_path)
예제 #54
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        disk_format = self._tgt_utils.get_supported_disk_format()
        temp_vhd_path = os.path.join(CONF.image_conversion_dir,
                                     str(image_meta['id']) + '.' + disk_format)

        try:
            with self._temporary_snapshot(volume.name) as tmp_snap_name:
                # qemu-img cannot access VSS snapshots, for which reason it
                # must be exported first.
                self._tgt_utils.export_snapshot(tmp_snap_name, temp_vhd_path)
                image_utils.upload_volume(context, image_service, image_meta,
                                          temp_vhd_path, 'vhd')
        finally:
            fileutils.delete_if_exists(temp_vhd_path)
예제 #55
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.debug(_('copy_volume_to_image %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.upload_volume(context,
                                      image_service,
                                      image_meta,
                                      volume_path)
        finally:
            self.terminate_connection(volume, connector)
예제 #56
0
    def copy_volume_to_image(self, context, volume, image_service, image_meta):
        """Copy the volume to the specified image."""
        LOG.debug(_('copy_volume_to_image %s.') % volume['name'])
        initiator = self._get_iscsi_initiator()
        connector = {}
        connector['initiator'] = initiator

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

        try:
            image_utils.upload_volume(context,
                                      image_service,
                                      image_meta,
                                      volume_path)
        finally:
            self.terminate_connection(volume, connector)
예제 #57
0
    def _copy_volume_to_image(self, context, volume, image_service,
                              image_meta):
        """Copy the volume to the specified image."""

        volume_format = self.get_volume_format(volume)
        if volume_format == DISK_FORMAT_PLOOP:
            with PloopDevice(self.local_path(volume),
                             execute=self._execute) as dev:
                image_utils.upload_volume(context,
                                          image_service,
                                          image_meta,
                                          dev,
                                          volume_format='raw')
        else:
            super(VZStorageDriver,
                  self)._copy_volume_to_image(context, volume, image_service,
                                              image_meta)
예제 #58
0
 def copy_volume_to_image(self, context, volume, image_service, image_meta):
     """Copy the volume to the specified image."""
     LOG.info(
         _LI("ScaleIO copy_volume_to_image volume: %(vol)s image service: "
             "%(service)s image meta: %(meta)s."), {
                 'vol': volume,
                 'service': six.text_type(image_service),
                 'meta': six.text_type(image_meta)
             })
     properties = utils.brick_get_connector_properties()
     sdc_ip = properties['ip']
     LOG.debug("SDC ip is: {0}".format(sdc_ip))
     try:
         image_utils.upload_volume(context, image_service, image_meta,
                                   self._sio_attach_volume(volume, sdc_ip))
     finally:
         self._sio_detach_volume(volume, sdc_ip)
예제 #59
0
    def _copy_volume_to_image(self, context, volume, image_service,
                              image_meta):
        """Copy the volume to the specified image."""

        volume_format = self.get_volume_format(volume)
        if volume_format == DISK_FORMAT_PLOOP:
            with PloopDevice(self.local_path(volume),
                             execute=self._execute) as dev:
                image_utils.upload_volume(context,
                                          image_service,
                                          image_meta,
                                          dev,
                                          volume_format='raw')
        else:
            super(VZStorageDriver, self)._copy_volume_to_image(context, volume,
                                                               image_service,
                                                               image_meta)