Skip to content
This repository was archived by the owner on Dec 17, 2021. It is now read-only.

Commit feb4c89

Browse files
committed
drivers/virtualbox: Adapt for lambda-machine-local
1 parent 6a79b0d commit feb4c89

2 files changed

Lines changed: 29 additions & 24 deletions

File tree

drivers/virtualbox/virtualbox.go

Lines changed: 22 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222

2323
const (
2424
defaultCPU = 1
25-
defaultMemory = 1024
25+
defaultMemory = 2048
2626
defaultBoot2DockerURL = ""
2727
defaultBoot2DockerImportVM = ""
2828
defaultHostOnlyCIDR = "192.168.99.1/24"
@@ -125,16 +125,16 @@ func (d *Driver) GetCreateFlags() []mcnflag.Flag {
125125
EnvVar: "VIRTUALBOX_DISK_SIZE",
126126
},
127127
mcnflag.StringFlag{
128-
Name: "virtualbox-boot2docker-url",
129-
Usage: "The URL of the boot2docker image. Defaults to the latest available version",
128+
Name: "virtualbox-lambda-linux-vbox-url",
129+
Usage: "The URL of the Lambda Linux VirtualBox image. Defaults to the latest available version",
130130
Value: defaultBoot2DockerURL,
131-
EnvVar: "VIRTUALBOX_BOOT2DOCKER_URL",
131+
EnvVar: "VIRTUALBOX_LAMBDA_LINUX_VBOX_URL",
132132
},
133133
mcnflag.StringFlag{
134-
Name: "virtualbox-import-boot2docker-vm",
135-
Usage: "The name of a Boot2Docker VM to import",
134+
Name: "virtualbox-import-lambda-linux-vbox-vm",
135+
Usage: "The name of a Lambda Linux VirtualBox VM to import",
136136
Value: defaultBoot2DockerImportVM,
137-
EnvVar: "VIRTUALBOX_BOOT2DOCKER_IMPORT_VM",
137+
EnvVar: "VIRTUALBOX_LAMBDA_LINUX_VBOX_IMPORT_VM",
138138
},
139139
mcnflag.BoolFlag{
140140
Name: "virtualbox-host-dns-resolver",
@@ -205,7 +205,7 @@ func (d *Driver) GetSSHHostname() (string, error) {
205205

206206
func (d *Driver) GetSSHUsername() string {
207207
if d.SSHUser == "" {
208-
d.SSHUser = "docker"
208+
d.SSHUser = "ll-user"
209209
}
210210

211211
return d.SSHUser
@@ -229,15 +229,14 @@ func (d *Driver) GetURL() (string, error) {
229229

230230
func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
231231
if drivers.EngineInstallURLFlagSet(flags) {
232-
return errors.New("--engine-install-url cannot be used with the virtualbox driver, use --virtualbox-boot2docker-url instead")
232+
return errors.New("--engine-install-url cannot be used with the virtualbox driver, use --virtualbox-lambda-linux-vbox-url instead")
233233
}
234234
d.CPU = flags.Int("virtualbox-cpu-count")
235235
d.Memory = flags.Int("virtualbox-memory")
236236
d.DiskSize = flags.Int("virtualbox-disk-size")
237-
d.Boot2DockerURL = flags.String("virtualbox-boot2docker-url")
238-
d.SetSwarmConfigFromFlags(flags)
239-
d.SSHUser = "docker"
240-
d.Boot2DockerImportVM = flags.String("virtualbox-import-boot2docker-vm")
237+
d.Boot2DockerURL = flags.String("virtualbox-lambda-linux-vbox-url")
238+
d.SSHUser = "ll-user"
239+
d.Boot2DockerImportVM = flags.String("virtualbox-import-lambda-linux-vbox-vm")
241240
d.HostDNSResolver = flags.Bool("virtualbox-host-dns-resolver")
242241
d.NatNicType = flags.String("virtualbox-nat-nictype")
243242
d.HostOnlyCIDR = flags.String("virtualbox-hostonly-cidr")
@@ -261,6 +260,10 @@ func (d *Driver) PreCreateCheck() error {
261260
return err
262261
}
263262

263+
// Set GithubAPIToken which can be used to set Authorization headers when
264+
// communicating with Github
265+
mcnutils.GithubAPIToken = d.GithubAPIToken
266+
264267
// Check that VBoxManage is of a supported version
265268
if err = checkVBoxManageVersion(strings.TrimSpace(version)); err != nil {
266269
return err
@@ -336,7 +339,7 @@ func (d *Driver) CreateVM() error {
336339
d.Memory = vmInfo.Memory
337340

338341
log.Debugf("Importing SSH key...")
339-
keyPath := filepath.Join(mcnutils.GetHomeDir(), ".ssh", "id_boot2docker")
342+
keyPath := filepath.Join(mcnutils.GetHomeDir(), ".ssh", "id_lambda_linux_vbox")
340343
if err := mcnutils.CopyFile(keyPath, d.GetSSHKeyPath()); err != nil {
341344
return err
342345
}
@@ -423,7 +426,8 @@ func (d *Driver) CreateVM() error {
423426
if err := d.vbm("storagectl", d.MachineName,
424427
"--name", "SATA",
425428
"--add", "sata",
426-
"--hostiocache", "on"); err != nil {
429+
"--hostiocache", "on",
430+
"--portcount", "2"); err != nil {
427431
return err
428432
}
429433

@@ -432,7 +436,7 @@ func (d *Driver) CreateVM() error {
432436
"--port", "0",
433437
"--device", "0",
434438
"--type", "dvddrive",
435-
"--medium", d.ResolveStorePath("boot2docker.iso")); err != nil {
439+
"--medium", d.ResolveStorePath("lambda-linux-vbox.iso")); err != nil {
436440
return err
437441
}
438442

@@ -789,7 +793,8 @@ func (d *Driver) GetIP() (string, error) {
789793

790794
log.Debugf("Host-only MAC: %s\n", macAddress)
791795

792-
output, err := drivers.RunSSHCommandFromDriver(d, "ip addr show")
796+
// Provide full path for `ip`
797+
output, err := drivers.RunSSHCommandFromDriver(d, "/sbin/ip addr show")
793798
if err != nil {
794799
return "", err
795800
}

drivers/virtualbox/virtualbox_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ func TestSSHHostname(t *testing.T) {
5959
func TestDefaultSSHUsername(t *testing.T) {
6060
username := newTestDriver("default").GetSSHUsername()
6161

62-
assert.Equal(t, "docker", username)
62+
assert.Equal(t, "ll-user", username)
6363
}
6464

6565
var parseShareFolderTestCases = []struct {
@@ -516,7 +516,7 @@ func mockCalls(t *testing.T, driver *Driver, expectedCalls []Call) {
516516
func TestCreateVM(t *testing.T) {
517517
shareName, shareDir := getShareDriveAndName()
518518

519-
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"
519+
modifyVMcommand := "vbm modifyvm default --firmware bios --bioslogofadein off --bioslogofadeout off --bioslogodisplaytime 0 --biosbootmenu disabled --ostype Linux26_64 --cpus 1 --memory 2048 --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"
520520
if runtime.GOOS == "windows" && runtime.GOARCH == "386" {
521521
modifyVMcommand += " --longmode on"
522522
}
@@ -529,8 +529,8 @@ func TestCreateVM(t *testing.T) {
529529
{"vbm createvm --basefolder path/machines/default --name default --register", "", nil},
530530
{modifyVMcommand, "", nil},
531531
{"vbm modifyvm default --nic1 nat --nictype1 82540EM --cableconnected1 on", "", nil},
532-
{"vbm storagectl default --name SATA --add sata --hostiocache on", "", nil},
533-
{"vbm storageattach default --storagectl SATA --port 0 --device 0 --type dvddrive --medium path/machines/default/boot2docker.iso", "", nil},
532+
{"vbm storagectl default --name SATA --add sata --hostiocache on --portcount 2", "", nil},
533+
{"vbm storageattach default --storagectl SATA --port 0 --device 0 --type dvddrive --medium path/machines/default/lambda-linux-vbox.iso", "", nil},
534534
{"vbm storageattach default --storagectl SATA --port 1 --device 0 --type hdd --medium path/machines/default/disk.vmdk", "", nil},
535535
{"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountPrefix /", "", nil},
536536
{"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountDir /", "", nil},
@@ -546,7 +546,7 @@ func TestCreateVM(t *testing.T) {
546546
func TestCreateVMWithSpecificNatNicType(t *testing.T) {
547547
shareName, shareDir := getShareDriveAndName()
548548

549-
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"
549+
modifyVMcommand := "vbm modifyvm default --firmware bios --bioslogofadein off --bioslogofadeout off --bioslogodisplaytime 0 --biosbootmenu disabled --ostype Linux26_64 --cpus 1 --memory 2048 --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"
550550
if runtime.GOOS == "windows" && runtime.GOARCH == "386" {
551551
modifyVMcommand += " --longmode on"
552552
}
@@ -560,8 +560,8 @@ func TestCreateVMWithSpecificNatNicType(t *testing.T) {
560560
{"vbm createvm --basefolder path/machines/default --name default --register", "", nil},
561561
{modifyVMcommand, "", nil},
562562
{"vbm modifyvm default --nic1 nat --nictype1 Am79C973 --cableconnected1 on", "", nil},
563-
{"vbm storagectl default --name SATA --add sata --hostiocache on", "", nil},
564-
{"vbm storageattach default --storagectl SATA --port 0 --device 0 --type dvddrive --medium path/machines/default/boot2docker.iso", "", nil},
563+
{"vbm storagectl default --name SATA --add sata --hostiocache on --portcount 2", "", nil},
564+
{"vbm storageattach default --storagectl SATA --port 0 --device 0 --type dvddrive --medium path/machines/default/lambda-linux-vbox.iso", "", nil},
565565
{"vbm storageattach default --storagectl SATA --port 1 --device 0 --type hdd --medium path/machines/default/disk.vmdk", "", nil},
566566
{"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountPrefix /", "", nil},
567567
{"vbm guestproperty set default /VirtualBox/GuestAdd/SharedFolders/MountDir /", "", nil},

0 commit comments

Comments
 (0)