コード例 #1
0
    def create_volume_from_snapshot(self, volume, snapshot):
        """Creates a volume from a snapshot."""

        LOG.debug('Creating volume from snapshot: %s', snapshot.name)

        vpsa_volume = self._get_vpsa_volume(snapshot.volume, False)
        if not vpsa_volume:
            LOG.error('Snapshot %(name)s not found.',
                      {'name': snapshot.name})
            raise cinder_exception.SnapshotNotFound(snapshot_id=snapshot.id)

        # Retrieve the CG name for the base volume
        cg_name = vpsa_volume['cg_name']
        snap_id = self.vpsa._get_snap_id(cg_name, snapshot.name)
        if not snap_id:
            LOG.error('Snapshot %(name)s not found',
                      {'name': snapshot.name})
            raise cinder_exception.SnapshotNotFound(snapshot_id=snapshot.id)

        volume_name = self._get_zadara_vol_template_name(volume.name)
        self.vpsa_send_cmd('create_clone_from_snap',
                           cg_name=cg_name,
                           name=volume_name,
                           snap_id=snap_id)

        vpsa_volume = self._get_vpsa_volume(volume)
        if volume.size > snapshot.volume_size:
            self.extend_volume(volume, volume.size)
        return {'provider_location': vpsa_volume.get('name')}
コード例 #2
0
    def _check_iscsi_response(self, out, **kwargs):
        LUN_BAD_LUN_UUID = 18990505
        LUN_NO_SUCH_SNAPSHOT = 18990532

        if not self.check_value_valid(out, ['error', 'code'], int):
            raise exception.MalformedResponse(cmd='_check_iscsi_response',
                                              reason=_('no error code found'))

        code = out['error']['code']
        exc = None
        message = ''

        if code == LUN_BAD_LUN_UUID:
            exc = exception.SynoLUNNotExist(**kwargs)
            message = 'Bad LUN UUID'
        elif code == LUN_NO_SUCH_SNAPSHOT:
            exc = exception.SnapshotNotFound(**kwargs)
            message = 'No such snapshot'
        else:
            data = 'internal error'
            exc = exception.VolumeBackendAPIException(data=data)
            message = 'Internal error'

        message = '%s [%d]' % (message, code)

        return (message, exc)
コード例 #3
0
ファイル: zadara.py プロジェクト: nikesh-biarca/cinder
    def create_volume_from_snapshot(self, volume, snapshot):
        """Creates a volume from a snapshot."""

        LOG.debug('Creating volume from snapshot: %s', snapshot['name'])

        # Retrieve the CG name for the base volume
        volume_name = (self.configuration.zadara_vol_name_template %
                       snapshot['volume_name'])
        cg_name = self._get_volume_cg_name(volume_name)
        if not cg_name:
            LOG.error(_LE('Volume %(name)s not found'), {'name': volume_name})
            raise exception.VolumeNotFound(volume_id=volume['id'])

        snap_id = self._get_snap_id(cg_name, snapshot['name'])
        if not snap_id:
            LOG.error(_LE('Snapshot %(name)s not found'),
                      {'name': snapshot['name']})
            raise exception.SnapshotNotFound(snapshot_id=snapshot['id'])

        self.vpsa.send_cmd('create_clone_from_snap',
                           cg_name=cg_name,
                           name=self.configuration.zadara_vol_name_template %
                           volume['name'],
                           snap_id=snap_id)

        if (volume['size'] > snapshot['volume_size']):
            self.extend_volume(volume, volume['size'])
コード例 #4
0
    def test_show_nonexistent_snapshot(self, snapshot_get_by_id):
        snapshot_get_by_id.side_effect = \
            exc.SnapshotNotFound(snapshot_id=fake.WILL_NOT_BE_FOUND_ID)

        req = fakes.HTTPRequest.blank(self.url + '/key2')
        self.assertRaises(exc.SnapshotNotFound, self.controller.show, req,
                          fake.SNAPSHOT_ID, 'key2')
コード例 #5
0
    def test_index_nonexistent_snapshot(self, snapshot_get_by_id):
        snapshot_get_by_id.side_effect = \
            exc.SnapshotNotFound(snapshot_id=fake.WILL_NOT_BE_FOUND_ID)

        req = fakes.HTTPRequest.blank(self.url)
        self.assertRaises(exc.SnapshotNotFound, self.controller.index, req,
                          self.url)
