Ejemplo n.º 1
0
    def post(self, request, sid):
        with self._handle_exception(request):
            share = Share.objects.get(id=sid)
            options = {
                "owner": "root",
                "group": "root",
                "perms": "755",
                "orecursive": True,
                "precursive": True,
            }
            options["owner"] = request.data.get("owner", options["owner"])
            options["group"] = request.data.get("group", options["group"])
            options["perms"] = request.data.get("perms", options["perms"])
            options["orecursive"] = request.data.get(
                "orecursive", options["orecursive"]
            )
            options["precursive"] = request.data.get(
                "precursive", options["precursive"]
            )
            share.owner = options["owner"]
            share.group = options["group"]
            share.perms = options["perms"]
            share.save()

            mnt_pt = "%s%s" % (settings.MNT_PT, share.name)
            force_mount = False
            if not share.is_mounted:
                mount_share(share, mnt_pt)
                force_mount = True
            chown(mnt_pt, options["owner"], options["group"], options["orecursive"])
            chmod(mnt_pt, options["perms"], options["precursive"])
            if force_mount is True:
                umount_root(mnt_pt)
            return Response(ShareSerializer(share).data)
Ejemplo n.º 2
0
    def delete(self, request, pname, command=''):
        force = True if (command == 'force') else False
        with self._handle_exception(request):
            try:
                pool = Pool.objects.get(name=pname)
            except:
                e_msg = ('Pool(%s) does not exist.' % pname)
                handle_exception(Exception(e_msg), request)

            if (pool.role == 'root'):
                e_msg = ('Deletion of Pool(%s) is not allowed as it contains '
                         'the operating system.' % pname)
                handle_exception(Exception(e_msg), request)

            if (Share.objects.filter(pool=pool).exists()):
                if not force:
                    e_msg = ('Pool(%s) is not empty. Delete is not allowed until '
                             'all shares in the pool are deleted' % (pname))
                    handle_exception(Exception(e_msg), request)
                for so in Share.objects.filter(pool=pool):
                    remove_share(so.pool, so.subvol_name, so.pqgroup, force=force)
            pool_path = ('%s%s' % (settings.MNT_PT, pname))
            umount_root(pool_path)
            pool.delete()
            try:
                self._update_disk_state()
            except Exception as e:
                logger.error('Exception while updating disk state: %s' % e.__str__())
            return Response()
Ejemplo n.º 3
0
    def delete(self, request, sname, export_id):
        try:
            share = Share.objects.get(name=sname)
            if (not NFSExport.objects.filter(id=export_id).exists()):
                e_msg = ('NFS export with id: %d does not exist' % export_id)
                handle_exception(Exception(e_msg), request)
            export = NFSExport.objects.get(id=export_id)

            if (len(NFSExport.objects.filter(share=share)) == 1):
                export_mnt_pt = ('/export/%s' % sname)
                umount_root(export_mnt_pt)
                if (is_share_mounted(sname, mnt_prefix='/export/')):
                    e_msg = ('Cannot delete nfs export with id: %d due to '
                             'busy mount. Try again later.' % export_id)
                    handle_exception(Exception(e_msg), request)

            export.enabled = False
            exports = self._create_nfs_export_input(export)
            export.delete()
            refresh_nfs_exports(exports)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 4
0
    def post(self, request, sname):
        with self._handle_exception(request):
            share = Share.objects.get(name=sname)
            options = {"owner": "root", "group": "root", "perms": "755", "orecursive": True, "precursive": True}
            options["owner"] = request.data.get("owner", options["owner"])
            options["group"] = request.data.get("group", options["group"])
            options["perms"] = request.data.get("perms", options["perms"])
            options["orecursive"] = request.data.get("orecursive", options["orecursive"])
            options["precursive"] = request.data.get("precursive", options["precursive"])
            share.owner = options["owner"]
            share.group = options["group"]
            share.perms = options["perms"]
            share.save()

            mnt_pt = "%s%s" % (settings.MNT_PT, share.name)
            force_mount = False
            if not is_share_mounted(share.name):
                pool_device = Disk.objects.filter(pool=share.pool)[0].name
                mount_share(share, pool_device, mnt_pt)
                force_mount = True
            chown(mnt_pt, options["owner"], options["group"], options["orecursive"])
            chmod(mnt_pt, options["perms"], options["precursive"])
            if force_mount is True:
                umount_root(mnt_pt)
            return Response(ShareSerializer(share).data)
Ejemplo n.º 5
0
    def delete(self, request, pname, command=''):
        force = True if (command == 'force') else False
        with self._handle_exception(request):
            try:
                pool = Pool.objects.get(name=pname)
            except:
                e_msg = ('Pool(%s) does not exist.' % pname)
                handle_exception(Exception(e_msg), request)

            if (pool.role == 'root'):
                e_msg = ('Deletion of Pool(%s) is not allowed as it contains '
                         'the operating system.' % pname)
                handle_exception(Exception(e_msg), request)

            if (Share.objects.filter(pool=pool).exists()):
                if not force:
                    e_msg = (
                        'Pool(%s) is not empty. Delete is not allowed until '
                        'all shares in the pool are deleted' % (pname))
                    handle_exception(Exception(e_msg), request)
                for so in Share.objects.filter(pool=pool):
                    remove_share(so.pool,
                                 so.subvol_name,
                                 so.pqgroup,
                                 force=force)
            pool_path = ('%s%s' % (settings.MNT_PT, pname))
            umount_root(pool_path)
            pool.delete()
            try:
                self._update_disk_state()
            except Exception as e:
                logger.error('Exception while updating disk state: %s' %
                             e.__str__())
            return Response()
