Exemplo n.º 1
0
    u"The filecap from which the previous version of this file was downloaded.",
)

LAST_DOWNLOADED_TIMESTAMP = Field.for_types(
    u"last_downloaded_timestamp",
    [float, int, long],
    u"(XXX probably not really, don't trust this) The timestamp of the last download of this file.",
)

PATHINFO = Field(
    u"pathinfo",
    lambda v: None if v is None else {
        "isdir": v.isdir,
        "isfile": v.isfile,
        "islink": v.islink,
        "exists": v.exists,
        "size": v.size,
        "mtime_ns": v.mtime_ns,
        "ctime_ns": v.ctime_ns,
    },
    u"The metadata for this version of this file.",
    validateInstanceOf((type(None), PathInfo)),
)


def eliot_logging_service(reactor, destinations):
    """
    Parse the given Eliot destination descriptions and return an ``IService``
    which will add them when started and remove them when stopped.

    See ``--help-eliot-destinations`` for details about supported
    destinations.
Exemplo n.º 2
0

class AlreadyAttachedVolume(VolumeException):
    """
    A failed attempt to attach a block device that is already attached.
    """


class UnattachedVolume(VolumeException):
    """
    An attempt was made to operate on an unattached volume but the operation
    requires the volume to be attached.
    """


DATASET = Field(u"dataset", lambda dataset: dataset.dataset_id,
                u"The unique identifier of a dataset.")

VOLUME = Field(u"volume", lambda volume: volume.blockdevice_id,
               u"The unique identifier of a volume.")

DATASET_ID = Field(u"dataset_id", lambda dataset_id: unicode(dataset_id),
                   u"The unique identifier of a dataset.")

MOUNTPOINT = Field(
    u"mountpoint",
    lambda path: path.path,
    u"The absolute path to the location on the node where the dataset will be "
    u"mounted.",
)

DEVICE_PATH = Field(
Exemplo n.º 3
0
        }


class LoopExceeded(Exception):
    """
    Raised when ``loop_until`` looped too many times.
    """
    def __init__(self, predicate, last_result):
        super(LoopExceeded,
              self).__init__('%r never True in loop_until, last result: %r' %
                             (predicate, last_result))


LOOP_UNTIL_ACTION = ActionType(
    action_type="flocker:common:loop_until",
    startFields=[Field("predicate", function_serializer)],
    successFields=[Field("result", serializer=safe_repr)],
    description="Looping until predicate is true.")

LOOP_UNTIL_ITERATION_MESSAGE = MessageType(
    message_type="flocker:common:loop_until:iteration",
    fields=[Field("result", serializer=safe_repr)],
    description="Predicate failed, trying again.")


def loop_until(reactor, predicate, steps=None):
    """Repeatedly call ``predicate``, until it returns something ``Truthy``.

    :param reactor: The reactor implementation to use to delay.
    :type reactor: ``IReactorTime``.
Exemplo n.º 4
0
    def connectionMade(self):
        AMP.connectionMade(self)
        self.control_amp_service.connected(self)
        self._pinger.start(self, PING_INTERVAL)

    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.
Exemplo n.º 5
0
            return FilePath(dictionary.get(u"path").encode("utf-8"))
        elif class_name == u"PMap":
            return pmap(dictionary[u"values"])
        elif class_name == u"UUID":
            return UUID(dictionary[u"hex"])
        elif class_name in _CONFIG_CLASS_MAP:
            dictionary = dictionary.copy()
            dictionary.pop(_CLASS_MARKER)
            return _CONFIG_CLASS_MAP[class_name].create(dictionary)
        else:
            return dictionary

    return loads(data, object_hook=decode)


_DEPLOYMENT_FIELD = Field(u"configuration", repr)
_LOG_STARTUP = MessageType(u"flocker-control:persistence:startup",
                           [_DEPLOYMENT_FIELD])
_LOG_SAVE = ActionType(u"flocker-control:persistence:save",
                       [_DEPLOYMENT_FIELD], [])

