예제 #1
0
    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)
예제 #2
0
    def _toggle_visibility(self, share, snap_name, on=True):
        cur_exports = list(NFSExport.objects.all())
        snap_mnt_pt = ('%s%s/.%s' % (settings.MNT_PT, share.name, snap_name))
        export_pt = snap_mnt_pt.replace(settings.MNT_PT,
                                        settings.NFS_EXPORT_ROOT)
        if (on):
            mount_snap(share, snap_name)

            if (NFSExport.objects.filter(share=share).exists()):
                se = NFSExport.objects.filter(share=share)[0]
                export_group = NFSExportGroup(
                    host_str=se.export_group.host_str, nohide=True)
                export_group.save()
                export = NFSExport(share=share,
                                   export_group=export_group,
                                   mount=export_pt)
                export.full_clean()
                export.save()
                cur_exports.append(export)
        else:
            for mnt in (snap_mnt_pt, export_pt):
                try:
                    export = NFSExport.objects.get(share=share, mount=mnt)
                    cur_exports.remove(export)
                    export.export_group.delete()
                    export.delete()
                except NFSExport.DoesNotExist:
                    pass
                except Exception, e:
                    logger.exception(e)
                finally:
                    umount_root(export_pt)
예제 #3
0
    def _toggle_visibility(self, share, snap_name, on=True):
        cur_exports = list(NFSExport.objects.all())
        snap_mnt_pt = ('%s%s/.%s' % (settings.MNT_PT, share.name, snap_name))
        export_pt = snap_mnt_pt.replace(settings.MNT_PT,
                                        settings.NFS_EXPORT_ROOT)
        if (on):
            mount_snap(share, snap_name)

            if (NFSExport.objects.filter(share=share).exists()):
                se = NFSExport.objects.filter(share=share)[0]
                export_group = NFSExportGroup(
                    host_str=se.export_group.host_str, nohide=True)
                export_group.save()
                export = NFSExport(share=share, export_group=export_group,
                                   mount=export_pt)
                export.full_clean()
                export.save()
                cur_exports.append(export)
        else:
            for mnt in (snap_mnt_pt, export_pt):
                try:
                    export = NFSExport.objects.get(share=share, mount=mnt)
                    cur_exports.remove(export)
                    export.export_group.delete()
                    export.delete()
                except NFSExport.DoesNotExist:
                    pass
                except Exception, e:
                    logger.exception(e)
                finally:
                    umount_root(export_pt)
예제 #4
0
    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 = self.parse_options(request)
            for s in shares:
                self.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))
                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)
예제 #5
0
    def _toggle_visibility(self, share, snap_name, on=True):
        cur_exports = list(NFSExport.objects.all())
        snap_short_name = snap_name.split(share.name)[-1][1:]
        snap_mnt_pt = ('%s%s/.%s' %
                       (settings.MNT_PT, share.name, snap_short_name))
        export_pt = snap_mnt_pt.replace(settings.MNT_PT,
                                        settings.NFS_EXPORT_ROOT)
        if (on):
            pool_device = Disk.objects.filter(pool=share.pool)[0].name
            if (not is_share_mounted(share.name)):
                share_mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
                mount_share(share.subvol_name, pool_device, share_mnt_pt)
            mount_share(snap_name, pool_device, snap_mnt_pt)

            if (NFSExport.objects.filter(share=share).exists()):
                se = NFSExport.objects.filter(share=share)[0]
                export_group = NFSExportGroup(
                    host_str=se.export_group.host_str, nohide=True)
                export_group.save()
                export = NFSExport(share=share,
                                   export_group=export_group,
                                   mount=snap_mnt_pt)
                export.full_clean()
                export.save()
                cur_exports.append(export)
        else:
            try:
                export = NFSExport.objects.get(share=share, mount=snap_mnt_pt)
                cur_exports.remove(export)
                export.export_group.delete()
                export.delete()
            except Exception, e:
                logger.exception(e)
            finally:
예제 #6
0
    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)
예제 #7
0
    def _toggle_visibility(self, share, snap_name, on=True):
        cur_exports = list(NFSExport.objects.all())
        snap_short_name = snap_name.split(share.name)[-1][1:]
        snap_mnt_pt = ('%s%s/.%s' % (settings.MNT_PT, share.name,
                                     snap_short_name))
        export_pt = snap_mnt_pt.replace(settings.MNT_PT,
                                        settings.NFS_EXPORT_ROOT)
        if (on):
            pool_device = Disk.objects.filter(pool=share.pool)[0].name
            if (not is_share_mounted(share.name)):
                share_mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
                mount_share(share.subvol_name, pool_device, share_mnt_pt)
            mount_share(snap_name, pool_device, snap_mnt_pt)

            if (NFSExport.objects.filter(share=share).exists()):
                se = NFSExport.objects.filter(share=share)[0]
                export_group = NFSExportGroup(
                    host_str=se.export_group.host_str, nohide=True)
                export_group.save()
                export = NFSExport(share=share, export_group=export_group,
                                   mount=snap_mnt_pt)
                export.full_clean()
                export.save()
                cur_exports.append(export)
        else:
            try:
                export = NFSExport.objects.get(share=share, mount=snap_mnt_pt)
                cur_exports.remove(export)
                export.export_group.delete()
                export.delete()
            except Exception, e:
                logger.exception(e)
            finally:
예제 #8
0
    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)
예제 #9
0
    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)