Ejemplo n.º 6
0
    def delete(self, request, id):
        with self._handle_exception(request):
            try:
                sftpo = SFTP.objects.get(id=id)
            except:
                e_msg = (
                    "SFTP config for the id ({}) does not exist.").format(id)
                handle_exception(Exception(e_msg), request)

            mnt_prefix = "{}{}/".format(settings.SFTP_MNT_ROOT,
                                        sftpo.share.owner)

            if is_share_mounted(sftpo.share.name, mnt_prefix):
                sftp_snap_toggle(sftpo.share, mount=False)
                mnt_pt = "{}{}".format(mnt_prefix, sftpo.share.name)
                umount_root(mnt_pt)
                if os.path.isdir(mnt_pt):
                    shutil.rmtree(mnt_pt)
            sftpo.delete()
            input_map = {}
            for so in SFTP.objects.all():
                if so.id != sftpo.id:
                    input_map[so.share.owner] = "{}{}".format(
                        settings.SFTP_MNT_ROOT,
                        so.share.owner,
                    )
            update_sftp_config(input_map)
            return Response()
Ejemplo n.º 7
0
    def delete(self, request, pid, command=''):
        force = True if (command == 'force') else False
        with self._handle_exception(request):
            try:
                pool = Pool.objects.get(id=pid)
            except:
                e_msg = 'Pool with id ({}) does not exist.'.format(pid)
                handle_exception(Exception(e_msg), request)

            if (pool.role == 'root'):
                e_msg = ('Deletion of pool ({}) is not allowed as it contains '
                         'the operating system.').format(pool.name)
                handle_exception(Exception(e_msg), request)

            if (Share.objects.filter(pool=pool).exists()):
                if not force:
                    e_msg = ('Pool ({}) is not empty. Delete is not allowed '
                             'until all shares in the pool '
                             'are deleted.').format(pool.name)
                    handle_exception(Exception(e_msg), request)
                for so in Share.objects.filter(pool=pool):
                    remove_share(so.pool, so.subvol_name, so.pqgroup,
                                 force=force)
            pool_path = ('%s%s' % (settings.MNT_PT, pool.name))
            umount_root(pool_path)
            pool.delete()
            try:
                # TODO: this call fails as the inheritance of disks was removed
                # We need another method to invoke this as self no good now.
                self._update_disk_state()
            except Exception as e:
                logger.error(('Exception while updating disk state: '
                             '({}).').format(e.__str__()))
            return Response()
Ejemplo n.º 8
0
    def delete(self, request, pname):
        with self._handle_exception(request):
            try:
                pool = Pool.objects.get(name=pname)
            except:
                e_msg = ('Pool(%s) does not exist.' % pname)
                handle_exception(Exception(e_msg), request)

            if (pool.role == 'root'):
                e_msg = ('Deletion of Pool(%s) is not allowed as it contains '
                         'the operating system.' % pname)
                handle_exception(Exception(e_msg), request)

            if (Share.objects.filter(pool=pool).exists()):
                e_msg = ('Pool(%s) is not empty. Delete is not allowed until '
                         'all shares in the pool are deleted' % (pname))
                handle_exception(Exception(e_msg), request)
            pool_path = ('%s%s' % (settings.MNT_PT, pname))
            umount_root(pool_path)
            pool.delete()
            try:
                self._update_disk_state()
            except Exception, e:
                logger.error('Exception while updating disk state: %s' %
                             e.__str__())
            return Response()
Ejemplo n.º 9
0
    def post(self, request, sname):
        with self._handle_exception(request):
            share = Share.objects.get(name=sname)
            options = {
                'owner': 'root',
                'group': 'root',
                'perms': '755',
                'orecursive': True,
                'precursive': True,
                }
            options['owner'] = request.data.get('owner', options['owner'])
            options['group'] = request.data.get('group', options['group'])
            options['perms'] = request.data.get('perms', options['perms'])
            options['orecursive'] = request.data.get('orecursive',
                                                     options['orecursive'])
            options['precursive'] = request.data.get('precursive',
                                                     options['precursive'])
            share.owner = options['owner']
            share.group = options['group']
            share.perms = options['perms']
            share.save()

            mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
            force_mount = False
            if (not is_share_mounted(share.name)):
                mount_share(share, mnt_pt)
                force_mount = True
            chown(mnt_pt, options['owner'], options['group'],
                  options['orecursive'])
            chmod(mnt_pt, options['perms'], options['precursive'])
            if (force_mount is True):
                umount_root(mnt_pt)
            return Response(ShareSerializer(share).data)