_UPGRADE_SOURCE_FIELD = Field.for_types(
    u"source_version", [int], u"Configuration version to upgrade from.")
_UPGRADE_TARGET_FIELD = Field.for_types(
    u"target_version", [int], u"Configuration version to upgrade to.")
_LOG_UPGRADE = ActionType(u"flocker-control:persistence:migrate_configuration",
                          [
                              _DEPLOYMENT_FIELD,
                              _UPGRADE_SOURCE_FIELD,
                              _UPGRADE_TARGET_FIELD,
                          ], [])
Exemplo n.º 6
0
    # immediately stop:
    CONVERGING_STOPPING = NamedConstant()


class ConvergenceLoopOutputs(Names):
    """
    Converence loop FSM outputs.
    """
    # Store AMP client, desired configuration and cluster state for later
    # use:
    STORE_INFO = NamedConstant()
    # Start an iteration of the covergence loop:
    CONVERGE = NamedConstant()


_FIELD_CONNECTION = Field(u"connection", lambda client: repr(client),
                          "The AMP connection to control service")

LOG_SEND_TO_CONTROL_SERVICE = ActionType(
    u"flocker:agent:send_to_control_service", [_FIELD_CONNECTION], [],
    "Send the local state to the control service.")


class ConvergenceLoop(object):
    """
    World object for the convergence loop state machine, executing the actions
    indicated by the outputs from the state machine.

    :ivar AMP client: An AMP client connected to the control
        service. Initially ``None``.

    :ivar Deployment configuration: Desired cluster
Exemplo n.º 7
0
    # immediately stop:
    CONVERGING_STOPPING = NamedConstant()


class ConvergenceLoopOutputs(Names):
    """
    Converence loop FSM outputs.
    """
    # Store AMP client, desired configuration and cluster state for later
    # use:
    STORE_INFO = NamedConstant()
    # Start an iteration of the covergence loop:
    CONVERGE = NamedConstant()


_FIELD_CONNECTION = Field(u"connection", lambda client: repr(client),
                          "The AMP connection to control service")

_FIELD_LOCAL_CHANGES = Field(u"local_changes", repr,
                             "Changes discovered in local state.")

LOG_SEND_TO_CONTROL_SERVICE = ActionType(
    u"flocker:agent:send_to_control_service",
    [_FIELD_CONNECTION, _FIELD_LOCAL_CHANGES], [],
    "Send the local state to the control service.")

_FIELD_CLUSTERSTATE = Field(
    u"cluster_state", repr,
    "The state of the cluster, according to control service.")

_FIELD_CONFIGURATION = Field(
    u"desired_configuration", repr,
Exemplo n.º 8
0

def validate_ipv4_address(value):
    if not isinstance(value, IPv4Address):
        raise ValidationError(
            value, u"Field %s requires type to be IPv4Address (not %s)" %
            (u"target_ip", type(value)))


def serialize_ipv4_address(address):
    return unicode(address)


TARGET_IP = Field(
    key=u"target_ip",
    serializer=serialize_ipv4_address,
    extraValidator=validate_ipv4_address,
    description=u"The IP address which is the target of a proxy.")

TARGET_PORT = Field.forTypes(
    u"target_port", [int], u"The port number which is the target of a proxy.")

ARGV = Field.forTypes(u"argv", [list],
                      u"The argument list of a child process being executed.")

IPTABLES = ActionType(
    _system(u"iptables"), [ARGV], [],
    u"An iptables command which Flocker is executing against the system.")

CREATE_PROXY_TO = ActionType(_system(u"create_proxy_to"),
                             [TARGET_IP, TARGET_PORT], [],
Exemplo n.º 9
0
from eliot import ActionType, Field, fields

_SEARCH_CLASS = Field(u'searchClass', lambda c: c.value, u'The search class')

LOG_LOOKUP_GET = ActionType(
    u'fusion_index:lookup:get',
    fields(environment=unicode, indexType=unicode, key=unicode),
    [Field.for_types('value', [bytes, None], u'Value in the index, if any')],
    u'Retrieving a value from the lookup index')

LOG_LOOKUP_PUT = ActionType(
    u'fusion_index:lookup:put',
    fields(environment=unicode, indexType=unicode, key=unicode),
    fields(value=bytes), u'Storing a value in the lookup index')

_SEARCH_TYPE = Field.for_types('searchType', [unicode, None],
                               u'The search type')
LOG_SEARCH_GET = ActionType(
    u'fusion_index:search:get',
    fields(_SEARCH_CLASS,
           _SEARCH_TYPE,
           environment=unicode,
           indexType=unicode,
           searchValue=unicode), fields(results=list),
    u'Searching the search index')

LOG_SEARCH_PUT = ActionType(
    u'fusion_index:search:put',
    fields(_SEARCH_CLASS,
           environment=unicode,
           indexType=unicode,
Exemplo n.º 10
0
"""
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')

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],
                           u'Content-Type header field'),
           code=int), u'A JWSClient request')

