Skip to content
This repository was archived by the owner on Feb 27, 2018. It is now read-only.

Add VirtualBox 5 support #373

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions virtualbox/machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ func (m *Machine) Modify() error {
"--cpuhotplug", m.Flag.Get(F_cpuhotplug),
"--pae", m.Flag.Get(F_pae),
"--longmode", m.Flag.Get(F_longmode),
"--synthcpu", m.Flag.Get(F_synthcpu),
//"--synthcpu", m.Flag.Get(F_synthcpu),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove before merging?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, probably a good idea.

"--hpet", m.Flag.Get(F_hpet),
"--hwvirtex", m.Flag.Get(F_hwvirtex),
"--triplefaultreset", m.Flag.Get(F_triplefaultreset),
Expand Down Expand Up @@ -690,13 +690,13 @@ func (m *Machine) Modify() error {

// AddNATPF adds a NAT port forarding rule to the n-th NIC with the given name.
func (m *Machine) AddNATPF(n int, name string, rule driver.PFRule) error {
return vbm("controlvm", m.Name, fmt.Sprintf("natpf%d", n),
return vbm("modifyvm", m.Name, fmt.Sprintf("--natpf%d", n),

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems to make sense as this is what docker-machine does, but what's the effect / reason behind changing this?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The reason is that "controlvm" only works if the VM is already running: see https://www.virtualbox.org/manual/ch08.html#vboxmanage-controlvm

The controlvm subcommand allows you to change the state of a virtual machine that is currently running.

Is boot2docker-cli supposed to start the VM before performing this? If so, it doesn't do that on VBox 5.

Or did those commands work on VBox 4 without starting the VM first? I do not know.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm definitely also surprised by this change -- does it not work as-is after removing the --synthcpu flag? I'd prefer to have this PR be as conservative as possible (especially so we can merge a fix before 1.7.1 which is supposed to happen sometime today), and perhaps a new PR to bring us better parity with docker-machine afterwards (but I'd even more prefer that we encourage users to just use docker-machine directly instead).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, the diff in this PR looks as much like the diff in docker/machine#1496 as we can and actually have VBox 5 "work".

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the record, yes, I believed this not to work without this change. That seems consistent with the VirtualBox documentation. After all, this call is being made while the VM is shut down, or is it not?

fmt.Sprintf("%s,%s", name, rule.Format()))
}

// DelNATPF deletes the NAT port forwarding rule with the given name from the n-th NIC.
func (m *Machine) DelNATPF(n int, name string) error {
return vbm("controlvm", m.Name, fmt.Sprintf("natpf%d", n), "delete", name)
return vbm("modifyvm", m.Name, fmt.Sprintf("--natpf%d", n), "delete", name)
}

// SetNIC set the n-th NIC.
Expand Down
6 changes: 6 additions & 0 deletions virtualbox/vbm.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package virtualbox
import (
"bytes"
"errors"
"fmt"
"io"
"log"
"os"
Expand Down Expand Up @@ -99,6 +100,11 @@ func getHostOnlyNetworkInterface(mc *driver.MachineConfig) (string, error) {

for _, n := range nets {
if dhcp, ok := dhcps[n.NetworkName]; ok {
fmt.Printf("IPv4 / DHCP IP: %s == %s\n", dhcp.IPv4.IP, mc.DHCPIP)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the print statements before merging?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well, the print statements are essential for how I'm working with this:

For some reason, I didn't have any proper host-only networks. (That might be because I upgraded from VBox 4 / 5rc1 on this machine, when host-only networks didn't work yet.)

So what I'm doing is rerunning "boot2docker init" with these print statements, making changes to my host-only networks with the VBox GUI until they exactly match the network that boot2docker-cli expects to find.

I'm not sure what's really supposed to happen here. I guess boot2docker-cli should automatically create the host-only network it needs? Maybe we just need to fix that for VBox 5.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, boot2docker init should set everything up, so if its not working for vbox5, it needs to be fixed too.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's probably a bigger issue to tackle. Maybe even an issue with VirtualBox 5, I don't think the creation of host-only networks works anymore. I just reported the same issue for docker-machine: docker/machine#1521

fmt.Printf("IPv4 netmask: %s == %s\n", dhcp.IPv4.Mask, mc.NetMask)
fmt.Printf("DHCP lower bound: %s == %s\n", dhcp.LowerIP, mc.LowerIP)
fmt.Printf("DHCP upper bound: %s == %s\n", dhcp.UpperIP, mc.UpperIP)
fmt.Printf("DHCP enabled: %s == %s\n", dhcp.Enabled, mc.DHCPEnabled)
if dhcp.IPv4.IP.Equal(mc.DHCPIP) &&
dhcp.IPv4.Mask.String() == mc.NetMask.String() &&
dhcp.LowerIP.Equal(mc.LowerIP) &&
Expand Down