I am trying to create a dashboard that will show all the VMs in a datacenter with # cpu, memory size, and storage size. I can get that info for VMs that are powered on: virtualMachine.get("cpus/cores/latest/average")
The only way to get those is if the VM is powered on. What you can get is the total allocated storage, regardless of powerstate based on the VMDK file layouts. To do this, you need to sum up all of the disks (if the VM has any) and then divide to get you the units you want. This little code snippit I use in a lot of places for the exact reason.
I use vm as a variable in a function that used the type VMWVirtualMachine or you can run this in script editor from a VMWVirtualMachine and pass something like vm = scope based on a VM you selected
//begin code
result = 0
// Disk Calculation
list = vm.get("vmdkFileLayouts")
if(list.size() == 0)
{
totalDisk = 0
}
else
{
disk = list.diskSize.sum()
removeDisk = list[0].diskSize
totalDisk = disk / 1024 / 1024 / 1024 // Convert to GB
DELL-Thomas B
171 Posts
341
1
Posted April 11th, 2012 03:00
The only way to get those is if the VM is powered on. What you can get is the total allocated storage, regardless of powerstate based on the VMDK file layouts. To do this, you need to sum up all of the disks (if the VM has any) and then divide to get you the units you want. This little code snippit I use in a lot of places for the exact reason.
I use vm as a variable in a function that used the type VMWVirtualMachine or you can run this in script editor from a VMWVirtualMachine and pass something like vm = scope based on a VM you selected
//begin code
result = 0
// Disk Calculation
list = vm.get("vmdkFileLayouts")
if(list.size() == 0)
{
totalDisk = 0
}
else
{
disk = list.diskSize.sum()
removeDisk = list[0].diskSize
totalDisk = disk / 1024 / 1024 / 1024 // Convert to GB
}
// Add data to result
result = totalDisk
return result