Sha256: 4afb4b260a76063adcffd4304649b409c93036fc206e21983bcc946790a5e791

Contents?: true

Size: 1.45 KB

Versions: 23

Compression:

Stored size: 1.45 KB

Contents

module Fog
  module Vsphere
    class Compute
      class Real
        def vm_suspend(options = {})
          raise(ArgumentError, 'instance_uuid is a required parameter') unless options.key?('instance_uuid')
          options = { 'force' => false }.merge(options)

          search_filter = { :uuid => options['instance_uuid'], 'vmSearch' => true, 'instanceUuid' => true }
          vm = connection.searchIndex.FindAllByUuid(search_filter).first

          if options['force']
            suspend_forcefully(vm)
          else
            suspend_gracefully(vm)
          end
        end

        private

        def suspend_forcefully(vm)
          task = vm.SuspendVM_Task
          task.wait_for_completion
          {
            'task_state'   => task.info.result,
            'suspend_type' => 'suspend'
          }
        end

        def suspend_gracefully(vm)
          vm.StandbyGuest
          {
            'task_state'   => 'running',
            'suspend_type' => 'standby_guest'
          }
        end
      end

      class Mock
        def vm_suspend(options = {})
          raise ArgumentError, 'instance_uuid is a required parameter' unless options.key? 'instance_uuid'

          vm = get_virtual_machine(options['instance_uuid'])
          vm['power_state'] = 'suspended'

          {
            'task_state'   => 'running',
            'suspend_type' => options['force'] ? 'suspend' : 'standby_guest'
          }
        end
      end
    end
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
fog-vsphere-3.7.0 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.6.8 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.6.7 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.6.6 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.6.5 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.6.4 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.6.3 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.6.2 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.5.3 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.6.0 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.5.2 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.5.1 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.5.0 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.4.0 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.3.1 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.3.0 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.2.5 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.2.2 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.2.1 lib/fog/vsphere/requests/compute/vm_suspend.rb
fog-vsphere-3.2.0 lib/fog/vsphere/requests/compute/vm_suspend.rb