Class: VagrantPlugins::OpenStack::Action::DeleteServer

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



8
9
10
11
# File 'lib/vagrant-openstack-plugin/action/delete_server.rb', line 8

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

Instance Method Details

#call(env) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant-openstack-plugin/action/delete_server.rb', line 13

def call(env)
  machine = env[:machine]
  id = machine.id || env[:openstack_compute].servers.all( :name => machine.name ).first.id

  if id
    env[:ui].info(I18n.t("vagrant_openstack.deleting_server"))

    # TODO: Validate the fact that we get a server back from the API.
    server = env[:openstack_compute].servers.get(id)
    if server
      ip = server.floating_ip_address
      server.destroy
      if machine.provider_config.floating_ip_pool
        address = env[:openstack_compute].list_all_addresses.body["floating_ips"].find{|i| i["ip"] == ip}
        if address
          env[:openstack_compute].release_address(address["id"])
        end
      end
    end
  end

  @app.call(env)
end