- Variables are local to your scriptable task unless you make them an input or output (or both)
- You really should validate your input before taking an action
I have rewritten a whole script to find out I missed a case for example a common one would be that is valid is:
Will all fail with a odd error. You have to watch case on reserved commands. This is true of API explorer objects VcVirtualMachine is VcVirtualMachine not VCvirtualmachine etc…
Will output the type of object into the log window when run. This is very useful for discovering the object type. In the vCenter API you might have something like
If you want to understand your object type just use:
And it will tell you the object. (this is a example and will not work)
Almost everything in vRO is a complex object which can be loosely defined as a combination of key value pairs in an array. A traditional array have multiple objects referenced like this:
array = "magic"
array = "cheese"
array = "need"
This is a array of strings with a length of 3. If I called this:
The log would display “magic”
An object is an array with multiple key value pairs for each array element for example
array.firstname = Joseph
array.lastname = Griffiths
array.firstname = Tom
array.lastname = Bobo
array.firstname = Mac
array.lastname = Cheese
This allows me to store multiple elements that are connected and entries in the object don’t have to be the same type (e.g. firstname and lastname are both strings but I could add a age entry to hold a number). This provides a huge flexibility… those familiar with powercli this is the same as:
get-vm | fl
This will display all vm’s with a full list of the elements on the object of vm.
Errors will display the line number. Use that to determine the cause or source. I know almost every programmer needs to have the ability to test their assumptions around variables when writing programs use the System.log for this:
System.log("variable 1: " + var1 + " variable 2: " + var2);
System log is readable only by someone in vRO and not exposed to customers (unless they are running it from vRO)
First check for null
if (variable1 == null)
Then validate your object type using the System.log method above. There is a way for checking for complex system defined objects like this:
if (vm instanceof VcVirtualMachine)
//Do some action
This can be very useful when working with objects validate before you act.
Hope it helps