コード例 #6
0
 def create_volume_from_snapshot(self, volume, snapshot):
     """Create a volume from a snapshot."""
     if snapshot.get('provider_location') is not None:
         snapshot_id = snapshot.get('provider_location')
         snapshot_location_flag = True
     else:
         snapshot_id = snapshot.get('id')
         snapshot_location_flag = False
     provider_snapshot = self.get_snapshot_from_provider_id(
         snapshot_id, snapshot_location_flag)
     if not provider_snapshot:
         raise exception.SnapshotNotFound(snapshot_id=snapshot_id)
     location = self.adpter.get_location(
         self.configuration.availability_zone)
     size = volume.get('size')
     name = volume.get('name')
     provider_volume = self.adpter.create_volume(
         size, name, location=location, snapshot=provider_snapshot[0])
     LOG.info("create volume: %s; provider_volume: %s " %
              (volume['id'], provider_volume.id))
     create_tags_func = getattr(self.adpter, 'ex_create_tags')
     if create_tags_func:
         create_tags_func(provider_volume,
                          {'hybrid_cloud_volume_id': volume['id']})
     ctx = cinder.context.get_admin_context()
     if ctx:
         self.db.volume_metadata_update(
             ctx, volume['id'], {'provider_volume_id': provider_volume.id},
             False)
     model_update = {'provider_location': provider_volume.id}
     return model_update
コード例 #7
0
    def _local_clone_copy(self, volume, clone, action=None, snapshot=''):
        LOG.debug('enter: copy volume %(vol)s to %(clone)s by %(action)s.',
                  {'vol': volume,
                   'clone': clone,
                   'action': action})
        if self._wait_volume_copy(volume, clone, action, 'wait'):
            LOG.info('start copy task.')
            ret = self._cmd.create_clone(volume, clone)
            if ret['key'] != 0:
                self._cmd.delete_volume(clone)
            if ret['key'] == 306:
                raise exception.VolumeBackendAPIException(
                    data='The source volume must not be larger '
                         'than the target volume in a clone relation. ')
            elif ret['key'] == 0:
                ret = self._cmd.start_clone(volume, snapshot)
                if ret['key'] == 505:
                    raise exception.SnapshotNotFound(snapshot_id=snapshot)
        else:
            LOG.error('%(action)s failed.', {'action': action})
            raise exception.VolumeBackendAPIException(data='clone failed!')

        if self._wait_volume_copy(volume, clone, action, 'copy'):
            self._cmd.delete_clone(volume, snapshot)
            LOG.info('%s successfully.', action)
        else:
            LOG.error('%(action)s failed.', {'action': action})
            raise exception.VolumeBackendAPIException(data='clone failed!')
        LOG.debug('leave: copy volume %(vol)s to %(clone)s by %(action)s. ',
                  {'vol': volume,
                   'clone': clone,
                   'action': action})
コード例 #8
0
    def test_show_nonexistent_snapshot(self, snapshot_get_by_id):
        snapshot_get_by_id.side_effect = \
            exception.SnapshotNotFound(snapshot_id=self.req_id)

        req = fakes.HTTPRequest.blank(self.url + '/key2')
        self.assertRaises(exception.SnapshotNotFound,
                          self.controller.show, req, self.req_id, 'key2')
コード例 #9
0
    def _create_volume_from_snapshot_2_2(self, volume, snapshot):
        # Handle case where snapshot is "managed"
        dummy_vol = {'id': snapshot['volume_id'],
                     'project_id': snapshot['project_id']}
        tenant = self.get_tenant(dummy_vol['project_id'])
        dvol = self.cvol_to_dvol(dummy_vol, tenant=tenant)
        found_snap = None
        provider_location = snapshot.get('provider_location')
        if provider_location:
            found_snap = dvol.snapshots.get(provider_location, tenant=tenant)
        else:
            snapshots = dvol.snapshots.list(tenant=tenant)
            for snap in snapshots:
                if snap.uuid == snapshot['id']:
                    found_snap = snap
                    break
            else:
                raise exception.SnapshotNotFound(snapshot_id=snapshot['id'])

        self._snap_poll_2_2(found_snap, tenant)

        src = found_snap.path
        app_params = (
            {
                'create_mode': 'openstack',
                'uuid': str(volume['id']),
                'name': datc.get_name(volume),
                'clone_snapshot_src': {'path': src},
            })

        self.api.app_instances.create(tenant=tenant, **app_params)
        if (volume['size'] > snapshot['volume_size']):
            self._extend_volume_2_2(volume, volume['size'])
        self._add_vol_meta_2_2(volume)
