Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
"""
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):
"""
A ``_IDiffChange`` that is simply the serial application of other diff
changes.
operated on.
: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)
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``.
:param predicate: Callable returning termination condition.
:type predicate: 0-argument callable returning a Deferred.
:param steps: An iterable of delay intervals, measured in seconds.
If not provided, will default to retrying every 0.1 seconds forever.
:raise LoopExceeded: If given a finite sequence of steps, and we exhaust
],
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",
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))
self.code = code
class NotFound(Exception):
"""
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))
self.code = code
class NotFound(Exception):
"""
Result was not found.
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.
return u"flocker:route:" + name
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.")
"""
This module defines the Eliot log events emitted by the API implementation.
"""
from eliot import Field, ActionType
__all__ = [
"JSON_REQUEST",
"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"JSON, either request or response depending on context.")
RESPONSE_CODE = Field.forTypes(
u"code", [int],
u"The response code for the request.")
# It would be nice if RESPONSE_CODE was in REQUEST instead of
# JSON_REQUEST; see FLOC-1586.
REQUEST = ActionType(
LOG_SYSTEM + u":request",
[REQUEST_PATH, METHOD],
[],
u"dataset is attached.",
)
BLOCK_DEVICE_ID = Field(
u"block_device_id",
lambda id: unicode(id),
u"The unique identifier if the underlying block device."
)
BLOCK_DEVICE_SIZE = Field(
u"block_device_size",
identity,
u"The size of the underlying block device."
)
BLOCK_DEVICE_COMPUTE_INSTANCE_ID = Field(
u"block_device_compute_instance_id",
identity,
u"An identifier for the host to which the underlying block device is "
u"attached.",
)
BLOCK_DEVICE_PATH = Field(
u"block_device_path",
lambda path: path.path,
u"The system device file for an attached block device."
)
CREATE_BLOCK_DEVICE_DATASET = ActionType(
u"agent:blockdevice:create",
[DATASET, MOUNTPOINT],
[],