VMware {code} Community
JonnyL831
Contributor
Contributor

Writing VM guestinfo

I can set the extraConfig property of VirtualMachineConfigSpec and call ReconfigVM to set guestinfo variables. However, this only works when the VM is powered on. I can set other variables with the VM powered off, just not the guestinfo ones.

I have a VM I clone from a template (using the vSphere Perl SDK). I want to set some configuration parameters for the VM so when it's powered on it can kind of configure itself (using a script I'm writing). The idea is to set values using the above technique after I create the clone. Then, when the VM is powered in, my script will use the vmware-guestd --cmd 'info-get ...' command to fish out the values I set above.

Problem is I don't want to have to power on the VM just to set the guestinfo values.

Can anyone think of a workaround? I'd appreciate any and all information, comments, etc.

0 Kudos
12 Replies
lamw
Community Manager
Community Manager

What guestinfo values are you trying to populate? Since these are guest info variables, its probably required for the system to be powered on to update.

A simple work around is to not rely on it, use the "annotations" field or if you're using vCenter and these are defined fields, then create a custom field and update these upon provisioning. This is something I do in my environment to keep custom fields to run reports/etc. Using the annotations will just be 1 big text box, but even then you can still use it to store fields and just parse using some delimiter and it's associated with the VM as it's written to the .vmx file.

Here's a vSphere SDK for Perl script that uses "annotations" to add custom values -

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

William Lam

VMware vExpert 2009

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

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

VMware Developer Community

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

0 Kudos
JonnyL831
Contributor
Contributor

Thanks William, for the quick reply. I know I can write values to the .VMX file during provisioning. The information I want to put in the VMX file is network information. So when the VM starts up it has no network connectivity. So then, how do scripts on the VM itself (presumably running at startup) read/get the information?

0 Kudos
lamw
Community Manager
Community Manager

I'm not exactly sure which networking info you're trying to work with, but the VM does not need to have connectivity to update itself and pass back the guest attributes. The key is "VMware Tools" running, that is how much of the guest information is populated back to the ESX/ESXi/vCenter host, even the guest customization utilizes the VMware Tools feature to be able to have it execute scripts which is really leveraging piece of the VIX API to do some of the guest operation.

I'm still a little confused on exactly what "guest info" you're trying to set? Like I said before, it's probably better that you implement this as custom fields within vCenter or in the annotations field.

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

William Lam

VMware vExpert 2009

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

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

VMware Developer Community

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

0 Kudos
JonnyL831
Contributor
Contributor

Using the vSphere Perl SDK I set the annotations field when the VM is created (the script first creates a clone from a template). Then, when the VM is powered on, a startup script running on the VM needs to read/get the values set in the annotations field (with NO network connectivity). How is this accomplished? Would it be via some command in VMware Tools? Does the VMware Tools provide some API for this?

0 Kudos
lamw
Community Manager
Community Manager

Okay, lets step back because your initial question is starting to differ from what you're stating now.

1) What "information" are you trying to get? Please list them all out, then we can go forward in discussing a solution

2) What state of the VM would you like to retrieve this information?

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

William Lam

VMware vExpert 2009

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

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

VMware Developer Community

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

0 Kudos
JonnyL831
Contributor
Contributor

The information I want to set/get would look something like:

myVMConfig.ipAddress = 192.168.1.100

myVMConfig.netmask = 255.255.255.0

myVMConfig.useSSL = 1

As for question #2, I don't know what you mean by "...What state of the VM...". I need to set the above values when the VM is powered off, then get the above values (from a script running on the VM itself) when the VM is powered on.

0 Kudos
lamw
Community Manager
Community Manager

So why are you setting this values? What is the purpose? Are you trying to just extract this information? If you're cloning, I'm guessing you're customizing the guest as well? If so, then this information should already be known, if you want to have it available as just info without having the VM be online, then again, I suggest you add it into the annotations field.

I really don't understand why you're setting these values, what purpose is it being used for. If you can clarify this, then I can give you some potential solutions but right now its still vague that you're trying to force some data into variables that may not be all that useful? especially if the VM is offline, there's only so much you can do in terms of pulling information from the guestOS

Does this make sense?

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

William Lam

VMware vExpert 2009

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

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

VMware Developer Community

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

0 Kudos
JonnyL831
Contributor
Contributor

Okay I'll try to explain exactly what I'm trying to do.

I want to monitor network traffic and events for every switch on every HostSystem. I'll do this by deploying a VM with our monitoring software running onto every switch.

On VCenter, I make a VM template (using the vSphere client). I have an addtional VM running that acts as our installer and control center (call it the ccVM). The lone ccVM will (using the vSphere Perl SDK) make clones of the template and deploy them to every host/switch. Now, each agentVM needs to connect back to the ccVM when it starts up. Also each agentVM needs network information (IP address and netmask), and maybe more. So, after I make the clone I want to write this information so the agentVM can get it when it starts up.

Then, when the agentVM starts up, a script we'll have on it needs to read this information and "configure itself". This information will include the network information (it's IPaddress, netmask, etc.) values it needs (URL, credentials, SSL information) to connect to our controlcenter VM (ccVM), etc.

Again, I can write values into the annotations field of the VM, but then how does agentVM itself get them?

I really appreciate your patience...and your help!

0 Kudos
lamw
Community Manager
Community Manager

Okay I get what you're trying to do.

High level, you want to deploy clone of "this" VM and have it configure itself with certain configurations which includes networking and some other parameters.

So my question is, why are you setting guest vars to customized the guest? Since you're cloning a VM, why not use guest customization? Do you not have vCenter? If your answer is the latter, you can actually do all this customization + customize your application or anything else for that matter within the guest by using the VIX API, it just requires the VM to have VMware Tools running and you can transfer scripts directly to the guest and the guest VM does not need to have any networking for this to function. VMware Tools is a proxy to transfer files in/out and you can run these scripts which can IP your host and do whatever configuration you need.

Since you're cloning, I'm assuming you have vCenter so you can use the built in customization to customize your OSes upon completion of the clone which allows you to setup all networking. From here, the system is online and reachable via network and you can use the VIX API to transfer any custom scripts to configure and startup your application.

There's nothing I can see that would require you to use guest info to setup your application and this method is much more reliable and consistent.

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

William Lam

VMware vExpert 2009

VMware scripts and resources at:

Twitter: @lamw

Getting Started with the vMA (tips/tricks)

Getting Started with the vSphere SDK for Perl

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

VMware Developer Community

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

0 Kudos
prossi1
Contributor
Contributor

> Here's a vSphere SDK for Perl script that uses "annotations" to add custom values

Hi,

I'm interested in that script but cant find a link or attachment on this post.

Georges

0 Kudos
lamw
Community Manager
Community Manager

Here is the annotation script - http://communities.vmware.com/docs/DOC-10779

Here is a collection of other scripts I've written - http://communities.vmware.com/docs/DOC-9852

0 Kudos
prossi1
Contributor
Contributor

Cool, thanks a lot.

Is it also possible to read the annotations back? (yes, I'm new to VMa 🙂 sorry)

Georges

0 Kudos