21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
|
# File 'lib/vagrant-openstack-plugin/action/read_ssh_info.rb', line 21
def read_ssh_info(openstack, machine, floating_ip)
id = machine.id || openstack.servers.all( :name => machine.name ).first.id rescue nil
return nil if id.nil?
server = openstack.servers.get(id)
if server.nil?
@logger.info("Machine couldn't be found, assuming it got destroyed.")
machine.id = nil
return nil
end
config = machine.provider_config
server.addresses.each do |network_name, network_info|
@logger.debug("OpenStack Network Name: #{network_name}")
end
if config.network
host = server.addresses[config.network].last['addr'] rescue nil
else
if config.address_id.to_sym == :floating_ip
host = floating_ip
else
host = server.addresses[config.address_id].last['addr'] rescue nil
end
end
if host.nil?
@logger.debug("Was unable to determine what network to use. Trying to find a valid IP to use.")
if server.public_ip_addresses.length > 0
@logger.debug("Public IP addresses available: #{server.public_ip_addresses}")
if floating_ip
if server.public_ip_addresses.include?(floating_ip)
@logger.debug("Using the floating IP defined in Vagrantfile.")
host = machine.floating_ip
else
@logger.debug("The floating IP that was specified is not available to this instance.")
raise Errors::FloatingIPNotValid
end
else
host = server.public_ip_address
@logger.debug("Using the first available public IP address: #{host}.")
end
elsif server.private_ip_addresses.length > 0
@logger.debug("Private IP addresses available: #{server.private_ip_addresses}")
if config.ssh_ip_family.nil?
host = server.private_ip_address
@logger.debug("Using the first available private IP address: #{host}.")
else
for ip in server.private_ip_addresses
addr = IPAddr.new ip
if addr.send("#{config.ssh_ip_family}?".to_sym)
host = ip.to_s
@logger.debug("Using the first available #{config.ssh_ip_family} IP address: #{host}.")
break
end
end
end
end
end
if host.nil? or host.empty?
@logger.debug("No valid SSH host could be found.")
raise Errors::SSHNoValidHost
end
return {
:host => host,
:port => 22,
:username => config.ssh_username
}
end
|