class VagrantPlugins::VSphere::Action::GetState

Public Class Methods

new(app, _env) click to toggle source
# File lib/vSphere/action/get_state.rb, line 12
def initialize(app, _env)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/vSphere/action/get_state.rb, line 16
def call(env)
  env[:machine_state_id] = get_state(env[:vSphere_connection], env[:machine])

  @app.call env
end

Private Instance Methods

get_state(connection, machine) click to toggle source
# File lib/vSphere/action/get_state.rb, line 24
def get_state(connection, machine)
  return :not_created  if machine.id.nil?

  vm = get_vm_by_uuid connection, machine

  return :not_created if vm.nil?

  if powered_on?(vm)
    :running
  else
    # If the VM is powered off or suspended, we consider it to be powered off. A power on command will either turn on or resume the VM
    :poweroff
  end
end