Пример #1
0
def agent_detail(request,pk,format=None):
    """
    Retrieve, update or delete a service
    """
    try:
        #print name
        agent = Serviceagent.objects.get(pk=pk)
    except Serviceagent.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = ServiceagentSerializer(agent)
        return Response(serializer.data)

    elif request.method == 'PUT':
        #data = JSONParser().parse(request)
        serializer = ServiceagentSerializer(agent, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        agent.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Пример #2
0
def agent_detail(request, pk, format=None):
    """
    Retrieve, update or delete a service
    """
    try:
        #print name
        agent = Serviceagent.objects.get(pk=pk)
    except Serviceagent.DoesNotExist:
        return Response(status=status.HTTP_404_NOT_FOUND)

    if request.method == 'GET':
        serializer = ServiceagentSerializer(agent)
        return Response(serializer.data)

    elif request.method == 'PUT':
        #data = JSONParser().parse(request)
        serializer = ServiceagentSerializer(agent, data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)

    elif request.method == 'DELETE':
        agent.delete()
        return Response(status=status.HTTP_204_NO_CONTENT)
Пример #3
0
def agent_list(request,format=None):
    if request.method == 'GET':
        agents = Serviceagent.objects.all()
        c = consul.Consul()
        
	services = c.agent.services()
        #print services.keys()
        #for keys in services.keys():
	string = str(services.keys())
        responseAgent = Serviceagent(agent=string)	 
	serializer = ServiceagentSerializer(responseAgent)
        return Response(serializer.data)

    elif request.method == 'POST':
        #data = JSONParser().parse(request)
        serializer = ServiceagentSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
Пример #4
0
def agent_list(request, format=None):
    if request.method == 'GET':
        agents = Serviceagent.objects.all()
        c = consul.Consul()

        services = c.agent.services()
        #print services.keys()
        #for keys in services.keys():
        string = str(services.keys())
        responseAgent = Serviceagent(agent=string)
        serializer = ServiceagentSerializer(responseAgent)
        return Response(serializer.data)

    elif request.method == 'POST':
        #data = JSONParser().parse(request)
        serializer = ServiceagentSerializer(data=request.data)
        if serializer.is_valid():
            serializer.save()
            return Response(serializer.data, status=status.HTTP_201_CREATED)
        return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)