LOG_JWS_CHECK_RESPONSE = ActionType(
Exemplo n.º 11
0
_watchdog_541.patch()

NOT_STARTED = "NOT_STARTED"
STARTED = "STARTED"
STOPPING = "STOPPING"
STOPPED = "STOPPED"

_PATH = Field.for_types(
    u"path",
    [bytes, unicode],
    u"The path an inotify event concerns.",
)

_EVENT = Field(
    u"event",
    lambda e: e.__class__.__name__,
    u"The watchdog event that has taken place.",
    validateInstanceOf(FileSystemEvent),
)

ANY_INOTIFY_EVENT = ActionType(
    u"watchdog:inotify:any-event",
    [_PATH, _EVENT],
    [],
    u"An inotify event is being dispatched.",
)


class INotifyEventHandler(FileSystemEventHandler):
    def __init__(self, path, mask, callbacks, pending_delay):
        FileSystemEventHandler.__init__(self)
        self._path = path
Exemplo n.º 12
0
    u"magic-folder:process-queue",
    [_COUNT],
    [],
    u"A Magic-Folder is working through an item queue.",
)

SCAN_REMOTE_COLLECTIVE = ActionType(
    u"magic-folder:scan-remote-collective",
    [],
    [],
    u"The remote collective is being scanned for peer DMDs.",
)

_DMDS = Field(
    u"dmds",
    lambda participants: list(participant.name
                              for participant in participants),
    u"The (D)istributed (M)utable (D)irectories belonging to each participant are being scanned for changes.",
)

COLLECTIVE_SCAN = MessageType(
    u"magic-folder:downloader:get-latest-file:collective-scan",
    [_DMDS],
    u"Participants in the collective are being scanned.",
)

SCAN_REMOTE_DMD = ActionType(
    u"magic-folder:scan-remote-dmd",
    [_NICKNAME],
    [],
    u"A peer DMD is being scanned for changes.",
)
Exemplo n.º 13
0
    graph = json_graph.adjacency_data(graph)
    graph["nodes"] = [{
        "id":
        n["id"] if not isinstance(n["id"], Step) else repr(n["id"])
    } for n in graph["nodes"]]
    graph["adjacency"] = [[{
        "id":
        a["id"] if not isinstance(a["id"], Step) else repr(a["id"])
    } for a in adj] for adj in graph["adjacency"]]

    return graph


BUILDING_DEPENDENCY_GRAPH = ActionType(
    "bootsteps:blueprint:building_dependency_graph",
    [Field("name", str, "The name of the blueprint")],
    [
        Field("name", str, "The name of the blueprint"),
        Field("graph", _serialize_graph, "The resulting graph"),
    ],
)

START_BLUEPRINT = ActionType("bootsteps:blueprint:start",
                             [Field("name", str, "The name of the blueprint")],
                             [])

STOP_BLUEPRINT = ActionType("bootsteps:blueprint:stop",
                            [Field("name", str, "The name of the blueprint")],
                            [])

