예제 #1
0
def service_up(request, project_name, service_name):
    try:
        docker.service_up(project_name, service_name)
        return Response(
            {f"service '{service_name}' for project '{project_name}' is up"})
    except NotFound as error:
        raise RestNotFound(detail=error.explanation)
예제 #2
0
def project_remove(request, project_name):
    try:
        docker.project_remove(project_name)
        return Response({
            f"stopped containers for project '{project_name}' have been removed"
        })
    except NotFound as error:
        raise RestNotFound(detail=error.explanation)
예제 #3
0
def service_rollback(request, project_name, service_name):
    try:
        docker.service_rollback(project_name, service_name)
        return Response({
            f"service '{service_name}' for project '{project_name}' has been rolled back"
        })
    except NotFound as error:
        raise RestNotFound(detail=error.explanation)
예제 #4
0
def container_remove(request, container_id):
    try:
        container = docker.container_remove(user=request.user,
                                            container_id=container_id)
        return Response({f"container '{container.name}' has been removed"})
    except NotFound as error:
        raise RestNotFound(detail=error.explanation)
    except CalledProcessError:
        raise APIException(detail="error removing container")
예제 #5
0
def service_logs(request, project_name, service_name):
    lines = request.GET.get("lines", 100)
    try:
        logs = docker.service_logs(project_name,
                                   service_name,
                                   lines=lines,
                                   array=True)
        return Response({
            "lines": lines,
            "logs": logs,
            "project_name": project_name,
            "service_name": service_name
        })
    except NotFound as error:
        raise RestNotFound(detail=error.explanation)
예제 #6
0
def container_logs(request, container_id):
    try:
        container = docker.container_by_id(container_id)
        docker.check_container_permission(user=request.user,
                                          container=container,
                                          perm="container_logs")
        lines = int(request.GET.get("lines", 100))
        logs = container.logs(lines=lines, array=True)
        return Response({
            "lines": lines,
            "logs": logs,
            "container_name": container.name,
            "container_id": container_id
        })
    except NotFound as error:
        raise RestNotFound(detail=error.explanation)
    except CalledProcessError:
        raise APIException(detail="error getting container logs")
예제 #7
0
def project_restart(request, project_name):
    try:
        docker.project_restart(project_name)
        return Response({f"project '{project_name}' has been restarted"})
    except NotFound as error:
        raise RestNotFound(detail=error.explanation)
예제 #8
0
def project_down(request, project_name):
    try:
        docker.project_down(project_name)
        return Response({f"project '{project_name}' is down"})
    except NotFound as error:
        raise RestNotFound(detail=error.explanation)