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)
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)
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()
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()
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()