Ejemplo n.º 10
0
    def delete(self, request, id):
        try:
            sftpo = SFTP.objects.get(id=id)
        except:
            e_msg = ('SFTP config for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            mnt_prefix = ('%s%s/' % (settings.SFTP_MNT_ROOT,
                                     sftpo.share.owner))

            if (is_share_mounted(sftpo.share.name, mnt_prefix)):
                sftp_snap_toggle(sftpo.share, mount=False)
                umount_root(('%s%s' % (mnt_prefix, sftpo.share.name)))
                import shutil
                shutil.rmtree(mnt_prefix)
            sftpo.delete()
            input_list = []
            for so in SFTP.objects.all():
                if (so.id != sftpo.id):
                    input_list.append({'user': so.share.owner,
                                       'dir': ('%s%s' %
                                               (settings.SFTP_MNT_ROOT,
                                                so.share.name)), })
            update_sftp_config(input_list)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 11
0
    def delete(self, request, id):
        try:
            sftpo = SFTP.objects.get(id=id)
        except:
            e_msg = ('SFTP config for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            mnt_prefix = ('%s%s/' %
                          (settings.SFTP_MNT_ROOT, sftpo.share.owner))

            if (is_share_mounted(sftpo.share.name, mnt_prefix)):
                sftp_snap_toggle(sftpo.share, mount=False)
                umount_root(('%s%s' % (mnt_prefix, sftpo.share.name)))
                import shutil
                shutil.rmtree(mnt_prefix)
            sftpo.delete()
            input_list = []
            for so in SFTP.objects.all():
                if (so.id != sftpo.id):
                    input_list.append({
                        'user':
                        so.share.owner,
                        'dir':
                        ('%s%s' % (settings.SFTP_MNT_ROOT, so.share.name)),
                    })
            update_sftp_config(input_list)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 12
0
    def delete(self, request, id):
        try:
            sftpo = SFTP.objects.get(id=id)
        except:
            e_msg = ('SFTP config for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            mnt_prefix = ('%s%s/' % (settings.SFTP_MNT_ROOT,
                                     sftpo.share.owner))

            if (is_share_mounted(sftpo.share.name, mnt_prefix)):
                sftp_snap_toggle(sftpo.share, mount=False)
                mnt_pt = ('%s%s' % (mnt_prefix, sftpo.share.name))
                umount_root(mnt_pt)
                if (os.path.isdir(mnt_pt)):
                    shutil.rmtree(mnt_pt)
            sftpo.delete()
            input_map = {}
            for so in SFTP.objects.all():
                if (so.id != sftpo.id):
                    input_map[so.share.owner] = (
                        '%s%s' % (settings.SFTP_MNT_ROOT, so.share.owner))
            update_sftp_config(input_map)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 13
0
    def delete(self, request, sname, export_id):
        try:
            share = Share.objects.get(name=sname)
            if (not NFSExport.objects.filter(id=export_id).exists()):
                e_msg = ('NFS export with id: %d does not exist' % export_id)
                handle_exception(Exception(e_msg), request)
            export = NFSExport.objects.get(id=export_id)

            if (len(NFSExport.objects.filter(share=share)) == 1):
                export_mnt_pt = ('/export/%s' % sname)
                umount_root(export_mnt_pt)
                if (is_share_mounted(sname, mnt_prefix='/export/')):
                    e_msg = ('Cannot delete nfs export with id: %d due to '
                             'busy mount. Try again later.' % export_id)
                    handle_exception(Exception(e_msg), request)

            export.enabled = False
            exports = self._create_nfs_export_input(export)
            export.delete()
            refresh_nfs_exports(exports)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 14
0
    def delete(self, request, pname):
        with self._handle_exception(request):
            try:
                pool = Pool.objects.get(name=pname)
            except:
                e_msg = ('Pool(%s) does not exist.' % pname)
                handle_exception(Exception(e_msg), request)

            if (pool.role == 'root'):
                e_msg = ('Deletion of Pool(%s) is not allowed as it contains '
                         'the operating system.' % pname)
                handle_exception(Exception(e_msg), request)

            if (Share.objects.filter(pool=pool).exists()):
                e_msg = ('Pool(%s) is not empty. Delete is not allowed until '
                         'all shares in the pool are deleted' % (pname))
                handle_exception(Exception(e_msg), request)
            pool_path = ('%s%s' % (settings.MNT_PT, pname))
            umount_root(pool_path)
            pool.delete()
            try:
                self._update_disk_state()
            except Exception, e:
                logger.error('Exception while updating disk state: %s' % e.__str__())
            return Response()
Ejemplo n.º 15
0
    def post(self, request, sname):
        with self._handle_exception(request):
            share = Share.objects.get(name=sname)
            options = {
                'owner': 'root',
                'group': 'root',
                'perms': '755',
                'orecursive': True,
                'precursive': True,
            }
            options['owner'] = request.data.get('owner', options['owner'])
            options['group'] = request.data.get('group', options['group'])
            options['perms'] = request.data.get('perms', options['perms'])
            options['orecursive'] = request.data.get('orecursive',
                                                     options['orecursive'])
            options['precursive'] = request.data.get('precursive',
                                                     options['precursive'])
            share.owner = options['owner']
            share.group = options['group']
            share.perms = options['perms']
            share.save()

            mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
            force_mount = False
            if (not is_share_mounted(share.name)):
                pool_device = Disk.objects.filter(pool=share.pool)[0].name
                mount_share(share, pool_device, mnt_pt)
                force_mount = True
            chown(mnt_pt, options['owner'], options['group'],
                  options['orecursive'])
            chmod(mnt_pt, options['perms'], options['precursive'])
            if (force_mount is True):
                umount_root(mnt_pt)
            return Response(ShareSerializer(share).data)
