chef-boneyard / chef-provisioning-vsphere

DEPRECATED: A chef-provisioning provisioner for VMware vSphere
MIT License
17 stars 15 forks source link

Any way to reconfigure existing VMs? #80

Open Ryuzavi opened 6 years ago

Ryuzavi commented 6 years ago

Versions:

Version of Chef-Provisioning: 2.6.0 Version of Chef-Provisioning-vSphere: 2.0.10

Platform Details

Version of vSphere/vCenter: 6.0.0 Version of ESXi: 6.0.0

Scenario:

Was trying to see if there was any way to reconfigure an existing VM as part or or separate from a clone task. Was specifically looking for a way to reconfigure the memory. Currently changing the memory on the bootstrap_option's has no affect.

I don't know the rbvmomi api too well but it seems like there's a few select references to ReconfigVM_Task for the vm object which seems to be the one that can do this. But it's only used for adding NICs and so on.

As an aside is there a way to access the VM object directly in a recipe? That way I can call the method directly myself.

Steps to Reproduce:

Changing memory setting on bootstrap_options and rerun the recipe against a VM that's already been created.

Expected Result:

That a reconfigure is attempted on the existing VM and settings updated to what's in bootstrap_options.

Actual Result:

No reconfigure is attempted and the VM stays the same.

hrmmmwhynot commented 6 years ago

I'm not a ruby expert and so I'm sure maybe the proper way is maybe to write something in your cookbook to extend "class VsphereHelper", and perhaps this is a bad answer, however you could also directly use rbvmomi in your recipe and it would work:

chef_gem 'rbvmomi' do
    action :install
    version "1.8.2"
    clear_sources true
    compile_time true
end

Then you should be able to use rbvmomi directly, but you need to establish connection to vsphere all over again or somehow get the connection from chef vsphere.

I've been using fog-vsphere, they wrote a pretty complete set of wrappers so you don't need to use the very bad rbvmomi interface directly. https://github.com/fog/fog-vsphere

Example:

 chef_gem 'fog-vsphere' do
      action :install
 end

def connect
    # connect using fog
    creds = Chef::EncryptedDataBagItem.load('databag_name', 'databag_item')
    vsphere_user = creds['vsphere_user']
    vsphere_user = "#{vsphere_user}"
    vsphere_pw = creds['vsphere_pw']
    vsphere_server = 'myvsphere.mydomain.com'

    compute = Fog::Compute.new(
        provider: :vsphere,
        vsphere_username: vsphere_user,
        vsphere_password: vsphere_pw,
        vsphere_server: vsphere_server,
        vsphere_expected_pubkey_hash: vsphere_expected_pubkey_hash,
        vsphere_ssl: true,
        vsphere_rev: '6.5'
    )
    compute
end

# connect to vsphere
connect_obj = connect

# list datacenters
dc_list = connect_obj.list_datacenters
puts dc_list