Class: VagrantPlugins::Sakura::Action::Halt

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

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Halt

Returns a new instance of Halt.



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

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

Instance Method Details

#call(env) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/vagrant-sakura/action/halt.rb', line 12

def call(env)
  api      = env[:sakura_api]
  serverid = env[:machine].id

  env[:ui].info(I18n.t("vagrant_sakura.power_off"))

  response = api.delete("/server/#{serverid}/power")
  sleep 3
  while true
    response = api.get("/server/#{serverid}/power")
    break if response["Instance"]["Status"] == "down"
    sleep 1
  end

  @app.call(env)
end