Merge pull request #8831 from chrisroberts/hyperv/ipv6
Update guest IP address discovery for hyper-v guests.
This commit is contained in:
commit
18d3e5d286
|
@ -23,19 +23,23 @@ module VagrantPlugins
|
|||
return if env[:interrupted]
|
||||
|
||||
# Try to get the IP
|
||||
network_info = env[:machine].provider.driver.read_guest_ip
|
||||
guest_ip = network_info["ip"]
|
||||
begin
|
||||
network_info = env[:machine].provider.driver.read_guest_ip
|
||||
guest_ip = network_info["ip"]
|
||||
|
||||
if guest_ip
|
||||
begin
|
||||
IPAddr.new(guest_ip)
|
||||
break
|
||||
rescue IPAddr::InvalidAddressError
|
||||
# Ignore, continue looking.
|
||||
@logger.warn("Invalid IP address returned: #{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
|
||||
rescue Errors::PowerShellError
|
||||
# Ignore, continue looking.
|
||||
@logger.warn("Failed to read guest IP.")
|
||||
end
|
||||
|
||||
sleep 1
|
||||
end
|
||||
end
|
||||
|
|
|
@ -7,21 +7,36 @@ Param(
|
|||
$Dir = Split-Path $script:MyInvocation.MyCommand.Path
|
||||
. ([System.IO.Path]::Combine($Dir, "utils\write_messages.ps1"))
|
||||
|
||||
$ip_address = ""
|
||||
$vm = Get-VM -Id $VmId -ErrorAction "Stop"
|
||||
$networks = Get-VMNetworkAdapter -VM $vm
|
||||
foreach ($network in $networks) {
|
||||
if ($network.IpAddresses.Length -gt 0) {
|
||||
$ip_address = $network.IpAddresses[0]
|
||||
if (-Not ([string]::IsNullOrEmpty($ip_address))) {
|
||||
# We found our IP address!
|
||||
break
|
||||
foreach ($ip_address in $network.IpAddresses) {
|
||||
if ($ip_address.Contains(".")) {
|
||||
$ip4_address = $ip_address
|
||||
} elseif ($ip_address.Contains(":")) {
|
||||
$ip6_address = $ip_address
|
||||
}
|
||||
if (-Not ([string]::IsNullOrEmpty($ip4_address)) -Or -Not ([string]::IsNullOrEmpty($ip6_address))) {
|
||||
# We found our IP address!
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$resultHash = @{
|
||||
ip = "$ip_address"
|
||||
if (-Not ([string]::IsNullOrEmpty($ip4_address))) {
|
||||
$guest_ipaddress = $ip4_address
|
||||
} elseif (-Not ([string]::IsNullOrEmpty($ip6_address))) {
|
||||
$guest_ipaddress = $ip6_address
|
||||
}
|
||||
|
||||
if (-Not ([string]::IsNullOrEmpty($guest_ipaddress))) {
|
||||
$resultHash = @{
|
||||
ip = $guest_ipaddress
|
||||
}
|
||||
$result = ConvertTo-Json $resultHash
|
||||
Write-Output-Message $result
|
||||
} else {
|
||||
Write-Error-Message "Failed to determine IP address"
|
||||
}
|
||||
$result = ConvertTo-Json $resultHash
|
||||
Write-Output-Message $result
|
||||
|
|
Loading…
Reference in New Issue