Class: VagrantPlugins::Sakura::Action::ReadState

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-sakura/action/read_state.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ReadState

Returns a new instance of ReadState.



8
9
10
11
# File 'lib/vagrant-sakura/action/read_state.rb', line 8

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant_sakura::action::read_state")
end

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
# File 'lib/vagrant-sakura/action/read_state.rb', line 13

def call(env)
  env[:machine_state_id] = read_state(env[:sakura_api], env[:machine])
  @app.call(env)
end

#read_state(api, machine) ⇒ Object

returns one of [ :cleaning, :down, :not_created, :up, ]



19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-sakura/action/read_state.rb', line 19

def read_state(api, machine)

  return :not_created if machine.id.nil?

  serverid = machine.id
  begin
    response = api.get("/server/#{serverid}")
  rescue Driver::NotFoundError
    machine.id = nil
    return :not_created
  end
  return response["Server"]["Instance"]["Status"].to_sym
end