Class: VagrantPlugins::Linode::Actions::ReadState

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-linode/actions/read_state.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ReadState

Returns a new instance of ReadState.



5
6
7
8
9
# File 'lib/vagrant-linode/actions/read_state.rb', line 5

def initialize(app, env)
  @app = app
  @machine = env[:machine]
  @logger = Log4r::Logger.new('vagrant_linode::action::read_state')
end

Instance Method Details

#call(env) ⇒ Object



11
12
13
14
15
# File 'lib/vagrant-linode/actions/read_state.rb', line 11

def call(env)
  env[:machine_state] = read_state(env[:linode_api], @machine)
  @logger.info "Machine state is '#{env[:machine_state]}'"
  @app.call(env)
end

#read_state(_linode, machine) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-linode/actions/read_state.rb', line 17

def read_state(_linode, machine)
  return :not_created if machine.id.nil?
  server = Provider.linode(machine)
  return :not_created if server.nil?
  status = server[:status]
  return :not_created if status.nil?
  states = {
    ''  => :not_created,
    '-2' => :boot_failed,
    '-1' => :being_created,
    '0' => :brand_new,
    '1' => :active, # running
    '2' => :off, # powered off
    '3' => :shutting_down
  }
  states[status.to_s]
end