await/asyncmechanics, to increase code execution efficiency.
worker()function is specified, which will be called by the high-level library engine for each provider, to iterate over the work commands and send the commands to the Provider. This function (representing the task-based execution model) receives:
WorkContextobject, which is used to construct the commands (which is common to both the task-based API and the services' one),
Taskobjects which specify individual parts of the batch process to be executed (specific to the task-based API).
new_script()is called on the
WorkContextinstance to create a
Scriptobject to hold our execution script.
run()method is called on the
Scriptinstance to build a command to issue a
bashstatement on a remote VM. This call builds a RUN command. Note that we're saving a handle to its future result (which is an async awaitable that will be filled with the actual result later).
yieldstatement then sends the prepared script to the caller of the
worker()method, which effectively passes it for execution by the provider.
runcommand and the
yieldstatement return awaitable objects wrapping the results. Those
Futureobjects can be awaited upon to obtain the response for a specific command or for the whole script respectively, which can be processed further. The
worker()execution for this specific provider halts until the generated work command gets processed.
Scriptis a facade which exposes APIs to build various commands. Some useful methods are listed below:
send_*(), these are utility methods which allow for convenient transfer and conversion of remote content into local files, bytes or JSON objects.