Example #1
0
    def post(self, request, sname, command):
        with self._handle_exception(request):
            share = self._validate_share(request, sname)

            if (command == 'clone'):
                new_name = request.data.get('name', '')
                return create_clone(share, new_name, request, logger)

            if (command == 'rollback'):
                snap = self._validate_snapshot(request, share)

                if (NFSExport.objects.filter(share=share).exists()):
                    e_msg = ('Share(%s) cannot be rolled back as it is '
                             'exported via nfs. Delete nfs exports and '
                             'try again' % sname)
                    handle_exception(Exception(e_msg), request)

                if (SambaShare.objects.filter(share=share).exists()):
                    e_msg = ('Share(%s) cannot be rolled back as it is shared'
                             ' via Samba. Unshare and try again' % sname)
                    handle_exception(Exception(e_msg), request)

                rollback_snap(snap.real_name, share.name, share.subvol_name,
                              share.pool)
                update_quota(share.pool, snap.qgroup, share.size * 1024)
                share.qgroup = snap.qgroup
                share.save()
                snap.delete()
                return Response()
Example #2
0
    def post(self, request, sname, command):
        with self._handle_exception(request):
            share = self._validate_share(request, sname)

            if command == "clone":
                new_name = request.DATA.get("name", "")
                return create_clone(share, new_name, request, logger)

            if command == "rollback":
                snap = self._validate_snapshot(request, share)

                if NFSExport.objects.filter(share=share).exists():
                    e_msg = (
                        "Share(%s) cannot be rolled back as it is "
                        "exported via nfs. Delete nfs exports and "
                        "try again" % sname
                    )
                    handle_exception(Exception(e_msg), request)

                if SambaShare.objects.filter(share=share).exists():
                    e_msg = (
                        "Share(%s) cannot be rolled back as it is shared" " via Samba. Unshare and try again" % sname
                    )
                    handle_exception(Exception(e_msg), request)

                pool_device = Disk.objects.filter(pool=share.pool)[0].name
                rollback_snap(snap.real_name, share.name, share.subvol_name, share.pool, pool_device)
                update_quota(share.pool, pool_device, snap.qgroup, share.size * 1024)
                share.qgroup = snap.qgroup
                share.save()
                snap.delete()
                return Response()

            if command == "compress":
                algo = request.DATA.get("compress", None)
                if algo is None:
                    e_msg = (
                        "Compression algorithm must be specified. Valid " "options are: %s" % settings.COMPRESSION_TYPES
                    )
                    handle_exception(Exception(e_msg), request)
                if algo not in settings.COMPRESSION_TYPES:
                    e_msg = (
                        "Compression algorithm(%s) is invalid. Valid " "options are: %s" % settings.COMPRESSION_TYPES
                    )
                    handle_exception(Exception(e_msg), request)
                mnt_pt = "%s%s" % (settings.MNT_PT, share.name)
                if not is_share_mounted(share.name):
                    disk = Disk.objects.filter(pool=share.pool)[0].name
                    mount_share(share, disk, mnt_pt)
                share.compression_algo = algo
                share.save()
                if algo == "no":
                    algo = ""
                set_property(mnt_pt, "compression", algo)
                return Response(ShareSerializer(share).data)
Example #3
0
    def post(self, request, sname, command):
        try:
            share = Share.objects.get(name=sname)
        except:
            e_msg = ('Share: %s does not exist' % sname)
            handle_exception(Exception(e_msg), request)

        if (command == 'clone'):
            new_name = request.DATA['name']
            if (Share.objects.filter(name=new_name).exists()):
                e_msg = ('Share with name: %s already exists.' % new_name)
                handle_exception(Exception(e_msg), request)
            pool_device = Disk.objects.filter(pool=share.pool)[0].name
            return create_clone(share, new_name, pool_device, request)

        elif (command == 'rollback'):
            snap_name = request.DATA['name']
            try:
                snap = Snapshot.objects.get(share=share, name=snap_name)
            except:
                e_msg = ('Snapshot with name: %s does not exist for the '
                         'share: %s' % (snap_name, share.name))
                handle_exception(Exception(e_msg), request)

            if (NFSExport.objects.filter(share=share).exists()):
                e_msg = ('Share: %s cannot be rolled back as it is exported '
                         'via nfs. Delete nfs exports and try again' % sname)
                handle_exception(Exception(e_msg), request)

            if (SambaShare.objects.filter(share=share).exists()):
                e_msg = ('Share: %s cannot be rolled back as it is shared '
                         ' via Samba. Unshare and try again' % sname)
                handle_exception(Exception(e_msg), request)

            try:
                pool_device = Disk.objects.filter(pool=share.pool)[0].name
                rollback_snap(snap.real_name, share.name, share.subvol_name,
                              share.pool.name, pool_device)
                share.subvol_name = snap.real_name
                update_quota(share.pool.name, pool_device, snap.qgroup,
                             share.size * 1024)
                share.qgroup = snap.qgroup
                share.save()
                snap.delete()
                return Response()
            except Exception, e:
                logger.exception(e)
                handle_exception(e, request)
