Virtualization Pro

Dec 17 2007   4:39PM GMT

Reconfiguring vmreconfig



Posted by: Akutz
Tags:
Andrew Kutz
VI3
Virtualization
VMware ESX

The Perl script, vmreconfig.pl, is designed to reconfigure a virtual machine (VM). You can read more about it here. The tool can be used to make changes to the state of the VM. For example, you want to turn off a VM’s guest network interface card (NIC). You would use the command vmreconfig.pl in conjunction with an XML file that contains the necessary options to turn off the NIC.

The command might look like:

vmreconfig.pl --username akutz --password mypassword --server vcms.lostcreations.local --filename vmgnicoff.xml

And the XML file might look like:

<?xml version="1.0"?>
<Reconfigure-Virtual-Machine>
  <Name>purple.lostcreations.local</Name>
  <Host>morning.lostcreations.local</Host>
  <Disconnect-Device>
        <Network-Adapter>
          <Name>VM Network</Name>
        </Network-Adapter>
  </Disconnect-Device>
  <PowerOn-Flag>
        <Network-Adapter>
          <Name>VM Network</Name>
          <PowerOn>False</PowerOn>
        </Network-Adapter>
  </PowerOn-Flag>
</Reconfigure-Virtual-Machine>

This is where the trouble begins. The are a few problems with vmreconfig.pl (and I suspect with the other VI Perl tools as well; I will be documenting their issues as I use them):

- Poor error messages
- Schema is poorly designed
- Incomplete Perl modules
- Documentation is misleading

Poor Error Messages

When you execute the above command here is the error you will receive


Error in 'vmgnicoff.xml':
Element 'Reconfigure-Virtual-Machine' [CT local]: The element content is not valid.

This doesn’t really tell us all that much, does it? This is common with the VI Perl scripts. After some digging we are able to figure out that this problem has something to do with the XML schema file.

Poorly Designed Schema

The vmreconfig.xsd XML schema document (XSD) file included with the VI Perl Toolkit is poorly designed. It requires that every element be present in the file even when not in use. If you were to open the XML file in an XML editor and link the provided schema file you get a warning that the “AddDevice” node is not present? Well, we are not trying to add a device, so why should we need it? It turns out that the schema file does not implement the “minOccurs” attribute on its node definitions (even though the Perl script can cope with the absence of these elements). The solution is to go through the schema file and add a “minOccurs=’0′” attribute to the appropriate locations. You can download a copy of the schema I’ve already marked up for this purpose here.

Now you can use the simpler, easier-to-read XML that is printed above.

Incomplete Perl Modules

However, the next time you run the command you will possibly receive yet another error:


Can't locate object method "new" via package "XML::LibXML::XPathContext" (perhaps you forgot to load "XML::LibXML::XPathContext"?)

This error occurs because some OSs do not have the XPathContext Perl module installed by default. To install this module from CPAN simply type:


sudo cpan XML::LibXML::XPathContext

That solves that problem.

Misleading Documentation

The last issue you can run into is the VMware documentation itself. The online documentation for vmreconfig.pl clearly implies that the name that should be used with a network adapter is the name of the network it is associated with. The documentation uses the example “VM Network”. This is the default name of a port group created for use by VMs in ESX. In fact, if you use this name when attempting to make changes to a network device you will receive this message:


No reconfiguration performed as there is no device config spec created.

You must specify the name of the network adapter, not the network it belongs to.

In Summary

To make vmreconfig.pl turn off and disconnect a VMs network adapter download my updated vmreconfig.xsd schema file and use the following XML:

<?xml version="1.0"?>
<Reconfigure-Virtual-Machine>
  <Name>purple.lostcreations.local</Name>
  <Host>morning.lostcreations.local</Host>
  <Disconnect-Device>
        <Network-Adapter>
          <Name>Network Adapter 1</Name>
        </Network-Adapter>
  </Disconnect-Device>
  <PowerOn-Flag>
        <Network-Adapter>
          <Name>Network Adapter 1</Name>
          <PowerOn>False</PowerOn>
        </Network-Adapter>
  </PowerOn-Flag>
</Reconfigure-Virtual-Machine>

Hope this helps!

1  Comment on this Post

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when other members comment.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy
  • Array
    Thanks for this information! I however, have a problem: when I try to add a CDROM (when there is none installed) I get an error in VMUtil.pm. When I trie to add a CDROM after I added via the VI Client vmreconfig does work properly. I think it has to do with the absence of the IDE controller. Do you know how to fix this? The error: C:\Program Files\VMware\VMware VI Perl Toolkit\Perl\apps\vm>vmreconfig.pl --filename c:\config\testvmreconfig.xml --schema c:\config \vmreconfig.xsd Adding NIC with the name 'Network Adapter 2' . . . Can't use an undefined value as an ARRAY reference at C:/Program Files/VMware/VMware VI Perl Toolkit/Perl/apps/vm/..//AppUtil/VMUtil .pm line 889. Adding floppy 'Floppy1' . . . the testvmreconfig.xml: --> XMLTestVM links.esxtest.int Network Adapter 2 Floppy1 CDROM1 I allready use the .xsd you have made. Thanks in advance, Regards, Remko
    0 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to: