Beispiel #1
0
    def _delete_snapshot(self, request, sname, id=None, snap_name=None):
        share = self._validate_share(sname, request)
        try:
            snapshot = None
            if (id is not None):
                snapshot = Snapshot.objects.get(id=id)
            elif (snap_name is not None):
                snapshot = Snapshot.objects.get(share=share, name=snap_name)
            else:
                return True
        except:
            e_msg = ''
            if (id is not None):
                e_msg = ('Snapshot(%s) does not exist.' % id)
            else:
                e_msg = ('Snapshot(%s) does not exist.' % snap_name)
            handle_exception(Exception(e_msg), request)

        if (snapshot.uvisible):
            self._toggle_visibility(share, snapshot.real_name, on=False)
            toggle_sftp_visibility(share, snapshot.real_name, on=False)

        remove_snap(share.pool, sname, snapshot.name)
        snapshot.delete()
        return Response()
Beispiel #2
0
    def _delete_snapshot(self, request, sname, id=None, snap_name=None):
        share = self._validate_share(sname, request)
        try:
            snapshot = None
            if (id is not None):
                snapshot = Snapshot.objects.get(id=id)
            elif (snap_name is not None):
                snapshot = Snapshot.objects.get(share=share, name=snap_name)
            else:
                return True
        except:
            e_msg = ''
            if (id is not None):
                e_msg = ('Snapshot(%s) does not exist.' % id)
            else:
                e_msg = ('Snapshot(%s) does not exist.' % snap_name)
            handle_exception(Exception(e_msg), request)

        if (snapshot.uvisible):
            self._toggle_visibility(share, snapshot.real_name, on=False)
            toggle_sftp_visibility(share, snapshot.real_name, on=False)

        remove_snap(share.pool, sname, snapshot.name)
        snapshot.delete()
        return Response()
Beispiel #3
0
    def _delete_snapshot(self, request, sname, id=None, snap_name=None):
        share = self._validate_share(sname, request)
        try:
            snapshot = None
            if (id is not None):
                snapshot = Snapshot.objects.get(id=id)
            elif (snap_name is not None):
                snapshot = Snapshot.objects.get(share=share, name=snap_name)
            else:
                return True
        except:
            e_msg = ''
            if (id is not None):
                e_msg = ('Snapshot(%s) does not exist.' % id)
            else:
                e_msg = ('Snapshot(%s) does not exist.' % snap_name)
            handle_exception(Exception(e_msg), request)

        pool_device = Disk.objects.filter(pool=share.pool)[0].name
        if (snapshot.uvisible):
            e_msg = ('A low level error occured while deleting '
                     'snapshot(%s). Try again later.' % snapshot.name)
            try:
                self._toggle_visibility(share, snapshot.real_name, on=False)
            except Exception, e:
                logger.error(e_msg)
                logger.exception(e)
                handle_exception(Exception(e_msg), request)

            try:
                toggle_sftp_visibility(share, snapshot.real_name, on=False)
            except Exception, e:
                logger.error(e_msg)
                logger.exception(e)
                handle_exception(Exception(e_msg), request)
Beispiel #4
0
    def _delete_snapshot(self, request, sid, id=None, snap_name=None):
        share = self._validate_share(sid, request)
        try:
            snapshot = None
            if (id is not None):
                snapshot = Snapshot.objects.get(id=id)
            elif (snap_name is not None):
                snapshot = Snapshot.objects.get(share=share, name=snap_name)
            else:
                return True
        except:
            e_msg = ''
            if (id is not None):
                e_msg = 'Snapshot id ({}) does not exist.'.format(id)
            else:
                # Note e_msg consumed by replication/util.py update_repclone()
                # and delete_snapshot()
                e_msg = 'Snapshot name ({}) does not exist.'.format(snap_name)
            handle_exception(Exception(e_msg), request)

        if (snapshot.uvisible):
            self._toggle_visibility(share, snapshot.real_name, snapshot.qgroup,
                                    on=False)
            toggle_sftp_visibility(share, snapshot.real_name, snapshot.qgroup,
                                   on=False)

        remove_snap(share.pool, share.name, snapshot.name, snapshot.qgroup)
        snapshot.delete()
        return Response()