NEXT_BOOTSTEPS = MessageType(
Exemplo n.º 14
0
small number of fields.
"""

from __future__ import unicode_literals

import time

from eliot import Logger, MessageType, Field, ActionType


def _ascii(s):
    return s.decode("ascii")


F1 = Field.forTypes("integer", [int], "")
F2 = Field("string", _ascii, "")
F3 = Field("string2", _ascii, "")
F4 = Field.forTypes("list", [list], "list of integers")

M = MessageType("system:message", [F1, F2, F3, F4], "description")
A = ActionType("action", [], [], [], "desc")

log = Logger()

N = 100000


def run():
    start = time.time()
    with A(log):
        for i in xrange(N):
Exemplo n.º 15
0
# Copyright ClusterHQ Inc.  See LICENSE file for details.
"""
Helper module to provide macros for logging support
for storage drivers (AWS, Cinder).
See https://clusterhq.atlassian.net/browse/FLOC-2053
for consolidation opportunities.
"""

from eliot import Field, ActionType, MessageType

# Begin: Common structures used by all (AWS, OpenStack)
# storage drivers.

DATASET_ID = Field(u"dataset_id", lambda dataset_id: unicode(dataset_id),
                   u"The unique identifier of a dataset.")

# An OPERATION is a list of:
# IBlockDeviceAPI name, positional arguments, keyword arguments.
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(
Exemplo n.º 16
0
Eliot field, message, and action definitions for ZKAPAuthorizer.
"""

from __future__ import (
    absolute_import,
)

from eliot import (
    Field,
    MessageType,
    ActionType,
)

PRIVACYPASS_MESSAGE = Field(
    u"message",
    unicode,
    u"The PrivacyPass request-binding data associated with a pass.",
)

INVALID_REASON = Field(
    u"reason",
    unicode,
    u"The reason given by the server for rejecting a pass as invalid.",
)

PASS_COUNT = Field(
    u"count",
    int,
    u"A number of passes.",
)
Exemplo n.º 17
0
# Copyright ClusterHQ Inc.  See LICENSE file for details.
"""
This module defines the Eliot log events emitted by the API implementation.
"""

from eliot import Field, ActionType

__all__ = [
    "REQUEST",
]

LOG_SYSTEM = u"api"

METHOD = Field(u"method", lambda method: method,
               u"The HTTP method of the request.")
REQUEST_PATH = Field(
    u"request_path", lambda path: path,
    u"The absolute path of the resource to which the request was issued.")
JSON = Field.forTypes(u"json", [unicode, bytes, dict, list, None, bool, float],
                      u"The JSON request body.")
RESPONSE_CODE = Field.forTypes(u"code", [int],
                               u"The response code for the request.")

# It would be nice if RESPONSE_CODE was in REQUEST; see FLOC-1586.
REQUEST = ActionType(LOG_SYSTEM + u":request", [REQUEST_PATH, METHOD], [],
                     u"A request was received on the public HTTP interface.")
Exemplo n.º 18
0
        :param ControlAMPService control_amp_service: The service managing AMP
             connections to the control service.
        """
        AMP.__init__(self, locator=ControlServiceLocator(control_amp_service))
        self.control_amp_service = control_amp_service

    def connectionMade(self):
        AMP.connectionMade(self)
        self.control_amp_service.connected(self)

    def connectionLost(self, reason):
        AMP.connectionLost(self, reason)
        self.control_amp_service.disconnected(self)


DEPLOYMENT_CONFIG = Field(u"configuration", repr, u"The cluster configuration")
CLUSTER_STATE = Field(u"state", repr, 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.")

AGENT = Field(u"agent", repr, 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.")


class ControlAMPService(Service):
Exemplo n.º 19
0
            return dictionary

    return loads(data, object_hook=decode)


def to_unserialized_json(obj):
    """
    Convert a wire encodeable object into structured Python objects that
    are JSON serializable.

    :param obj: An object that can be passed to ``wire_encode``.
    :return: Python object that can be JSON serialized.
    """
    return _cached_dfs_serialize(obj)

_DEPLOYMENT_FIELD = Field(u"configuration", to_unserialized_json)
_LOG_STARTUP = MessageType(u"flocker-control:persistence:startup",
                           [_DEPLOYMENT_FIELD])
_LOG_SAVE = ActionType(u"flocker-control:persistence:save",
                       [_DEPLOYMENT_FIELD], [])

_UPGRADE_SOURCE_FIELD = Field.for_types(
    u"source_version", [int], u"Configuration version to upgrade from.")
_UPGRADE_TARGET_FIELD = Field.for_types(
    u"target_version", [int], u"Configuration version to upgrade to.")
_LOG_UPGRADE = ActionType(u"flocker-control:persistence:migrate_configuration",
                          [_DEPLOYMENT_FIELD, _UPGRADE_SOURCE_FIELD,
                           _UPGRADE_TARGET_FIELD, ], [])
_LOG_EXPIRE = MessageType(
    u"flocker-control:persistence:lease-expired",
    [Field(u"dataset_id", unicode), Field(u"node_id", unicode)],
Exemplo n.º 20
0
    return loads(data, object_hook=decode)


def to_unserialized_json(obj):
    """
    Convert a wire encodeable object into structured Python objects that
    are JSON serializable.

    :param obj: An object that can be passed to ``wire_encode``.
    :return: Python object that can be JSON serialized.
    """
    return _cached_dfs_serialize(obj)


_DEPLOYMENT_FIELD = Field(u"configuration", to_unserialized_json)
_LOG_STARTUP = MessageType(u"flocker-control:persistence:startup",
                           [_DEPLOYMENT_FIELD])
_LOG_SAVE = ActionType(u"flocker-control:persistence:save",
                       [_DEPLOYMENT_FIELD], [])

_UPGRADE_SOURCE_FIELD = Field.for_types(
    u"source_version", [int], u"Configuration version to upgrade from.")
_UPGRADE_TARGET_FIELD = Field.for_types(
    u"target_version", [int], u"Configuration version to upgrade to.")
_LOG_UPGRADE = ActionType(u"flocker-control:persistence:migrate_configuration",
                          [
                              _DEPLOYMENT_FIELD,
                              _UPGRADE_SOURCE_FIELD,
                              _UPGRADE_TARGET_FIELD,
                          ], [])
Exemplo n.º 21
0
        :param callable operation: A function to be applied to an evolver of
             the object at ``path``
        :returns: ``self``
        """
        target = self._root
        for segment in path:
            target = _get_or_add_proxy_child(target, segment)
        operation(target)
        return self

    def commit(self):
        return self._root.commit()


TARGET_OBJECT = Field(
    u"target_object", repr,
    u"The object to which the diff was applied."
)
CHANGES = Field(
    u"changes", repr,
    u"The changes being applied."
)

DIFF_COMMIT_ERROR = MessageType(
    u"flocker:control:Diff:commit_error",
    [TARGET_OBJECT, CHANGES],
    u"The target and changes that failed to apply."
)


@implementer(_IDiffChange)
class Diff(PClass):
Exemplo n.º 22
0
    Converence loop FSM outputs.
    """
    # Store AMP client, desired configuration and cluster state for later
    # use:
    STORE_INFO = NamedConstant()
    # Start an iteration of the covergence loop:
    CONVERGE = NamedConstant()
    # Schedule timeout for sleep so we don't sleep forever:
    SCHEDULE_WAKEUP = NamedConstant()
    # Clear/cancel the sleep wakeup timeout:
    CLEAR_WAKEUP = NamedConstant()
    # Check if we need to wakeup due to update from AMP client:
    UPDATE_MAYBE_WAKEUP = NamedConstant()


_FIELD_CONNECTION = Field(u"connection", repr,
                          u"The AMP connection to control service")

_FIELD_LOCAL_CHANGES = Field(u"local_changes", to_unserialized_json,
                             u"Changes discovered in local state.")

LOG_SEND_TO_CONTROL_SERVICE = ActionType(
    u"flocker:agent:send_to_control_service",
    [_FIELD_CONNECTION, _FIELD_LOCAL_CHANGES], [],
    u"Send the local state to the control service.")

_FIELD_CLUSTERSTATE = Field(
    u"cluster_state", to_unserialized_json,
    u"The state of the cluster, according to control service.")

_FIELD_CONFIGURATION = Field(
    u"desired_configuration", to_unserialized_json,
Exemplo n.º 23
0
            return pmap(dictionary[u"values"])
        elif class_name == u"UUID":
            return UUID(dictionary[u"hex"])
        elif class_name == u"datetime":
            return datetime.fromtimestamp(dictionary[u"seconds"], UTC)
        elif class_name in _CONFIG_CLASS_MAP:
            dictionary = dictionary.copy()
            dictionary.pop(_CLASS_MARKER)
            return _CONFIG_CLASS_MAP[class_name].create(dictionary)
        else:
            return dictionary

    return loads(data, object_hook=decode)


_DEPLOYMENT_FIELD = Field(u"configuration", repr)
_LOG_STARTUP = MessageType(u"flocker-control:persistence:startup",
                           [_DEPLOYMENT_FIELD])
_LOG_SAVE = ActionType(u"flocker-control:persistence:save",
                       [_DEPLOYMENT_FIELD], [])

_UPGRADE_SOURCE_FIELD = Field.for_types(
    u"source_version", [int], u"Configuration version to upgrade from.")
_UPGRADE_TARGET_FIELD = Field.for_types(
    u"target_version", [int], u"Configuration version to upgrade to.")
_LOG_UPGRADE = ActionType(u"flocker-control:persistence:migrate_configuration",
                          [
                              _DEPLOYMENT_FIELD,
                              _UPGRADE_SOURCE_FIELD,
                              _UPGRADE_TARGET_FIELD,
                          ], [])
Exemplo n.º 24
0
)
from eliot import (
    Field,
    ActionType,
)

PathEntry = namedtuple('PathEntry', 'size mtime_ns ctime_ns version last_uploaded_uri '
                                    'last_downloaded_uri last_downloaded_timestamp')

PATHENTRY = Field(
    u"pathentry",
    lambda v: None if v is None else {
        "size": v.size,
        "mtime_ns": v.mtime_ns,
        "ctime_ns": v.ctime_ns,
        "version": v.version,
        "last_uploaded_uri": v.last_uploaded_uri,
        "last_downloaded_uri": v.last_downloaded_uri,
        "last_downloaded_timestamp": v.last_downloaded_timestamp,
    },
    u"The local database state of a file.",
    validateInstanceOf((type(None), PathEntry)),
)

_INSERT_OR_UPDATE = Field.for_types(
    u"insert_or_update",
    [unicode],
    u"An indication of whether the record for this upload was new or an update to a previous entry.",
    validateSetMembership({u"insert", u"update"}),
)

UPDATE_ENTRY = ActionType(
Exemplo n.º 25
0
)
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)


class ServerResponseMissingElementError(Exception):
    """
    Output the invalid server response if a response does not contain an
Exemplo n.º 26
0
"""
Eliot field, message, and action definitions for ZKAPAuthorizer.
"""

from __future__ import (
    absolute_import, )

from eliot import (
    Field,
    MessageType,
    ActionType,
)

PRIVACYPASS_MESSAGE = Field(
    u"message",
    unicode,
    u"The PrivacyPass request-binding data associated with a pass.",
)

PASS_COUNT = Field(
    u"count",
    int,
    u"A number of passes.",
)

GET_PASSES = MessageType(
    u"zkapauthorizer:get-passes",
    [PRIVACYPASS_MESSAGE, PASS_COUNT],
    u"Passes are being spent.",
)
Exemplo n.º 27
0
    u"The filecap from which the previous version of this file was downloaded.",
)

