Exemplo n.º 1
0
    def post(self):
        args = container_name_args.parse_args(request)
        container_identifier = args.get(CONTAINER_IDENTIFIER)
        if not container_identifier:
            return error_400_no_container_id()

        try:
            docker_connection_proxy.find_container(container_identifier)
            return {}, http.HTTPStatus.OK.real
        except NotFound:
            return error_404_non_existent_container_id(container_identifier)
        except APIError:
            logger.exception(f"Could not finish processing request")
            return error_500_internal_server_error()
Exemplo n.º 2
0
    def post(self):
        args = container_name_args.parse_args(request)
        container_identifier = args.get(CONTAINER_IDENTIFIER)
        if not container_identifier:
            return error_400_no_container_id()

        try:
            container: Container = docker_connection_proxy.find_container(
                container_identifier
            )
            logger.debug(
                f"Found container with name='{container.name}' using input container identifier='{container_identifier}'"
            )
            if is_container_running(container):
                logger.warning(
                    f"Container with name='{container.name}' was running when trying to delete, executing stop"
                )
                container.stop()

            container.remove(force=True)
            return {}, http.HTTPStatus.OK.real
        except NotFound:
            return error_404_non_existent_container_id(container_identifier)
        except APIError:
            logger.exception(f"Could not finish processing request")
            return error_500_internal_server_error()
Exemplo n.º 3
0
    def post(self):
        args = container_name_args.parse_args(request)
        container_identifier = args.get(CONTAINER_IDENTIFIER)
        if not container_identifier:
            return error_400_no_container_id()

        try:
            # a_container.attrs['State']['StartedAt']
            # >>> abc
            # '2020-10-28T14:32:23.518166769Z'

            container: Container = docker_connection_proxy.find_container(
                container_identifier
            )
            logger.debug(
                f"Found container with name='{container.name}' using input container identifier='{container_identifier}'"
            )
            started_at_datetime = parse_docker_started_at_time(
                container.attrs["State"]["StartedAt"]
            )

            current_time = get_utc_now()
            uptime_in_seconds = (current_time - started_at_datetime).total_seconds()

            return {"uptime": int(uptime_in_seconds)}, http.HTTPStatus.OK.real
        except NotFound:
            return error_404_non_existent_container_id(container_identifier)
        except APIError:
            logger.exception(f"Could not finish processing request")
            return error_500_internal_server_error()