Ejemplo n.º 16
0
    def delete(self, request, id):
        try:
            sftpo = SFTP.objects.get(id=id)
        except:
            e_msg = ('SFTP config for the id(%s) does not exist' % id)
            handle_exception(Exception(e_msg), request)

        try:
            mnt_prefix = ('%s%s/' %
                          (settings.SFTP_MNT_ROOT, sftpo.share.owner))

            if (is_share_mounted(sftpo.share.name, mnt_prefix)):
                sftp_snap_toggle(sftpo.share, mount=False)
                mnt_pt = ('%s%s' % (mnt_prefix, sftpo.share.name))
                umount_root(mnt_pt)
                if (os.path.isdir(mnt_pt)):
                    shutil.rmtree(mnt_pt)
            sftpo.delete()
            input_map = {}
            for so in SFTP.objects.all():
                if (so.id != sftpo.id):
                    input_map[so.share.owner] = (
                        '%s%s' % (settings.SFTP_MNT_ROOT, so.share.owner))
            update_sftp_config(input_map)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 17
0
def sftp_snap_toggle(share, mount=True):
    for snap in Snapshot.objects.filter(share=share, uvisible=True):
        mnt_pt = "{}/{}/{}/.{}".format(settings.SFTP_MNT_ROOT, share.owner,
                                       share.name, snap.name)
        if mount and not is_mounted(mnt_pt):
            mount_snap(share, snap.name, snap.qgroup, mnt_pt)
        elif is_mounted(mnt_pt) and not mount:
            umount_root(mnt_pt)
Ejemplo n.º 18
0
def sftp_snap_toggle(share, mount=True):
    for snap in Snapshot.objects.filter(share=share, uvisible=True):
        mnt_pt = ('%s/%s/%s/.%s' %
                  (settings.SFTP_MNT_ROOT, share.owner, share.name, snap.name))
        if (mount and not is_mounted(mnt_pt)):
            mount_snap(share, snap.name, mnt_pt)
        elif (is_mounted(mnt_pt) and not mount):
            umount_root(mnt_pt)
Ejemplo n.º 19
0
def sftp_snap_toggle(share, mount=True):
    for snap in Snapshot.objects.filter(share=share, uvisible=True):
        mnt_pt = ('%s/%s/%s/.%s' % (settings.SFTP_MNT_ROOT,
                                    share.owner, share.name,
                                    snap.name))
        if (mount and not is_mounted(mnt_pt)):
            mount_snap(share, snap.name, mnt_pt)
        elif (is_mounted(mnt_pt) and not mount):
            umount_root(mnt_pt)
Ejemplo n.º 20
0
def sftp_snap_toggle(share, mount=True):
    pool_device = Disk.objects.filter(pool=share.pool)[0].name
    for snap in Snapshot.objects.filter(share=share, uvisible=True):
        mnt_pt = ('%s/%s/%s/.%s' % (settings.SFTP_MNT_ROOT,
                                    share.owner, share.name,
                                    snap.name))
        if (mount and not is_mounted(mnt_pt)):
            mount_share(snap.real_name, pool_device, mnt_pt)
        elif (is_mounted(mnt_pt) and not mount):
            umount_root(mnt_pt)
Ejemplo n.º 21
0
def toggle_sftp_visibility(share, snap_name, on=True):
    if (not SFTP.objects.filter(share=share).exists()):
        return

    mnt_pt = ('%s/%s/%s/.%s' %
              (settings.SFTP_MNT_ROOT, share.owner, share.name, snap_name))
    if (on):
        if (not is_mounted(mnt_pt)):
            mount_snap(share, snap_name, mnt_pt)
    else:
        umount_root(mnt_pt)
Ejemplo n.º 22
0
 def delete(self, request, pname):
     with self._handle_exception(request):
         pool = Pool.objects.get(name=pname)
         if (Share.objects.filter(pool=pool).exists()):
             e_msg = ('Pool: %s is not empty. Cannot delete until all '
                      'shares in the pool are deleted' % (pname))
             handle_exception(Exception(e_msg), request)
         pool_path = ('%s%s' % (settings.MNT_PT, pname))
         umount_root(pool_path)
         pool.delete()
         return Response()
Ejemplo n.º 23
0
def toggle_sftp_visibility(share, snap_name, on=True):
    if (not SFTP.objects.filter(share=share).exists()):
        return

    mnt_pt = ('%s/%s/%s/.%s' % (settings.SFTP_MNT_ROOT, share.owner,
                                share.name, snap_name))
    if (on):
        if (not is_mounted(mnt_pt)):
            mount_snap(share, snap_name, mnt_pt)
    else:
        umount_root(mnt_pt)
Ejemplo n.º 24
0
def toggle_sftp_visibility(share, snap_name, snap_qgroup, on=True):
    if not SFTP.objects.filter(share=share).exists():
        return

    mnt_pt = "{}/{}/{}/.{}".format(settings.SFTP_MNT_ROOT, share.owner,
                                   share.name, snap_name)
    if on:
        if not is_mounted(mnt_pt):
            mount_snap(share, snap_name, snap_qgroup, mnt_pt)
    else:
        umount_root(mnt_pt)
