Class: VagrantPlugins::Openstack::Utils
- Inherits:
-
Object
- Object
- VagrantPlugins::Openstack::Utils
- Defined in:
- lib/vagrant-openstack-provider/utils.rb
Instance Method Summary collapse
- #get_ip_address(env) ⇒ Object
-
#initialize ⇒ Utils
constructor
A new instance of Utils.
Constructor Details
#initialize ⇒ Utils
Returns a new instance of Utils.
4 5 6 |
# File 'lib/vagrant-openstack-provider/utils.rb', line 4 def initialize @logger = Log4r::Logger.new('vagrant_openstack::action::config_resolver') end |
Instance Method Details
#get_ip_address(env) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vagrant-openstack-provider/utils.rb', line 8 def get_ip_address(env) addresses = env[:openstack_client].nova.get_server_details(env, env[:machine].id)['addresses'] addresses.each do |_, network| network.each do |network_detail| return network_detail['addr'] if network_detail['OS-EXT-IPS:type'] == 'floating' end # Do not choose IPv6 address network.delete_if do |network_detail| network_detail['version'] == 6 end end fail Errors::UnableToResolveIP if addresses.size == 0 if addresses.size == 1 net_addresses = addresses.first[1] else first_network = env[:machine].provider_config.networks[0] if first_network.is_a? String net_addresses = addresses[first_network] else net_addresses = addresses[first_network[:name]] end end fail Errors::UnableToResolveIP if net_addresses.size == 0 net_addresses[0]['addr'] end |