Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
from twisted.python.components import proxyForInterface
from eliot import __version__
if tuple(int(part) for part in __version__.split(".")[:2]) < (0, 4):
raise ImportError("eliot version %s is too old for machinist")
from eliot import Field, ActionType, Logger
from ._interface import IFiniteStateMachine, IRichInput
def _system(suffix):
return u":".join((u"fsm", suffix))
FSM_IDENTIFIER = Field.forTypes(
u"fsm_identifier", [unicode],
u"An unique identifier for the FSM to which the event pertains.")
FSM_STATE = Field.forTypes(
u"fsm_state", [unicode], u"The state of the FSM prior to the transition.")
FSM_RICH_INPUT = Field.forTypes(
u"fsm_rich_input", [unicode, None],
(u"The string representation of the rich input delivered to the FSM, "
u"or None, if there was no rich input."))
FSM_INPUT = Field.forTypes(
u"fsm_input", [unicode],
u"The string representation of the input symbol delivered to the FSM.")
FSM_NEXT_STATE = Field.forTypes(
u"fsm_next_state", [unicode],
u"The string representation of the state of the FSM after the transition.")
FSM_OUTPUT = Field.forTypes(
u"fsm_output", [list], # of unicode
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],
[],
U"Flocker is creating a new proxy.")
:return: A :class:`Deferred` firing with the bytes of the result (on
exit code 0), or errbacking with :class:`CommandFailed` or
:class:`BadArguments` depending on the exit code (1 or 2).
"""
endpoint = ProcessEndpoint(reactor, b"zfs", [b"zfs"] + arguments,
os.environ)
d = connectProtocol(endpoint, _AccumulatingProtocol())
d.addCallback(lambda protocol: protocol._result)
return d
_ZFS_COMMAND = Field.forTypes(
"zfs_command", [bytes], u"The command which was run.")
_OUTPUT = Field.forTypes(
"output", [bytes], u"The output generated by the command.")
_STATUS = Field.forTypes(
"status", [int], u"The exit status of the command")
ZFS_ERROR = MessageType(
"filesystem:zfs:error", [_ZFS_COMMAND, _OUTPUT, _STATUS],
u"The zfs command signaled an error.")
def _sync_command_error_squashed(arguments, logger):
"""
Synchronously run a command-line tool with the given arguments.
:param arguments: A ``list`` of ``bytes``, command-line arguments to
execute.
:param eliot.Logger logger: The log writer to use to log errors running the
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"A request was received on the public HTTP interface.")
JSON_REQUEST = ActionType(
LOG_SYSTEM + u":json_request",
:param arguments: A ``list`` of ``bytes``, command-line arguments to
``zfs``.
:return: A :class:`Deferred` firing with the bytes of the result (on
exit code 0), or errbacking with :class:`CommandFailed` or
:class:`BadArguments` depending on the exit code (1 or 2).
"""
endpoint = ProcessEndpoint(reactor, b"zfs", [b"zfs"] + arguments,
os.environ)
d = connectProtocol(endpoint, _AccumulatingProtocol())
d.addCallback(lambda protocol: protocol._result)
return d
_ZFS_COMMAND = Field.forTypes(
"zfs_command", [bytes], u"The command which was run.")
_OUTPUT = Field.forTypes(
"output", [bytes], u"The output generated by the command.")
_STATUS = Field.forTypes(
"status", [int], u"The exit status of the command")
ZFS_ERROR = MessageType(
"filesystem:zfs:error", [_ZFS_COMMAND, _OUTPUT, _STATUS],
u"The zfs command signaled an error.")
def _sync_command_error_squashed(arguments, logger):
"""
Synchronously run a command-line tool with the given arguments.
u"fsm_state", [unicode], u"The state of the FSM prior to the transition.")
FSM_RICH_INPUT = Field.forTypes(
u"fsm_rich_input", [unicode, None],
(u"The string representation of the rich input delivered to the FSM, "
u"or None, if there was no rich input."))
FSM_INPUT = Field.forTypes(
u"fsm_input", [unicode],
u"The string representation of the input symbol delivered to the FSM.")
FSM_NEXT_STATE = Field.forTypes(
u"fsm_next_state", [unicode],
u"The string representation of the state of the FSM after the transition.")
FSM_OUTPUT = Field.forTypes(
u"fsm_output", [list], # of unicode
u"A list of the string representations of the outputs produced by the "
u"transition.")
FSM_TERMINAL_STATE = Field.forTypes(
u"fsm_terminal_state", [unicode],
u"The string representation of the terminal state entered by the the FSM.")
LOG_FSM_INITIALIZE = ActionType(
_system(u"initialize"),
[FSM_IDENTIFIER, FSM_STATE],
[FSM_TERMINAL_STATE],
u"A finite state machine was initialized.")
LOG_FSM_TRANSITION = ActionType(
_system(u"transition"),
[FSM_IDENTIFIER, FSM_STATE, FSM_RICH_INPUT, FSM_INPUT],
[FSM_NEXT_STATE, FSM_OUTPUT],
u"A finite state machine received an input made a transition.")
FSM_IDENTIFIER = Field.forTypes(
u"fsm_identifier", [unicode],
u"An unique identifier for the FSM to which the event pertains.")
FSM_STATE = Field.forTypes(
u"fsm_state", [unicode], u"The state of the FSM prior to the transition.")
FSM_RICH_INPUT = Field.forTypes(
u"fsm_rich_input", [unicode, None],
(u"The string representation of the rich input delivered to the FSM, "
u"or None, if there was no rich input."))
FSM_INPUT = Field.forTypes(
u"fsm_input", [unicode],
u"The string representation of the input symbol delivered to the FSM.")
FSM_NEXT_STATE = Field.forTypes(
u"fsm_next_state", [unicode],
u"The string representation of the state of the FSM after the transition.")
FSM_OUTPUT = Field.forTypes(
u"fsm_output", [list], # of unicode
u"A list of the string representations of the outputs produced by the "
u"transition.")
FSM_TERMINAL_STATE = Field.forTypes(
u"fsm_terminal_state", [unicode],
u"The string representation of the terminal state entered by the the FSM.")
LOG_FSM_INITIALIZE = ActionType(
_system(u"initialize"),
[FSM_IDENTIFIER, FSM_STATE],
[FSM_TERMINAL_STATE],
u"A finite state machine was initialized.")
LOG_FSM_TRANSITION = ActionType(
_system(u"transition"),
[FSM_IDENTIFIER, FSM_STATE, FSM_RICH_INPUT, FSM_INPUT],
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.")