Ejemplo n.º 25
0
def toggle_sftp_visibility(share, snap_name, on=True):
    if (not SFTP.objects.filter(share=share).exists()):
        return

    snap_short_name = snap_name.split(share.name)[-1][1:]
    mnt_pt = ('%s/%s/%s/.%s' % (settings.SFTP_MNT_ROOT, share.owner,
                                share.name, snap_short_name))
    if (on):
        if (not is_mounted(mnt_pt)):
            pool_device = Disk.objects.filter(pool=share.pool)[0].name
            mount_share(snap_name, pool_device, mnt_pt)
    else:
        umount_root(mnt_pt)
Ejemplo n.º 26
0
 def delete(self, request, pname):
     try:
         pool = Pool.objects.get(name=pname)
         if (Share.objects.filter(pool=pool).exists()):
             e_msg = ('Pool: %s is not empty. Cannot delete until all '
                      'shares in the pool are deleted' % (pname))
             handle_exception(Exception(e_msg), request)
         umount_root('%s%s' % (settings.MNT_PT, pname))
         remove_pool(pname)
         pool.delete()
         return Response()
     except RockStorAPIException:
         raise
     except Exception, e:
         handle_exception(e, request)
Ejemplo n.º 27
0
 def delete(self, request, pname):
     try:
         pool = Pool.objects.get(name=pname)
         if (Share.objects.filter(pool=pool).exists()):
             e_msg = ('Pool: %s is not empty. Cannot delete until all '
                      'shares in the pool are deleted' % (pname))
             handle_exception(Exception(e_msg), request)
         umount_root('%s%s' % (settings.MNT_PT, pname))
         remove_pool(pname)
         pool.delete()
         return Response()
     except RockStorAPIException:
         raise
     except Exception, e:
         handle_exception(e, request)
Ejemplo n.º 28
0
    def post(self, request, sname):
        try:
            share = Share.objects.get(name=sname)
            options = {
                'owner': 'root',
                'group': 'root',
                'perms': '755',
                'orecursive': False,
                'precursive': False,
            }
            if ('owner' in request.DATA):
                options['owner'] = request.DATA['owner']
            if ('group' in request.DATA):
                options['group'] = request.DATA['group']
            else:
                options['group'] = options['owner']
            if ('orecursive' in request.DATA):
                options['orecursive'] = True
            if ('perms' in request.DATA):
                options['perms'] = request.DATA['perms']
            if ('precursive' in request.DATA):
                options['precursive'] = True

            share.owner = options['owner']
            share.group = options['group']
            share.perms = options['perms']
            share.save()

            mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
            force_mount = False
            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)
                force_mount = True
            chown(mnt_pt, options['owner'], options['group'],
                  options['orecursive'])
            chmod(mnt_pt, options['perms'], options['precursive'])
            if (force_mount is True):
                umount_root(mnt_pt)
            return Response(ShareSerializer(share).data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 29
0
    def post(self, request, sname):
        try:
            share = Share.objects.get(name=sname)
            options = {
                'owner': 'root',
                'group': 'root',
                'perms': '755',
                'orecursive': False,
                'precursive': False,
                }
            if ('owner' in request.DATA):
                options['owner'] = request.DATA['owner']
            if ('group' in request.DATA):
                options['group'] = request.DATA['group']
            else:
                options['group'] = options['owner']
            if ('orecursive' in request.DATA):
                options['orecursive'] = True
            if ('perms' in request.DATA):
                options['perms'] = request.DATA['perms']
            if ('precursive' in request.DATA):
                options['precursive'] = True

            share.owner = options['owner']
            share.group = options['group']
            share.perms = options['perms']
            share.save()

            mnt_pt = ('%s%s' % (settings.MNT_PT, share.name))
            force_mount = False
            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)
                force_mount = True
            chown(mnt_pt, options['owner'], options['group'],
                  options['orecursive'])
            chmod(mnt_pt, options['perms'], options['precursive'])
            if (force_mount is True):
                umount_root(mnt_pt)
            return Response(ShareSerializer(share).data)
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 30
0
 def delete(self, request, pname):
     with self._handle_exception(request):
         if (pname == settings.ROOT_POOL):
             e_msg = ('Deletion of Pool(%s) is not allowed as it contains '
                      'the operating system.' % pname)
             handle_exception(Exception(e_msg), request)
         try:
             pool = Pool.objects.get(name=pname)
         except:
             e_msg = ('Pool(%s) does not exist.' % pname)
             handle_exception(Exception(e_msg), request)
         if (Share.objects.filter(pool=pool).exists()):
             e_msg = ('Pool(%s) is not empty. Delete is not allowed until '
                      'all shares in the pool are deleted' % (pname))
             handle_exception(Exception(e_msg), request)
         pool_path = ('%s%s' % (settings.MNT_PT, pname))
         umount_root(pool_path)
         pool.delete()
         return Response()
Ejemplo n.º 31
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)
         if (not NFSExport.objects.filter(share=share).exists() and
             is_share_mounted(share.name)):
             umount_root(samba_share.path)
         samba_share.delete()
         refresh_smb_config(list(SambaShare.objects.all()),
                            settings.SMB_CONF)
         restart_samba()
         return Response()
     except RockStorAPIException:
         raise
     except Exception, e:
         handle_exception(e, request)
