Module: VagrantPlugins::Skytap::API::RunstateOperations

Included in:
Environment, Vm
Defined in:
lib/vagrant-skytap/api/runstate_operations.rb

Constant Summary collapse

RUNSTATE_RETRY =
5

Instance Method Summary collapse

Instance Method Details

#busy?Boolean



82
83
84
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 82

def busy?
  runstate == 'busy'
end

#poweroff!Object



43
44
45
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 43

def poweroff!
  set_runstate :halted, completed_runstate: :stopped
end

#run!Object



31
32
33
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 31

def run!
  set_runstate :running
end

#running?Boolean



90
91
92
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 90

def running?
  runstate == 'running'
end

#runstateObject



78
79
80
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 78

def runstate
  get_api_attribute('runstate')
end

#set_runstate(new_runstate, opts = {}) ⇒ Object



47
48
49
50
51
52
53
54
55
56
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 47

def set_runstate(new_runstate, opts = {})
  completed_runstate = opts.delete(:completed_runstate) || new_runstate

  params = {runstate: new_runstate}.tap do |ret|
    ret[:multiselect] = opts[:vm_ids] if opts[:vm_ids]
  end
  update(params)

  wait_for_runstate(completed_runstate) unless runstate == completed_runstate
end

#stop!Object



39
40
41
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 39

def stop!
  set_runstate :stopped
end

#stopped?Boolean



86
87
88
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 86

def stopped?
  runstate == 'stopped'
end

#suspend!Object



35
36
37
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 35

def suspend!
  set_runstate :suspended
end

#wait_for_runstate(expected_runstate) ⇒ Object



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 62

def wait_for_runstate(expected_runstate)
  expected_runstate = expected_runstate.to_s
  begin
    Timeout.timeout(provider_config.instance_ready_timeout) do
      loop do
        unless reload.busy?
          break if runstate == expected_runstate || expected_runstate == 'ready'
        end
        sleep RUNSTATE_RETRY
      end
    end
  rescue Timeout::Error => ex
    raise Errors::InstanceReadyTimeout, timeout: provider_config.instance_ready_timeout
  end
end

#wait_until_readyObject



58
59
60
# File 'lib/vagrant-skytap/api/runstate_operations.rb', line 58

def wait_until_ready
  wait_for_runstate :ready
end