当前位置: 首页>>代码示例>>Python>>正文


Python share_helpers.validate_share函数代码示例

本文整理汇总了Python中share_helpers.validate_share函数的典型用法代码示例。如果您正苦于以下问题:Python validate_share函数的具体用法?Python validate_share怎么用?Python validate_share使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了validate_share函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: delete

 def delete(self, request, sname, export_id):
     try:
         share = validate_share(sname, request)
         eg = validate_export_group(export_id, request)
         cur_exports = list(NFSExport.objects.all())
         export = NFSExport.objects.get(export_group=eg, share=share)
         for e in NFSExport.objects.filter(share=share):
             if (e.export_group.host_str == eg.host_str):
                 export_pt = ('%s%s' % (settings.NFS_EXPORT_ROOT,
                                        share.name))
                 if (e.export_group.nohide):
                     snap_name = e.mount.split(e.share.name + '_')[-1]
                     export_pt = ('%s%s/%s' % (settings.NFS_EXPORT_ROOT,
                                               e.share.name, snap_name))
                 teardown_wrapper(export_pt, request, logger)
                 cur_exports.remove(e)
         exports = create_nfs_export_input(cur_exports)
         export.delete()
         if (NFSExport.objects.filter(export_group=eg).count() == 0):
             #delete only when this is the only share in the group
             eg.delete()
         refresh_wrapper(exports, request, logger)
         return Response()
     except RockStorAPIException:
         raise
     except Exception, e:
         handle_exception(e, request)
开发者ID:kamal-gade,项目名称:rockstor-core,代码行数:27,代码来源:share_nfs.py

