Class: VagrantPlugins::HP::Action::DeleteServer

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

Overview

This deletes the running server, if there is one.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ DeleteServer

Returns a new instance of DeleteServer.



13
14
15
16
# File 'lib/vagrant-hp/action/delete_server.rb', line 13

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

Instance Method Details

#call(env) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/vagrant-hp/action/delete_server.rb', line 18

def call(env)
  if env[:machine].id
    config = env[:machine].provider_config
    if not config.floating_ip
      @logger.info(I18n.t('vagrant_hp.deleting_floating_ip'))
      ip = env[:hp_compute].addresses.find { |ip| ip.instance_id==env[:machine].id }
      ip.destroy
    end
    @logger.info(I18n.t('vagrant_hp.deleting_server'))
    server = env[:hp_compute].servers.get(env[:machine].id)
    server.destroy
    env[:machine].id = nil
  end
  @app.call(env)
end