Skip to content

Commit

Permalink
updating path to just vboxmanage constructing import command argument…
Browse files Browse the repository at this point in the history
…s before actual use to avoid escaped chars in homedirname
  • Loading branch information
akhiljns committed Mar 19, 2024
1 parent 2feda54 commit 975f086
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
.idea
*.iml
.vscode/
vermin.exe
4 changes: 1 addition & 3 deletions db/db.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package db

import (
"fmt"
"log"
"os"
"path/filepath"
Expand All @@ -19,8 +18,7 @@ var (
)

func GetImageFilePath(imageName string) string {
imagePath := fmt.Sprintf("`%s`", filepath.Join(ImagesDir, imageName+".ova"))
return imagePath
return filepath.Join(ImagesDir, imageName+".ova")
}

func GetVMPath(vm string) string {
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ module github.com/mhewedy/vermin
go 1.13

require (
github.com/artonge/go-csv-tag/v2 v2.0.7
github.com/matishsiao/goInfo v0.0.0-20200404012835-b5f882ee2288
github.com/mhewedy/go-gistlog v0.0.5
github.com/schollz/progressbar/v3 v3.3.3
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAE
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
github.com/artonge/go-csv-tag/v2 v2.0.7 h1:15R880S8+SHSKjvCZyNE2r3gNSaS0RQlGuU7s+w2/Fw=
github.com/artonge/go-csv-tag/v2 v2.0.7/go.mod h1:MhLKePA0uu/+2jUJ4IER31uhRV/0GsIKyrSqSRR7Mkc=
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
Expand Down Expand Up @@ -98,9 +96,7 @@ github.com/spf13/pflag v1.0.3 h1:zPAT6CGy6wXeQ7NtTnaTerfKOsV6V6F8agHXFiazDkg=
github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
github.com/spf13/viper v1.4.0/go.mod h1:PTJ7Z/lr49W6bUbkmS1V3by4uWynFiR9p7+dSq/yZzE=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/objx v0.1.1 h1:2vfRuCMp5sSVIDSqO8oNnWJq7mPa6KVP3iPIwFBuy8A=
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0Q=
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
Expand Down
28 changes: 20 additions & 8 deletions hypervisor/virtualbox/virtualbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,14 @@ import (
"bufio"
"errors"
"fmt"
"github.com/mhewedy/vermin/cmd"
"github.com/mhewedy/vermin/db"
"github.com/mhewedy/vermin/hypervisor/base"
"runtime"
"strconv"
"strings"
"time"

"github.com/mhewedy/vermin/cmd"
"github.com/mhewedy/vermin/db"
"github.com/mhewedy/vermin/hypervisor/base"
)

var Instance = &virtualbox{}
Expand All @@ -37,14 +38,25 @@ func (*virtualbox) Commit(vmName, imageName string) error {
}

func (*virtualbox) Create(imageName, vmName string, cpus int, mem int) error {
importCmd := vboxManage(
"import", db.GetImageFilePath(imageName),

imagePath := db.GetImageFilePath(imageName)

importArgs := []string{
"import",
imagePath,
"--vsys", "0",
"--vmname", vmName,
"--basefolder", db.VMsBaseDir,
"--cpus", fmt.Sprintf("%d", cpus),
"--memory", fmt.Sprintf("%d", mem),
)
"--cpus", strconv.Itoa(cpus),
"--memory", strconv.Itoa(mem),
}

for i, arg := range importArgs {
importArgs[i] = `"` + arg + `"`
}

importCmd := vboxManage(importArgs...)

if _, err := importCmd.CallWithProgress(fmt.Sprintf("Creating %s from image %s", vmName, imageName)); err != nil {
return err
}
Expand Down

0 comments on commit 975f086

Please sign in to comment.