コード例 #10
0
    def test_index_nonexistent_snapshot(self, snapshot_get_by_id):
        snapshot_get_by_id.side_effect = \
            exception.SnapshotNotFound(snapshot_id=self.req_id)

        req = fakes.HTTPRequest.blank(self.url)
        self.assertRaises(webob.exc.HTTPNotFound, self.controller.index, req,
                          self.url)
コード例 #11
0
    def test_show_nonexistent_snapshot(self, snapshot_get_by_id):
        snapshot_get_by_id.side_effect = \
            exc.SnapshotNotFound(snapshot_id=fake.will_not_be_found_id)

        req = fakes.HTTPRequest.blank(self.url + '/key2')
        self.assertRaises(webob.exc.HTTPNotFound, self.controller.show, req,
                          fake.snapshot_id, 'key2')
コード例 #12
0
def return_snapshot(context, snapshot_id):
    if snapshot_id == fake.WILL_NOT_BE_FOUND_ID:
        raise exc.SnapshotNotFound(snapshot_id)
    return {'id': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
            'name': 'fake',
            'status': 'available',
            'metadata': {}}
コード例 #13
0
    def test_index_nonexistent_snapshot(self, snapshot_get_by_id):
        snapshot_get_by_id.side_effect = \
            exception.SnapshotNotFound(snapshot_id=self.req_id)

        req = fakes.HTTPRequest.blank(self.url)
        req.environ['cinder.context'] = self.ctx
        self.assertRaises(exception.SnapshotNotFound, self.controller.index,
                          req, self.url)
コード例 #14
0
ファイル: iscsi.py プロジェクト: openstack/cinder
    def _clone_object(self, oname, coname):
        """Creates a clone of specified object

        :param: oname: name of an object to clone
        :param: coname: name of a new clone
        """
        LOG.debug('cloning %(oname)s to %(coname)s', {
            "oname": oname,
            "coname": coname
        })

        try:
            self.ra.create_snapshot(oname, coname)
        except jexc.JDSSSnapshotExistsException:
            try:
                self.ra.delete_snapshot(oname, coname)
            except jexc.JDSSSnapshotIsBusyException as jerrisbusy:
                raise exception.Duplicate() from jerrisbusy
            except jexc.JDSSException as jerr:
                raise exception.VolumeBackendAPIException(
                    (_("Unable to create volume %s.") % coname)) from jerr
        except jexc.JDSSResourceNotFoundException as jerrnotfound:
            if jcom.is_volume(oname):
                raise exception.VolumeNotFound(
                    volume_id=jcom.idname(oname)) from jerrnotfound
            raise exception.SnapshotNotFound(
                snapshot_id=jcom.idname(oname)) from jerrnotfound

        except jexc.JDSSException as jerr:
            args = {'snapshot': coname, 'object': oname, 'err': jerr}
            msg = (_('Failed to create tmp snapshot %(snapshot)s '
                     'for object %(object)s: %(err)s') % args)
            raise exception.VolumeBackendAPIException(msg)

        try:
            self.ra.create_volume_from_snapshot(coname,
                                                coname,
                                                oname,
                                                sparse=self.jovian_sparse)
        except jexc.JDSSResourceExistsException as jerr:
            raise exception.Duplicate() from jerr
        except jexc.JDSSException as jerr:
            try:
                self.ra.delete_snapshot(oname,
                                        coname,
                                        recursively_children=True,
                                        recursively_dependents=True,
                                        force_umount=True)
            except jexc.JDSSException as jerrd:
                LOG.warning(
                    "Because of %s physical snapshot %s of volume"
                    " %s have to be removed manually", jerrd, coname, oname)

            raise exception.VolumeBackendAPIException(
                _("Unable to create volume %(vol)s because of %(err)s.") % {
                    'vol': coname,
                    'err': jerr
                }) from jerr
コード例 #15
0
def stub_new_snapshot_metadata(snapshot_id):
    if snapshot_id == fake.WILL_NOT_BE_FOUND_ID:
        raise exc.SnapshotNotFound(snapshot_id)
    metadata = {
        'key10': 'value10',
        'key99': 'value99',
        'KEY20': 'value20',
    }
    return metadata
コード例 #16
0
def stub_snapshot_metadata(snapshot_id):
    if snapshot_id == fake.WILL_NOT_BE_FOUND_ID:
        raise exc.SnapshotNotFound(snapshot_id)
    metadata = {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3",
    }
    return metadata
コード例 #17
0
def return_snapshot(context, snapshot_id):
    if snapshot_id == fake.will_not_be_found_id:
        raise exc.SnapshotNotFound(snapshot_id)
    return {
        'id': '0cc3346e-9fef-4445-abe6-5d2b2690ec64',
        'name': 'fake',
        'status': 'available',
        'metadata': {}
    }
