Merge pull request #3124 from StefanScherer/set-nictype1

Add flag --virtualbox-nictype to set NIC type of eth0
This commit is contained in:
Nathan LeClaire 2016-03-15 11:39:10 -07:00
commit 282fdebeaf
2 changed files with 41 additions and 1 deletions

View File

@ -55,6 +55,7 @@ type Driver struct {
CPU int
Memory int
DiskSize int
NatNicType string
Boot2DockerURL string
Boot2DockerImportVM string
HostDNSResolver bool
@ -81,6 +82,7 @@ func NewDriver(hostName, storePath string) *Driver {
Memory: defaultMemory,
CPU: defaultCPU,
DiskSize: defaultDiskSize,
NatNicType: defaultHostOnlyNictype,
HostOnlyCIDR: defaultHostOnlyCIDR,
HostOnlyNicType: defaultHostOnlyNictype,
HostOnlyPromiscMode: defaultHostOnlyPromiscMode,
@ -132,6 +134,12 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
Usage: "Use the host DNS resolver",
EnvVar: "VIRTUALBOX_HOST_DNS_RESOLVER",
},
mcnflag.StringFlag{
Name: "virtualbox-nat-nictype",
Usage: "Specify the Network Adapter Type",
Value: defaultHostOnlyNictype,
EnvVar: "VIRTUALBOX_NAT_NICTYPE",
},
mcnflag.StringFlag{
Name: "virtualbox-hostonly-cidr",
Usage: "Specify the Host Only CIDR",
@ -208,6 +216,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
d.SSHUser = "docker"
d.Boot2DockerImportVM = flags.String("virtualbox-import-boot2docker-vm")
d.HostDNSResolver = flags.Bool("virtualbox-host-dns-resolver")
d.NatNicType = flags.String("virtualbox-nat-nictype")
d.HostOnlyCIDR = flags.String("virtualbox-hostonly-cidr")
d.HostOnlyNicType = flags.String("virtualbox-hostonly-nictype")
d.HostOnlyPromiscMode = flags.String("virtualbox-hostonly-nicpromisc")
@ -380,7 +389,7 @@ func (d *Driver) CreateVM() error {
if err := d.vbm("modifyvm", d.MachineName,
"--nic1", "nat",
"--nictype1", "82540EM",
"--nictype1", d.NatNicType,
"--cableconnected1", "on"); err != nil {
return err
}

View File

@ -470,6 +470,37 @@ func TestCreateVM(t *testing.T) {
assert.NoError(t, err)
}
func TestCreateVMWithSpecificNatNicType(t *testing.T) {
shareName, shareDir := getShareDriveAndName()
modifyVMcommand := "vbm modifyvm default --firmware bios --bioslogofadein off --bioslogofadeout off --bioslogodisplaytime 0 --biosbootmenu disabled --ostype Linux26_64 --cpus 1 --memory 1024 --acpi on --ioapic on --rtcuseutc on --natdnshostresolver1 off --natdnsproxy1 on --cpuhotplug off --pae on --hpet on --hwvirtex on --nestedpaging on --largepages on --vtxvpid on --accelerate3d off --boot1 dvd"
if runtime.GOOS == "windows" && runtime.GOARCH == "386" {
modifyVMcommand += " --longmode on"
}
driver := NewDriver("default", "path")
driver.NatNicType = "Am79C973"
mockCalls(t, driver, []Call{
{"CopyIsoToMachineDir path default http://b2d.org", "", nil},
{"Generate path/machines/default/id_rsa", "", nil},
{"Create 20000 path/machines/default/id_rsa.pub path/machines/default/disk.vmdk", "", nil},
{"vbm createvm --basefolder path/machines/default --name default --register", "", nil},
{modifyVMcommand, "", nil},
{"vbm modifyvm default --nic1 nat --nictype1 Am79C973 --cableconnected1 on", "", nil},
{"vbm storagectl default --name SATA --add sata --hostiocache on", "", nil},
{"vbm storageattach default --storagectl SATA --port 0 --device 0 --type dvddrive --medium path/machines/default/boot2docker.iso", "", nil},
{"vbm storageattach default --storagectl SATA --port 1 --device 0 --type hdd --medium path/machines/default/disk.vmdk", "", nil},
{"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountPrefix /", "", nil},
{"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountDir /", "", nil},
{"vbm sharedfolder add default --name " + shareName + " --hostpath " + shareDir + " --automount", "", nil},
{"vbm setextradata default VBoxInternal2/SharedFoldersEnableSymlinksCreate/" + shareName + " 1", "", nil},
})
err := driver.CreateVM()
assert.NoError(t, err)
}
func TestStart(t *testing.T) {
driver := NewDriver("default", "path")
mockCalls(t, driver, []Call{