示例#1
0
def get_form(request, dialog_name, action, filters):
    logger.debug("Rendering %s form" % action)
    if action == 'createinstance':
        return render_to_response('platforms/oc4j/instanceform.html', {
            'action': action,
            'filters': filters,
            'form': InstanceForm([]),
            'dialog_name': dialog_name,
            'base_url': settings.BASE_URL
        },
                                  context_instance=RequestContext(request))
    elif action == 'addpool':
        return render_to_response('platforms/oc4j/poolform.html', {
            'action': action,
            'filters': filters,
            'form': PoolForm([]),
            'dialog_name': dialog_name,
            'base_url': settings.BASE_URL
        },
                                  context_instance=RequestContext(request))
示例#2
0
def create_instance(request, filters, dialog_name, xhr=None):
    if request.method == "POST":
        logger.debug("Recreating form")
        form = InstanceForm(request.POST)

        #Check if the <xhr> var had something passed to it.
        if xhr == "xhr":
            #TODO: Try to use dynamic form validation
            clean = form.is_valid()
            rdict = {'bad': 'false', 'filters': filters}
            try:
                instancename = request.POST['instancename']
                groupname = request.POST['groupname']
                isflow = request.POST['isflow']
            except:
                instancename = None
                groupname = None
            if instancename and groupname:
                logger.debug("Parameters check: OK.")
                logger.debug(
                    "Calling MCollective to create instance %s on %s filtered server"
                    % (instancename, filters))
                args = 'instancename=%s;groupname=%s' % (instancename,
                                                         groupname)
                if isflow:
                    args = "%s;isflow=%s" % (args, isflow)
                response, content = callRestServer(request.user,
                                                   filters,
                                                   'a7xoas',
                                                   'createinstance',
                                                   args,
                                                   wait_response=True,
                                                   use_task=True,
                                                   use_backend_scheduler=True)
                if response.getStatus() == 200:
                    s_resps = []
                    for server_response in content:
                        if server_response.getStatusCode() == 0:
                            response_message = 'Instance Created'
                            if server_response.getData(
                            ) and "statusmsg" in server_response.getData(
                            ) and server_response.getData(
                            )["statusmsg"] != 'OK':
                                response_message = server_response.getData(
                                )["statusmsg"]
                            elif server_response.getStatusMessage(
                            ) and server_response.getStatusMessage() != 'OK':
                                response_message = server_response.getStatusMessage(
                                )
                            s_resps.append({
                                "server":
                                server_response.getSender(),
                                "response":
                                response_message
                            })
                        else:
                            s_resps.append({
                                "server":
                                server_response.getSender(),
                                "message":
                                server_response.getStatusMessage()
                            })
                    rdict.update({"result": s_resps})
                else:
                    logger.error(str(content))
                    rdict.update({
                        "result": "KO",
                        "message": "Error communicating with server"
                    })

                rdict.update({'dialog_name': dialog_name})
                # And send it off.
            else:
                rdict.update({'bad': 'true'})
                d = {}
                # This was painful, but I can't find a better way to extract the error messages:
                for e in form.errors.iteritems():
                    d.update({
                        e[0]: unicode(e[1])
                    })  # e[0] is the id, unicode(e[1]) is the error HTML.
                # Bung all that into the dict
                rdict.update({'errs': d})
                # Make a json whatsit to send back.

            return HttpResponse(json.dumps(rdict, ensure_ascii=False),
                                mimetype='application/javascript')
        # It's a normal submit - non ajax.
        else:
            if form.is_valid():
                # We don't accept non-ajax requests for the moment
                return HttpResponseRedirect("/")
    else:
        # It's not post so make a new form
        logger.warn("Cannot access this page using GET")
        raise Http404
示例#3
0
def create_instance(request, filters, dialog_name, xhr=None):
    if request.method == "POST":
        logger.debug("Recreating form")
        form = InstanceForm(request.POST)

        #Check if the <xhr> var had something passed to it.
        if xhr == "xhr":
            #TODO: Try to use dynamic form validation
            clean = form.is_valid()
            rdict = {'bad':'false', 'filters':filters }
            try:
                instancename = request.POST['instancename']
                groupname = request.POST['groupname']
                isflow = request.POST['isflow']
            except:
                instancename=None
                groupname=None
            if instancename and groupname:
                logger.debug("Parameters check: OK.")
                logger.debug("Calling MCollective to create instance %s on %s filtered server" % (instancename, filters))
                args = 'instancename=%s;groupname=%s' %(instancename, groupname)
                if isflow:
                    args = "%s;isflow=%s" % (args, isflow)
                response, content = callRestServer(request.user, filters, 'a7xoas', 'createinstance', args, wait_response=True, use_task=True, use_backend_scheduler=True)
                if response.getStatus() == 200:
                    s_resps = []
                    for server_response in content:
                        if server_response.getStatusCode()==0:
                            response_message = 'Instance Created'
                            if server_response.getData() and "statusmsg" in server_response.getData() and server_response.getData()["statusmsg"]!='OK':
                                response_message = server_response.getData()["statusmsg"]
                            elif server_response.getStatusMessage() and server_response.getStatusMessage()!='OK':
                                response_message = server_response.getStatusMessage()
                            s_resps.append({"server": server_response.getSender(), "response":response_message})
                        else:
                            s_resps.append({"server": server_response.getSender(), "message":server_response.getStatusMessage()})
                    rdict.update({"result":s_resps})
                else:
                    logger.error(str(content));
                    rdict.update({"result": "KO", "message": "Error communicating with server"})
                
                rdict.update({'dialog_name':dialog_name})
                # And send it off.
            else:
                rdict.update({'bad':'true'})
                d = {}
                # This was painful, but I can't find a better way to extract the error messages:
                for e in form.errors.iteritems():
                    d.update({e[0]:unicode(e[1])}) # e[0] is the id, unicode(e[1]) is the error HTML.
                # Bung all that into the dict
                rdict.update({'errs': d })
                # Make a json whatsit to send back.
                
            return HttpResponse(json.dumps(rdict, ensure_ascii=False), mimetype='application/javascript')
        # It's a normal submit - non ajax.
        else:
            if form.is_valid():
                # We don't accept non-ajax requests for the moment
                return HttpResponseRedirect("/")
    else:
        # It's not post so make a new form
        logger.warn("Cannot access this page using GET")
        raise Http404