Beispiel #5
0
    def post(self, request, sname, snap_name, command=None):
        with self._handle_exception(request):
            share = self._validate_share(sname, request)
            uvisible = request.data.get('uvisible', False)
            if (type(uvisible) != bool):
                e_msg = ('uvisible must be a boolean, not %s' % type(uvisible))
                handle_exception(Exception(e_msg), request)

            snap_type = request.data.get('snap_type', 'admin')
            writable = request.data.get('writable', 'rw')
            writable = True if (writable == 'rw') else False
            if (command is None):
                ret = self._create(share, snap_name, request,
                                   uvisible=uvisible, snap_type=snap_type,
                                   writable=writable)

                if (uvisible):
                    try:
                        self._toggle_visibility(share, ret.data['real_name'])
                    except Exception, e:
                        msg = ('Failed to make the Snapshot(%s) visible. '
                               'Exception: %s' % (snap_name, e.__str__()))
                        logger.error(msg)
                        logger.exception(e)

                    try:
                        toggle_sftp_visibility(share, ret.data['real_name'])
                    except Exception, e:
                        msg = ('Failed to make the Snapshot(%s) visible for '
                               'SFTP. Exception: %s' % (snap_name, e.__str__()))
                        logger.error(msg)
                        logger.exception(e)

                return ret
Beispiel #6
0
    def post(self, request, sname, snap_name, command=None):
        share = self._validate_share(sname, request)
        uvisible = request.DATA.get('uvisible', False)
        if (type(uvisible) != bool):
            e_msg = ('uvisible must be a boolean, not %s' % type(uvisible))
            handle_exception(Exception(e_msg), request)

        snap_type = request.DATA.get('snap_type', 'admin')
        writable = request.DATA.get('writable', 'rw')
        if (writable == 'rw'):
            writable = True
        else:
            writable = False
        pool_device = Disk.objects.filter(pool=share.pool)[0].name
        if (command is None):
            ret = self._create(share, snap_name, pool_device, request,
                               uvisible=uvisible, snap_type=snap_type,
                               writable=writable)

            if (uvisible):
                try:
                    self._toggle_visibility(share, ret.data['real_name'])
                except Exception, e:
                    msg = ('Failed to make the Snapshot(%s) visible.' %
                           snap_name)
                    logger.error(msg)
                    logger.exception(e)

                try:
                    toggle_sftp_visibility(share, ret.data['real_name'])
                except Exception, e:
                    msg = ('Failed to make the Snapshot(%s) visible for SFTP.'
                           % snap_name)
                    logger.error(msg)
                    logger.exception(e)
Beispiel #7
0
    def _delete_snapshot(self, request, sname, id=None, snap_name=None):
        share = self._validate_share(sname, request)
        try:
            snapshot = None
            if (id is not None):
                snapshot = Snapshot.objects.get(id=id)
            elif (snap_name is not None):
                snapshot = Snapshot.objects.get(share=share, name=snap_name)
            else:
                return True
        except:
            e_msg = ''
            if (id is not None):
                e_msg = ('Snapshot with id: %s does not exist' % id)
            else:
                e_msg = ('Snapshot with name: %s does not exist' % snap_name)
            handle_exception(Exception(e_msg), request)

        pool_device = Disk.objects.filter(pool=share.pool)[0].name
        if (snapshot.uvisible):
            e_msg = ('A low level error occured while deleting '
                     'snapshot(%s). Try again later.' % snapshot.name)
            try:
                self._toggle_visibility(share, snapshot.real_name, on=False)
            except Exception, e:
                logger.error(e_msg)
                logger.exception(e)
                handle_exception(Exception(e_msg), request)

            try:
                toggle_sftp_visibility(share, snapshot.real_name, on=False)
            except Exception, e:
                logger.error(e_msg)
                logger.exception(e)
                handle_exception(Exception(e_msg), request)
