To be efficient in programming using Orchestrator plugins, one needs to know how to work with the Orchestrator API. In this recipe, we showcase how to access and get information from the Orchestrator API.
We will split this recipe into several sections.
The first step is to have a look at the API. To access the API, follow these steps:
The API Explorer opens, and you have four sections, as marked in the preceding screenshot:
virtualmachine
, as well as select what kinds of results you are afterThis part will showcase how the Orchestrator API can help us program. In this showcase, we will begin to write a program similar to the one that we will create in the recipe Working with mails in Chapter 9, Essential Plugins. Please note that this is only a showcase and won't result in a working program:
mailclient
in the pop-up search window.MailClient
object in the API tree:
MailClient()
constructor (the C symbol) and select Copy. If there is no dedicated constructor, you can always copy the object (the green circle) directly.MailClient
object. See the preceding screenshot. This will create an instance of the MailClient
type and assign it to the myMailClient
variable.connect()
method. In the detail area underneath, you will see details for this command, such as what inputs are needed and of what type. The method needs a host, a port, a username, and a password.connect()
method as you did in steps 8 and 9 into a new line in the scripting area. Orchestrator automatically fills in some parts, and the new line will look like this:connect(?String_host , ?number_port , ?String_username , ?String_password)
MailClient
object we created in step 9. Just add myMailClient
before connect
with a period between them. This will enact the method connect
on the MailClient
instance. The result will look like this:myMailClient.connect(?String_host , ?number_port , ?String_username , ? String_password).
?names
) with either Orchestrator variables or values. Replace the first placeholder, ?String_host
, with a mail host address, such as mail.mylab.local
.?number_port
placeholder a bit differently. Insert a new line above the connect line.getDefaultPort
. You will see that it is an action in the module called com.vmware.libary.mail
and needs the input of a type string
(a protocol name). Its return value is a number
(the port). If you like, take a look at the action itself and its script. This will help you understand how it works and what input it requires.System.getModule("com.vmware.library.mail").getDefaultPort(protocol)
var port =
before System.getModule
.protocol
with imap
. This will save the default port for IMAP into the variable port
.?number_port
placeholder in the connect line with the port
variable.string
called userName
.?String_username
placeholder with userName
. Notice the color change of userName
when it matches the in-parameter.At this stage, we leave the showcase, as we have explored the interesting parts. Your little script should look something like this:
var myMailClient = new MailClient(); var port = System.getModule("com.vmware.library.mail").getDefaultPort("imap"); myMailClient.connect("192.168.220.4" , port , userName, ?String_password);
The full working script can be found in the recipe Working with mails in Chapter 9, Essential Plugins.
The Orchestrator API contains all types, methods, attributes, objects, and so on that can be used for programming. All the content comes from Orchestrator or its plugins and gives the Orchestrator programmer a wide range of tools to use.
As you can see in the preceding showcase, the items in the API are color-coded; the following table shows you all the item colors along with a short description of their meaning:
Icon |
Name |
Usage |
Gray bullet |
Type |
Types are complex variables. |
Purple bullet |
Function set |
A set of functions that centers on certain topics, for instance, the |
Blue bullet |
Primitive |
A primitive is a basic variable type. These are array, function, number, object, secure string, string, Boolean, and char. String and array contain methods. |
Green bullet |
Object |
Objects contain attributes, constructors, and methods. |
Gray and blue gear |
Module |
Modules contain actions. We worked with actions and modules in the recipe Creating actions in this chapter. |
Color icons |
SDKModule |
SDKModule is part of the plugins and contains types and objects. |
C-shaped icon |
Constructor |
A constructor creates a new entity of a given type. Sometimes, there is no constructor; in this case, you can try to copy and paste the parent object. |
Empty square |
Attribute |
An attribute is a property of an object; it can be either read-only or read-write. |
Filled square |
Method |
The function (action) that is implemented with the object and acts on the object. |
In the recipe Working with the vCenter API (to change a VM's HA settings) in Chapter 12, Working with Vsphere, we will explore the vCenter API integration in Orchestrator.