nsidc / vagrant-vsphere

VMware vSphere provider for Vagrant
Other
607 stars 166 forks source link

Add support for setting guestinfo variables #174

Closed Sharpie closed 8 years ago

Sharpie commented 8 years ago

This patch adds an extra_config section to the provider configuration which can be set to a hash. This hash is used to populate the extraConfig section of the VirtualMachineConfigSpec used to clone new VMs. The keys of the hash must start with guestinfo. and the values are available to guest VMs with VMware tools installed via the vmtoolsd command.

Sharpie commented 8 years ago

Cleaned up some RuboCop issues reported by the Travis runs, but there are still style failures that don't appear to be related to my changes.

rylarson commented 8 years ago

This would be good to have. It needs unit tests though. Take a look at clone_spec.rb. You should add a spec that asserts that if you set these properties, they end up on the VirtualMachineConfigSpec

Sharpie commented 8 years ago

@rylarson Good call. Some tests were failing because extra_config needed to be added to the test doubles. Updated patch pushed with test coverage.

ghost commented 8 years ago

Hi @Sharpie,

While testing your changes on our vSphere host, I haven't been able to get the guestinfo variables set on creation of a VM. With vsphere.extra_config = { 'guestinfo.foo' => 'testpasses' } in my Vagrantfile, I get this output:

  > vagrant up --provider=vsphere
Bringing machine 'default' up with 'vsphere' provider...
==> default: Calling vSphere CloneVM with the following settings:
==> default:  -- Template VM: NSIDC/vm/Linux/SCM/trusty64-nsidc
==> default:  -- Target VM: NSIDC/vm/Linux/SCM/dev/mbrandt-vsphere-pr-testing
NoPermission: Permission to perform this operation was denied.

However, if I remove the extra_config setting from my Vagrantfile and create a machine, after SSHing to it, I can set guestinfo variables with vmtoolsd:

vagrant@trusty64:~$ vmtoolsd --cmd 'info-get guestinfo.foo'
No value found
vagrant@trusty64:~$ vmtoolsd --cmd 'info-set guestinfo.foo bar'

vagrant@trusty64:~$ vmtoolsd --cmd 'info-get guestinfo.foo'
bar

Do you know if there's some vSphere setting that we need to change for the guestinfo variables to be set when creating the VM?

I've also filed a ticket with our SysAdmins to see if they can be of any help. Naturally, I'd like to be able to see your changes work before merging them in :smile:

- Michael

rylarson commented 8 years ago

It looks like you are getting a permission denied error. You probably just don't have the required Reconfigure privilege: VirtualMachine.Config.AdvancedConfig permission. This is the only operation in VirtualMachineConfigSpec that requires this permission.

ghost commented 8 years ago

I have a couple follow-up questions from our SAs:

Are the guestinfo settings stored in vSphere? If not, how are they stored?

vagrant-vsphere provides support for Custom Attributes, which are stored in vSphere, and can be viewed in the vSphere Web Client. How do guestinfo variables differ from Custom Attributes? I'm having trouble finding info comparing the two in web searches.

ghost commented 8 years ago

Since the issue I'm having is only with NSIDC's internal vSphere configuration, and not with the code here, I'll go ahead and merge it now.

Thanks @Sharpie! And thanks @rylarson for the note about the relevant permissions.