Exemple #1
0
def testConnection(request):
    if request.method == "POST":
        form = NodeForm(request.POST)
        form.fields.pop("name", "")     # We don't need check name
        if form.is_valid():

            testNode = form.save(commit = False)

            data = {
                "status":           200,
                "statusMessage":    "OK"
            }

            try:
                virNode = virtualization.virNode(testNode)
                result = virNode.getInfo()
            except virtualization.ErrorException, e:
                data['success'] = False
                data['error'] = unicode(e)
            else:
                data['success'] = True
                data['info'] = result
            #endtry

        else:
            data = {
                "status":           400,
                "statusMessage":    "Data not valid!",
                "errors":           [(k, v[0].__unicode__()) for k, v in form.errors.items()]
            }
        #endif

        return HttpResponse(simplejson.dumps(data))
Exemple #2
0
def edit(request, nodeId):
    node = get_object_or_404(Node, id=nodeId)

    if not isAllowedTo(request, node, "change_node"):
        return HttpResponseRedirect("%s" % (reverse("403")))
    #endif

    if request.method == "POST":
        form = NodeForm(request.POST, instance=node)
        if form.is_valid():
            node = form.save()

            # Redirect
            return HttpResponseRedirect(
                reverse("nodes:node_edit", kwargs={ "nodeId": node.id })
            )
        #endif
    else:
        form = NodeForm(instance=node)
    #endif

    return render_to_response(
        "nodes/node/edit.html",
        {
            "form":         form,
            "managedNode":  node
        },
        context_instance=RequestContext(request)
    )
Exemple #3
0
def add(request):
    if request.method == "POST":
        form = NodeForm(request.POST)
        if form.is_valid():
            newNode = form.save(commit=False)
            newNode.owner = request.user
            newNode.save()
            return HttpResponseRedirect(reverse("nodes:node_list"))
        #endif
    else:
        form = NodeForm()
    #endif

    return render_to_response(
        "nodes/node/add.html",
        {
            "form":     form
        },
        context_instance=RequestContext(request)
    )