LAST_DOWNLOADED_TIMESTAMP = Field.for_types(
    u"last_downloaded_timestamp",
    [float, int, long],
    u"(XXX probably not really, don't trust this) The timestamp of the last download of this file.",
)

PATHINFO = Field(
    u"pathinfo",
    lambda v: None if v is None else {
        "isdir": v.isdir,
        "isfile": v.isfile,
        "islink": v.islink,
        "exists": v.exists,
        "size": v.size,
        "mtime_ns": v.mtime_ns,
        "ctime_ns": v.ctime_ns,
    },
    u"The metadata for this version of this file.",
    validateInstanceOf((type(None), PathInfo)),
)

INOTIFY_EVENTS = Field(
    u"inotify_events",
    humanReadableMask,
    u"Details about a filesystem event generating a notification event.",
    validateInstanceOf((int, long)),
)

MAYBE_NOTIFY = ActionType(
Exemplo n.º 28
0
)
RUN_ERROR_MESSAGE = MessageType(
    message_type="flocker.common.runner:run:stderr",
    fields=[
        Field.for_types(u"line", [bytes], u"The error."),
    ],
    description=u"A line of command stderr.",
)

# Logging for the scp, upload, and download functions
SCP_ACTION = ActionType(
    action_type="flocker.common.runner:scp",
    startFields=[
        Field.for_types(u"username", [bytes], u"SSH username."),
        Field.for_types(u"host", [bytes], u"SSH hostname."),
        Field(u"remote_path", lambda f: f.path, u"Remote path."),
        Field(u"local_path", lambda f: f.path, u"Local path."),
        Field.for_types(u"port", [int], u"SSH port."),
        Field(u"identity_file", lambda f: f and f.path, u"SSH identity file."),
    ],
    successFields=[],
    description="An SCP operation.",
)
SCP_OUTPUT_MESSAGE = MessageType(
    message_type="flocker.common.runner:scp:stdout",
    fields=[
        Field.for_types(u"line", [bytes], u"The output."),
    ],
    description=u"A line of command output.",
)
SCP_ERROR_MESSAGE = MessageType(
Exemplo n.º 29
0
URL = Field.for_types("url", [bytes, unicode], u"The request URL.")
METHOD = Field.for_types("method", [bytes, unicode], u"The request method.")

NOVA_CLIENT_EXCEPTION = MessageType(
    u"flocker:node:agents:blockdevice:openstack:nova_client_exception",
    [CODE, MESSAGE, DETAILS, REQUEST_ID, URL, METHOD],
)

RESPONSE = Field.for_types("response", [bytes, unicode], u"The response body.")

KEYSTONE_HTTP_ERROR = MessageType(
    u"flocker:node:agents:blockdevice:openstack:keystone_http_error",
    [CODE, RESPONSE, MESSAGE, DETAILS, REQUEST_ID, URL, METHOD],
)

LOCAL_IPS = Field(u"local_ips", repr,
                  u"The IP addresses found on the target node.")

API_IPS = Field(u"api_ips", repr,
                u"The IP addresses and instance_ids for all nodes.")

COMPUTE_INSTANCE_ID_NOT_FOUND = MessageType(
    u"flocker:node:agents:blockdevice:openstack:compute_instance_id:not_found",
    [LOCAL_IPS, API_IPS],
    u"Unable to determine the instance ID of this node.",
)

CINDER_LOG_HEADER = u'flocker:node:agents:blockdevice:openstack'

# ActionType used by OpenStack storage driver.
OPENSTACK_ACTION = ActionType(
    CINDER_LOG_HEADER, [OPERATION], [],
Exemplo n.º 30
0
    def validator(v):
        if not isinstance(v, t):
            raise ValidationError("{} not an instance of {}".format(v, t))

    return validator


RELPATH = Field.for_types(
    u"relpath",
    [str],
    u"The relative path of a file in a magic-folder.",
)

ABSPATH = Field(
    u"abspath",
    lambda fp: fp.path,
    u"The absolute path of a file in a magic-folder.",
    validateInstanceOf(FilePath),
)

VERSION = Field.for_types(
    u"version",
    [int],
    u"The version of the file.",
)

LAST_UPLOADED_URI = Field.for_types(
    u"last_uploaded_uri",
    [str, bytes, None],
    u"The filecap to which this version of this file was uploaded.",
)