Example #1
0
    def create_samba_share(self, rdata):
        if "shares" not in rdata:
            e_msg = "Must provide share names."
            handle_exception(Exception(e_msg), rdata)
        shares = [self._validate_share(rdata, s) for s in rdata["shares"]]
        options = self._validate_input(rdata)
        custom_config = options["custom_config"]
        del options["custom_config"]
        with self._handle_exception(rdata):
            for share in shares:
                if SambaShare.objects.filter(share=share).exists():
                    e_msg = (
                        "Share ({}) is already exported via Samba.").format(
                            share.name)
                    logger.error(e_msg)
                    smb_share = SambaShare.objects.get(share=share)
                    # handle_exception(Exception(e_msg), rdata)
                    continue
                mnt_pt = "{}{}".format(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 share.is_mounted:
                    mount_share(share, mnt_pt)

                admin_users = rdata.get("admin_users", [])
                if admin_users is None:
                    admin_users = []
                self._set_admin_users(admin_users, smb_share)
        return smb_share
Example #2
0
    def post(self, request):
        if ('shares' not in request.data):
            e_msg = ('Must provide share names')
            handle_exception(Exception(e_msg), request)
        shares = [
            self._validate_share(request, s) 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)):
                    mount_share(share, mnt_pt)

                admin_users = request.data.get('admin_users', [])
                if (admin_users is None): admin_users = []
                self._set_admin_users(admin_users, smb_share)
            refresh_smb_config(list(SambaShare.objects.all()))
            self._restart_samba()
            return Response(SambaShareSerializer(smb_share).data)
Example #3
0
    def post(self, request):
        if ('shares' not in request.data):
            e_msg = ('Must provide share names')
            handle_exception(Exception(e_msg), request)
        shares = [self._validate_share(request, s) 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)):
                    mount_share(share, mnt_pt)

                admin_users = request.data.get('admin_users', [])
                if (admin_users is None): admin_users = []
                self._set_admin_users(admin_users, smb_share)
            refresh_smb_config(list(SambaShare.objects.all()))
            self._restart_samba()
            return Response(SambaShareSerializer(smb_share).data)
    def post(self, request, sname):
        with self._handle_exception(request):
            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)
Example #5
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 = 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)
Example #6
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)
Example #7
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)
Example #8
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)