Beispiel #8
0
    def post(self, request, sname, snap_name, command=None):
        with self._handle_exception(request):
            share = self._validate_share(sname, request)
            uvisible = request.data.get('uvisible', False)
            if (type(uvisible) != bool):
                e_msg = ('uvisible must be a boolean, not %s' % type(uvisible))
                handle_exception(Exception(e_msg), request)

            snap_type = request.data.get('snap_type', 'admin')
            writable = request.data.get('writable', False)
            if (type(writable) != bool):
                e_msg = ('writable must be a boolean, not %s' % type(writable))
                handle_exception(Exception(e_msg), request)
            if (command is None):
                ret = self._create(share,
                                   snap_name,
                                   request,
                                   uvisible=uvisible,
                                   snap_type=snap_type,
                                   writable=writable)

                if (uvisible):
                    try:
                        self._toggle_visibility(share, ret.data['real_name'])
                    except Exception as e:
                        msg = ('Failed to make the Snapshot(%s) visible. '
                               'Exception: %s' % (snap_name, e.__str__()))
                        logger.error(msg)
                        logger.exception(e)

                    try:
                        toggle_sftp_visibility(share, ret.data['real_name'])
                    except Exception as e:
                        msg = ('Failed to make the Snapshot(%s) visible for '
                               'SFTP. Exception: %s' %
                               (snap_name, e.__str__()))
                        logger.error(msg)
                        logger.exception(e)

                return ret
            if (command == 'clone'):
                new_name = request.data.get('name', None)
                snapshot = Snapshot.objects.get(share=share, name=snap_name)
                return create_clone(share,
                                    new_name,
                                    request,
                                    logger,
                                    snapshot=snapshot)
            e_msg = ('Unknown command: %s' % command)
            handle_exception(Exception(e_msg), request)
Beispiel #9
0
    def post(self, request, sname, snap_name, command=None):
        share = self._validate_share(sname, request)
        uvisible = False
        if (request.DATA is not None and 'uvisible' in request.DATA):
            uvisible = request.DATA['uvisible']
            if (type(uvisible) != bool):
                e_msg = ('uvisible must be a boolean, not %s' % type(uvisible))
                handle_exception(Exception(e_msg), request)

        snap_type = 'admin'
        if (request.DATA is not None and 'snap_type' in request.DATA):
            snap_type = request.DATA['snap_type']

        pool_device = Disk.objects.filter(pool=share.pool)[0].name
        if (command is None):
            ret = self._create(share,
                               snap_name,
                               pool_device,
                               request,
                               uvisible=uvisible,
                               snap_type=snap_type)

            if (uvisible):
                try:
                    self._toggle_visibility(share, ret.data['real_name'])
                except Exception, e:
                    msg = ('Failed to make the Snapshot(%s) visible.' %
                           snap_name)
                    logger.error(msg)
                    logger.exception(e)

                try:
                    toggle_sftp_visibility(share, ret.data['real_name'])
                except Exception, e:
                    msg = (
                        'Failed to make the Snapshot(%s) visible for SFTP.' %
                        snap_name)
                    logger.error(msg)
                    logger.exception(e)
    def post(self, request, sname, snap_name, command=None):
        with self._handle_exception(request):
            share = self._validate_share(sname, request)
            uvisible = request.data.get('uvisible', False)
            if (type(uvisible) != bool):
                e_msg = ('uvisible must be a boolean, not %s' % type(uvisible))
                handle_exception(Exception(e_msg), request)

            snap_type = request.data.get('snap_type', 'admin')
            writable = request.data.get('writable', 'rw')
            writable = True if (writable == 'rw') else False
            pool_device = Disk.objects.filter(pool=share.pool)[0].name
            if (command is None):
                ret = self._create(share,
                                   snap_name,
                                   pool_device,
                                   request,
                                   uvisible=uvisible,
                                   snap_type=snap_type,
                                   writable=writable)

                if (uvisible):
                    try:
                        self._toggle_visibility(share, ret.data['real_name'])
                    except Exception, e:
                        msg = ('Failed to make the Snapshot(%s) visible.' %
                               snap_name)
                        logger.error(msg)
                        logger.exception(e)

                    try:
                        toggle_sftp_visibility(share, ret.data['real_name'])
                    except Exception, e:
                        msg = ('Failed to make the Snapshot(%s) visible for '
                               'SFTP.' % snap_name)
                        logger.error(msg)
                        logger.exception(e)

                return ret
