Esempio n. 1
0
def getWithTemplate(request, template):
    if request.method != "POST":
        return HttpResponseForbidden()

    agent = request.POST["agent"]
    action = request.POST["action"]
    filters = request.POST["filters"]
    if request.POST["parameters"]:
        args = request.POST["parameters"]

    if verify_agent_acl(request.user, agent) and verify_action_acl(
            request.user, agent, action):
        response, content = callRestServer(request.user, filters, agent,
                                           action, args, True)
        if response.getStatus() == 200:
            jsonObj = []
            for entry in content:
                jsonObj.append(entry.to_dict())
            templatePath = 'ajax/' + template + '.html'
            data = {'content': jsonObj}
            return render_to_response(templatePath,
                                      data,
                                      context_instance=RequestContext(request))
        return response
    else:
        return HttpResponseForbidden()
Esempio n. 2
0
def getWithTemplate(request, template):
    if request.method != "POST":
        return HttpResponseForbidden()

    agent = request.POST["agent"]
    action = request.POST["action"]
    filters = request.POST["filters"]
    if request.POST["parameters"]:
        args = request.POST["parameters"]
        
    if verify_agent_acl(request.user, agent) and verify_action_acl(request.user, agent, action):
        response, content = callRestServer(request.user, filters, agent, action, args, True)
        if response.getStatus() == 200:
            jsonObj = []
            for entry in content:
                jsonObj.append(entry.to_dict())
            templatePath = 'ajax/' + template + '.html'
            data = {
                    'content': jsonObj
            }
            return render_to_response( templatePath, data,
                context_instance = RequestContext( request ) )
        return response
    else:
        return HttpResponseForbidden()
Esempio n. 3
0
def get(request, wait_for_response=False):
    if request.method != "POST":
        return HttpResponseForbidden()

    agent = request.POST["agent"]
    action = request.POST["action"]
    filters = request.POST["filters"]
    if request.POST["parameters"]:
        args = request.POST["parameters"]
        
    #Fix for unicode wait_for_response variable (actually used in url only for Virtualization Platform)
    if wait_for_response == "false" or wait_for_response == "False":
        wait_for_response = False
    elif wait_for_response == "true" or wait_for_response == "True":
        wait_for_response = True
        
    if verify_agent_acl(request.user, agent) and verify_action_acl(request.user, agent, action):
        response, content = callRestServer(request.user, filters, agent, action, args, wait_for_response)
        if wait_for_response:
            if response.getStatus() == 200:
                json_data = render_agent_template(request, {}, content, {}, agent, action)
                return HttpResponse(json_data, mimetype="application/json")
        else:
            logger.debug("Returning request UUID")
            update_url = reverse('get_progress', kwargs={'taskname':content, 'taskid':response.task_id})
            json_data = json.dumps({"UUID": response.task_id, "taskname": content, 'update_url': update_url})
            return HttpResponse(json_data, mimetype="application/json")
    else:
        return HttpResponseForbidden()
Esempio n. 4
0
def get(request, filters, agent, action, args=None):
    if verify_agent_acl(request.user, agent) and verify_action_acl(request.user, agent, action):
        response, content = callRestServer(request.user, filters, agent, action, args)
        if response.status == 200:
            json_data = render_agent_template(request, {}, content, {}, agent, action)
            return HttpResponse(json_data, mimetype="application/json")
        return response
    else:
        return HttpResponseForbidden()
Esempio n. 5
0
def get(request, filters, agent, action, args=None):
    if verify_agent_acl(request.user, agent) and verify_action_acl(
            request.user, agent, action):
        response, content = callRestServer(request.user, filters, agent,
                                           action, args)
        if response.status == 200:
            json_data = render_agent_template(request, {}, content, {}, agent,
                                              action)
            return HttpResponse(json_data, mimetype="application/json")
        return response
    else:
        return HttpResponseForbidden()
Esempio n. 6
0
def getWithTemplate(request, template, filters, agent, action, args=None):
    if verify_agent_acl(request.user, agent) and verify_action_acl(request.user, agent, action):
        response, content = callRestServer(request.user, filters, agent, action, args)
        if response.status == 200:
            jsonObj = json.loads(content)
            templatePath = 'ajax/' + template + '.html'
            data = {
                    'content': jsonObj
            }
            return render_to_response( templatePath, data,
                context_instance = RequestContext( request ) )
        return response
    else:
        return HttpResponseForbidden()
Esempio n. 7
0
def get(request, filters, agent, action, args=None, wait_for_response=False):
    if verify_agent_acl(request.user, agent) and verify_action_acl(request.user, agent, action):
        response, content = callRestServer(request.user, filters, agent, action, args, wait_for_response)
        if wait_for_response:
            if response.status == 200:
                json_data = render_agent_template(request, {}, content, {}, agent, action)
                return HttpResponse(json_data, mimetype="application/json")
        else:
            logger.debug("Returning request UUID")
            update_url = reverse('get_progress', kwargs={'taskname':content, 'taskid':response.task_id})
            json_data = json.dumps({"UUID": response.task_id, "taskname": content, 'update_url': update_url})
            return HttpResponse(json_data, mimetype="application/json")
    else:
        return HttpResponseForbidden()
Esempio n. 8
0
def getWithTemplate(request, template, filters, agent, action, args=None):
    if verify_agent_acl(request.user, agent) and verify_action_acl(
            request.user, agent, action):
        response, content = callRestServer(request.user, filters, agent,
                                           action, args)
        if response.status == 200:
            jsonObj = json.loads(content)
            templatePath = 'ajax/' + template + '.html'
            data = {'content': jsonObj}
            return render_to_response(templatePath,
                                      data,
                                      context_instance=RequestContext(request))
        return response
    else:
        return HttpResponseForbidden()
Esempio n. 9
0
def get(request, wait_for_response=False):
    if request.method != "POST":
        return HttpResponseForbidden()

    agent = request.POST["agent"]
    action = request.POST["action"]
    filters = request.POST["filters"]
    if request.POST["parameters"]:
        args = request.POST["parameters"]

    #Fix for unicode wait_for_response variable (actually used in url only for Virtualization Platform)
    if wait_for_response == "false" or wait_for_response == "False":
        wait_for_response = False
    elif wait_for_response == "true" or wait_for_response == "True":
        wait_for_response = True

    if verify_agent_acl(request.user, agent) and verify_action_acl(
            request.user, agent, action):
        response, content = callRestServer(request.user, filters, agent,
                                           action, args, wait_for_response)
        if wait_for_response:
            if response.getStatus() == 200:
                json_data = render_agent_template(request, {}, content, {},
                                                  agent, action)
                return HttpResponse(json_data, mimetype="application/json")
        else:
            logger.debug("Returning request UUID")
            update_url = reverse('get_progress',
                                 kwargs={
                                     'taskname': content,
                                     'taskid': response.task_id
                                 })
            json_data = json.dumps({
                "UUID": response.task_id,
                "taskname": content,
                'update_url': update_url
            })
            return HttpResponse(json_data, mimetype="application/json")
    else:
        return HttpResponseForbidden()