Sha256: a08c99744d5dc73642755b5048e686f306c78b366326fe5b2ac651145c762e45

Contents?: true

Size: 1.87 KB

Versions: 7

Compression:

Stored size: 1.87 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.is_a? 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_options = { pool: options['pool'], host: options['host'], state: options['state'] }
          if options['check']
            checker = connection.serviceContent.vmProvisioningChecker
            task = checker.CheckMigrate_Task(task_options.merge(vm: vm_mob_ref))
            task.wait_for_completion
            { 'error' => task.info.result[0].error, 'warning' => task.info.result[0].warning }
          else
            task = vm_mob_ref.MigrateVM_Task(task_options.merge(priority: priority.to_s))
            task.wait_for_completion
            { 'task_state' => task.info.state }
          end
        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

7 entries across 5 versions & 2 rubygems

Version Path
fog-vsphere-2.5.0 lib/fog/vsphere/requests/compute/vm_migrate.rb
fog-vsphere-2.4.0 lib/fog/vsphere/requests/compute/vm_migrate.rb
fog-vsphere-2.3.0 lib/fog/vsphere/requests/compute/vm_migrate.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.3.0/gems/fog-vsphere-2.2.0/lib/fog/vsphere/requests/compute/vm_migrate.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.4.0/gems/fog-vsphere-2.2.0/lib/fog/vsphere/requests/compute/vm_migrate.rb
vagrant-packet-0.1.1 vendor/bundle/ruby/2.5.0/gems/fog-vsphere-2.2.0/lib/fog/vsphere/requests/compute/vm_migrate.rb
fog-vsphere-2.2.0 lib/fog/vsphere/requests/compute/vm_migrate.rb