예제 #10
0
    def _toggle_visibility(self, share, snap_name, on=True):
        cur_exports = list(NFSExport.objects.all())
        for se in NFSExport.objects.filter(share=share):
            mnt_pt = ('%s%s/%s' % (settings.MNT_PT, share.pool.name,
                                   snap_name))
            export_pt = mnt_pt.replace(settings.MNT_PT,
                                       settings.NFS_EXPORT_ROOT)
            export = None
            if (on):
                if (se.export_group.nohide is False):
                    continue

                export_group = NFSExportGroup(host_str=se.host_str,
                                              nohide=True)
                export_group.save()
                export = NFSExport(share=share, export_group=export_group,
                                   mount=export_pt)
                export.full_clean()
                export.save()
                cur_exports.append(export)
            else:
                try:
                    export = NFSExport.objects.get(share=share,
                                                   mount=export_pt)
                    export.delete()
                    export.export_group.delete()
                    cur_exports.remove(export)
                except Exception, e:
                    logger.exception(e)
                    continue
예제 #11
0
    def setUpClass(cls):
        super(NFSExportTests, cls).setUpClass()

        # post mocks
        cls.patch_mount_share = patch('storageadmin.views.nfs_exports.'
                                      'mount_share')
        cls.mock_mount_share = cls.patch_mount_share.start()
        cls.mock_mount_share.return_value = ['out'], ['err'], 0

        cls.patch_refresh_nfs_exports = patch('storageadmin.views.nfs_exports.'
                                              'refresh_nfs_exports')
        cls.mock_refresh_nfs_exports = cls.patch_refresh_nfs_exports.start()
        cls.mock_refresh_nfs_exports.return_value = ['out'], ['err'], 0

        # potential mocks for NFSExportGroup
        # validate_nfs_host_str
        # validate_nfs_modify_str
        # validate_nfs_sync_choice

        # all values as per fixture
        cls.temp_pool = Pool(id=11, name='rock-pool', size=5242880)
        cls.temp_share_nfs = Share(id=21, name='share-nfs', pool=cls.temp_pool)
        # the following is not picking up from db !!
        # cls.temp_nfsexportgroup = NFSExportGroup.objects.get(id=1)
        cls.temp_nfsexportgroup = NFSExportGroup(id=1)
        cls.temp_nfsexport = NFSExport(export_group=cls.temp_nfsexportgroup,
                                       share=cls.temp_share_nfs,
                                       mount='/export/share-nfs', id=1)

        cls.temp_share2 = Share(id=22, name='share2', pool=cls.temp_pool)
예제 #12
0
    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)
예제 #13
0
    def _toggle_visibility(self, share, snap_name, snap_qgroup, on=True):
        cur_exports = list(NFSExport.objects.all())
        # The following may be buggy when used with system mounted (fstab) /home
        # but we currently don't allow /home to be exported.
        snap_mnt_pt = "{}{}/.{}".format(settings.MNT_PT, share.name, snap_name)
        export_pt = snap_mnt_pt.replace(settings.MNT_PT, settings.NFS_EXPORT_ROOT)
        if on:
            mount_snap(share, snap_name, snap_qgroup)

            if NFSExport.objects.filter(share=share).exists():
                se = NFSExport.objects.filter(share=share)[0]
                export_group = NFSExportGroup(
                    host_str=se.export_group.host_str, nohide=True
                )
                export_group.save()
                export = NFSExport(
                    share=share, export_group=export_group, mount=export_pt
                )
                export.full_clean()
                export.save()
                cur_exports.append(export)
        else:
            for mnt in (snap_mnt_pt, export_pt):
                try:
                    export = NFSExport.objects.get(share=share, mount=mnt)
                    cur_exports.remove(export)
                    export.export_group.delete()
                    export.delete()
                except NFSExport.DoesNotExist:
                    pass
                except Exception as e:
                    logger.exception(e)
                finally:
                    umount_root(export_pt)
                    umount_root(snap_mnt_pt)
        exports = self.create_nfs_export_input(cur_exports)
        adv_entries = [x.export_str for x in AdvancedNFSExport.objects.all()]
        exports_d = self.create_adv_nfs_export_input(adv_entries, self.request)
        exports.update(exports_d)
        refresh_nfs_exports(exports)
예제 #14
0
    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)
            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)
예제 #15
0
    def _toggle_visibility(self, share, snap_name, snap_qgroup, on=True):
        cur_exports = list(NFSExport.objects.all())
        snap_mnt_pt = ('%s%s/.%s' % (settings.MNT_PT, share.name, snap_name))
        export_pt = snap_mnt_pt.replace(settings.MNT_PT,
                                        settings.NFS_EXPORT_ROOT)
        if (on):
            mount_snap(share, snap_name, snap_qgroup)

            if (NFSExport.objects.filter(share=share).exists()):
                se = NFSExport.objects.filter(share=share)[0]
                export_group = NFSExportGroup(
                    host_str=se.export_group.host_str, nohide=True)
                export_group.save()
                export = NFSExport(share=share, export_group=export_group,
                                   mount=export_pt)
                export.full_clean()
                export.save()
                cur_exports.append(export)
        else:
            for mnt in (snap_mnt_pt, export_pt):
                try:
                    export = NFSExport.objects.get(share=share, mount=mnt)
                    cur_exports.remove(export)
                    export.export_group.delete()
                    export.delete()
                except NFSExport.DoesNotExist:
                    pass
                except Exception as e:
                    logger.exception(e)
                finally:
                    umount_root(export_pt)
                    umount_root(snap_mnt_pt)
        exports = self.create_nfs_export_input(cur_exports)
        adv_entries = [x.export_str for x in AdvancedNFSExport.objects.all()]
        exports_d = self.create_adv_nfs_export_input(adv_entries, self.request)
        exports.update(exports_d)
        refresh_nfs_exports(exports)