コード例 #1
0
    def create_cloned_volume(self, volume, src_vref):
        """Creates cloned volume.

        1. Take an internal snapshot of source volume, and attach it.
        2. Create a new volume, and attach it.
        3. Copy from attached snapshot of step 1 to the volume of step 2.
        4. Delete the internal snapshot created in step 1.
        """

        src_lun_id = self.get_lun_id(src_vref)
        if src_lun_id is None:
            raise exception.VolumeBackendAPIException(
                data=_("LUN ID of source volume: %s not found.") %
                src_vref.name)
        src_snap_name = 'snap_clone_%s' % volume.id

        create_snap_func = functools.partial(self.client.create_snap,
                                             src_lun_id, src_snap_name)
        with utils.assure_cleanup(create_snap_func, self.client.delete_snap,
                                  True) as src_snap:
            LOG.debug(
                'Internal snapshot for clone is created, '
                'name: %(name)s, id: %(id)s.', {
                    'name': src_snap_name,
                    'id': src_snap.get_id()
                })
            return self._create_volume_from_snap(volume,
                                                 src_snap,
                                                 size_in_m=utils.gib_to_mib(
                                                     volume.size))
コード例 #2
0
    def create_cloned_volume(self, volume, src_vref):
        """Creates cloned volume.

        1. Take an internal snapshot of source volume, and attach it.
        2. Create a new volume, and attach it.
        3. Copy from attached snapshot of step 1 to the volume of step 2.
        4. Delete the internal snapshot created in step 1.
        """

        src_lun_id = self.get_lun_id(src_vref)
        if src_lun_id is None:
            raise exception.VolumeBackendAPIException(
                data=_("LUN ID of source volume: %s not found.") %
                src_vref.name)
        src_snap_name = 'snap_clone_%s' % volume.id

        create_snap_func = functools.partial(self.client.create_snap,
                                             src_lun_id, src_snap_name)
        with utils.assure_cleanup(create_snap_func,
                                  self.client.delete_snap,
                                  True) as src_snap:
            LOG.debug('Internal snapshot for clone is created, '
                      'name: %(name)s, id: %(id)s.',
                      {'name': src_snap_name,
                       'id': src_snap.get_id()})
            return self._create_volume_from_snap(
                volume, src_snap, size_in_m=utils.gib_to_mib(volume.size))
コード例 #3
0
ファイル: test_utils.py プロジェクト: yongwc09/cinder
 def test_gib_to_mib(self):
     self.assertEqual(5 * units.Gi / units.Mi, utils.gib_to_mib(5))
コード例 #4
0
ファイル: test_utils.py プロジェクト: j-griffith/cinder
 def test_gib_to_mib(self):
     self.assertEqual(5 * units.Gi / units.Mi, utils.gib_to_mib(5))