コード例 #1
0
def create_nfs_share(request):
  return_dict = {}
  try:
    if request.method == "GET":
      #Return the conf page
      form = nfs_shares_forms.ShareForm()
      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.ShareForm(request.POST)
      path = request.POST["path"]
      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
      try :
        result, err = nfs.save_share(cd, True)
        if not result:
          if not err:
            raise Exception('Unknown error!')
          else:
            raise Exception(err)
      except Exception, e:
        return_dict["error"] = "Error creating NFS share information - %s"%str(e)
        return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))
 
      audit_str = "Created NFS share %s"%path
      audit.audit("create_nfs_share", audit_str, request.META["REMOTE_ADDR"])
      return django.http.HttpResponseRedirect('/view_nfs_shares?action=created')
  except Exception, e:
    s = str(e)
    return_dict["error"] = "An error occurred when processing your request : %s"%s
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
コード例 #2
0
def edit_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 not d:
        raise Exception('Could not find the specified share. Please use the menus. : %s'%err)
      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("edit_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("edit_nfs_share.html", return_dict, context_instance = django.template.context.RequestContext(request))
      cd = form.cleaned_data
      try :
        result, err = nfs.save_share(cd)
        if not result:
          if not err:
            raise Exception('Unknown error!')
          else:
            raise Exception(err)
      except Exception, e:
        return_dict["error"] = "Error saving NFS share information - %s"%str(e)
        return django.shortcuts.render_to_response('logged_in_error.html', return_dict, context_instance=django.template.context.RequestContext(request))
 
      audit_str = "Edited NFS share %s"%path
      audit.audit("edit_nfs_share", audit_str, request.META["REMOTE_ADDR"])
      return django.http.HttpResponseRedirect('/view_nfs_shares?action=saved')
  except Exception, e:
    s = str(e)
    return_dict["error"] = "An error occurred when processing your request : %s"%s
    return django.shortcuts.render_to_response("logged_in_error.html", return_dict, context_instance=django.template.context.RequestContext(request))
コード例 #3
0
def edit_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("edit_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("edit_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.META["REMOTE_ADDR"])
      return django.http.HttpResponseRedirect('/view_nfs_shares?action=saved')
  except Exception, e:
    return_dict['base_template'] = "networking_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))
コード例 #4
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.')

    if request.method == "GET":
      #Return the conf page
      form = nfs_shares_forms.CreateShareForm(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)
      path = request.POST.get("path")
      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
      result, err = nfs.save_share(cd, True)
      if err:
        raise Exception(err)
 
      audit_str = "Created NFS share %s"%path
      audit.audit("create_nfs_share", audit_str, request.META["REMOTE_ADDR"])
      return django.http.HttpResponseRedirect('/view_nfs_shares?action=created')
  except Exception, e:
    return_dict['base_template'] = "networking_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))
コード例 #5
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.'
            )

        if 'dataset' in request.REQUEST:
            dataset = request.REQUEST['dataset']
        else:
            dataset = ds_list[0]['mountpoint']

        if 'path' in request.REQUEST:
            path = request.REQUEST['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.META)
                    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.META)
            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))
コード例 #6
0
def edit_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(
                "edit_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(
                    "edit_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.META)
            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))