VMware Cloud Community
GBrown1983
Enthusiast
Enthusiast

Correlate GuestDiskInfo with VirtualHardware

Hi,

I'm trying to create a workflow to automate disk extend based on free space (less than 10%).

I get the free space with GuestDiskInfo -  "vm.guest.disk.freeSpace" and "vm.guest.disk.capacity".

The problem is that I can't correlate this to the VirtualHardware disk (vm.config.hardware.device) so I can't tell which disk needed to be extend.

I can get what seems like the disk object with " vm.guest.disk[i]" but I don’t know how to use it for something useful.

Any tips on how to do this?

The script I use to get the free space – (it's in a very initial stage…)

var disks = vm.guest.disk;

for (i in disks)

{

System.log("DiskPath - " + (disks[i].diskPath));

    System.log("FreeSpace (GB) - " + (disks[i].freeSpace / 1024 / 1024 / 1024));

    System.log("Capacity (GB) - " + (disks[i].capacity / 1024 / 1024 / 1024));

          

    if ((disks[i].freeSpace / disks[i].capacity) <= 0.1)

    {

//      var diskToGrow = disks[i];

        var diskNewSize = Math.round(((disks[i].capacity * 1.05) / 1024 / 1024 / 1024));      

    }

}

Tags (2)
0 Kudos
5 Replies
jacksonecac
Enthusiast
Enthusiast

This is a tricky one...

Unfortunately I don't have any code to help you with this but perhaps some advice..

Which type of OS are you dealing with? I know that I used a powershell script for Windows for the same problem. The Windows volumes have the disk index of the SCSI as a property and so you can relate them that way and then resize the appropriate disk. Match the volume is on the SCSI from the OS with the index from the disk properties and you should then know which disk you are dealing with.

Typically with *Nix systems particularly ones using LVM they will want to simply add a VMDK to the VM and then add that disk into the existing volume.

I hope that points you in the right direction.

Check out this link to see the disk properties available to you from the Windows OS

Win32_Volume class (Windows)

0 Kudos
jarushepic
Enthusiast
Enthusiast

I would love to be able to do this all within vRO.  I'd like to have a vRA task that i can present to our SQL Admins and it populates the disk path with stuff from guest info, they pick which one they want to expand, and then vRO expands it.  However, we have never been able to figure out how to do this.  Right now this is a very manual process where the requester (Linux or WIndows) runs a script to get the UUID of the device.  Then we can run some powershell to match the UUID to the "Hard Disk #", then we can manually grow the disk on the VM.

I really don't want to run powershell or bash in order to do this, i want to do it all in vRO.  We have thousands of VMs and vRO has no business logging into them.

0 Kudos
jacksonecac
Enthusiast
Enthusiast

The problem is naming. vmware doesn't care whether or not a disk is named C, T, Z... etc. Unfortunately all the app developers, admins etc do care about those names and so since that is what they are referring to then that is how you need to make your connection. To sidestep this you would need the requester to provide the SCSI index and Bus in order to do the expansion without touching the OS layer. Smiley Sad

0 Kudos
jacksonecac
Enthusiast
Enthusiast

This angered me so I did some digging. I am not sure if this works or not but judging by the API it looks like it is relevant. Check it out:

input: Virtualmachine vm, String diskName

var guest = vm.guest

var disks = guest.disk;

for each(var i disk in disk)

{

    if i.diskPath == diskName

          var diskToReize = i;

}

0 Kudos
jarushepic
Enthusiast
Enthusiast

That will get you the VcGuestDiskInfo object (https://www.vmware.com/support/orchestrator/doc/vro-vsphere60-api/html/VcGuestDiskInfo.html), which just tells you the mount path and the size.  Helpful.  However, to be useful, you need to be able to get the VcVirtualDisk under vm.config.hardware.device.

For example, this will show you what the guest OS sees from a mount path standpoint:

for (var ix in u_vm.guest.disk)

{

  System.log('----------');

  System.log(ix.toString());

  System.log('DiskPath: ' + u_vm.guest.disk[ix].diskPath);

  System.log('Freespace (GB): ' + (u_vm.guest.disk[ix].freeSpace / 1024 / 1024 / 1024).toString());

  System.log('Capacity (GB): ' + (u_vm.guest.disk[ix].capacity / 1024 / 1024 / 1024).toString());

}

However, none of that corresponds to anything I've been able to find in other objects.  There is no order that universally works that I can find.

for (var ix in u_vm.config.hardware.device)

{

  if (u_vm.config.hardware.device[ix] instanceof VcVirtualDisk)

  {

  System.log(ix.toString() + ': ' + u_vm.config.hardware.device[ix].deviceInfo.label);

  System.log(ix.toString() + ': ' + u_vm.config.hardware.device[ix].deviceInfo.summary);

  System.log(ix.toString() + ': ' + u_vm.config.hardware.device[ix].diskObjectId);

  }

}

So in general, we need to match these two for loops up.

0 Kudos