class Chef::Knife::VsphereVmMigrate
migrate vm to specified resource pool , datastore and host
Public Instance Methods
run()
click to toggle source
# File lib/chef/knife/vsphere_vm_migrate.rb, line 37 def run $stdout.sync = true vmname = @name_args[0] if vmname.nil? show_usage fatal_exit("You must specify a virtual machine name") end vm = get_vm_by_name(vmname, get_config(:folder)) || fatal_exit("Could not find #{vmname}") priority = config[:priority] dest_host = get_vm_host_by_name(config[:dest_host]) if config[:dest_host] ndc = find_datastore(config[:dest_datastore]) if config[:dest_datastore] pool = find_pool(config[:resource_pool]) if config[:resource_pool] unless dest_host || ndc || pool fatal_exit("You need to specify one or more of --dest-host, --dest-datastore, or --resource-pool") end migrate_spec = RbVmomi::VIM.VirtualMachineRelocateSpec(datastore: ndc, pool: pool, host: dest_host) vm.RelocateVM_Task(spec: migrate_spec, priority: priority).wait_for_completion end