Merge pull request #9450 from jhawk28/vsphere_multi_ip_wait

(vsphere) look at all IPs when waiting for the IP
pull/9483/head
Megan Marsh 6 years ago committed by GitHub
commit f8e21db9bc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -493,37 +493,27 @@ func (vm *VirtualMachine) PowerOn() error {
}
func (vm *VirtualMachine) WaitForIP(ctx context.Context, ipNet *net.IPNet) (string, error) {
var ip string
netIP, err := vm.vm.WaitForNetIP(ctx, false)
if err != nil {
return "", err
}
p := property.DefaultCollector(vm.vm.Client())
err := property.Wait(ctx, p, vm.vm.Reference(), []string{"guest.ipAddress"}, func(pc []types.PropertyChange) bool {
for _, c := range pc {
if c.Name != "guest.ipAddress" {
continue
}
if c.Op != types.PropertyChangeOpAssign {
for _, ips := range netIP {
for _, ip := range ips {
parseIP := net.ParseIP(ip)
if ipNet != nil && !ipNet.Contains(parseIP) {
// ip address is not in range
continue
}
if c.Val == nil {
// default to an ipv4 addresses if no ipNet is defined
if ipNet == nil && parseIP.To4() == nil {
continue
}
ip = c.Val.(string)
if ipNet != nil && !ipNet.Contains(net.ParseIP(ip)) {
// ip address is not in range
return false
}
return true
return ip, nil
}
return false
})
if err != nil {
return "", err
}
return ip, nil
return "", fmt.Errorf("unable to find an IP")
}
func (vm *VirtualMachine) PowerOff() error {

Loading…
Cancel
Save