Ejemplo n.º 32
0
 def delete(self, request, pname):
     with self._handle_exception(request):
         if (pname == settings.ROOT_POOL):
             e_msg = ('Deletion of Pool(%s) is not allowed as it contains '
                      'the operating system.' % pname)
             handle_exception(Exception(e_msg), request)
         try:
             pool = Pool.objects.get(name=pname)
         except:
             e_msg = ('Pool(%s) does not exist.' % pname)
             handle_exception(Exception(e_msg), request)
         if (Share.objects.filter(pool=pool).exists()):
             e_msg = ('Pool(%s) is not empty. Delete is not allowed until '
                      'all shares in the pool are deleted' % (pname))
             handle_exception(Exception(e_msg), request)
         pool_path = ('%s%s' % (settings.MNT_PT, pname))
         umount_root(pool_path)
         pool.delete()
         return Response()
Ejemplo n.º 33
0
    def delete(self, request, sname, export_id):
        try:
            share = Share.objects.get(name=sname)
            if (not NFSExport.objects.filter(id=export_id).exists()):
                e_msg = ('NFS export with id: %d does not exist' % export_id)
                handle_exception(Exception(e_msg), request)
            export = NFSExport.objects.get(id=export_id)

            if (is_share_mounted(share.name) and
                not SambaShare.objects.filter(share=share).exists() and
                not len(NFSExport.objects.filter(share=share)) > 1):
                umount_root(export.mount)
            export.enabled = False
            exports = self._create_nfs_export_input(export)
            export.delete()
            refresh_nfs_exports(exports)
            return Response()
        except RockStorAPIException:
            raise
        except Exception, e:
            handle_exception(e, request)
Ejemplo n.º 34
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)
Ejemplo n.º 35
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 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)
Ejemplo n.º 36
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)
Ejemplo n.º 37
0
    def delete(self, request, pid, command=""):
        force = True if (command == "force") else False
        with self._handle_exception(request):
            try:
                pool = Pool.objects.get(id=pid)
            except:
                e_msg = "Pool with id ({}) does not exist.".format(pid)
                handle_exception(Exception(e_msg), request)

            if pool.role == "root":
                e_msg = ("Deletion of pool ({}) is not allowed as it contains "
                         "the operating system.").format(pool.name)
                handle_exception(Exception(e_msg), request)

            if Share.objects.filter(pool=pool).exists():
                if not force:
                    e_msg = ("Pool ({}) is not empty. Delete is not allowed "
                             "until all shares in the pool "
                             "are deleted.").format(pool.name)
                    handle_exception(Exception(e_msg), request)
                for so in Share.objects.filter(pool=pool):
                    remove_share(so.pool,
                                 so.subvol_name,
                                 so.pqgroup,
                                 force=force)
            pool_path = "{}{}".format(settings.MNT_PT, pool.name)
            umount_root(pool_path)
            pool.delete()
            try:
                # TODO: this call fails as the inheritance of disks was removed
                # We need another method to invoke this as self no good now.
                self._update_disk_state()
            except Exception as e:
                logger.error(
                    ("Exception while updating disk state: ({}).").format(
                        e.__str__()))
            return Response()
Ejemplo n.º 38
0
    def delete(self, request, pid, command=''):
        force = True if (command == 'force') else False
        with self._handle_exception(request):
            try:
                pool = Pool.objects.get(id=pid)
            except:
                e_msg = ('Pool(%d) does not exist.' % pid)
                handle_exception(Exception(e_msg), request)

            if (pool.role == 'root'):
                e_msg = ('Deletion of Pool(%d) is not allowed as it contains '
                         'the operating system.' % pid)
                handle_exception(Exception(e_msg), request)

            if (Share.objects.filter(pool=pool).exists()):
                if not force:
                    e_msg = ('Pool(%d) is not empty. Delete is not allowed '
                             'until '
                             'all shares in the pool are deleted' % (pid))
                    handle_exception(Exception(e_msg), request)
                for so in Share.objects.filter(pool=pool):
                    remove_share(so.pool,
                                 so.subvol_name,
                                 so.pqgroup,
                                 force=force)
            pool_path = ('%s%s' % (settings.MNT_PT, pool.name))
            umount_root(pool_path)
            pool.delete()
            try:
                # TODO: this call fails as the inheritance of disks was removed
                # We need another method to invoke this as self no good now.
                self._update_disk_state()
            except Exception as e:
                logger.error('Exception while updating disk state: %s' %
                             e.__str__())
            return Response()
Ejemplo n.º 39
0
def btrfs_rem_pool(pname):
    pool_path = ('%s%s' % (MNT_PT, pname))
    umount_root(pool_path)
    return "over"
Ejemplo n.º 40
0
                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:
                umount_root(export_pt)
                umount_root(snap_mnt_pt)
        exports = create_nfs_export_input(cur_exports)
        adv_entries = [x.export_str for x in AdvancedNFSExport.objects.all()]
        exports_d = create_adv_nfs_export_input(adv_entries, self.request)
        exports.update(exports_d)
        refresh_nfs_exports(exports)

    @transaction.commit_on_success
    def _create(self, share, snap_name, pool_device, request, uvisible,
                snap_type):
        if (Snapshot.objects.filter(share=share, name=snap_name).exists()):
            e_msg = ('Snapshot with name: %s already exists for the '
                     'share: %s' % (snap_name, share.name))
            handle_exception(Exception(e_msg), request)
