netdef.Shared package¶
Internal¶
-
class
netdef.Shared.Internal.
Statistics
[source]¶ Bases:
object
A singleton class to store statistics as key-value pair. Can be turned off for performance or security.
Can be imported from Rules, Controllers and Expressions.
Example:
import psutil from netdef.Shared.Internal import Statistics from netdef.Sources.SystemMonitorSource import bytes2human if Statistics.on: uss = psutil.Process().memory_full_info().uss Statistics.set("process.memory.startup", bytes2human(uss))
-
on
= True¶
-
statistics
= {}¶
-
Shared¶
-
class
netdef.Shared.Shared.
Shared
(identifier, install_path, proj_path, default_config_string)[source]¶ Bases:
object
Shared memory for the application. This is the class of the shared instance that is passed to all controllers, rules, engines and expressions. You will use this class to read configs, get message queues etc.
Parameters: - identifier (str) – a unique identifier for this app.
- install_path (str) – Full filepath to application package location
- proj_path (str) – Full filepath to project location
- default_config_string (str) – initial config text for
SharedConfig.Config
SharedConfig¶
-
class
netdef.Shared.SharedConfig.
Config
(identifier, install_path, proj_path, default_config_string, read_from_files=True)[source]¶ Bases:
object
A wrapper class for the configparser module in standard python library.
Parameters: - identifier (str) – a unique identifier for this app.
- install_path (str) – Full filepath to application package location
- proj_path (str) – Full filepath to project location
- default_config_string (str) – initial config text for configparser
SharedExpressions¶
SharedQueues¶
-
class
netdef.Shared.SharedQueues.
MessageType
[source]¶ Bases:
enum.Enum
An enumeration.
-
ADD_PARSER
= 6¶ Instruct the controller to use the given source class as a parser
-
ADD_SOURCE
= 2¶ Instruct the controller to update the given source’s value from external datasource
-
APP_STATE
= 9¶ Inform the controller of application state
-
READ_ALL
= 1¶ warning: Not implemented yet
-
READ_SOURCE
= 3¶ warning: Not implemented yet
-
REMOVE_SOURCE
= 7¶ warning: Not implemented yet
-
RUN_EXPRESSION
= 5¶ Instruct the rule or engine to execute the given expression’s function
-
TICK
= 8¶ Instruct the controller to send a reply
-
WRITE_SOURCE
= 4¶ Instruct the controller to update external datasource from the given source’s value
-
-
class
netdef.Shared.SharedQueues.
AppStateType
[source]¶ Bases:
enum.Enum
An enumeration.
-
RUNNING
= 2¶
-
SETUP
= 1¶
-
-
class
netdef.Shared.SharedQueues.
SharedQueues
(maxsize=0)[source]¶ Bases:
object
Message queues for all controllers, rules and the engine
-
run_expressions_in_engine
(source_instance, expressions, value, source_time, status_code)[source]¶ Send a RUN_EXPRESSION message to the engine.
Parameters: - source_instance – the source that triggered given expressions
- expressions (list) – list of expressions
-
run_expressions_in_rule
(source_instance)[source]¶ Send a RUN_EXPRESSION message to given rule.
Parameters: source_instance – the source
-
send_message_to_controller
(messagetype, controllername, message_object)[source]¶ Send a message to given controller
Parameters: - messagetype (self.MessageType) –
- controllername (str) –
- message_object – usually a source instance. can also be a tuple.
-
send_message_to_engine
(messagetype, message_object)[source]¶ Send a message to the engine
Parameters: - messagetype (self.MessageType) – probably MessageType.RUN_EXPRESSION
- message_object – usually a source instance.
-
send_message_to_rule
(messagetype, rule_name, message_object)[source]¶ Send a message to given rule
Parameters: - messagetype (self.MessageType) –
- rule_name (str) –
- message_object – usually a source instance.
-
send_running_state_to_controller
(controllername)[source]¶ Send a APP_STATE message to given controller
Parameters: controllername – the controller
-
SharedSources¶
-
class
netdef.Shared.SharedSources.
SharedSources
[source]¶ Bases:
object
classes
contain a dict (classes.items
) with uninitiated sources classes. (key is name from config, value is class) Used by rules when parsing config files and finding the right source.instances
contains a list of all sources (instances.items
) instances created by the rules.-
classes
= <netdef.Shared.SharedSources.SourceClasses object>¶
-
instances
= <netdef.Shared.SharedSources.SourceInstances object>¶
-