Class: VagrantPlugins::Openstack::Action::DeleteServer

Inherits:
AbstractAction
  • Object
show all
Defined in:
lib/vagrant-openstack-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-openstack-provider/action/delete_server.rb', line 10

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

Instance Method Details

#execute(env) ⇒ Object



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

def execute(env)
  if env[:machine].id
    @logger.info "Deleting server #{env[:machine].id}..."
    env[:ui].info(I18n.t('vagrant_openstack.deleting_server'))
    env[:openstack_client].nova.delete_server(env, env[:machine].id)
    env[:openstack_client].nova.delete_keypair_if_vagrant(env, env[:machine].id)

    waiting_for_instance_to_be_deleted(env, env[:machine].id)

  end

  @app.call(env)
end