-
Notifications
You must be signed in to change notification settings - Fork 1
Darwin API object
A class used to call Darwin via a Unix socket or a TCP connection handled by HAProxy.
-
FILTER_CODE_MAP (
dict): a dict containing the different filter codes used by Darwin. This dict takes a plugin name as a key, and returns the associated filter code -
DEFAULT_TIMEOUT (
float/None): the default timeout (expressed in seconds). If None is set, no timeout is active -
socket (
socket.socket): the socket instance used to call Darwin - **verbose (
bool): whether to print debug lines or not
__init__(self, socket_type, **kwargs)Create a darwin.DarwinApi instance, either with a Unix or a TCP socket.
-
kwargs-
verbose (
bool): whether to print debug lines or not. If not given, the default value isFalse -
socket_type (
str): the socket type to be used."tcp"or"unix"(case insensitive) -
socket_path (
str): if the socket type given is"unix", this is the socket path which will be used to connect to Darwin -
socket_host (
str): if the socket type given is"tcp", this is the socket host which will be used to connect to Darwin -
socket_port (
int): if the socket type given is"tcp", this is the socket port which will be used to connect to Darwin -
timeout (
float/None): the timeout (expressed in seconds). If not given, the default timeout is set
-
verbose (
get_filter_code(filter_code)Return a filter code from a given filter name. This is case insensitive.
-
filter_name (
str): the name of the filter code (case insensitive)
int: the associated filter code.
call(self,
arguments,
packet_type="other",
response_type="no",
filter_code=DarwinPacket.DARWIN_FILTER_CODE_NO,
**kwargs)Perform an API call to Darwin, and return the result. This function is useful to make higher-level API calls to Darwin, compared to the darwin.DarwinApi.low_level_call method.
-
arguments (
list): the list of arguments to be sent to Darwin. Please note that the arguments will be casted to strings -
packet_type (
str): the packet type to be sent."darwin"for any packet coming from a Darwin filter,"other"for everything else -
response_type (
str): the response type which tells Darwin what it is expected to do."no"to not answer anything,"back"to answer back to us,"darwin"to send the answer to the next filter, and"both"to apply both the"back"and"darwin"response types -
filter_code (
int/str): the filter code to be provided. If a string is given,darwin.DarwinApiwill try to retrieve the filter code associated to it -
kwargs- other keyword arguments can be given. This function uses
darwin.DarwinAPI.low_level_callinternally. For a more advanced use, please refer to thedarwin.DarwinApi.low_level_callmethod documentation
- other keyword arguments can be given. This function uses
int: if the call is synchronous, the Darwin result is returned. If no result are available, None is returned. If the call is asynchronous, the event ID is returned.
bulk_call(self,
data,
packet_type="other",
response_type="no",
filter_code=DarwinPacket.DARWIN_FILTER_CODE_NO,
**kwargs)Perform an API call to Darwin, and return the results or the event ID, depending on wheter the call is asynchronous or not.
-
data (
list): list of arguments to send to Darwin -
packet_type (
str): the packet type to be sent."darwin"for any packet coming from a Darwin filter, `"other" for everything else -
response_type (
str): the response type which tells Darwin what it is expected to do."no"to not answer anything,"back"to answer back to us,"darwin"to send the answer to the next filter, and"both"to apply both the"back"and"darwin"response types -
filter_code (
int/str): the filter code to be provided. If a string is given,darwin.DarwinApiwill try to retrieve the filter code associated to it -
kwargs- other keyword arguments can be given. This function uses
darwin.DarwinAPI.low_level_callinternally. For a more advanced use, please refer to thedarwin.DarwinApi.low_level_callmethod documentation
- other keyword arguments can be given. This function uses
list: the Darwin results stored in a list
low_level_call(self, **kwargs)Perform an API call to Darwin, and return the results.
-
kwargs-
socket_type (
str): the socket type to be used."tcp"or"unix" -
header (
darwin.DarwinPacket): if provided, thedarwin.DarwinPacketheader instance to be sent to Darwin. If no header is given, a header description has to be provided (see the header_descr keyword argument) -
header_descr (
dict): if provided, the Darwin header description to create adarwin.DarwinPacketheader instance, which will be sent to Darwin. Please refer to thedarwin.DarwinPacketclass documentation to know more about Darwin packets creation -
data (
list): the arguments to send to Darwin
-
socket_type (
If the call is synchronous the Darwin results are returned as a dictionary:
-
"certitude_list": the list of certitudes returned by darwin -
"body": the body of the response
If the call is asynchronous, the event ID is returned.
close(self)Close the Darwin socket.