Sha256: 6be2103cc139daff58be923e8b046aeabd832350697fca2ed051bce938a9a464

Contents?: true

Size: 1.49 KB

Versions: 3

Compression:

Stored size: 1.49 KB

Contents

module Fog
  module Compute
    class Vsphere
      class Real
        def vm_migrate(options = {})
          #priority is the only required option, and it has a sane default option.
          priority = options['priority'].nil? ? 'defaultPriority' : options["priority"]
          raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'

          # Find the VM Object
          search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
          vm_mob_ref = @connection.searchIndex.FindAllByUuid(search_filter).first

          unless vm_mob_ref.kind_of? RbVmomi::VIM::VirtualMachine
            raise Fog::Vsphere::Errors::NotFound,
              "Could not find VirtualMachine with instance uuid #{options['instance_uuid']}"
          end
          options['host'] = get_raw_host(options['host'], options['cluster'], options['datacenter']) if options['host']
          task = vm_mob_ref.MigrateVM_Task(:pool => options['pool'], :host => options['host'], :priority => "#{priority}", :state => options['state'] )
          task.wait_for_completion
          { 'task_state' => task.info.state }
        end
      end

      class Mock
        def vm_migrate(options = {})
          priority = options['priority'].nil? ? 'defaultPriority' : options["priority"]
          raise ArgumentError, "instance_uuid is a required parameter" unless options.key? 'instance_uuid'
          { 'task_state' => 'success' }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
fog-vsphere-1.9.0 lib/fog/vsphere/requests/compute/vm_migrate.rb
fog-vsphere-1.8.0 lib/fog/vsphere/requests/compute/vm_migrate.rb
fog-vsphere-1.7.1 lib/fog/vsphere/requests/compute/vm_migrate.rb