Callback¶
Callbacks allow users to run some command when a particular event occurs. These callbacks are typically used for notification purposes.
The following callback events are supported:
|
|
|
The following PixStor variables are available to use as callback parameters:
|
|
|
|
If you want to use PixStor variables (as listed above) with a Python function callback, they can be passed with the ‘parms’ keyword as normal, e.g.
>>> def logger(msg):
... ...
>>>
>>> Callback(command=logger, parm=['%eventNode'])
Or they can be specified as part of the function definition, in which case they don’t need to be passed seperately, e.g.
>>> def logger(eventNode):
... ...
>>>
>>> Callback(command=logger)
Warning
Callback scripts and functions are run as root.
Description¶
-
class
arcapix.fs.gpfs.callback.
Callback
(callbackId, command=None, event=None, **kwargs)¶ A callback is an executable that is triggered by some event
Parameters: - callbackId – An identifier for the callback
- command – Path to an executable, or some Python callable, that the callback should run.
- event – An event or list of events that should trigger the callback
- parms – List of parameters to be passed to the command. These can include GPFS variables.
- node – A node or list of nodes on which the callback should be installed (default=all)
Note
A callback executable should be installed on all nodes on which the callback could be triggered, and its path should be fully qualified.
-
command
¶ Returns the path to the callback script or the Python callable
Return type: str Return type: callable
-
script
¶ Resturns the script that the callback runs.
If the callback is Python callable-based the ArcaPix callback driver script will be returned
Return type: str
-
function
¶ Resturns the function that the callback runs.
If the callback is script-based a wrapper function that calls the script will be returned
Return type: callable
-
events
¶ Returns a list of events that trigger the callback
Return type: list of str
-
nodes
¶ Returns a list of nodes that the callback is installed on
Return type: list of str
-
parms
¶ Returns a list of command parameters
Doesn’t include implicit parms from callable-based callbacks
Return type: list of str
-
onError
¶ Action to take if callback command fails.
Can be one of [continue, quorumLoss, shutdown].
Default: ‘continue’ Return type: str
-
validate
()¶ Tries to pre-catch issues before they are sent to GPFS.
This is faster, and less destructive than relying on GPFS to catch errors. This can make debugging easier.
-
create
()¶ Install the callback on GPFS
-
delete
()¶ Deletes the callback from GPFS
-
add
(**kwargs)¶ Add extra events or nodes to the callback
Parameters: - events – list of events (names) which should trigger the callback
- nodes – list of nodes (names) on which the callback should run
-
remove
(**kwargs)¶ Remove events or nodes from the callback
Parameters: - events – list of events (names) which should no longer trigger the callback
- nodes – list of nodes (names) on which the callback should no longer run
-
change
(**kwargs)¶ Change one of the callback’s parameters
Parameters: - nodes – list of nodes (names) on which the callback should run
- events – list of events (names) that should trigger the callback
- parms – list of parameters that should be passed to the callback script
- sync (bool) – Specifies whether GPFS will wait for the user program to complete (default=False)
- timeout – If sync=True, timeout is how long GPFS will wait for the user program to complete (in seconds)
- onerror – Action to take if callback command fails. One of: ‘continue’, ‘quorumLoss’, ‘shutdown’. (default=’continue’)
- priority (float) – Determines the order in which callbacks run. Smallest runs first. (default=lowest priority)
Examples¶
Create a new callback¶
>>> from arcapix.fs.gpfs import Callback
>>>
>>> # Instantiate a callback object
... mycallback = Callback("test1", "/tmp/myscript.sh", "startup")
>>>
>>> # Install on cluster
... mycallback.create()
>>>
Create a new callback on a node¶
>>> from arcapix.fs.gpfs import Node
>>>
>>> # Instantiate a node
... local = Node("localhost")
>>>
>>> # Create shutdown callback
... local.onShutdown.new("/home/auser/callbacks/notify.sh", callbackId="local_sd", params=["%eventNode"])
>>>
Create a shutdown log for all nodes on a cluster¶
>>> from arcapix.fs.gpfs import Cluster
>>> from time import strftime, localtime
>>>
>>> # Define a logging function
... def logger(eventNode):
... with open("/tmp/shutdown.log", 'a') as log
... out = "{0} shutdown as {1}\n".format(eventNode, strftime("%H:%M:%S, %a %d %b %Y", localtime()))
... log.write(out)
... return out
>>>
>>> # Create shutdown callback
... Cluster().onShutdown.new(logger)
>>>