Ejemplo n.º 41
0
class SnapshotView(rfc.GenericView):
    serializer_class = SnapshotSerializer

    def get_queryset(self, *args, **kwargs):
        with self._handle_exception(self.request):
            try:
                share = Share.objects.get(name=self.kwargs['sname'])
            except:
                if ('sname' not in self.kwargs):
                    for s in Share.objects.all():
                        self._refresh_snapshots_state(s)
                    return Snapshot.objects.filter().order_by('-id')

                e_msg = ('Share with name: %s does not exist' %
                         self.kwargs['sname'])
                handle_exception(Exception(e_msg), self.request)

            if ('snap_name' in self.kwargs):
                self.paginate_by = 0
                try:
                    return Snapshot.objects.get(share=share,
                                                name=self.kwargs['snap_name'])
                except:
                    return []

            self._refresh_snapshots_state(share)
            snap_type = self.request.query_params.get('snap_type', None)
            if (snap_type is not None and snap_type != ''):
                return Snapshot.objects.filter(
                    share=share, snap_type=snap_type).order_by('-id')

            return Snapshot.objects.filter(share=share).order_by('-id')

    @transaction.atomic
    def _refresh_snapshots_state(self, share):
        snaps_d = snaps_info('%s%s' % (settings.MNT_PT, share.pool.name),
                             share.name)
        disk = Disk.objects.filter(pool=share.pool)[0].name
        snaps = [s.name for s in Snapshot.objects.filter(share=share)]
        for s in snaps:
            if (s not in snaps_d):
                Snapshot.objects.get(share=share, name=s).delete()
        for s in snaps_d:
            if (s in snaps):
                so = Snapshot.objects.get(share=share, name=s)
            else:
                so = Snapshot(share=share,
                              name=s,
                              real_name=s,
                              writable=snaps_d[s][1],
                              qgroup=snaps_d[s][0])
            rusage, eusage = share_usage(share.pool, disk, snaps_d[s][0])
            ts = datetime.utcnow().replace(tzinfo=utc)
            if (rusage != so.rusage or eusage != so.eusage):
                so.rusage = rusage
                so.eusage = eusage
                su = ShareUsage(name=s, r_usage=rusage, e_usage=eusage, ts=ts)
                su.save()
            else:
                try:
                    su = ShareUsage.objects.filter(name=s).latest('id')
                    su.ts = ts
                    su.count += 1
                except ShareUsage.DoesNotExist:
                    su = ShareUsage(name=s,
                                    r_usage=rusage,
                                    e_usage=eusage,
                                    ts=ts)
                finally:
                    su.save()
            so.save()

    @transaction.atomic
    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):
            pool_device = Disk.objects.filter(pool=share.pool)[0].name
            mount_snap(share, snap_name, pool_device)

            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)
                    umount_root(snap_mnt_pt)
Ejemplo n.º 42
0
                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:
                umount_root(export_pt)
                umount_root(snap_mnt_pt)
        exports = create_nfs_export_input(cur_exports)
        adv_entries = [x.export_str for x in AdvancedNFSExport.objects.all()]
        exports_d = create_adv_nfs_export_input(adv_entries, self.request)
        exports.update(exports_d)
        refresh_nfs_exports(exports)

    @transaction.atomic
    def _create(self, share, snap_name, pool_device, request, uvisible,
                snap_type, writable):
        if (Snapshot.objects.filter(share=share, name=snap_name).exists()):
            e_msg = ('Snapshot(%s) already exists for the Share(%s).' %
                     (snap_name, share.name))
            handle_exception(Exception(e_msg), request)
Ejemplo n.º 43
0
def btrfs_rem_pool(pname):
	pool_path = ('%s%s' % (MNT_PT, pname))
	umount_root(pool_path)
	return "over"
Ejemplo n.º 44
0
    def post(self, request, uuid):
        """
        import a pool with given uuid
        """
        disks = Disk.objects.filter(btrfs_uuid=uuid)

        if (not btrfs_importable(disks[0].name)):
            e_msg = ('btrfs check failed on device: %s Cannot automatically '
                     'import the pool with uuid: %s' % (disks[0].name, uuid))
            handle_exception(Exception(e_msg), request)


        #get name of the pool
        pname = btrfs_label(uuid)

        #mount the pool
        mount_root(pname, '/dev/%s' % disks[0].name)
        pool_mnt_pt = '%s/%s' % (settings.MNT_PT, pname)

        #get raid level
        raid_level = btrfs_raid_level(pname)
        if (raid_level is None):
            umount_root(pool_mnt_pt)
            e_msg = ('Problem while probing for the raid level of the pool.'
                     'Cannot automatically import the pool with uuid: %s' %
                     uuid)
            handle_exception(Exception(e_msg), request)

        #check for shares in the pool
        subvols, e, rc = subvol_list_helper(pool_mnt_pt)
        snap_list = snapshot_list(pool_mnt_pt)
        share_map = {}
        for s in subvols:
            s_fields = s.split()
            if (s_fields[-1] not in snap_list):
                share_map[s_fields[-1]] = s_fields[1]

        entries = os.listdir(pool_mnt_pt)
        e_msg_prefix = ('Only btrfs filesystem with nothing but subvolumes in '
                        'it can be imported.')
        for e in entries:
            if (os.path.isfile('%s/%s' % (pool_mnt_pt, e))):
                e_msg = ('%s Unexpected file %s found. Due to this reason, '
                         'pool with uuid: %s cannot be imported' %
                         (e_msg_prefix, e, uuid))
                handle_exception(Exception(e_msg), request)
            elif (e not in share_map):
                e_msg = ('%s Unexpected directory %s found. Due to this '
                         'reason, pool with uuid: %s cannot be imported' %
                         (e_msg_prefix, e, uuid))
                handle_exception(Exception(e_msg), request)

        #add pool model
        pool_size = self._pool_size(disks, raid_level)
        p = Pool(name=pname, raid=raid_level, size=pool_size, uuid=uuid)
        p.save()

        #import shares
        for s in share_map.keys():
            so = Share(pool=p, qgroup='0/%s' % share_map[s], name=s,
                       size=qgroup_size, subvol_name=s, replica=False)
            so.save()

            #import snapshots?
            for snap in snap_list:
                snap_fields = snap.split('_')
                snap_name = snap_fields[-1]
                sname = '_'.join(snap_fields[0:-1])
                if (sname == s):
                    snapo = Snapshot(share=so, name=snap_name,
                                     real_name=snap, qgroup=qgroup_id)
                    snapo.save()
