VMware, knife-vsphere, rbvmomi and NicSettingMismatch

I finished my Chef Recipes and obviously next step is to create and bootstrap VMware virtual machines directly from scripts. I started to test 2 knife plugins knife-esx and knife-vsphere. Quickly I dropped knife-esx solution, because was based on ssh access to the ESX host and we, “the common people”, don’t have rights on that machine. A little bit about my ESX environment: Is an environment with multiple datacenters, multiple clusters, hundreds of virtual machines. On this environment I don’t have full access and requesting one, it takes weeks/months (a lot of bureaucracy).

I read the documentation about knife-vsphere and after 10 minutes I was ready to start experimenting. But very fast I was stopped by an error.

If I comment out the vsphere_dc option in my knife.rb and run knife vsphere vm list again, it *works*, but selects the first datacenter it finds on the vsphere host, which of course is not the datacenter I want.

If I’m using a knife-vsphere with -d or –vsdc I will get this error, so don’t use any datacenter as parameter or option in your knife.rb (delete or comment knife[:vsphere_dc])
Next, I tried again, but this time I get another error:

create a customization spec in Vsphere then specifying it using the –cspec switch

But was my unlucky day, I don’t have access to create my customized spec. I was almost going crazy. I tried to force knife-vsphere to use rbvmomi 1.6.0 (customizing /var/lib/gems/1.9.1/specifications/knife-vsphere-0.3.0.gemspec and removing rbvmomi 1.5.1), but no luck, same errors. I tried to use rvc (Ruby vSphere Console) and everything appears to be ok there.

So I have only 1 choice! Is RUBY time. Let’s learn rbvmomi.
Most simple example is provided by Patrick Debois (DevOPS Days father): https://gist.github.com/jedi4ever/1001978

The error is pretty obvious … we need to select the correct pool. I’m pretty sure, this example will run if you have only 1 ESX Server or 1 ESX Cluster, because then is 1 single pool defined (by default), Having multiple datacenters / clusters the application is not able to choose a pool, mainly because I don’t have permissions to choose my datacenter directly.

Now we need to modify our code to add pool location. It’s not very obvious to add pool location if you are not connected to the correct datacenter, so we need to search after it. Next example show how to search after the correct pool in all clusters and clone.

And success! I create a machine from a template. Now is time to see how can we do that on knife-vsphere. The main problems appear to be in generate_clone_spec. I hacked a little bit on vsphere_vm_clone.rb and succeeded to clone a machine. In fact I skipped entire generate_clone_spec function and create a simple function based VirtualMachineRelocateSpec and find_pool.

I was pretty sure something from generate_clone_spec function is creating entire “problem”, but I didn’t want to skip entire generate_clone_spec function, because there you also have machine specification settings (CPU, RAM, VLAN,) and this are very useful. Looking further in source code after nicSettings, I realized what vmware machine expect from us: nicSettingsMap. Ok I added cips and cgw parameters to my command to see what happen.

OK, I said. One step closer. Let’s install the latest VMware Tools. I already had open-vm-tools installed. I uninstalled open-vm-tools and I tried to install VMWare-Tools-8.6.5 (which came with ESX). Bad luck. vmtoolsd is crashing with Segmentation Fault. Let’s install open-vm-tools the newest version … no luck. It needs glib >= 2.6 and my systems come with 2.24.

So we need to skip identity customization settings (OS Settings like ip, gw, hostname, domainname) to fix the problem. I just comment out line 289 from vsphere_vm_clone.rb (knife-vsphere package)

clone_spec.customization = cust_spec

clone_spec.customization = cust_spec

The guys who create knife-vsphere have this idea to add hostname and domain name for each new cloned machine, so when it boots, at least you will have the domain and hostname changed. But this doesn’t work if you have a combination of old vmware tools, LVM, and not a very new OS.

Next step was to create a patch to add –no-customization option and skip the section with default customization for new machine. Unlucky me, again:

mixlib-cli was recently changed to allow for options using the –[no]-whatever format provided by ruby’s OptionParser.

Hi, I have been trying to use RVC to manage templates.
I have cloned a VM from a template with RVC, but the
limitation is that I cannot specify a Customization to
override the IP address, DNS name etc for Linux deployments.

So, the cloning of the VM works successfully, but I have to
manually intervene to set the DNS and IP details for the Guest. I am not at all skilled with Ruby and am still finding my way around RVC, so I am not sure what to do,
but surely it must be possible to set an IP/DNS etc during
the vm.clone job from within RVC?

Any help, code-snippets etc or just commiserations would
be gratefully appreciated!

rachel

# 22 April 2013 at 3:12 am

admin (author) said:

What distro do you have ? If is debian like You can set the distribution on Ubuntu and everything will work well …