4.2

Table Of Contents
Accessing Operating System Commands from JavaScript
The Orchestrator API provides a scripting class, Command, that runs commands in the Orchestrator server host
operating system. To prevent unauthorized access to the Orchestrator server host, by default, Orchestrator
applications do not have permission to run the Command class.
The Orchestrator administrator can allow access to the Command scripting class by setting the
com.vmware.js.allow-local-process=true system property.
For information about setting system properties, see Administering VMware vCenter Orchestrator.
Exception Handling Guidelines
The Orchestrator implementation of the Mozilla Rhina JavaScript Engine supports exception handling, to allow
you to process errors. You must use the following guidelines when writing exception handlers in scripts.
n
Use the following European Computer Manufacturers Association (ECMA) error types. Use Error as a
generic exception that plug-in functions return, and the following specific error types.
n
TypeError
n
RangeError
n
EvalError
n
ReferenceError
n
URIError
n
SyntaxError
The following example shows a URIError definition.
try {
...
throw new URIError("VirtualMachine with ID 'vm-0056'
not found on 'vcenter-test-1'") ;
...
} catch ( e if e instanceof URIError ) {
}
n
All exceptions that scripts do not catch must be simple string objects of the form <type>:SPACE<human
readable message>, as the following example shows.
throw "ValidationError: The input parameter 'myParam' of type 'string' is too short."
n
Write human readable messages as clearly as possible.
n
Simple string exception type checking must use the following pattern.
try {
throw "VMwareNoSpaceLeftOnDatastore: Datastore 'myDatastore' has no space left" ;
} catch ( e if (typeof(e)=="string" && e.indexOf("VMwareNoSpaceLeftOnDatastore:") == 0) ) {
System.log("No space left on device") ;
// Do something useful here
}
Developing with VMware vCenter Orchestrator
112 VMware, Inc.