示例#1
0
def update_nfs_share(request):
    return_dict = {}
    try:
        if request.method == "GET":
            # Return the conf page
            path = request.GET["path"]
            d, err = nfs.get_share(path)
            if err:
                raise Exception(err)
            if not d:
                raise Exception(
                    'Could not find the specified share. Please use the menus.')
            initial = {}
            initial['path'] = d['path']
            if 'clients' in d:
                client_list = []
                for client in d['clients']:
                    client_list.append(client['name'])
                initial['clients'] = ','.join(client_list)
            initial['readonly'] = False
            initial['root_squash'] = False
            initial['all_squash'] = False
            if 'options' in d:
                for option in d['options']:
                    if option == 'ro':
                        initial['readonly'] = True
                    elif option == 'root_squash':
                        initial['root_squash'] = True
                    elif option == 'all_squash':
                        initial['all_squash'] = True
            form = nfs_shares_forms.ShareForm(initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("update_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = nfs_shares_forms.ShareForm(request.POST)
            path = request.POST["path"]
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("update_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            result, err = nfs.save_share(cd)
            if err:
                raise Exception(err)

            audit_str = "Edited NFS share %s" % path
            audit.audit("edit_nfs_share", audit_str, request)
            return django.http.HttpResponseRedirect('/view_nfs_shares?ack=saved')
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'Modify a NFS share '
        return_dict['tab'] = 'view_nfs_shares_tab'
        return_dict["error"] = 'Error modifying a NFS share'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def update_nfs_share(request):
    return_dict = {}
    try:
        if request.method == "GET":
            # Return the conf page
            path = request.GET["path"]
            d, err = nfs.get_share(path)
            if err:
                raise Exception(err)
            if not d:
                raise Exception(
                    'Could not find the specified share. Please use the menus.')
            initial = {}
            initial['path'] = d['path']
            if 'clients' in d:
                client_list = []
                for client in d['clients']:
                    client_list.append(client['name'])
                initial['clients'] = ','.join(client_list)
            initial['readonly'] = False
            initial['root_squash'] = False
            initial['all_squash'] = False
            if 'options' in d:
                for option in d['options']:
                    if option == 'ro':
                        initial['readonly'] = True
                    elif option == 'root_squash':
                        initial['root_squash'] = True
                    elif option == 'all_squash':
                        initial['all_squash'] = True
            form = nfs_shares_forms.ShareForm(initial=initial)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("update_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = nfs_shares_forms.ShareForm(request.POST)
            path = request.POST["path"]
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("update_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            result, err = nfs.save_share(cd)
            if err:
                raise Exception(err)

            audit_str = "Edited NFS share %s" % path
            audit.audit("edit_nfs_share", audit_str, request)
            return django.http.HttpResponseRedirect('/storage_access/view_nfs_shares?ack=saved')
    except Exception, e:
        return_dict['base_template'] = "storage_access_base.html"
        return_dict["page_title"] = 'Modify a NFS share '
        return_dict['tab'] = 'view_nfs_shares_tab'
        return_dict["error"] = 'Error modifying a NFS share'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
示例#3
0
def create_nfs_share(request):
    return_dict = {}
    try:
        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(
                        {'name': ds["name"], 'mountpoint': ds["mountpoint"]})
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.')

        req_ret, err = django_utils.get_request_parameter_values(
            request, ['dataset', 'path'])
        if err:
            raise Exception(err)

        if 'dataset' in req_ret:
            dataset = req_ret['dataset']
        else:
            dataset = ds_list[0]['mountpoint']
        if 'path' in req_ret:
            path = req_ret['path']
        else:
            path = dataset

        return_dict['path'] = path
        return_dict["dataset"] = ds_list

        if request.method == "GET":
            # Return the conf page
            initial = {}
            initial['path'] = path
            initial['dataset'] = dataset
            form = nfs_shares_forms.CreateShareForm(
                initial=initial, dataset_list=ds_list)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = nfs_shares_forms.CreateShareForm(
                request.POST, dataset_list=ds_list)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            if 'new_folder' in cd and cd['new_folder']:
                try:
                    os.mkdir('%s/%s' % (cd['path'], cd['new_folder']))
                    audit_str = 'Created new directory "%s" in "%s"' % (
                        cd['new_folder'], cd['path'])
                    audit.audit("create_dir", audit_str, request)
                    cd['path'] = '%s/%s' % (cd['path'], cd['new_folder'])
                except Exception, e:
                    raise Exception('Error creating subfolder %s : %s' % (
                        cd['new_folder'], str(e)))
            result, err = nfs.save_share(cd, True)
            if err:
                raise Exception(err)

            audit_str = "Created NFS share %s" % cd['path']
            audit.audit("create_nfs_share", audit_str, request)
            return django.http.HttpResponseRedirect('/view_nfs_shares?ack=created')
    except Exception, e:
        return_dict['base_template'] = "shares_base.html"
        return_dict["page_title"] = 'Create a NFS share '
        return_dict['tab'] = 'view_nfs_shares_tab'
        return_dict["error"] = 'Error creating a NFS share'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
def create_nfs_share(request):
    return_dict = {}
    try:
        pools, err = zfs.get_pools()
        if err:
            raise Exception(err)

        ds_list = []
        for pool in pools:
            for ds in pool["datasets"]:
                if ds['properties']['type']['value'] == 'filesystem':
                    ds_list.append(
                        {'name': ds["name"], 'mountpoint': ds["mountpoint"]})
        if not ds_list:
            raise Exception(
                'No ZFS datasets available. Please create a dataset before creating shares.')

        req_ret, err = django_utils.get_request_parameter_values(
            request, ['dataset', 'path'])
        if err:
            raise Exception(err)

        if 'dataset' in req_ret:
            dataset = req_ret['dataset']
        else:
            dataset = ds_list[0]['mountpoint']
        if 'path' in req_ret:
            path = req_ret['path']
        else:
            path = dataset

        return_dict['path'] = path
        return_dict["dataset"] = ds_list

        if request.method == "GET":
            # Return the conf page
            initial = {}
            initial['path'] = path
            initial['dataset'] = dataset
            form = nfs_shares_forms.CreateShareForm(
                initial=initial, dataset_list=ds_list)
            return_dict['form'] = form
            return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
        else:
            form = nfs_shares_forms.CreateShareForm(
                request.POST, dataset_list=ds_list)
            return_dict['form'] = form
            if not form.is_valid():
                return django.shortcuts.render_to_response("create_nfs_share.html", return_dict, context_instance=django.template.context.RequestContext(request))
            cd = form.cleaned_data
            if 'new_folder' in cd and cd['new_folder']:
                try:
                    os.mkdir('%s/%s' % (cd['path'], cd['new_folder']))
                    audit_str = 'Created new directory "%s" in "%s"' % (
                        cd['new_folder'], cd['path'])
                    audit.audit("create_dir", audit_str, request)
                    cd['path'] = '%s/%s' % (cd['path'], cd['new_folder'])
                except Exception, e:
                    raise Exception('Error creating subfolder %s : %s' % (
                        cd['new_folder'], str(e)))
            result, err = nfs.save_share(cd, True)
            if err:
                raise Exception(err)

            audit_str = "Created NFS share %s" % cd['path']
            audit.audit("create_nfs_share", audit_str, request)
            return django.http.HttpResponseRedirect('/storage_access/view_nfs_shares?ack=created')
    except Exception, e:
        return_dict['base_template'] = "storage_access_base.html"
        return_dict["page_title"] = 'Create a NFS share '
        return_dict['tab'] = 'view_nfs_shares_tab'
        return_dict["error"] = 'Error creating a NFS share'
        return_dict["error_details"] = str(e)
        return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))