tags:

views:

777

answers:

1

In VMware ESX/i, how can I use the VMware Virtual Infrastructure Remote CLI to find unused machines/disks? I have a huge inventory and many files on disk, and I want to find files that are candidates for deletion.

What I want is to determine whether

  • a vmdk disk is in use by any vmx machine on the host, or whether
  • a vmx machine exists in the inventory on the host.

Surely some smart method exists for finding this? If not the VIRCLI, then maybe something else? Or do I need Virtual Center for this?

EDIT: This is a single host that does not share machines or disks with any other host.

+2  A: 

The IC doesn't know if you've got those disks shared an in use by another ESXi host, it's very common to have a SAN on the backend and multiple hosts accessing the same storage device. In this case there's no way to know which hosts are accessing which machines, the scenario you describe only makes sense if you've got a single host - which is not the typical scenario for many of VMware's corporate customers.

Using the RCLI or shell you could iterate through all existing machines and then compare that to a list of what's on disk. If you've got disks shared between hosts however, then things become a lot more complicated and you'd need to iterate through the devices on each machine as well.

Update: Right, now it's more of a nuts n bolts scripting/programming question ;)

Starting with the RCLI documentation I'd probably do something like using vmware-cmd -l to list all registered machines on the host. Then using vifs download the config files, grep through those looking for mentions of virtual disks (.vmdk) and storing all those in a file.

Part two, would be writing a script to do a recursive directory listing, again using vifs, running grep again on that to only include .vmdk and .vmx files. Now you've got two lists, pipe these through sort and then diff the results to find out what .vmx files are not registered on the machine and what .vmdk files are not in use by any active VM. And then you have your candidates for deletion :)

sascha
Excellent. Thanks!
bzlm