Ejemplo n.º 45
0
class SnapshotView(NFSExportMixin, rfc.GenericView):
    serializer_class = SnapshotSerializer

    def get_queryset(self, *args, **kwargs):
        with self._handle_exception(self.request):
            try:
                share = Share.objects.get(name=self.kwargs['sname'])
            except:
                if ('sname' not in self.kwargs):
                    return Snapshot.objects.filter().order_by('-id')

                e_msg = ('Share with name: %s does not exist' %
                         self.kwargs['sname'])
                handle_exception(Exception(e_msg), self.request)

            if ('snap_name' in self.kwargs):
                self.paginate_by = 0
                try:
                    return Snapshot.objects.get(share=share,
                                                name=self.kwargs['snap_name'])
                except:
                    return []

            snap_type = self.request.query_params.get('snap_type', None)
            if (snap_type is not None and snap_type != ''):
                return Snapshot.objects.filter(
                    share=share, snap_type=snap_type).order_by('-id')

            return Snapshot.objects.filter(share=share).order_by('-id')

    @transaction.atomic
    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)
                    umount_root(snap_mnt_pt)
Ejemplo n.º 46
0
    def post(self, request, uuid):
        """
        import a pool with given uuid
        """
        disks = Disk.objects.filter(btrfs_uuid=uuid)

        if (not btrfs_importable(disks[0].name)):
            e_msg = ('btrfs check failed on device: %s Cannot automatically '
                     'import the pool with uuid: %s' % (disks[0].name, uuid))
            handle_exception(Exception(e_msg), request)

        #get name of the pool
        pname = btrfs_label(uuid)

        #mount the pool
        mount_root(pname, '/dev/%s' % disks[0].name)
        pool_mnt_pt = '%s/%s' % (settings.MNT_PT, pname)

        #get raid level
        raid_level = btrfs_raid_level(pname)
        if (raid_level is None):
            umount_root(pool_mnt_pt)
            e_msg = ('Problem while probing for the raid level of the pool.'
                     'Cannot automatically import the pool with uuid: %s' %
                     uuid)
            handle_exception(Exception(e_msg), request)

        #check for shares in the pool
        subvols, e, rc = subvol_list_helper(pool_mnt_pt)
        snap_list = snapshot_list(pool_mnt_pt)
        share_map = {}
        for s in subvols:
            s_fields = s.split()
            if (s_fields[-1] not in snap_list):
                share_map[s_fields[-1]] = s_fields[1]

        entries = os.listdir(pool_mnt_pt)
        e_msg_prefix = ('Only btrfs filesystem with nothing but subvolumes in '
                        'it can be imported.')
        for e in entries:
            if (os.path.isfile('%s/%s' % (pool_mnt_pt, e))):
                e_msg = ('%s Unexpected file %s found. Due to this reason, '
                         'pool with uuid: %s cannot be imported' %
                         (e_msg_prefix, e, uuid))
                handle_exception(Exception(e_msg), request)
            elif (e not in share_map):
                e_msg = ('%s Unexpected directory %s found. Due to this '
                         'reason, pool with uuid: %s cannot be imported' %
                         (e_msg_prefix, e, uuid))
                handle_exception(Exception(e_msg), request)

        #add pool model
        pool_size = self._pool_size(disks, raid_level)
        p = Pool(name=pname, raid=raid_level, size=pool_size, uuid=uuid)
        p.save()

        #import shares
        for s in share_map.keys():
            so = Share(pool=p,
                       qgroup='0/%s' % share_map[s],
                       name=s,
                       size=qgroup_size,
                       subvol_name=s,
                       replica=False)
            so.save()

            #import snapshots?
            for snap in snap_list:
                snap_fields = snap.split('_')
                snap_name = snap_fields[-1]
                sname = '_'.join(snap_fields[0:-1])
                if (sname == s):
                    snapo = Snapshot(share=so,
                                     name=snap_name,
                                     real_name=snap,
                                     qgroup=qgroup_id)
                    snapo.save()