Class: VagrantPlugins::Joyent::Action::TerminateInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-joyent/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-joyent/action/terminate_instance.rb', line 8

def initialize(app, env)
  @app    = app
  @logger = Log4r::Logger.new("vagrant_joyent::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
41
42
43
# File 'lib/vagrant-joyent/action/terminate_instance.rb', line 13

def call(env)
  server = env[:joyent_compute].servers.get(env[:machine].id)

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

  # Machine must be in a stopped state before it's destroyed.
  #
  # More info here:
  #
  #   https://us-west-1.api.joyentcloud.com/docs#DeleteMachine
  #
  server.stop
  server.destroy

  # Wait for server to be completely gone from invetory
  while true do
    ids = []
    env[:joyent_compute].servers.collect.each { |s|
      ids << s.id
    }

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

  env[:machine].id = nil

  @app.call(env)
end