providers/hyperv: validate IP address returned [GH-3069]

This commit is contained in:
Mitchell Hashimoto 2014-03-06 07:35:46 -08:00
parent 35adc6063b
commit 0037d2c767
1 changed files with 12 additions and 1 deletions

View File

@ -1,3 +1,4 @@
require "ipaddr"
require "timeout" require "timeout"
module VagrantPlugins module VagrantPlugins
@ -6,6 +7,7 @@ module VagrantPlugins
class WaitForIPAddress class WaitForIPAddress
def initialize(app, env) def initialize(app, env)
@app = app @app = app
@logger = Log4r::Logger.new("vagrant::hyperv::wait_for_ip_addr")
end end
def call(env) def call(env)
@ -24,7 +26,16 @@ module VagrantPlugins
network_info = env[:machine].provider.driver.execute( network_info = env[:machine].provider.driver.execute(
"get_network_config.ps1", VmId: env[:machine].id) "get_network_config.ps1", VmId: env[:machine].id)
guest_ip = network_info["ip"] guest_ip = network_info["ip"]
break if guest_ip && guest_ip != ""
if guest_ip
begin
IPAddr.new(guest_ip)
break
rescue IPAddr::InvalidAddressError
# Ignore, continue looking.
@logger.warn("Invalid IP address returned: #{guest_ip}")
end
end
sleep 1 sleep 1
end end