Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Any way to reconfigure existing VMs? #80

Open
Ryuzavi opened this issue Feb 21, 2018 · 1 comment
Open

Any way to reconfigure existing VMs? #80

Ryuzavi opened this issue Feb 21, 2018 · 1 comment

Comments

@Ryuzavi
Copy link

Ryuzavi commented Feb 21, 2018

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.

@Ryuzavi Ryuzavi changed the title Any way to reconfigureing Existing VMs? Any way to reconfigure existing VMs? Feb 21, 2018
@hrmmmwhynot
Copy link

hrmmmwhynot commented Jul 12, 2018

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants