VMware Cloud Community
mabraham1
Contributor
Contributor

Set 'guest info" variables through REST api (or other ideas)

i can check and set variables inside a vm with something like

vmtoolsd --cmd "info-set guestinfo.host foo"
 
is there a good way of "setting" such a variable, other than PowerCLI or the VCenter "advanced vm settings" gui?
 
Looking for any good ways of passing metadata via the hypervisor without networking to the VM.
0 Kudos
3 Replies
lamw
Community Manager
Community Manager

Both PowerCLI and vCenter UI (vSphere UI) is only possible because an API exists, these are merely interfaces to the underlying API. There is NOT a REST API for managing guest variables and you will need to use vSphere (SOAP) API to update/add these values which is under VM object using ReconfigVM_Task() and specifically the extraConfig which is an array of various key/values and you'll need to add a new key/value to that and reconfigure VM https://vdc-repo.vmware.com/vmwb-repository/dcr-public/c476b64b-c93c-4b21-9d76-be14da0148f9/04ca12ad...

Using vSphere UI, there's something called Code Capture which will capture the API calls and output it in a number of interfaces including PowerCLI, vRO (Javascript) Python and Golang ... so these would alternative interfaces to API if you don't want to use PowerCLI or UI. 

Folks forget that PowerCLI is just one interface to API and is NOT the only interface to API 🙂 

mabraham1
Contributor
Contributor

lamw thanks for your reply!

I do know that the powercli is just one example of using the API, which i learned from reading your excellent blog! i guess i was just hoping that the vcenter REST API was one of the options, as our project is trying to stick to that one interface as a design principle. But i supposed that its absence from the REST docs shouldve been a good clue that its not possible.

 

I'm actually trying to do something i took from your blog about "instant clone"; where i re-generated a machine identifier and get a new MAC address as part of the "freeze" script that resumes on instant clone. I have a bit of chicken-and-egg problem where the machine gets a new IP instantly, but the "guest tools" aren't detected via vcenter for about ~20 seconds and i just get "tools not avialble" via the guest identity rest API. So i thought maybe i'd stash some stuff in "guestInfo" , such as the vcenter VM name, then set the hostname via that lookup. 

vmware-toolbox-cmd info update network has been useful to avoid sending the hypervisor some bad, cached info but its not the best solution. let me know if you have any other thoughts or advice related to this situation! Thanks!

0 Kudos
lamw
Community Manager
Community Manager

If you can't find a particular API/setting in REST API docs, its probably not there and is in vSphere SOAP API. All new features built post-7.0, will have REST API as first class citizen, so thats always an easy way to check

In terms of IP not showing up immediately, not sure if you've seen https://williamlam.com/2019/04/how-to-immediately-refresh-the-network-guestinfo-using-vmware-tools.h... which could help

0 Kudos