4.0

Table Of Contents
// in a 'Data Object Type'. virtualMachineSnapshotRef is only the reference to the
// 'Managed Object Type' not the object itself
var virtualMachineSnapshotRef = virtualMachineSnapshotInfo.currentSnapshot;
// Convert from ManagedObjectReference to a VimManagedObject.
// The concrete class is VcVirtualMachineSnapshot.
var virtualMachineSnapshot = VcPlugin.toManagedObject(
virtualMachine, virtualMachineSnapshotRef);
// The reverse operation, if required.
//virtualMachineSnapshotInfo.currentSnapshot =virtualMachineSnapshot.reference;
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.name;
// Convert from the String value to a static value of VcSharesLevel
// SCRIPTING TYPE
var level = VcSharesLevel.fromString(sharesLevel.name);
// Assign to a DataObject
var sharesInfo = new VcSharesInfo();
sharesInfo.level = level;
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 vimHosts = VcPlugin.allSdkConnections();
System.log(vimHosts.length + " Vim hosts found");
for (var i = 0; i < vimHosts.length; i++) {
var vimHost = vimHosts[i];
System.log("Vim host '" + vimHost.id + "'");
// Hierarchy entry point
var rootFolder = vimHost.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 + "'");
}
vCenter Orchestrator Developer's Guide
128 VMware, Inc.