How to use the eliot.ActionType function in eliot

To help you get started, we’ve selected a few eliot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github ClusterHQ / flocker / flocker / control / _protocol.py View on Github external
"""
    Serialize a connected ``ControlAMP`` to the address of its peer.

    :return: A string representation of the Twisted address object describing
        the remote address of the connection of the given protocol.

    :rtype str:
    """
    return str(controlamp.transport.getPeer())


AGENT = Field(
    u"agent", _serialize_agent, u"The agent we're sending to",
)

LOG_SEND_TO_AGENT = ActionType(
    "flocker:controlservice:send_state_to_agent",
    [AGENT],
    [],
    "Send the configuration and state of the cluster to a specific agent.")

AGENT_CONNECTED = ActionType(
    "flocker:controlservice:agent_connected",
    [AGENT],
    [],
    "An agent connected to the control service."
)

AGENT_UPDATE_ELIDED = MessageType(
    "flocker:controlservice:agent_update_elided",
    [AGENT],
    u"An update to an agent was elided because a subsequent update supercedes "
github ClusterHQ / flocker / flocker / control / _protocol.py View on Github external
def connectionLost(self, reason):
        AMP.connectionLost(self, reason)
        self.control_amp_service.disconnected(self)
        self._pinger.stop()


# These two logging fields use caching_wire_encode as the serializer so
# that they can share the encoding cache with the network code related to
# this logging.  This reduces the overhead of logging these (potentially
# quite large) data structures.
DEPLOYMENT_CONFIG = Field(u"configuration", caching_wire_encode,
                          u"The cluster configuration")
CLUSTER_STATE = Field(u"state", caching_wire_encode, u"The cluster state")

LOG_SEND_CLUSTER_STATE = ActionType(
    "flocker:controlservice:send_cluster_state",
    [],
    [DEPLOYMENT_CONFIG, CLUSTER_STATE],
    "Send the configuration and state of the cluster to all agents.")


def _serialize_agent(controlamp):
    """
    Serialize a connected ``ControlAMP`` to the address of its peer.

    :return: A string representation of the Twisted address object describing
        the remote address of the connection of the given protocol.

    :rtype str:
    """
    return str(controlamp.transport.getPeer())
github twisted / txacme / src / txacme / logging.py View on Github external
fields(Field.for_types(u'content_type',
                           [unicode, None],
                           u'Content-Type header field'),
           code=int),
    u'A JWSClient request')

LOG_JWS_CHECK_RESPONSE = ActionType(
    u'txacme:jws:http:check-response',
    fields(Field.for_types(u'response_content_type',
                           [unicode, None],
                           u'Content-Type header field'),
           expected_content_type=unicode),
    fields(),
    u'Checking a JWSClient response')

LOG_JWS_GET_NONCE = ActionType(
    u'txacme:jws:nonce:get',
    fields(),
    fields(NONCE),
    u'Consuming a nonce')

LOG_JWS_ADD_NONCE = ActionType(
    u'txacme:jws:nonce:add',
    fields(Field.for_types(u'raw_nonce',
                           [bytes, None],
                           u'Nonce header field')),
    fields(NONCE),
    u'Adding a nonce')

LOG_HTTP_PARSE_LINKS = ActionType(
    u'txacme:http:parse-links',
    fields(raw_link=unicode),
github twisted / txacme / src / txacme / logging.py View on Github external
lambda nonce: nonce.encode('hex').decode('ascii'),
    u'A nonce value')

LOG_JWS_SIGN = ActionType(
    u'txacme:jws:sign',
    fields(NONCE, key_type=unicode, alg=unicode),
    fields(),
    u'Signing a message with JWS')

LOG_JWS_HEAD = ActionType(
    u'txacme:jws:http:head',
    fields(),
    fields(),
    u'A JWSClient HEAD request')

LOG_JWS_GET = ActionType(
    u'txacme:jws:http:get',
    fields(),
    fields(),
    u'A JWSClient GET request')

LOG_JWS_POST = ActionType(
    u'txacme:jws:http:post',
    fields(),
    fields(),
    u'A JWSClient POST request')