Beispiel #11
0
    def post(self, request, sid, snap_name, command=None):
        with self._handle_exception(request):
            share = self._validate_share(sid, request)
            uvisible = request.data.get('uvisible', False)
            if (type(uvisible) != bool):
                # N.B. quote type important - test string involves ('unicode')
                e_msg = ("Element 'uvisible' must be a boolean, "
                         "not ({}).").format(type(uvisible))
                handle_exception(Exception(e_msg), request)

            snap_type = request.data.get('snap_type', 'admin')
            writable = request.data.get('writable', False)
            if (type(writable) != bool):
                e_msg = ('Element "writable" must be a boolean, '
                         'not ({}).').format(type(writable))
                handle_exception(Exception(e_msg), request)
            if (command is None):
                ret = self._create(share, snap_name, request,
                                   uvisible=uvisible, snap_type=snap_type,
                                   writable=writable)

                if (uvisible):
                    try:
                        self._toggle_visibility(share, ret.data['real_name'],
                                                ret.data['qgroup'])
                    except Exception as e:
                        msg = ('Failed to make the snapshot ({}) visible. '
                               'Exception: ({}).').format(snap_name,
                                                          e.__str__())
                        logger.error(msg)
                        logger.exception(e)

                    try:
                        toggle_sftp_visibility(share, ret.data['real_name'],
                                               ret.data['qgroup'])
                    except Exception as e:
                        msg = ('Failed to make the snapshot ({}) visible for '
                               'SFTP. Exception: ({}).').format(snap_name,
                                                                e.__str__())
                        logger.error(msg)
                        logger.exception(e)

                return ret
            if (command == 'clone'):
                new_name = request.data.get('name', None)
                snapshot = Snapshot.objects.get(share=share, name=snap_name)
                return create_clone(share, new_name, request, logger,
                                    snapshot=snapshot)
            if (command == 'repclone'):
                # When repclone is first called the oldest snapshot is
                # actually a share. This is an artifact of import_shares()
                # identifying the first snapshot incorrectly as a share.
                # TODO: As a temporary work around for this, and to avoid
                # TODO: modifying import_shares / import_snapshots for what is
                # TODO: currently stable behaviour we simply try for a share
                # TODO: if no snapshot is found, ie failing over to accommodate
                # TODO: for the currently quirky behaviour of the imports.
                # TODO: Note: this snap as share quirk is temporary as once a
                # TODO: replication cycle has completed it is removed.
                try:
                    snapshot = Snapshot.objects.get(share=share,
                                                    name=snap_name)
                except Snapshot.DoesNotExist:
                    # Here we rely on the polymorphism of Share/Snap and that
                    # this quirky share is located as per regular snapshots.
                    # The subvol of our snap-as-share-quirk is as per a snap:
                    # ".snapshots/sharename/snapname"
                    quirk_snap_share = '.snapshots/{}/{}'.format(share.name,
                                                                 snap_name)
                    logger.debug('Fail through for snap-as-share-quirk')
                    snapshot = Share.objects.get(subvol_name=quirk_snap_share)
                return create_repclone(share, request, logger,
                                       snapshot=snapshot)
            e_msg = 'Unknown command: ({}).'.format(command)
            handle_exception(Exception(e_msg), request)