def _toggle_visibility(self, share, snap_name, on=True): for se in NFSExport.objects.filter(share=share): snap_realname = ('%s_%s' % (share.name, snap_name)) mnt_pt = ('%s%s/%s' % (settings.MNT_PT, share.pool.name, snap_realname)) export_pt = mnt_pt.replace(settings.MNT_PT, settings.NFS_EXPORT_ROOT) export = None if (on): if (not NFSExport.objects.filter(share=share, nohide=False)): #master share is not exported, so don't export the snap continue export = NFSExport(share=share, mount=export_pt, host_str=se.host_str, nohide=True) export.full_clean() export.save() else: try: export = NFSExport.objects.get(share=share, host_str=se.host_str, mount=export_pt, nohide=True) export.enabled = False except Exception, e: logger.exception(e) continue exports = create_nfs_export_input(export) refresh_nfs_exports(exports) if (not on): export.delete()
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:
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)
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)
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
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)
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)
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)
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)
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)
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)
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)
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)
def post(self, request, sname): try: share = Share.objects.get(name=sname) options = { 'host_str': '*', 'mod_choice': 'ro', 'sync_choice': 'async', 'security': 'insecure', 'id': -1, } if ('host_str' in request.DATA): options['host_str'] = request.DATA['host_str'] if ('mod_choice' in request.DATA): options['mod_choice'] = request.DATA['mod_choice'] if ('sync_choice' in request.DATA): options['sync_choice'] = request.DATA['sync_choice'] mnt_pt = ('%s%s' % (settings.MNT_PT, 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(share=share, mount=mnt_pt, host_str=options['host_str'], editable=options['mod_choice'], syncable=options['sync_choice'], mount_security=options['security']) export.full_clean() export.save() exports = self._create_nfs_export_input(export) refresh_nfs_exports(exports) nfs_serializer = NFSExportSerializer(export) return Response(nfs_serializer.data) except RockStorAPIException: raise except Exception, e: handle_exception(e, request)
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)
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)