Ejemplo n.º 1
0
    def delete(self, request, id):
        try:
            sftpo = SFTP.objects.get(id=id)
        except:
            e_msg = ('SFTP config for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            mnt_prefix = ('%s%s/' % (settings.SFTP_MNT_ROOT,
                                     sftpo.share.owner))

            if (is_share_mounted(sftpo.share.name, mnt_prefix)):
                sftp_snap_toggle(sftpo.share, mount=False)
                mnt_pt = ('%s%s' % (mnt_prefix, sftpo.share.name))
                umount_root(mnt_pt)
                if (os.path.isdir(mnt_pt)):
                    shutil.rmtree(mnt_pt)
            sftpo.delete()
            input_map = {}
            for so in SFTP.objects.all():
                if (so.id != sftpo.id):
                    input_map[so.share.owner] = (
                        '%s%s' % (settings.SFTP_MNT_ROOT, so.share.owner))
            update_sftp_config(input_map)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 2
0
    def delete(self, request, id):
        with self._handle_exception(request):
            try:
                sftpo = SFTP.objects.get(id=id)
            except:
                e_msg = (
                    "SFTP config for the id ({}) does not exist.").format(id)
                handle_exception(Exception(e_msg), request)

            mnt_prefix = "{}{}/".format(settings.SFTP_MNT_ROOT,
                                        sftpo.share.owner)

            if is_share_mounted(sftpo.share.name, mnt_prefix):
                sftp_snap_toggle(sftpo.share, mount=False)
                mnt_pt = "{}{}".format(mnt_prefix, sftpo.share.name)
                umount_root(mnt_pt)
                if os.path.isdir(mnt_pt):
                    shutil.rmtree(mnt_pt)
            sftpo.delete()
            input_map = {}
            for so in SFTP.objects.all():
                if so.id != sftpo.id:
                    input_map[so.share.owner] = "{}{}".format(
                        settings.SFTP_MNT_ROOT,
                        so.share.owner,
                    )
            update_sftp_config(input_map)
            return Response()
Ejemplo n.º 3
0
    def delete(self, request, id):
        try:
            sftpo = SFTP.objects.get(id=id)
        except:
            e_msg = ('SFTP config for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            mnt_prefix = ('%s%s/' % (settings.SFTP_MNT_ROOT,
                                     sftpo.share.owner))

            if (is_share_mounted(sftpo.share.name, mnt_prefix)):
                sftp_snap_toggle(sftpo.share, mount=False)
                umount_root(('%s%s' % (mnt_prefix, sftpo.share.name)))
                import shutil
                shutil.rmtree(mnt_prefix)
            sftpo.delete()
            input_list = []
            for so in SFTP.objects.all():
                if (so.id != sftpo.id):
                    input_list.append({'user': so.share.owner,
                                       'dir': ('%s%s' %
                                               (settings.SFTP_MNT_ROOT,
                                                so.share.name)), })
            update_sftp_config(input_list)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 4
0
    def delete(self, request, id):
        try:
            sftpo = SFTP.objects.get(id=id)
        except:
            e_msg = ('SFTP config for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            mnt_prefix = ('%s%s/' %
                          (settings.SFTP_MNT_ROOT, sftpo.share.owner))

            if (is_share_mounted(sftpo.share.name, mnt_prefix)):
                sftp_snap_toggle(sftpo.share, mount=False)
                mnt_pt = ('%s%s' % (mnt_prefix, sftpo.share.name))
                umount_root(mnt_pt)
                if (os.path.isdir(mnt_pt)):
                    shutil.rmtree(mnt_pt)
            sftpo.delete()
            input_map = {}
            for so in SFTP.objects.all():
                if (so.id != sftpo.id):
                    input_map[so.share.owner] = (
                        '%s%s' % (settings.SFTP_MNT_ROOT, so.share.owner))
            update_sftp_config(input_map)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 5
0
    def delete(self, request, id):
        try:
            sftpo = SFTP.objects.get(id=id)
        except:
            e_msg = ('SFTP config for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            mnt_prefix = ('%s%s/' %
                          (settings.SFTP_MNT_ROOT, sftpo.share.owner))

            if (is_share_mounted(sftpo.share.name, mnt_prefix)):
                sftp_snap_toggle(sftpo.share, mount=False)
                umount_root(('%s%s' % (mnt_prefix, sftpo.share.name)))
                import shutil
                shutil.rmtree(mnt_prefix)
            sftpo.delete()
            input_list = []
            for so in SFTP.objects.all():
                if (so.id != sftpo.id):
                    input_list.append({
                        'user':
                        so.share.owner,
                        'dir':
                        ('%s%s' % (settings.SFTP_MNT_ROOT, so.share.name)),
                    })
            update_sftp_config(input_list)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 6