コード例 #18
0
def stub_snapshot_metadata(snapshot_id):
    if snapshot_id == fake.will_not_be_found_id:
        raise exc.SnapshotNotFound(snapshot_id)
    metadata = {
        "key1": "value1",
        "key2": "value2",
        "key3": "value3",
    }
    return metadata
コード例 #19
0
def stub_new_snapshot_metadata(snapshot_id):
    if snapshot_id == fake.will_not_be_found_id:
        raise exc.SnapshotNotFound(snapshot_id)
    metadata = {
        'key10': 'value10',
        'key99': 'value99',
        'KEY20': 'value20',
    }
    return metadata
コード例 #20
0
 def _handle_snapshot_not_found(self, result, snapshot_info_list,
                                snapshot_name, volume_name):
     if not self._has_records(result):
         raise exception.SnapshotNotFound(snapshot_id=snapshot_name)
     elif len(snapshot_info_list) > 1:
         msg = _('Could not find unique snapshot %(snap)s on '
                 'volume %(vol)s.')
         msg_args = {'snap': snapshot_name, 'vol': volume_name}
         raise exception.VolumeBackendAPIException(data=msg % msg_args)
コード例 #21
0
 def _get_snapshot_by_name(self, name):
     result = self.conn.get("TierStore/Snapshots/by-id/")
     snap = [x for x in result if x['Name'] == name]
     if len(snap) == 1:
         return snap[0]
     elif len(snap) == 0:
         raise exception.SnapshotNotFound(name)
     else:
         msg = (_("FIO _get_snapshot_by_name Error: %(name)s, %(len)s") % {
             'name': name,
             'len': len(snap),
         })
         raise exception.VolumeDriverException(message=msg)
コード例 #22
0
ファイル: acs5000_common.py プロジェクト: openstack/cinder
 def delete_snapshot(self, snapshot):
     volume_name = self._convert_name(snapshot.volume_name)
     snapshot_name = self._convert_name(snapshot.name)
     ret = self._cmd.delete_snapshot(volume_name, snapshot_name)
     if ret['key'] == 505:
         raise exception.SnapshotNotFound(snapshot_id=snapshot['id'])
     elif ret['key'] != 0:
         msg = (_('Failed to delete_snapshot %(snap)s on volume %(vol)s '
                  'code=%(ret)s, error=%(msg)s.') % {
                      'vol': volume_name,
                      'snap': snapshot_name,
                      'ret': ret['key'],
                      'msg': ret['msg']
                  })
         raise exception.VolumeBackendAPIException(data=msg)
コード例 #23
0
 def delete_snapshot(self, snapshot):
     """Delete a snapshot."""
     provider_snapshots = self.adpter.list_snapshots()
     if not provider_snapshots:
         LOG.error('provider_snapshot %s is not found' %
                   snapshot['provider_location'])
         return
         #raise exception.SnapshotNotFound(snapshot_id=snapshot['id'])
     for provider_snapshot in provider_snapshots:
         if provider_snapshot.id == snapshot['provider_location']:
             target_snapshot = provider_snapshot
     if not target_snapshot:
         raise exception.SnapshotNotFound(snapshot['id'])
     delete_ret = self.adpter.destroy_volume_snapshot(target_snapshot)
     LOG.info("deleted snapshot return%d" % delete_ret)
コード例 #24
0
def api_snapshot_get(self, context, snp_id):
    """Replacement for cinder.volume.api.API.get_snapshot.

    We stub the cinder.volume.api.API.get_snapshot method to check for the
    existence of snapshot_id in our list of fake snapshots and raise an
    exception if the specified snapshot ID is not in our list.
    """
    snapshot = {'id': fake.SNAPSHOT_ID,
                'progress': '100%',
                'volume_id': fake.VOLUME_ID,
                'project_id': fake.PROJECT_ID,
                'status': fields.SnapshotStatus.AVAILABLE}
    if snp_id == snapshot_id:
        snapshot_objct = fake_snapshot.fake_snapshot_obj(context, **snapshot)
        return snapshot_objct
    else:
        raise exception.SnapshotNotFound(snapshot_id=snp_id)
コード例 #25
0
def api_snapshot_get(self, context, snp_id):
    """Replacement for cinder.volume.api.API.get_snapshot.

    We stub the cinder.volume.api.API.get_snapshot method to check for the
    existence of snapshot_id in our list of fake snapshots and raise an
    exception if the specified snapshot ID is not in our list.
    """
    snapshot = {'id': 'ffffffff-0000-ffff-0000-ffffffffffff',
                'progress': '100%',
                'volume_id': 'fake_volume_id',
                'project_id': 'fake_project',
                'status': 'available'}
    if snp_id == snapshot_id:
        snapshot_objct = fake_snapshot.fake_snapshot_obj(context, **snapshot)
        return snapshot_objct
    else:
        raise exception.SnapshotNotFound(snapshot_id=snp_id)
