Class: VagrantPlugins::Fifo::Action::TerminateInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-fifo/action/terminate_instance.rb

Overview

This terminates the running instance.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ TerminateInstance

Returns a new instance of TerminateInstance.



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

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

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/vagrant-fifo/action/terminate_instance.rb', line 13

def call(env)
  server = env[:fifo_compute].vms.get(env[:machine].id)

  # Destroy the server and remove the tracking ID
  env[:ui].info(I18n.t("vagrant_fifo.terminating"))

  # Machine must be in a stopped state before it's destroyed.
  #
  # More info here:
  #
  #   https://us-west-1.api.fifocloud.com/docs#DeleteMachine
  #
  env[:fifo_compute].vms.delete(server['uuid'])

  # Wait for server to be completely gone from invetory
  while true do
    ids = env[:fifo_compute].vms.list

    unless ids.include?(env[:machine].id) then
      break
    end
    sleep 5
  end

  env[:machine].id = nil

  @app.call(env)
end