0
    def post(self, request):
        if ('shares' not in request.DATA):
            e_msg = ('Must provide share names')
            handle_exception(Exception(e_msg), request)
        shares = [validate_share(s, request) for s in request.DATA['shares']]
        editable = 'rw'
        if ('read_only' in request.DATA and request.DATA['read_only'] is True):
            editable = 'ro'
        try:
            mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT)
            input_list = []
            for share in shares:
                if (SFTP.objects.filter(share=share).exists()):
                    e_msg = ('Share(%s) is already exported via SFTP' %
                             share.name)
                    handle_exception(Exception(e_msg), request)
                if (share.owner == 'root'):
                    e_msg = ('Share(%s) is owned by root. It cannot be '
                             'exported via SFTP with root ownership' %
                             share.name)
                    handle_exception(Exception(e_msg), request)
            for share in shares:
                sftpo = SFTP(share=share, editable=editable)
                sftpo.save()
                #  mount if not already mounted
                helper_mount_share(share)
                #  bindmount if not already
                sftp_mount(share, settings.MNT_PT, settings.SFTP_MNT_ROOT,
                           mnt_map, editable)
                sftp_snap_toggle(share)

                chroot_loc = ('%s%s' % (settings.SFTP_MNT_ROOT, share.owner))
                rsync_for_sftp(chroot_loc)
                input_list.append({
                    'user': share.owner,
                    'dir': chroot_loc,
                })
            for sftpo in SFTP.objects.all():
                if (sftpo.share not in shares):
                    input_list.append({
                        'user':
                        sftpo.share.owner,
                        'dir':
                        ('%s%s' % (settings.SFTP_MNT_ROOT, sftpo.share.owner)),
                    })
            update_sftp_config(input_list)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 7
0
    def post(self, request):
        if ('shares' not in request.DATA):
            e_msg = ('Must provide share names')
            handle_exception(Exception(e_msg), request)
        shares = [validate_share(s, request) for s in request.DATA['shares']]
        editable = 'rw'
        if ('read_only' in request.DATA and request.DATA['read_only'] is True):
            editable = 'ro'
        try:
            mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT)
            input_list = []
            for share in shares:
                if (SFTP.objects.filter(share=share).exists()):
                    e_msg = ('Share(%s) is already exported via SFTP' %
                             share.name)
                    handle_exception(Exception(e_msg), request)
                if (share.owner == 'root'):
                    e_msg = ('Share(%s) is owned by root. It cannot be '
                             'exported via SFTP with root ownership' %
                             share.name)
                    handle_exception(Exception(e_msg), request)
            for share in shares:
                sftpo = SFTP(share=share, editable=editable)
                sftpo.save()
                #  mount if not already mounted
                helper_mount_share(share)
                #  bindmount if not already
                sftp_mount(share, settings.MNT_PT, settings.SFTP_MNT_ROOT,
                           mnt_map, editable)
                sftp_snap_toggle(share)

                chroot_loc = ('%s%s' % (settings.SFTP_MNT_ROOT, share.owner))
                rsync_for_sftp(chroot_loc)
                input_list.append({'user': share.owner,
                                   'dir': chroot_loc, })
            for sftpo in SFTP.objects.all():
                if (sftpo.share not in shares):
                    input_list.append({'user': sftpo.share.owner,
                                       'dir': ('%s%s' %
                                               (settings.SFTP_MNT_ROOT,
                                                sftpo.share.owner)), })
            update_sftp_config(input_list)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 8
