I only recently started using vCenter Orchestrator and was hoping someone could help me out. I have the need to pull the amount of RAM and the number of vCPUs on a VM and place them in a variable. In powershell, I'd do something like this:
$vmName = get-vm vmname
$vmName.MemoryMB
$vmName.NumCpu
How do I go about doing this in orchestrator? Thanks for your help.
Like this:
cpuCount = vm.summary.config.numCpu;
memoryMB = vm.summary.config.memorySizeMB;
Christophe.
Like this:
cpuCount = vm.summary.config.numCpu;
memoryMB = vm.summary.config.memorySizeMB;
Christophe.
cdecanini_, this is great, thank-you. Where can I go to view documentation that outlines other VM or Host attributes?
Use the API Explorer that is built into the vCO Client... it is in the right pane when you are editing a scriptable task or action and it is also available from the tools menu. Just locate the object you wish to know more about, then drill down into the various properties until you find what you need
The same API search has links to the vCenter SDK API documentation if you need more details.
HI.
I'm learning vCO and I wanted to use this as excercise.
So I've created a flow with 2 steps (picture 0) :
1. Get Virtual machine by name (from \Library\vCenter\Virtual Machine Management\Basic\Get virtual machine by name
2. scriptable task
Global input is: "vmName" and it's bind to the input of 1 step ( picture attached 1.jpg) and output attribute is "vms".
Than in scriptable task I have "in" attribute "vms" bind to the "vms" and two Out Attributes.
I have error: "TypeError: Cannot read property "config" from undefined (Workflow:D_new_0.4 / Scriptable task (item2)#12758)"
What does it mean ?
DD
Hi DD,
I think you have to choose the first vm within your array of vms. So in your scriptabe task you can choose the first vm like this:
var vm = new new VcVirtualMachine() ;
vm = vms.shift(); // Returns the first item within the vms array
And then use vm to get the informations you want insted of vms.
If this is working. The error is, that you are trying to get the .config attribute from an array which only have the attribute length. Herefor you can take a look to the API explorer within orchestrator where you can see attributes and functions of objects like VcVirtualMachine or Array.
If this isn't, we have to see your code from the scriptable task to help you.
Regards,
Chris
Ok so I've moddify a bit this flow:
STEP1:
Get Virtual machine
input : vmNAME
Out Attrib : vms
(picture 001 attached)
STEP2
Scriptable Task
In Attrib : vms
Out Attrib : cpuCount
Out Attrib : memoryMB
Script:
System.log("VM: " + vms);
Server.log("VM: " + vms);
cpuCount = vms.summary.config.numCpu;
memoryMB = vms.summary.config.memorySizeMB;
(picture 002 and 002a attached)
When the flow run, I'm inserting vm name: for example "I_VM" (it exist in vCenter)
STEP1 it's finding this vm and passing to STEP2
Results failed...
I mean, you should change your script from STEP 2 to this:
System.log("VM: " + vms);
Server.log("VM: " + vms);
var vm = new new VcVirtualMachine() ;
vm = vms.shift(); // Returns the first item within the vms array
System.log("VM: " + vm.name);
Server.log("VM: " + vm.name);
cpuCount = vm.summary.config.numCpu;
memoryMB = vm.summary.config.memorySizeMB;
Cause your "vms" input is an array of virtualmachines and not one single virtualmachine. The attribute summary is not available on an array but on a virtualmachine object. So you have to pic the first virtualmachine object from within the array.
Regards
OK got it:
System.log("VM: " + vms);
Server.log("VM: " + vms);
vm = vms.shift(); // Returns the first item within the vms array
System.log("VM: " + vm.name);
Server.log("VM: " + vm.name);
cpuCount = vm.summary.config.numCpu;
memoryMB = vm.summary.config.memorySizeMB;
Results in screen
cpuCount and memory MB retrieved
THANKS FOR YOU HELP
Sorry there was an error on my side of the code. I wrote two times "new" where one was enough.
Have fun on your other projects with vCO.
Yes but this "bold" // var vm = VcVirtualMachine() ; in a code below is
System.log("VM: " + vms);
Server.log("VM: " + vms);
// var vm = VcVirtualMachine() ;
vm = vms.shift(); // Returns the first item within the vms array
System.log("VM: " + vm.name);
Server.log("VM: " + vm.name);
cpuCount = vm.summary.config.numCpu;
memoryMB = vm.summary.config.memorySizeMB;
not necessary, because vms is an object passed from STEP1 "get virtual machine by name" workflow
So I used only
vm = vms.shift();