VMware Cloud Community
c0pie
Contributor
Contributor

determining which ESX host a vm is on from script?

Hello,

I have a need to be able to determine which ESX host server a vm is running on from a script... Existing script infrastructure is in WSH/vbs for windows vm's. Is this possible? I know vmware offers an API, but I am limited in that I need to be able to do this from within WinPE, the boot environment from Microsoft's Microsoft Deployment Toolkit. In other words, I can't just install anything I want, at least not easily, and some things just can't be added to WinPE.

anyone know of any options?

0 Kudos
6 Replies
Troy_Clavell
Immortal
Immortal

not exactly a script,but you may want to look at RVTools

lamw
Community Manager
Community Manager

So yes, you can have a 'script' connect to all ESX hosts to query for the VM...this assumes you have a good naming convention between the VM display name and the guestOS, or if you have VMware Tools installed you can looking at it's hostname or/and IP Address.

The caveat to all this, if you allow a guestOS look this information up, you're basically allowing connectivity from your VMs into your management network which is a big no no from a security perspective. Is it really necessary that you need this information?

You can accomplish this with PowerCLI which might be easier if you're coming from Windows world, but again you'll need to install Powershell and the PowerCLI bindings on your guest.

Another approach to this, is automatically gather the mappings of ESX(i) host -> VMs and maybe dump that once a day/week to say a CIFS/SAMBA/NFS share, and have your guestOS pull this file and figure out which host it's on. This allows a separation of management network and your VMs and still get you the information you're seeking.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

0 Kudos
c0pie
Contributor
Contributor

thanks for the input. I certianly don't want to degrade our security posture. My issue is that our current deployment system (based on MDT) determines what site/location a system is from by checking the deployment server's name, which is a property build into the system. I am now experimenting using this deployment system with vmware vm's using something called a 'media' deployment, which will basically remove the 'deployment server' from the equation and I will just mount an ISO to the vm which will be used for the guest OS deployment. The first phase of the deployment runs in WindowsPE, and this is were I need my vm to determine which esx host it is on... so that I can apply my site-specific settings to the guest OS... running within winPE means I have no .net framework and no powershell.

Sounds like I will have to prompt the user for this info for vm deployments, instead of it just being automatically determined. To clarify, what I am talking about is being run from the vm, not a management machine.

0 Kudos
lamw
Community Manager
Community Manager

I see what you're trying to do, though I think the best approach is to run as much as you can outside of the guest. If you look at my suggestion from the last reply, it would aide in providing you the mapping. Other than that, you would basically have to open an ACL if it's not already to ESX management host and basically run a query whether that is using PowerCLI or directly querying on the Service Console using something like vmware-cmd, again this isn't recommended approach but its probably what you'll want to look at.

=========================================================================

William Lam

VMware vExpert 2009

VMware ESX/ESXi scripts and resources at:

Twitter: @lamw

VMware Code Central - Scripts/Sample code for Developers and Administrators

VMware Developer Comuunity

If you find this information useful, please award points for "correct" or "helpful".

c0pie
Contributor
Contributor

ok, thanks William, I appreciate the info.

0 Kudos
jpdicicco
Hot Shot
Hot Shot

Even though you aren't using a deployment server, you could bring up a network interface and use the IP info to determine location.






Happy virtualizing!

JP

Please consider awarding points to helpful or correct replies.

Happy virtualizing! JP Please consider awarding points to helpful or correct replies.
0 Kudos