コード例 #26
0
ファイル: acs5000_common.py プロジェクト: openstack/cinder
 def revert_to_snapshot(self, context, volume, snapshot):
     volume_name = self._convert_name(volume.name)
     snapshot_name = self._convert_name(snapshot.name)
     ret = self._cmd.rollback_snapshot(snapshot_name, volume_name)
     if ret['key'] == 303:
         raise exception.VolumeNotFound(volume_id=volume_name)
     elif ret['key'] == 505:
         raise exception.SnapshotNotFound(snapshot_id=snapshot_name)
     elif ret['key'] == 506:
         msg = (_('Snapshot %s is not the latest one.') % snapshot_name)
         raise exception.InvalidSnapshot(reason=msg)
     elif ret['key'] != 0:
         msg = (_('Failed to revert volume %(vol)s to snapshot %(snap)s, '
                  'code=%(ret)s, error=%(msg)s.') % {
                      'vol': volume_name,
                      'snap': snapshot_name,
                      'ret': ret['key'],
                      'msg': ret['msg']
                  })
         raise exception.VolumeBackendAPIException(data=msg)
コード例 #27
0
ファイル: client_7mode.py プロジェクト: bopopescu/stack
    def get_snapshot(self, volume_name, snapshot_name):
        """Gets a single snapshot."""
        snapshot_list_info = netapp_api.NaElement('snapshot-list-info')
        snapshot_list_info.add_new_child('volume', volume_name)
        result = self.connection.invoke_successfully(snapshot_list_info,
                                                     enable_tunneling=True)

        snapshots = result.get_child_by_name('snapshots')
        if not snapshots:
            msg = _('No snapshots could be found on volume %s.')
            raise exception.VolumeBackendAPIException(data=msg % volume_name)
        snapshot_list = snapshots.get_children()
        snapshot = None
        for s in snapshot_list:
            if (snapshot_name
                    == s.get_child_content('name')) and (snapshot is None):
                snapshot = {
                    'name': s.get_child_content('name'),
                    'volume': s.get_child_content('volume'),
                    'busy':
                    strutils.bool_from_string(s.get_child_content('busy')),
                }
                snapshot_owners_list = s.get_child_by_name(
                    'snapshot-owners-list') or netapp_api.NaElement('none')
                snapshot_owners = set([
                    snapshot_owner.get_child_content('owner')
                    for snapshot_owner in snapshot_owners_list.get_children()
                ])
                snapshot['owners'] = snapshot_owners
            elif (snapshot_name
                  == s.get_child_content('name')) and (snapshot is not None):
                msg = _('Could not find unique snapshot %(snap)s on '
                        'volume %(vol)s.')
                msg_args = {'snap': snapshot_name, 'vol': volume_name}
                raise exception.VolumeBackendAPIException(data=msg % msg_args)
        if not snapshot:
            raise exception.SnapshotNotFound(snapshot_id=snapshot_name)

        return snapshot
コード例 #28
0
    def create_volume_from_snapshot(self, volume, snapshot):
        """Creates a cloned volume from an existing snapshot."""

        vol_name = utils.convert_str(volume.name)
        snap_name = utils.convert_str(snapshot.name)

        snap = self._get_image(vol_name + '@' + snap_name)
        if not snap:
            raise exception.SnapshotNotFound(snapshot_id=snap_name)
        snap_inode_id = int(resp['responses'][0]['kvs'][0]['value']['id'])
        snap_pool_id = int(resp['responses'][0]['kvs'][0]['value']['pool_id'])

        size = snap['cfg']['size']
        if int(volume.size):
            size = int(volume.size) * units.Gi
        new_cfg = self._create_image(
            vol_name, {
                'size': size,
                'parent_id': snap['idx']['id'],
                'parent_pool_id': snap['idx']['pool_id'],
            })

        return {}
コード例 #29
0
def return_snapshot_nonexistent(context, snapshot_id):
    raise exception.SnapshotNotFound(snapshot_id=snapshot_id)
コード例 #30
0
def return_empty_container_metadata(context, snapshot_id, metadata, delete):
    if snapshot_id == fake.will_not_be_found_id:
        raise exc.SnapshotNotFound(snapshot_id)
    return {}