Class: VagrantPlugins::DigitalOcean::Actions::Destroy

Inherits:
Object
  • Object
show all
Includes:
Vagrant::Util::Retryable
Defined in:
lib/vagrant-digitalocean/actions/destroy.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ Destroy

Returns a new instance of Destroy.



9
10
11
12
13
# File 'lib/vagrant-digitalocean/actions/destroy.rb', line 9

def initialize(app, env)
  @app, @env = app, env
  @client = Helpers::Client.new
  @translator = Helpers::Translator.new("actions.destroy")
end

Instance Method Details

#call(env) ⇒ Object



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-digitalocean/actions/destroy.rb', line 15

def call(env)
  # TODO remove the key associated with this machine
  if [:active, :new].include?(env[:machine].state.id)
    env[:ui].info @translator.t("destroying")
    result = @client.request("/droplets/#{env[:machine].id}/destroy")

    env[:ui].info @translator.t("wait_off")

    retryable(:tries => 30, :sleep => 10) do
      # If we're interrupted don't worry about waiting
      next if env[:interrupted]

      # Wait for the server to be ready
      raise "not off" if env[:machine].state.id != :off
    end
  else
    env[:ui].info @translator.t("not_active_or_new")
  end

  # make sure to remove the export when the machine is destroyed
  # private in some hosts and requires a send
  env[:ui].info @translator.t("clean_nfs")
  env[:host].send(:nfs_cleanup, env[:machine].id)

  @app.call(env)
end