fog / fog-vsphere

Fog for vSphere
MIT License
36 stars 63 forks source link

add more options to vm_relocate #111

Closed scambra closed 6 years ago

scambra commented 7 years ago

add option to relocate vm's datastore Also I added support for diskBackingInfo in VirtualMachineRelocateSpecDiskLocator, I needed that option when migrating volumes between datastores of different type.

chris1984 commented 7 years ago

@scambra are we able to get a test added for the extra options?

chris1984 commented 7 years ago

@scambra any updates on this pr?

scambra commented 7 years ago

Sorry, I didn't have time to work on adding tests

scambra commented 6 years ago

Do you mean how to write a test for this? I don't have example, I didn't have time to write them.

This is how I use it, I have a vm and I want to migrate vm and disks to different datastore (datastore variable is name of datastore). vm_relocate allows to use different datastore for vm and each disk.


      disk_changes = vm.volumes.each do |vol|
        filename = vol.filename.gsub(/\[[^\]]+\]/, "[#{datastore}]")
        backing = {thinProvisioned: true, fileName: filename, diskMode: 'persistent', 'type' => 'FlatVer2'}
        {'diskId' => vol.key, 'datastore' => datastore, 'diskBackingInfo' => backing}
      end
      vm_relocate('instance_uuid' => vm.id, 'disks' => disk_changes, 'datastore' => datastore)
chris1984 commented 6 years ago

@scambra Can you help me test this, I want to get this merged so we can release 2.0.2

Here is what I have:


require 'fog'

client = ::Fog::Compute.new(
  :provider => 'vsphere',
  :vsphere_username => 'xx',
  :vsphere_password => 'xx',
  :vsphere_server => 'vcenter.toledo.satellite.lab.eng.rdu2.redhat.com',
  :vsphere_expected_pubkey_hash => 'af07d8080dffe627d03bec9ced12e9418857b3bc3ee4ee814ae486cc798a0f55'
)

vm = 'Toledo-Mongotest2'
disk_changes = vm.volumes.each do |vol|
  filename = vol.filename.gsub(/\[[^\]]+\]/, "[#{datastore}]")
  backing = {thinProvisioned: true, fileName: filename, diskMode: 'persistent', 'type' => 'FlatVer2'}
  {'diskId' => vol.key, 'datastore' => datastore, 'diskBackingInfo' => backing}
end
vm_relocate('instance_uuid' => vm.id, 'disks' => disk_changes, 'datastore' => datastore)

I am getting errors
test-fog.rb:12:in `<main>': undefined method `volumes' for "Toledo-Mongotest2":String (NoMethodError)
scambra commented 6 years ago

@chris1984 You need to get vm object, e.g.:

vm = client.servers.find { |server| server.name == 'Toledo-Mongotest2' }

Also, you will have to define datastore variable with name of one datastore in your cluster

chris1984 commented 6 years ago

@scambra Closing this pull request since it has been open a while, feel free to reopen when you are able to continue on it.

scambra commented 6 years ago

Submitted new PR #164 with requested changes