4.1

Table Of Contents
Handle Enumeration Types
The following JavaScript example allows Orchestrator to use scripting to handle vCenter Server enumerations
through the vCenter Server plug-in.
// a VcSharesLevel FINDER ENUMERATION TYPE, for example
// received from an input parameter
var sharesLevel = ...
// get the String value of the FINDER ENUMERATION TYPE
var sharesLevelString = sharesLevel.value;
// Assign to a DataObject
var sharesInfo = new VcSharesInfo();
sharesInfo.level = sharesLevel;
Discover Host Machines and Virtual Machines
The following JavaScript example allows Orchestrator to use scripting to find host machines and virtual
machines through the vCenter Server plug-in.
var sdkConnections = VcPlugin.allSdkConnections;
System.log(sdkConnections.length + " SdkConnections found");
for (var i = 0; i < sdkConnections.length; i++) {
var sdkConnection = sdkConnections[i];
System.log("SdkConnection '" + sdkConnection.id + "'");
// Hierarchy entry point
var rootFolder = sdkConnection.rootFolder;
// Get the property 'name'
var name = rootFolder.name;
System.log("--- Root folder '" + name + "'");
// Get the folder's data centers
var datacenters = rootFolder.datacenter;
if (datacenters != null) {
for (var j = 0; j < datacenters.length; j++) {
var datacenter = datacenters[j];
System.log("--- Datacenter '" + datacenter.id + "'");
}
}
// Method to get all the virtual machines in a vCenter Server host
var vms = sdkConnection.getAllVirtualMachines();
if (vms != null) {
for (var j = 0; j < vms.length; j++) {
var vm = vms[j];
System.log("--- VM '" + vm.id + "'");
System.log("--- VM '" + vm.name + "'");
var guestInfo = vm.guest;
System.log("--- VM guestInfo '" + guestInfo + "'");
if (guestInfo != null) {
System.log("--- VM guestInfo.guestFamily '" + guestInfo.guestFamily + "'");
Chapter 4 Scripting
VMware, Inc. 125