Class: VagrantPlugins::Deltacloud::Action::DeleteServer

Inherits:
AbstractAction
  • Object
show all
Defined in:
lib/vagrant-deltacloud-provider/action/delete_server.rb

Overview

This deletes the running server, if there is one.

Instance Method Summary collapse

Methods inherited from AbstractAction

#call

Constructor Details

#initialize(app, _env) ⇒ DeleteServer

Returns a new instance of DeleteServer.



10
11
12
13
# File 'lib/vagrant-deltacloud-provider/action/delete_server.rb', line 10

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

Instance Method Details

#execute(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vagrant-deltacloud-provider/action/delete_server.rb', line 15

def execute(env)
  env[:deltacloud_client] = Deltacloud::DeltacloudClient.instance
  if env[:machine].id
    @logger.info "Deleting server #{env[:machine].id}..."
    env[:ui].info(I18n.t('vagrant_deltacloud.deleting_server'))
    instance_details = env[:deltacloud_client].get_instance_details(env, env[:machine].id)
    key_id = instance_details.key_name
    env[:deltacloud_client].destroy_instance(env, env[:machine].id)
    env[:deltacloud_client].delete_public_key(env, key_id)
    env[:machine].id = nil
  end

  @app.call(env)
end