Class: VagrantPlugins::ProviderOpenStack::Action::ReleaseIp

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-openstack/action/release_ip.rb

Overview

This action reads the SSH info for the machine and puts it into the ‘:machine_ssh_info` key in the environment.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ReleaseIp

Returns a new instance of ReleaseIp.



9
10
11
12
# File 'lib/vagrant-openstack/action/release_ip.rb', line 9

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

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  os = env[:os_connection]
  config = env[:machine].provider_config

  # Find the machine
  server = os.servers.get(env[:machine].id)
  if server.nil?
    # The machine can't be found
    @logger.info("Machine couldn't be found, assuming it got destroyed.")
    machine.id = nil
    return nil
  end

  ips = os.list_all_addresses.body["floating_ips"]
             .select{|data| data['instance_id'] == server.id}

  ips.each do |ip|
      # Do not release the ip if it was explicitly
      # specified by the user.
      if not ip["ip"] == config.floating_ip
        os.release_address(ip["id"])
      end
  end

  @app.call(env)
end