Esempio n. 1
0
 def delete(self, request, sname):
     try:
         share = Share.objects.get(name=sname)
         if (not SambaShare.objects.filter(share=share).exists()):
             e_msg = ('Share is not exported via Samba. Nothing to delete')
             handle_exception(Exception(e_msg), request)
         samba_share = SambaShare.objects.get(share=share)
         samba_share.delete()
         refresh_smb_config(list(SambaShare.objects.all()))
         restart_samba()
         return Response()
     except RockStorAPIException:
         raise
     except Exception, e:
         handle_exception(e, request)
Esempio n. 2
0
    def delete(self, request, id):
        try:
            smbo = SambaShare.objects.get(id=id)
            smbo.delete()
        except:
            e_msg = ('Samba export for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            refresh_smb_config(list(SambaShare.objects.all()))
            restart_samba()
            return Response()
        except Exception, e:
            e_msg = ('System error occured while restarting Samba server')
            handle_exception(Exception(e_msg), request)
Esempio n. 3
0
    def delete(self, request, id):
        try:
            smbo = SambaShare.objects.get(id=id)
            smbo.delete()
        except:
            e_msg = ('Samba export for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            refresh_smb_config(list(SambaShare.objects.all()))
            restart_samba()
            return Response()
        except Exception, e:
            e_msg = ('System error occured while restarting Samba server')
            handle_exception(Exception(e_msg), request)
Esempio n. 4
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']]
        options = {
            'comment': 'samba export',
            'browsable': 'yes',
            'guest_ok': 'no',
            'read_only': 'no',
            'create_mask': '0755',
            }
        if ('comment' in request.DATA):
            options['comment'] = request.DATA['comment']
        if ('browsable' in request.DATA):
            if (request.DATA['browsable'] != 'yes' and
                request.DATA['browsable'] != 'no'):
                e_msg = ('Invalid choice for browsable. Possible '
                         'choices are yes or no.')
                handle_exception(Exception(e_msg), request)
            options['browsable'] = request.DATA['browsable']
        if ('guest_ok' in request.DATA):
            if (request.DATA['guest_ok'] != 'yes' and
                request.DATA['guest_ok'] != 'no'):
                e_msg = ('Invalid choice for guest_ok. Possible '
                         'options are yes or no.')
                handle_exception(Exception(e_msg), request)
                options['guest_ok'] = request.DATA['guest_ok']
        if ('read_only' in request.DATA):
            if (request.DATA['read_only'] != 'yes' and
                request.DATA['read_only'] != 'no'):
                e_msg = ('Invalid choice for read_only. Possible '
                         'options are yes or no.')
                handle_exception(Exception(e_msg), request)
            options['read_only'] = request.DATA['read_only']
        if ('create_mask' in request.DATA):
            if (request.DATA['create_mask'] not in self.CREATE_MASKS):
                e_msg = ('Invalid choice for create_mask. Possible '
                         'options are: %s' % self.CREATE_MASKS)
                handle_exception(Exception(e_msg), request)

        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)

        try:
            for share in shares:
                mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
                smb_share = SambaShare(share=share, path=mnt_pt,
                                       comment=options['comment'],
                                       browsable=options['browsable'],
                                       read_only=options['read_only'],
                                       guest_ok=options['guest_ok'],
                                       create_mask=options['create_mask'])
                smb_share.save()
                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)
            refresh_smb_config(list(SambaShare.objects.all()),
                               settings.SMB_CONF)
            restart_samba()
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Esempio n. 5
0
    def post(self, request, sname):
        try:
            share = Share.objects.get(name=sname)
            try:
                samba_o = SambaShare.objects.get(share=share)
                samba_serializer = SambaShareSerializer(samba_o)
                return Response(samba_serializer.data)
            except:
                options = {
                    'comment': ('samba for %s' % sname),
                    'browsable': 'yes',
                    'guest_ok': 'no',
                    'read_only': 'no',
                    'create_mask': '0755',
                    }
                if ('comment' in request.DATA):
                    options['comment'] = request.DATA['comment']
                if ('browsable' in request.DATA):
                    if (request.DATA['browsable'] != 'yes' and
                        request.DATA['browsable'] != 'no'):
                        e_msg = ('Invalid choice for browsable. Possible '
                                 'choices are yes or no.')
                        handle_exception(Exception(e_msg), request)
                    options['browsable'] = request.DATA['browsable']
                if ('guest_ok' in request.DATA):
                    if (request.DATA['guest_ok'] != 'yes' and
                        request.DATA['guest_ok'] != 'no'):
                        e_msg = ('Invalid choice for guest_ok. Possible '
                                 'options are yes or no.')
                        handle_exception(Exception(e_msg), request)
                    options['guest_ok'] = request.DATA['guest_ok']
                if ('read_only' in request.DATA):
                    if (request.DATA['read_only'] != 'yes' and
                        request.DATA['read_only'] != 'no'):
                        e_msg = ('Invalid choice for read_only. Possible '
                                 'options are yes or no.')
                        handle_exception(Exception(e_msg), request)
                if ('create_mask' in request.DATA):
                    if (request.DATA['create_mask'] not in self.CREATE_MASKS):
                        e_msg = ('Invalid choice for create_mask. Possible '
                                 'options are: %s' % self.CREATE_MASKS)
                        handle_exception(Exception(e_msg), request)

            mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
            smb_share = SambaShare(share=share, path=mnt_pt,
                                   comment=options['comment'],
                                   browsable=options['browsable'],
                                   read_only=options['read_only'],
                                   guest_ok=options['guest_ok'],
                                   create_mask=options['create_mask'])
            smb_share.save()
            if (not is_share_mounted(share.name)):
                pool_device = Disk.objects.filter(pool=share.pool)[0].name
                mount_share(share.name, pool_device, mnt_pt)
            refresh_smb_config(list(SambaShare.objects.all()),
                               settings.SMB_CONF)
            restart_samba()
            samba_serializer = SambaShareSerializer(smb_share)
            return Response(samba_serializer.data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Esempio n. 6
0
    def post(self, request, sname):
        try:
            share = Share.objects.get(name=sname)
            try:
                samba_o = SambaShare.objects.get(share=share)
                samba_serializer = SambaShareSerializer(samba_o)
                return Response(samba_serializer.data)
            except:
                options = {
                    'comment': ('samba for %s' % sname),
                    'browsable': 'yes',
                    'guest_ok': 'no',
                    'read_only': 'no',
                    'create_mask': '0755',
                    }
                if ('comment' in request.DATA):
                    options['comment'] = request.DATA['comment']
                if ('browsable' in request.DATA):
                    if (request.DATA['browsable'] != 'yes' and
                        request.DATA['browsable'] != 'no'):
                        e_msg = ('Invalid choice for browsable. Possible '
                                 'choices are yes or no.')
                        handle_exception(Exception(e_msg), request)
                    options['browsable'] = request.DATA['browsable']
                if ('guest_ok' in request.DATA):
                    if (request.DATA['guest_ok'] != 'yes' and
                        request.DATA['guest_ok'] != 'no'):
                        e_msg = ('Invalid choice for guest_ok. Possible '
                                 'options are yes or no.')
                        handle_exception(Exception(e_msg), request)
                    options['guest_ok'] = request.DATA['guest_ok']
                if ('read_only' in request.DATA):
                    if (request.DATA['read_only'] != 'yes' and
                        request.DATA['read_only'] != 'no'):
                        e_msg = ('Invalid choice for read_only. Possible '
                                 'options are yes or no.')
                        handle_exception(Exception(e_msg), request)
                    options['read_only'] = request.DATA['read_only']
                if ('create_mask' in request.DATA):
                    if (request.DATA['create_mask'] not in self.CREATE_MASKS):
                        e_msg = ('Invalid choice for create_mask. Possible '
                                 'options are: %s' % self.CREATE_MASKS)
                        handle_exception(Exception(e_msg), request)

            mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
            smb_share = SambaShare(share=share, path=mnt_pt,
                                   comment=options['comment'],
                                   browsable=options['browsable'],
                                   read_only=options['read_only'],
                                   guest_ok=options['guest_ok'],
                                   create_mask=options['create_mask'])
            smb_share.save()
            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)
            refresh_smb_config(list(SambaShare.objects.all()))
            restart_samba()
            samba_serializer = SambaShareSerializer(smb_share)
            return Response(samba_serializer.data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Esempio 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']]
        options = {
            'comment': 'samba export',
            'browsable': 'yes',
            'guest_ok': 'no',
            'read_only': 'no',
            'create_mask': '0755',
            'admin_users': 'Administrator',
        }
        if ('comment' in request.DATA):
            options['comment'] = request.DATA['comment']
        if ('browsable' in request.DATA):
            if (request.DATA['browsable'] != 'yes'
                    and request.DATA['browsable'] != 'no'):
                e_msg = ('Invalid choice for browsable. Possible '
                         'choices are yes or no.')
                handle_exception(Exception(e_msg), request)
            options['browsable'] = request.DATA['browsable']
        if ('guest_ok' in request.DATA):
            if (request.DATA['guest_ok'] != 'yes'
                    and request.DATA['guest_ok'] != 'no'):
                e_msg = ('Invalid choice for guest_ok. Possible '
                         'options are yes or no.')
                handle_exception(Exception(e_msg), request)
                options['guest_ok'] = request.DATA['guest_ok']
        if ('read_only' in request.DATA):
            if (request.DATA['read_only'] != 'yes'
                    and request.DATA['read_only'] != 'no'):
                e_msg = ('Invalid choice for read_only. Possible '
                         'options are yes or no.')
                handle_exception(Exception(e_msg), request)
            options['read_only'] = request.DATA['read_only']
        if ('create_mask' in request.DATA):
            if (request.DATA['create_mask'] not in self.CREATE_MASKS):
                e_msg = ('Invalid choice for create_mask. Possible '
                         'options are: %s' % self.CREATE_MASKS)
                handle_exception(Exception(e_msg), request)
        if ('admin_users' in request.DATA):
            options['admin_users'] = request.DATA['admin_users']

        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)

        try:
            for share in shares:
                mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
                smb_share = SambaShare(share=share,
                                       path=mnt_pt,
                                       comment=options['comment'],
                                       browsable=options['browsable'],
                                       read_only=options['read_only'],
                                       guest_ok=options['guest_ok'],
                                       create_mask=options['create_mask'],
                                       admin_users=options['admin_users'])
                smb_share.save()
                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)
            refresh_smb_config(list(SambaShare.objects.all()))
            restart_samba()
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)