Example #4
0
    def post(self, request, sname, command):
        try:
            share = Share.objects.get(name=sname)
        except:
            e_msg = ('Share: %s does not exist' % sname)
            handle_exception(Exception(e_msg), request)

        if (command == 'clone'):
            new_name = request.DATA['name']
            if (Share.objects.filter(name=new_name).exists()):
                e_msg = ('Share with name: %s already exists.' % new_name)
                handle_exception(Exception(e_msg), request)
            pool_device = Disk.objects.filter(pool=share.pool)[0].name
            return create_clone(share, new_name, pool_device, request)

        elif (command == 'rollback'):
            snap_name = request.DATA['name']
            try:
                snap = Snapshot.objects.get(share=share, name=snap_name)
            except:
                e_msg = ('Snapshot with name: %s does not exist for the '
                         'share: %s' % (snap_name, share.name))
                handle_exception(Exception(e_msg), request)

            if (NFSExport.objects.filter(share=share).exists()):
                e_msg = ('Share: %s cannot be rolled back as it is exported '
                         'via nfs. Delete nfs exports and try again' % sname)
                handle_exception(Exception(e_msg), request)

            if (SambaShare.objects.filter(share=share).exists()):
                e_msg = ('Share: %s cannot be rolled back as it is shared '
                         ' via Samba. Unshare and try again' % sname)
                handle_exception(Exception(e_msg), request)

            try:
                pool_device = Disk.objects.filter(pool=share.pool)[0].name
                rollback_snap(snap.real_name, share.name, share.subvol_name,
                              share.pool.name, pool_device)
                share.subvol_name = snap.real_name
                update_quota(share.pool.name, pool_device, snap.qgroup,
                             share.size * 1024)
                share.qgroup = snap.qgroup
                share.save()
                snap.delete()
                return Response()
            except Exception, e:
                logger.exception(e)
                handle_exception(e, request)
Example #5
0
 def _rollback(self, share, snap_name, pool_device, request):
     try:
         snap = Snapshot.objects.get(share=share, name=snap_name)
     except:
         e_msg = ('Snapshot with name: %s does not exist for the '
                  'share: %s' % (snap_name, share.name))
         handle_exception(Exception(e_msg), request)
     try:
         rollback_snap(snap_name, share.name, share.subvol_name,
                       share.pool.name, pool_device)
         share.subvol_name = snap_name
         update_quota(share.pool.name, pool_device, snap.qgroup,
                      share.size * 1024)
         share.qgroup = snap.qgroup
         share.save()
         snap.delete()
         return Response()
     except Exception, e:
         logger.exception(e)
         handle_exception(e, request)
Example #6
0
    def post(self, request, sname, snap_name, command=None):
        share = self._validate_share(sname, request)
        pool_device = Disk.objects.filter(pool=share.pool)[0].name
        if (command is None):
            if (Snapshot.objects.filter(share=share, name=snap_name).exists()):
                e_msg = ('Snapshot with name: %s already exists for the '
                         'share: %s' % (snap_name, sname))
                handle_exception(Exception(e_msg), request)

            add_snap(share.pool.name, pool_device, share.subvol_name,
                     snap_name)
            snap_id = share_id(share.pool.name, pool_device, snap_name)
            qgroup_id = ('0/%s' % snap_id)
            s = Snapshot(share=share, name=snap_name, qgroup=qgroup_id)
            s.save()
            return Response(SnapshotSerializer(s).data)

        if (command == 'rollback'):
            try:
                snap = Snapshot.objects.get(share=share, name=snap_name)
            except:
                e_msg = ('Snapshot with name: %s does not exist for the '
                         'share: %s' % (snap_name, sname))
                handle_exception(Exception(e_msg), request)
            try:
                rollback_snap(snap_name, sname, share.subvol_name,
                              share.pool.name, pool_device)
                share.subvol_name = snap_name
                update_quota(share.pool.name, pool_device, snap.qgroup,
                             share.size * 1024)
                share.qgroup = snap.qgroup
                share.save()
                snap.delete()
                return Response()
            except Exception, e:
                logger.exception(e)
                handle_exception(e, request)
Example #7
0
    def post(self, request, sname, snap_name, command=None):
        share = self._validate_share(sname, request)
        pool_device = Disk.objects.filter(pool=share.pool)[0].name
        if (command is None):
            if (Snapshot.objects.filter(share=share, name=snap_name).exists()):
                e_msg = ('Snapshot with name: %s already exists for the '
                         'share: %s' % (snap_name, sname))
                handle_exception(Exception(e_msg), request)

            add_snap(share.pool.name, pool_device, share.subvol_name,
                     snap_name)
            snap_id = share_id(share.pool.name, pool_device, snap_name)
            qgroup_id = ('0/%s' % snap_id)
            s = Snapshot(share=share, name=snap_name, qgroup=qgroup_id)
            s.save()
            return Response(SnapshotSerializer(s).data)

        if (command == 'rollback'):
            try:
                snap = Snapshot.objects.get(share=share, name=snap_name)
            except:
                e_msg = ('Snapshot with name: %s does not exist for the '
                         'share: %s' % (snap_name, sname))
                handle_exception(Exception(e_msg), request)
            try:
                rollback_snap(snap_name, sname, share.subvol_name,
                              share.pool.name, pool_device)
                share.subvol_name = snap_name
                update_quota(share.pool.name, pool_device, snap.qgroup,
                             share.size * 1024)
                share.qgroup = snap.qgroup
                share.save()
                snap.delete()
                return Response()
            except Exception, e:
                logger.exception(e)
                handle_exception(e, request)