virtualbox: check for hostonly iface and add if needed on start

Signed-off-by: Evan Hazlett <ejhazlett@gmail.com>
This commit is contained in:
Evan Hazlett
2015-06-02 23:00:13 -04:00
parent 7925bf2683
commit 3304bf8923
+30 -14
View File
@@ -273,20 +273,7 @@ func (d *Driver) Create() error {
return err
}
hostOnlyNetwork, err := getOrCreateHostOnlyNetwork(
net.ParseIP("192.168.99.1"),
net.IPv4Mask(255, 255, 255, 0),
net.ParseIP("192.168.99.2"),
net.ParseIP("192.168.99.100"),
net.ParseIP("192.168.99.254"))
if err != nil {
return err
}
if err := vbm("modifyvm", d.MachineName,
"--nic2", "hostonly",
"--nictype2", "82540EM",
"--hostonlyadapter2", hostOnlyNetwork.Name,
"--cableconnected2", "on"); err != nil {
if err := setupHostOnlyNetwork(d.MachineName); err != nil {
return err
}
@@ -372,6 +359,11 @@ func (d *Driver) Start() error {
return err
}
// check network to re-create if needed
if err := setupHostOnlyNetwork(d.MachineName); err != nil {
return err
}
switch s {
case state.Stopped, state.Saved:
d.SSHPort, err = setPortForwarding(d.MachineName, 1, "ssh", "tcp", 22, d.SSHPort)
@@ -678,3 +670,27 @@ func setPortForwarding(machine string, interfaceNum int, mapName, protocol strin
}
return actualHostPort, nil
}
func setupHostOnlyNetwork(machineName string) error {
hostOnlyNetwork, err := getOrCreateHostOnlyNetwork(
net.ParseIP("192.168.99.1"),
net.IPv4Mask(255, 255, 255, 0),
net.ParseIP("192.168.99.2"),
net.ParseIP("192.168.99.100"),
net.ParseIP("192.168.99.254"),
)
if err != nil {
return err
}
if err := vbm("modifyvm", machineName,
"--nic2", "hostonly",
"--nictype2", "82540EM",
"--hostonlyadapter2", hostOnlyNetwork.Name,
"--cableconnected2", "on"); err != nil {
return err
}
return nil
}