0
    def post(self, request):
        with self._handle_exception(request):
            if "shares" not in request.data:
                e_msg = "Must provide share names."
                handle_exception(Exception(e_msg), request)
            shares = [
                validate_share(s, request) for s in request.data["shares"]
            ]
            editable = "rw"
            if "read_only" in request.data and request.data[
                    "read_only"] is True:
                editable = "ro"

            mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT)
            input_map = {}
            for share in shares:
                if SFTP.objects.filter(share=share).exists():
                    e_msg = (
                        "Share ({}) is already exported via SFTP.").format(
                            share.name)
                    handle_exception(Exception(e_msg), request)
                if share.owner == "root":
                    e_msg = ("Share ({}) is owned by root. It cannot be "
                             "exported via SFTP with "
                             "root ownership.").format(share.name)
                    handle_exception(Exception(e_msg), request)
            for share in shares:
                sftpo = SFTP(share=share, editable=editable)
                sftpo.save()
                #  mount if not already mounted
                helper_mount_share(share)
                #  bindmount if not already
                sftp_mount(share, settings.MNT_PT, settings.SFTP_MNT_ROOT,
                           mnt_map, editable)
                sftp_snap_toggle(share)

                chroot_loc = "{}{}".format(settings.SFTP_MNT_ROOT, share.owner)
                rsync_for_sftp(chroot_loc)
                input_map[share.owner] = chroot_loc
            for sftpo in SFTP.objects.all():
                if sftpo.share not in shares:
                    input_map[sftpo.share.owner] = "{}{}".format(
                        settings.SFTP_MNT_ROOT,
                        sftpo.share.owner,
                    )
            update_sftp_config(input_map)
            return Response()
Ejemplo n.º 9
0
    def post(self, request):
        with self._handle_exception(request):
            if ('shares' not in request.data):
                e_msg = ('Must provide share names')
                handle_exception(Exception(e_msg), request)
            shares = [
                validate_share(s, request) for s in request.data['shares']
            ]
            editable = 'rw'
            if ('read_only' in request.data
                    and request.data['read_only'] is True):
                editable = 'ro'

            mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT)
            input_map = {}
            for share in shares:
                if (SFTP.objects.filter(share=share).exists()):
                    e_msg = ('Share(%s) is already exported via SFTP' %
                             share.name)
                    handle_exception(Exception(e_msg), request)
                if (share.owner == 'root'):
                    e_msg = ('Share(%s) is owned by root. It cannot be '
                             'exported via SFTP with root ownership' %
                             share.name)
                    handle_exception(Exception(e_msg), request)
            for share in shares:
                sftpo = SFTP(share=share, editable=editable)
                sftpo.save()
                #  mount if not already mounted
                helper_mount_share(share)
                #  bindmount if not already
                sftp_mount(share, settings.MNT_PT, settings.SFTP_MNT_ROOT,
                           mnt_map, editable)
                sftp_snap_toggle(share)

                chroot_loc = ('%s%s' % (settings.SFTP_MNT_ROOT, share.owner))
                rsync_for_sftp(chroot_loc)
                input_map[share.owner] = chroot_loc
            for sftpo in SFTP.objects.all():
                if (sftpo.share not in shares):
                    input_map[sftpo.share.owner] = (
                        '%s%s' % (settings.SFTP_MNT_ROOT, sftpo.share.owner))
            update_sftp_config(input_map)
            return Response()
Ejemplo n.º 10
0
    def post(self, request):
        with self._handle_exception(request):
            if ('shares' not in request.data):
                e_msg = ('Must provide share names')
                handle_exception(Exception(e_msg), request)
            shares = [validate_share(s, request) for s in
                      request.data['shares']]
            editable = 'rw'
            if ('read_only' in request.data and
                    request.data['read_only'] is True):
                editable = 'ro'

            mnt_map = sftp_mount_map(settings.SFTP_MNT_ROOT)
            input_map = {}
            for share in shares:
                if (SFTP.objects.filter(share=share).exists()):
                    e_msg = ('Share(%s) is already exported via SFTP' %
                             share.name)
                    handle_exception(Exception(e_msg), request)
                if (share.owner == 'root'):
                    e_msg = ('Share(%s) is owned by root. It cannot be '
                             'exported via SFTP with root ownership' %
                             share.name)
                    handle_exception(Exception(e_msg), request)
            for share in shares:
                sftpo = SFTP(share=share, editable=editable)
                sftpo.save()
                #  mount if not already mounted
                helper_mount_share(share)
                #  bindmount if not already
                sftp_mount(share, settings.MNT_PT, settings.SFTP_MNT_ROOT,
                           mnt_map, editable)
                sftp_snap_toggle(share)

                chroot_loc = ('%s%s' % (settings.SFTP_MNT_ROOT, share.owner))
                rsync_for_sftp(chroot_loc)
                input_map[share.owner] = chroot_loc
            for sftpo in SFTP.objects.all():
                if (sftpo.share not in shares):
                    input_map[sftpo.share.owner] = (
                        '%s%s' % (settings.SFTP_MNT_ROOT, sftpo.share.owner))
            update_sftp_config(input_map)
            return Response()