Example #1
0
def redeploy_app(request, filters, dialog_name, xhr=None):
    if request.method == "POST":
        logger.debug("Recreating form")
        form = DeployForm(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:
                appfile = request.POST['applist']
                app_type = request.POST['types']
                instancename = request.POST['instancename']
                appname = request.POST['appname']
            except:
                appname = None
                app_type = None
            if appname and app_type:
                logger.debug("Parameters check: OK.")
                logger.debug(
                    "Calling MCollective to deploy %s application on %s filtered server"
                    % (appfile, filters))
                response, content = callRestServer(
                    request.user, filters, 'a7xoas', 'redeploy',
                    'appname=%s;instancename=%s;appfile=%s' %
                    (appname, instancename, appfile))
                if response.status == 200:
                    json_content = json.loads(content)
                    rdict.update({"result": json_content[0]["statusmsg"]})
                else:
                    rdict.update({"result": "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
Example #2
0
def deploy_app(request, filters, dialog_name, xhr=None):
    if request.method == "POST":
        logger.debug("Recreating form")
        form = DeployForm(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:
                appfile = request.POST['applist']
                app_type = request.POST['types']
                instancename = request.POST['instancename']
                appname = request.POST['appname']
                action = request.POST['action']
            except:
                appname=None
                app_type=None
                action=None
            if appname and app_type and action:
                logger.debug("Parameters check: OK.")
                logger.debug("Calling MCollective to deploy %s application on %s filtered server" % (appfile, filters))
                response, content = callRestServer(request.user, filters, 'a7xoas', action, 'appname=%s;instancename=%s;appfile=%s' %(appname, instancename, appfile), True)
                if response.status == 200:
                    json_content = json.loads(content)
                    s_resps = []
                    for server_response in json_content:
                        if server_response['statuscode']==0:
                            s_resps.append({"server": server_response["sender"], "response":server_response["statusmsg"]})
                        else:
                            s_resps.append({"server": server_response["sender"], "message":server_response["statusmsg"]})
                    rdict.update({"result":s_resps})
                else:
                    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
Example #3
0
def get_deploy_form(request, dialog_name, action, filters):
    logger.debug('Rendering form')
    return render_to_response('platforms/oc4j/deployform.html', {
        'action': action,
        'filters': filters,
        'form': DeployForm([]),
        'dialog_name': dialog_name,
        'base_url': settings.BASE_URL
    },
                              context_instance=RequestContext(request))