LOG_JWS_REQUEST = ActionType(
    u'txacme:jws:http:request',
    fields(url=unicode),
    fields(Field.for_types(u'content_type',
                           [unicode, None],
github ClusterHQ / flocker / flocker / node / agents / remotefs.py View on Github external
key_type=unicode,
        value_type=unicode,
    )
    mount_point = field(FilePath)

    __invariant__ = TaggedUnionInvariant(
        tag_attribute='state',
        attributes_for_tag={
            DatasetStates.NOT_MOUNTED: {"metadata"},
            DatasetStates.MOUNTED: {"mount_point", "metadata"},
            DatasetStates.DELETED: set(),
        },
    )


API_CHANGE = ActionType(u"remotefs:deployer:action", [], [])


@provider(IDatasetStateChangeFactory)
@implementer(IStateChange)
class _APICommon(PClass):
    @property
    def eliot_action(self):
        return API_CHANGE()

    def run(self, deployer):
        try:
            self._run(deployer.api)
            return succeed(None)
        except:
            return fail()
github ClusterHQ / flocker / flocker / apiclient / _client.py View on Github external
from twisted.python.filepath import FilePath
from twisted.web.http import (
    CREATED, OK, CONFLICT, NOT_FOUND, PRECONDITION_FAILED,
)
from twisted.internet.utils import getProcessOutput
from twisted.internet.task import deferLater

from treq import json_content, content

from ..ca import treq_with_authentication
from ..control import Leases as LeasesModel, LeaseError, DockerImage
from ..common import retry_failure

from .. import __version__

_LOG_HTTP_REQUEST = ActionType(
    "flocker:apiclient:http_request",
    [Field.forTypes("url", [bytes, unicode], "Request URL."),
     Field.forTypes("method", [bytes, unicode], "Request method."),
     Field("request_body", lambda o: o, "Request JSON body.")],
    [Field.forTypes("response_code", [int], "Response code."),
     Field("response_body", lambda o: o, "JSON response body.")],
    "A HTTP request.")

_LOG_CONDITIONAL_CREATE = ActionType(
    u"flocker:apiclient:conditional_create", [], [],
    u"Conditionally create a dataset.")


NoneType = type(None)
github twisted / txacme / src / txacme / logging.py View on Github external
LOG_JWS_GET_NONCE = ActionType(
    u'txacme:jws:nonce:get',
    fields(),
    fields(NONCE),
    u'Consuming a nonce')

LOG_JWS_ADD_NONCE = ActionType(
    u'txacme:jws:nonce:add',
    fields(Field.for_types(u'raw_nonce',
                           [bytes, None],
                           u'Nonce header field')),
    fields(NONCE),
    u'Adding a nonce')

LOG_HTTP_PARSE_LINKS = ActionType(
    u'txacme:http:parse-links',
    fields(raw_link=unicode),
    fields(parsed_links=dict),
    u'Parsing HTTP Links')

DIRECTORY = Field(u'directory', methodcaller('to_json'), u'An ACME directory')

URL = Field(u'url', methodcaller('asText'), u'A URL object')

LOG_ACME_CONSUME_DIRECTORY = ActionType(
    u'txacme:acme:client:from-url',
    fields(URL, key_type=unicode, alg=unicode),
    fields(DIRECTORY),
    u'Creating an ACME client from a remote directory')

LOG_ACME_REGISTER = ActionType(
github ClusterHQ / flocker / flocker / control / configuration_storage / consul.py View on Github external
from treq import json_content, content
import treq

from twisted.internet import reactor
from twisted.internet.error import ConnectionRefusedError
from twisted.web.http import (
    OK, NOT_FOUND, INTERNAL_SERVER_ERROR
)

from zope.interface import implementer

from .interface import IConfigurationStore
from ...common import retry_failure, backoff


_LOG_HTTP_REQUEST = ActionType(
    "flocker:control:consul",
    [Field.forTypes("url", [bytes, unicode], "Request URL."),
     Field.forTypes("method", [bytes, unicode], "Request method."),
     Field("request_body", lambda o: o, "Request JSON body.")],
    [Field.forTypes("response_code", [int], "Response code."),
     Field("response_body", lambda o: o, "JSON response body.")],
    "A HTTP request.")


class ResponseError(Exception):
    """
    An unexpected response from the REST API.
    """
    def __init__(self, code, body):
        Exception.__init__(self, "Unexpected response code {}:\n{}\n".format(
            code, body))
github twisted / txacme / src / txacme / logging.py View on Github external
"""
Eliot message and action definitions.
"""
from operator import methodcaller

from eliot import ActionType, Field, fields
from twisted.python.compat import unicode

NONCE = Field(
    u'nonce',
    lambda nonce: nonce.encode('hex').decode('ascii'),
    u'A nonce value')

LOG_JWS_SIGN = ActionType(
    u'txacme:jws:sign',
    fields(NONCE, key_type=unicode, alg=unicode),
    fields(),
    u'Signing a message with JWS')

LOG_JWS_HEAD = ActionType(
    u'txacme:jws:http:head',
    fields(),
    fields(),
    u'A JWSClient HEAD request')

LOG_JWS_GET = ActionType(
    u'txacme:jws:http:get',
    fields(),
    fields(),
    u'A JWSClient GET request')
github ClusterHQ / flocker / flocker / node / agents / _logging.py View on Github external
OPERATION = Field.for_types(
    u"operation", [list],
    u"The IBlockDeviceAPI operation being executed,"
    u"along with positional and keyword arguments.")

COUNT = Field.for_types(
    u"count", [int],
    u"Count of operation calls.")

# End: Common structures used by all storage drivers.

# Begin: Helper datastructures to log IBlockDeviceAPI calls
# from AWS storage driver using Eliot.

# ActionType used by AWS storage driver.
AWS_ACTION = ActionType(
    u"flocker:node:agents:blockdevice:aws",
    [OPERATION, COUNT],
    [],
    u"An IBlockDeviceAPI operation is executing using AWS storage driver.")

# Three fields to gather from EC2 response to Boto.
AWS_CODE = Field.for_types(
    "aws_code", [bytes, unicode],
    u"The error response code.")
AWS_MESSAGE = Field.for_types(
    "aws_message", [unicode],
    u"A human-readable error message given by the response.",
)
AWS_REQUEST_ID = Field.for_types(
    "aws_request_id", [bytes, unicode],
    u"The unique identifier assigned by the server for this request.",