Class: VagrantPlugins::Packet::Action::TerminateInstance

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-packet/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.



11
12
13
14
# File 'lib/vagrant-packet/action/terminate_instance.rb', line 11

def initialize(app, _env)
  @app    = app
  @logger = Log4r::Logger.new('vagrant_packet::action::terminate_instance')
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/vagrant-packet/action/terminate_instance.rb', line 16

def call(env)
  server = env[:packet_compute].devices.get(env[:machine].id)

  # Destroy the server and remove the tracking ID
  env[:ui].info(I18n.t('vagrant_packet.terminating'))
  begin
    server.destroy
    env[:machine].id = nil
  rescue Exception => e
    env[:ui].info(I18n.t('vagrant_packet.terminate_while_provisioning'))
  end

  @app.call(env)
end