Call a jobsengine function and returns the result or None in case of error
Create a blank file if it doesn’t exist, delete the content if the file exist
Downloads the file with the url url to the target place at the file system. If you need html authentication, you may use webuser and webpass.
This function will be take care of the upstream proxy settings.
Parameters: |
|
---|
Returns true if the file exist.
Reads a configuration file and returns a hash
Return the ammount of free memory in Kb
Returns a dict with the upstream proxy settings of the fw.
Returns: | Dict with upstream proxy settings. |
---|---|
Return type: | dict |
Return the total ammount of memory in Kb
Exec an external command and returns the output as a string
Execute an external command and return a tuple (status, output). For compatibility with ‘commands.getstatusoutput’, a trailing newline is stripped from the output.
Parameters: | command_line (string) – The command line to be executed |
---|---|
Returns: | A tuple (status, output) The returned output will contain output and/or error messages. A trailing newline is stripped from the output. |
Return type: | tuple |
Checks if addr is and IP address
Parameters: | addr (string) – address to check |
---|---|
Returns: | True if the string is valid IP address |
Return type: | boolean |
Checks if addr is a MAC address
Parameters: | addr (string) – address to check |
---|---|
Returns: | True if the string is valid MAC address |
Return type: | boolean |
Checks if addr is a valid domain
Parameters: | addr (string) – address to check |
---|---|
Returns: | True if the string is valid domain |
Return type: | boolean |
Send a command to the monit daemon.
Parameters: |
|
---|---|
Returns: | The string return by monit or the exit status of the operation as number. For the ‘status’ command: 0 = running, 1 = not running |
Return type: | String or Number |
Read the content of a file into a string
Parameters: |
|
---|---|
Returns: | the file content as a single string or as a list of strings (one for each line) |
Return type: | a string or a list of strings |
Removes all the files that does not match exclude from a path. If the remove_directories parameter is True, remove also the directories. Roughly equivalent to find . ! -type d -exec rm -f – {} or find . ! -exec rm -f – {}
Equivalent to rm -f expression, e.g. rm -f /var/run/*.pid
Equivalent to rm -rf
Creates a settingsfile in /var/lib/efw/<service>/settings.<callingservice> with <key>=on whose purpose is to enable another service because callingservice needs it running.
Parameters: |
|
---|
Exec an external command.
Create a backup of a configuration file (filename<separator>old).
Send an internal cmd to the engine and wait for the response
Set each key to true
Writes down the SettingsFile object ‘config’ to the file ‘filename’ On success returns True otherwise False.
transforms ‘’‘value’‘’ to a boolean value.
In order to return True, ‘’‘value’‘’ may be one of (case insensitive) ‘on’, 1, ‘1’, True, ‘enabled’
If the value does not correspond to True or False, for example ‘’ or None, the value of ‘’‘default’‘’ will be returned, which is False if not specified.
Parameters: |
|
---|---|
Returns: | corresponding boolean value of ‘’‘value’‘’ |
Return type: | boolean |
Sets the modification and access times of file to the current time of day or create a file with default permissions if it doesn’t exist.
Removes settingsfile /var/lib/efw/<service>/settings.<callingservice> which causes that the service <service> is no longer required to be enabled because of service <callingservice>.
After calling this method it does not automatically mean that <service> is disabled!
Parameters: |
|
---|
Write the configuration with a cheetah template
Parameters: |
|
---|---|
Params config_values: | |
list which contains dictionaries or one dictionary which holds the value which substitutes the keys of the template |
|
Returns: | a boolean which informs if the config has changed |
Return type: | boolean |
Write a string to a file
Parameters: |
|
---|
Bases: object
Bases: object
This method is called by engine_job._fire_action to execute the action.
Check the satisfaction of the dependencies and emit the dependencies requests
Check if an action is fireable and fire the action or emit the dependencies requests
Return True if the action is fireable
Bases: object
Functions are job method executed synchronously.
Execute the function an return the result
Return an help message for this function
Bases: object
Bases: endian.job.engine_actions.InternalAction
This action is executed when a job failed (more precisely when ‘change_status(sub:err)’ is received)
Remove all the temporary handlers (installed for the dependencies) of the job This action is invoked when is received the following event:
e.g: change_status(status:, sub:err, name:)
job_a – depends on –> job_b job_b – depends on –> job_c
the job_c failed -> emit ‘change_status(status:start,sub:err,name:job_c)’ this action is executed:
we have to change status of job_b to ‘err’, and emit and event ‘change_status(status:start,sub:err,name: job_b)’
(and then it is executed again)
Bases: endian.job.engine_actions.InternalAction
This action reload all the jobs and the loaded modules It is executed when the event “event(msg:reload_jobs)” is received
Bases: endian.job.engine_actions.InternalAction
This handler run the triggers in the /etc/rc.d/event_<event name>.d directory (e.g ‘/etc/rc.d/event_startup.d’) when the event <evnet name> is received
Send a cmd to the engine and wait for the response
Send a query to the engine and wait for the response. If ‘single_result’ is True, return a single Fact instance (if any) or None else return a FactBase instance.
1 2 3 4 5 6 7 | facts = send_query_to_engine("action")
for fact in facts:
job = fact.get_value('job')
name = fact.get_value('name')
print job, name
for key, option in fact['options'].iteritems():
print " %s type: %s description: %s " % (key, option.get_value('type'), option.get_value('description'))
|
Bases: object
Add a new engine job
Parameters: | job (EngineJob) – a job |
---|
Start/stop jobs autoreloading
Add a new event to the event queue
Return the events queue as a list of strings.
Return a job by its name
Parameters: | name (string) – job’s name |
---|---|
Returns: | returns a job or None |
Return type: | EngineJob |
Return a job by its pid
Parameters: | pid (int) – job’s pid |
---|---|
Returns: | returns a job or None |
Return type: | EngineJob |
Return the jobs list as a list of string
Parameters: |
|
---|
Load (or reload) engine jobs from the packages in self._packages_names
Parameters: | force_modules_import (boolean) – if true, don’t use the the modules cache |
---|
Store a message in the jobsengine’s message list
Parameters: | msg (string) – a messagems formatted as: JOBNAME-SEVERITY-Message text e.g. HOSTNAME-I-Start |
---|
Store a request (i.e. an emit/start/stop/restart command sent to the jobsengine) on the job requests log file
Parameters: | cmd – a command, e.g. ‘restart ssh’ |
---|
Reload all the reloadable modules
Load the fact base and, if restore_status is True, the jobs status from a file
Save the jobs status in a file
Bases: object
Use this class to remotely control jobsengine
Return ture if connected, false otherwise (check if the ssh process is alive)
Exec a single jobsengine remote command on a target host and returns the command response.
Send a query to the engine and wait for the response. If ‘single_result’ is True, return a single Fact instance (if any) or None else return a FactBase instance.
Force the child process to terminate
Bases: exceptions.Exception
Exec a single jobsengine remote command on a target host. Dont’ raise exception but returns the errors a string, eg: 592 Error sending cmd to jobsengine: [Errno 5] Input/output error
Send a query to the engine and wait for the response. If ‘single_result’ is True, return a single Fact instance (if any) or None else return a FactBase instance.
Bases: dict
Prolog-like fact, i.e. a predicate followed by an optional list of attributes Example:
a_fact
emit(signal:startup)
service(job:ssh, status:start)
Fact arguments can be underscores, which will match anything. Example:
service(job:ssh, status: _) matches service(job:ssh, status:start)
Return the value of an attribute as a ‘basic’ value, e.g. a string, int, float or a boolean If the get_type parameter is presente and the values is not an instance of get_type, try typecast and if fail return the default value If the value is a fact with attributes, return it as a dictionary If include_predicate is True, include the predicate into the dictionary (if the result is dictionary)
True if the fact as attributes
Return True if query match self. Fact arguments can be underscores, which will match anything.
Predicate converted to string
Convert the fact into a dictionary. If include_predicate is True, include the predicate into the dictionary
Bases: object
Prolog-like fact base, more prosaically a set of facts
Assert a new fact
Parameters: | fact (string or Fact) – a fact |
---|
Returns if a fact a fact matching the parameter is ‘inverse in’ the fact base
Parameters: | fact (string or Fact:) – a fact |
---|---|
Returns: | True if the fact is ‘inverse in’ the fact base |
Return type: | boolean |
Returns a list of facts matching the parameter
Parameters: | fact (string or Fact) – a fact |
---|
Returns one of facts matching the parameter or None
Parameters: | fact (string or Fact) – a fact |
---|
Returns a list of facts matching the parameter
Parameters: | fact (string or Fact) – a fact |
---|
Returns one of facts matching the parameter or None
param fact: a fact type fact: string or Fact
Retract (remove) a single fact that matches the argument, raise a KeyError if the fact is not present in the fact base
Parameters: | fact (string or Fact) – a fact |
---|
Retract (remove) a single fact that matches the argument
Parameters: | fact (string or Fact) – a fact |
---|
Retract (remove) all facts that match the argument
Parameters: | fact (string or Fact) – a fact |
---|
Bases: object
A set of facts with the same predicate (i.e. of the same type)
Assert a new fact
Parameters: | fact (string or Fact) – a fact |
---|
Returns if the fact is ‘inverse in’ the table
Parameters: | fact (string or Fact:) – a fact |
---|---|
Returns: | True if the fact is ‘inverse in’ the table |
Return type: | boolean |
Returns a list of facts matching the parameter
Parameters: | fact (string or Fact) – a fact |
---|
Returns one of facts matching the parameter or None
Parameters: | fact (string or Fact) – a fact |
---|
Returns a list of facts matching the parameter
Parameters: | fact (string or Fact) – a fact |
---|
Returns one of facts matching the parameter or None
Parameters: | fact (string or Fact) – a fact |
---|
Retract (remove) a single fact that matches the argument, raise a KeyError if the fact is not present in the fact base
Parameters: | fact (string or Fact) – a fact |
---|
Retract (remove) a single fact that matches the argument
Parameters: | fact (string or Fact) – a fact |
---|
Retract (remove) all facts that match the argument
Parameters: | fact (string or Fact) – a fact |
---|
Bases: object
Log ‘msg % args’ with severity ‘CRITICAL’.
Log ‘msg % args’ with severity ‘DEBUG’.
Send log messages to the jobsengine
Disable sending log messages to the jobsengine
Log ‘msg % args’ with severity ‘ERROR’.
Log ‘msg % args’ with severity ‘INFO’.
Return true if the notification is enabled
Set the logging level.
Log ‘msg % args’ with severity ‘WARNING’.
Log ‘msg % args’ with severity ‘WARNING’.
Redirect log to syslog
Write log to console
Change the process name
Change the current thread name
Return the system monotonic time Monotonic clock cannot be set and represents monotonic time since some unspecified starting point.
Get the current thread ID
Bases: object
Assert a new handler
Parameters: | event (string or Fact) – a fact |
---|
Return true if there is a temp action handler for a given action
Returns a list of handler matching the event sorted by the handler priority or the action priority
Parameters: | event (string or Fact) – a fact |
---|
Remove all the handlers for an action
Remove an handler
Remove all the temporary handlers for a job
Bases: object
>>>>> OBSOLETE - use action annotation with argument ‘use_notifications’ ! <<<<
Use notification annotation
Enable the notification before the method execution and disable it after the execution. If the notification was enabled, does nothing. Use this annotation only on Job subclasses methods.
Usage example:
@use_notifications("serviceName")
def start(self):
self.info("bla, bla, bla")
Action’s annotation
Parameters: |
|
---|
Usage example:
@action(name="start", on="startup", depends=["network"], options={'debug': (bool,"enable debug"), 'force': (bool, "force restart")})
def start(self, options):
self.info("bla, bla, bla")
Exec a job out of the jobsengine context.
Parameters: | cmd (string) – A cmd to be executed, eg. ‘ssh.start’ |
---|
Return the list of modules in a given package. For each module, an Fact instance is returned.
Parameters: |
|
---|---|
Returns: | the list of modules |
Return type: | list of Fact |
Get the JobsEngine compilation date
Bases: object
actions Print the actions list
autoreload [on|off] Enable of disable jobs autoreload
call [sync|async] job.func [args] Exec a function
config var [value] Set (or display) the value of a config var
debug job [on|off] Enable of disable debug on a job
dump Dump the fact base
emit [delayed [sec]] event Emit an event
events Print the events queue
functions Print the functions list
handlers Print the list of the events handlers
info Print jobs engine info
list [ok|err|start|stop|exe|group] Print jobs short status information
log msg Log a message (JOBNAME-SEVERITY-Message text)
messages [raw] Print the last messages
query fact... Query the fact base
request [sync] [delayed [sec]] job.ac [args] Request job action execution
restart [sync] [delayed [sec]] job [args] Restart a job
start [sync] [delayed [sec]] job [args] Start a job
status job Print short status information about a job
stop [sync] [delayed [sec]] job [args] Stop a job
summary Print short status information for each job
threads Print jobsengine threads list
Exec a command and return the commands result as a string
Return true if demo mode is enabled
Bases: threading.Thread
Bases: threading.Thread