From b23b48a61420980e05b4319520609d25921c893c Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Mon, 23 Nov 2015 12:05:37 -0800 Subject: [PATCH] providers/hyper-v: support more than one NIC [GH-4346] --- CHANGELOG.md | 1 + .../hyperv/scripts/get_network_config.ps1 | 14 ++++++++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d926db4d5..d68390115 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -103,6 +103,7 @@ BUG FIXES: - guests/suse: DHCP network interfaces properly configured [GH-6502] - hosts/slackware: Better detection of NFS [GH-6367] - providers/hyper-v: support generation 2 VMs [GH-6372] + - providers/hyper-v: support VMs with more than one NIC [GH-4346] - providers/virtualbox: ignore "Unknown" status bridge interfaces [GH-6061] - provisioners/ansible: use quotes for the `ansible_ssh_private_key_file` value in the generated inventory [GH-6209] diff --git a/plugins/providers/hyperv/scripts/get_network_config.ps1 b/plugins/providers/hyperv/scripts/get_network_config.ps1 index f8554297c..b8eab5f9a 100644 --- a/plugins/providers/hyperv/scripts/get_network_config.ps1 +++ b/plugins/providers/hyperv/scripts/get_network_config.ps1 @@ -7,9 +7,19 @@ 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" -$network = Get-VMNetworkAdapter -VM $vm -$ip_address = $network.IpAddresses[0] +$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 + } + } +} + $resultHash = @{ ip = "$ip_address" }