示例2: post

    def post(self, request):
        if ('shares' not in request.DATA):
            e_msg = ('Cannot export without specifying shares')
            handle_exception(Exception(e_msg), request)
        shares = [validate_share(s, request) for s in request.DATA['shares']]
        try:
            options = parse_options(request)
            for s in shares:
                dup_export_check(s, options['host_str'], request)

            cur_exports = list(NFSExport.objects.all())
            eg = NFSExportGroup(**options)
            eg.save()
            for s in shares:
                mnt_pt = ('%s%s' % (settings.MNT_PT, s.name))
                export_pt = ('%s%s' % (settings.NFS_EXPORT_ROOT, s.name))
                if (not is_share_mounted(s.name)):
                    pool_device = Disk.objects.filter(pool=s.pool)[0].name
                    mount_share(s.subvol_name, pool_device, mnt_pt)
                export = NFSExport(export_group=eg, share=s, mount=export_pt)
                export.full_clean()
                export.save()
                cur_exports.append(export)

            exports = create_nfs_export_input(cur_exports)
            refresh_wrapper(exports, request, logger)
            nfs_serializer = NFSExportGroupSerializer(eg)
            return Response(nfs_serializer.data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
开发者ID:sigkill,项目名称:rockstor-core,代码行数:32,代码来源:nfs_exports.py

示例3: post

    def post(self, request, sname):
        try:
            share = validate_share(sname, request)
            options = parse_options(request)
            dup_export_check(share, options['host_str'], request)
            cur_exports = list(NFSExport.objects.all())
            eg = NFSExportGroup(**options)
            eg.save()
            mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
            export_pt = ('%s%s' % (settings.NFS_EXPORT_ROOT, share.name))
            if (not is_share_mounted(share.name)):
                pool_device = Disk.objects.filter(pool=share.pool)[0].name
                mount_share(share.subvol_name, pool_device, mnt_pt)
            export = NFSExport(export_group=eg, share=share, mount=export_pt)
            export.full_clean()
            export.save()
            cur_exports.append(export)

            exports = create_nfs_export_input(cur_exports)
            refresh_wrapper(exports, request, logger)
            nfs_serializer = NFSExportGroupSerializer(eg)
            return Response(nfs_serializer.data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
开发者ID:kamal-gade,项目名称:rockstor-core,代码行数:26,代码来源:share_nfs.py

示例4: post

    def post(self, request):
        with self._handle_exception(request):
            if ('shares' not in request.data):
                e_msg = ('Cannot export without specifying shares')
                handle_exception(Exception(e_msg), request)
            shares = [validate_share(s, request) for s in request.data['shares']]
            options = parse_options(request)
            for s in shares:
                dup_export_check(s, options['host_str'], request)

            cur_exports = list(NFSExport.objects.all())
            eg = NFSExportGroup(**options)
            eg.save()
            for s in shares:
                mnt_pt = ('%s%s' % (settings.MNT_PT, s.name))
                export_pt = ('%s%s' % (settings.NFS_EXPORT_ROOT, s.name))
                if (not is_share_mounted(s.name)):
                    pool_device = Disk.objects.filter(pool=s.pool)[0].name
                    mount_share(s, pool_device, mnt_pt)
                export = NFSExport(export_group=eg, share=s, mount=export_pt)
                export.full_clean()
                export.save()
                cur_exports.append(export)

            exports = create_nfs_export_input(cur_exports)
            adv_entries = [e.export_str for e in
                           AdvancedNFSExport.objects.all()]
            exports_d = create_adv_nfs_export_input(adv_entries, request)
            exports.update(exports_d)
            refresh_wrapper(exports, request, logger)
            nfs_serializer = NFSExportGroupSerializer(eg)
            return Response(nfs_serializer.data)
开发者ID:drtyhbo,项目名称:rockstor-core,代码行数:32,代码来源:nfs_exports.py

示例5: get_queryset

 def get_queryset(self, *args, **kwargs):
     share = validate_share(kwargs['sname'], self.request)
     if ('export_id' in kwargs):
         self.paginate_by = 0
         try:
             return NFSExportGroup.objects.get(id=kwargs['export_id'])
         except:
             return []
     exports = NFSExport.objects.filter(share=share)
     ids = [e.export_group.id for e in exports]
     return NFSExportGroup.objects.filter(nohide=False, id__in=ids)
开发者ID:kamal-gade,项目名称:rockstor-core,代码行数:11,代码来源:share_nfs.py

示例6: put

 def put(self, request, sname, export_id):
     with self._handle_exception(request):
         share = validate_share(sname, request)
         eg = validate_export_group(export_id, request)
         options = parse_options(request)
         dup_export_check(share, options["host_str"], request, export_id=int(export_id))
         NFSExportGroup.objects.filter(id=export_id).update(**options)
         NFSExportGroup.objects.filter(id=export_id)[0].save()
         cur_exports = list(NFSExport.objects.all())
         exports = create_nfs_export_input(cur_exports)
         refresh_wrapper(exports, request, logger)
         nfs_serializer = NFSExportGroupSerializer(eg)
         return Response(nfs_serializer.data)
开发者ID:WebSpider,项目名称:rockstor-core,代码行数:13,代码来源:share_nfs.py

示例7: post

    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)
开发者ID:rcgade,项目名称:rockstor-core,代码行数:47,代码来源:sftp.py

示例8: post

    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()
开发者ID:priyaganti,项目名称:rockstor-core,代码行数:43,代码来源:sftp.py

示例9: put

 def put(self, request, export_id):
     if ('shares' not in request.DATA):
         e_msg = ('Cannot export without specifying shares')
         handle_exception(Exception(e_msg), request)
     shares = [validate_share(s, request) for s in request.DATA['shares']]
     try:
         eg = validate_export_group(export_id, request)
         options = parse_options(request)
         for s in shares:
             dup_export_check(s, options['host_str'], request,
                              export_id=int(export_id))
         NFSExportGroup.objects.filter(id=export_id).update(**options)
         NFSExportGroup.objects.filter(id=export_id)[0].save()
         cur_exports = list(NFSExport.objects.all())
         for e in NFSExport.objects.filter(export_group=eg):
             if (e.share not in shares):
                 cur_exports.remove(e)
                 e.delete()
             else:
                 shares.remove(e.share)
         for s in shares:
             mnt_pt = ('%s%s' % (settings.MNT_PT, s.name))
             export_pt = ('%s%s' % (settings.NFS_EXPORT_ROOT, s.name))
             if (not is_share_mounted(s.name)):
                 pool_device = Disk.objects.filter(pool=s.pool)[0].name
                 mount_share(s.subvol_name, pool_device, mnt_pt)
             export = NFSExport(export_group=eg, share=s, mount=export_pt)
             export.full_clean()
             export.save()
             cur_exports.append(export)
         exports = create_nfs_export_input(cur_exports)
         adv_entries = [e.export_str for e in
                        AdvancedNFSExport.objects.all()]
         exports_d = create_adv_nfs_export_input(adv_entries, request)
         exports.update(exports_d)
         refresh_wrapper(exports, request, logger)
         nfs_serializer = NFSExportGroupSerializer(eg)
         return Response(nfs_serializer.data)
     except RockStorAPIException:
         raise
     except Exception, e:
         handle_exception(e, request)
开发者ID:kamal-gade,项目名称:rockstor-core,代码行数:42,代码来源:nfs_exports.py

示例10: post

    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']]
        description = request.data.get('description', '')
        if (description == ''):
            description = self.def_description

        time_machine = request.data.get('time_machine', 'yes')
        if (time_machine != 'yes' and time_machine != 'no'):
            e_msg = ('time_machine must be yes or now. not %s' %
                     time_machine)
            handle_exception(Exception(e_msg), request)

        for share in shares:
            if (NetatalkShare.objects.filter(share=share).exists()):
                e_msg = ('Share(%s) is already exported via AFP' % share.name)
                handle_exception(Exception(e_msg), request)

        try:
            for share in shares:
                mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
                cur_description = '%s %s' % (share.name, description)
                if (len(shares) == 1 and description != self.def_description):
                    cur_description = description
                afpo = NetatalkShare(share=share, path=mnt_pt,
                                     description=cur_description,
                                     time_machine=time_machine)
                afpo.save()
                if (not is_share_mounted(share.name)):
                    pool_device = Disk.objects.filter(pool=share.pool)[0].name
                    mount_share(share, pool_device, mnt_pt)
            refresh_afp_config(list(NetatalkShare.objects.all()))
            systemctl('netatalk', 'reload')
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
开发者ID:Type-of-iframe,项目名称:rockstor-core,代码行数:41,代码来源:netatalk.py

示例11: delete

 def delete(self, request, sname, export_id):
     with self._handle_exception(request):
         share = validate_share(sname, request)
         eg = validate_export_group(export_id, request)
         cur_exports = list(NFSExport.objects.all())
         export = NFSExport.objects.get(export_group=eg, share=share)
         for e in NFSExport.objects.filter(share=share):
             if e.export_group.host_str == eg.host_str:
                 export_pt = "%s%s" % (settings.NFS_EXPORT_ROOT, share.name)
                 if e.export_group.nohide:
                     snap_name = e.mount.split(e.share.name + "_")[-1]
                     export_pt = "%s%s/%s" % (settings.NFS_EXPORT_ROOT, e.share.name, snap_name)
                 nfs4_mount_teardown(export_pt)
                 cur_exports.remove(e)
         exports = create_nfs_export_input(cur_exports)
         export.delete()
         if NFSExport.objects.filter(export_group=eg).count() == 0:
             # delete only when this is the only share in the group
             eg.delete()
         refresh_wrapper(exports, request, logger)
         return Response()
开发者ID:WebSpider,项目名称:rockstor-core,代码行数:21,代码来源:share_nfs.py

示例12: post

    def post(self, request, sname):
        with self._handle_exception(request):
            share = validate_share(sname, request)
            options = parse_options(request)
            dup_export_check(share, options["host_str"], request)
            cur_exports = list(NFSExport.objects.all())
            eg = NFSExportGroup(**options)
            eg.save()
            mnt_pt = "%s%s" % (settings.MNT_PT, share.name)
            export_pt = "%s%s" % (settings.NFS_EXPORT_ROOT, share.name)
            if not is_share_mounted(share.name):
                mount_share(share, mnt_pt)
            export = NFSExport(export_group=eg, share=share, mount=export_pt)
            export.full_clean()
            export.save()
            cur_exports.append(export)

            exports = create_nfs_export_input(cur_exports)
            refresh_wrapper(exports, request, logger)
            nfs_serializer = NFSExportGroupSerializer(eg)
            return Response(nfs_serializer.data)
开发者ID:WebSpider,项目名称:rockstor-core,代码行数:21,代码来源:share_nfs.py

示例13: put

 def put(self, request, export_id):
     with self._handle_exception(request):
         if ('shares' not in request.data):
             e_msg = 'Cannot export without specifying shares.'
             handle_exception(Exception(e_msg), request)
         shares = [validate_share(s, request) for s in
                   request.data['shares']]
         eg = self.validate_export_group(export_id, request)
         options = self.parse_options(request)
         for s in shares:
             self.dup_export_check(s, options['host_str'], request,
                                   export_id=int(export_id))
         NFSExportGroup.objects.filter(id=export_id).update(**options)
         NFSExportGroup.objects.filter(id=export_id)[0].save()
         cur_exports = list(NFSExport.objects.all())
         for e in NFSExport.objects.filter(export_group=eg):
             if (e.share not in shares):
                 cur_exports.remove(e)
                 e.delete()
             else:
                 shares.remove(e.share)
         for s in shares:
             mnt_pt = ('%s%s' % (settings.MNT_PT, s.name))
             export_pt = ('%s%s' % (settings.NFS_EXPORT_ROOT, s.name))
             if not s.is_mounted:
                 mount_share(s, mnt_pt)
             export = NFSExport(export_group=eg, share=s, mount=export_pt)
             export.full_clean()
             export.save()
             cur_exports.append(export)
         exports = self.create_nfs_export_input(cur_exports)
         adv_entries = [e.export_str for e in
                        AdvancedNFSExport.objects.all()]
         exports_d = self.create_adv_nfs_export_input(adv_entries, request)
         exports.update(exports_d)
         self.refresh_wrapper(exports, request, logger)
         nfs_serializer = NFSExportGroupSerializer(eg)
         return Response(nfs_serializer.data)
开发者ID:MFlyer,项目名称:rockstor-core,代码行数:38,代码来源:nfs_exports.py

示例14: create_adv_nfs_export_input

 def create_adv_nfs_export_input(exports, request):
     exports_d = {}
     for e in exports:
         fields = e.split()
         if (len(fields) < 2):
             e_msg = ('Invalid exports input -- %s' % e)
             handle_exception(Exception(e_msg), request)
         share = fields[0].split('/')[-1]
         s = validate_share(share, request)
         mnt_pt = ('%s%s' % (settings.MNT_PT, s.name))
         if (not is_share_mounted(s.name)):
             mount_share(s, mnt_pt)
         exports_d[fields[0]] = []
         for f in fields[1:]:
             cf = f.split('(')
             if (len(cf) != 2 or cf[1][-1] != ')'):
                 e_msg = ('Invalid exports input -- %s. offending '
                          'section: %s' % (e, f))
                 handle_exception(Exception(e_msg), request)
             exports_d[fields[0]].append(
                 {'client_str': cf[0], 'option_list': cf[1][:-1],
                  'mnt_pt': ('%s%s' % (settings.MNT_PT, share))})
     return exports_d
开发者ID:priyaganti,项目名称:rockstor-core,代码行数:23,代码来源:nfs_exports.py

示例15: post

    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']]
        options = self._validate_input(request)
        custom_config = options['custom_config']
        del(options['custom_config'])
        for share in shares:
            if (SambaShare.objects.filter(share=share).exists()):
                e_msg = ('Share(%s) is already exported via Samba' %
                         share.name)
                handle_exception(Exception(e_msg), request)
        with self._handle_exception(request):
            for share in shares:
                mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
                options['share'] = share
                options['path'] = mnt_pt
                smb_share = SambaShare(**options)
                smb_share.save()
                for cc in custom_config:
                    cco = SambaCustomConfig(smb_share=smb_share,
                                            custom_config=cc)
                    cco.save()
                if (not is_share_mounted(share.name)):
                    pool_device = Disk.objects.filter(pool=share.pool)[0].name
                    mount_share(share, pool_device, mnt_pt)

                admin_users = request.data.get('admin_users', None)
                if (admin_users is None):
                    admin_users = []
                for au in admin_users:
                    auo = User.objects.get(username=au)
                    auo.smb_shares.add(smb_share)
            refresh_smb_config(list(SambaShare.objects.all()))
            self._restart_samba()
            return Response(SambaShareSerializer(smb_share).data)
开发者ID:drtyhbo,项目名称:rockstor-core,代码行数:37,代码来源:samba.py


注:本文中的share_helpers.validate_share函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。