Class: VagrantPlugins::Scaleway::Action::DestroyServer

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-scaleway/action/destroy_server.rb

Overview

This destroys the running server.

Instance Method Summary collapse

Constructor Details

#initialize(app, _env) ⇒ DestroyServer

Returns a new instance of DestroyServer.



6
7
8
# File 'lib/vagrant-scaleway/action/destroy_server.rb', line 6

def initialize(app, _env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-scaleway/action/destroy_server.rb', line 10

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

  # Destroy the server and remove the tracking ID
  env[:ui].info(I18n.t('vagrant_scaleway.destroying'))

  begin
    server.destroy
  rescue Fog::Scaleway::Compute::InvalidRequestError => e
    if e.message =~ /server should be stopped/
      server.terminate(false)
    else
      raise
    end
  end

  env[:machine].id = nil

  @app.call(env)
end