Merge pull request #2629 from dgageot/2617-check-hostonlyif-after-its-creation

FIX #2617 Check hostonlyif after its creation
This commit is contained in:
Nathan LeClaire 2015-12-18 16:15:26 -08:00
commit 932c4a2d27
1 changed files with 12 additions and 0 deletions

View File

@ -15,6 +15,7 @@ const (
var ( var (
reHostonlyInterfaceCreated = regexp.MustCompile(`Interface '(.+)' was successfully created`) reHostonlyInterfaceCreated = regexp.MustCompile(`Interface '(.+)' was successfully created`)
errDuplicateHostOnlyInterfaceNetworks = errors.New("VirtualBox is configured with multiple host-only interfaces with the same IP. Please remove all of them but one.") errDuplicateHostOnlyInterfaceNetworks = errors.New("VirtualBox is configured with multiple host-only interfaces with the same IP. Please remove all of them but one.")
errNewHostOnlyInterfaceNotVisible = errors.New("The host-only interface we just created is not visible. This is a well known bug of VirtualBox. You might want to uninstall it and reinstall the version listed here: https://www.virtualbox.org/ticket/14437?cversion=0&cnum_hist=42")
) )
// Host-only network. // Host-only network.
@ -173,6 +174,17 @@ func getOrCreateHostOnlyNetwork(hostIP net.IP, netmask net.IPMask, dhcpIP net.IP
return nil, err return nil, err
} }
// Check that the interface really exists.
// Sometimes, Vbox says it created the interface but then it cannot be found...
nets, err = listHostOnlyNetworks(vbox)
if err != nil {
return nil, err
}
hostOnlyNet = getHostOnlyNetwork(nets, hostIP, netmask)
if hostOnlyNet == nil {
return nil, errNewHostOnlyInterfaceNotVisible
}
return hostOnlyNet, nil return hostOnlyNet, nil
} }