Chapter 7. $evm and the Workspace
When we write automation scripts, we access the Automation Engine and all of its objects through a single
$evm variable.1 This is sometimes referred to as the workspace.
As discussed in Chapter 6, the
$evm variable is a
DRb::DRbObject object representing a dRuby client connection back to the Automation Engine. The object at the dRuby server side of our
$evm variable is an instance of an
MiqAeService object, which contains over 40 methods. In practice we generally use only a few of these methods, most commonly:
$evm.root $evm.object $evm.current (this is equivalent to calling $evm.object(nil)) $evm.parent $evm.log $evm.vmdb $evm.execute $evm.instantiate
We will look at these methods in more detail in the next sections.
$evm.log is a simple method that we’ve used already. It writes a message to automation.log and accepts two arguments: a log level and the text string to write. The log level can be written as a Ruby symbol (e.g.,
:warn), or as a text string (e.g.,
$evm.root, illustrated in Figure 7-1, is the method that returns to us the root object in the workspace (environment, variables, linked objects, etc.). This is the instance whose invocation took us into the Automation Engine. From
$evm.root we can access other service model objects, such as
$evm.root['miq_request'] (the actual objects available depend on the context of the Automate tasks that we are performing). ...