diff --git a/.gitignore b/.gitignore index c38fa4e..8e0fd9e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,4 @@ .idea *.iml +.vscode/ +vermin.exe \ No newline at end of file diff --git a/db/db.go b/db/db.go index e14a67d..d83cf79 100644 --- a/db/db.go +++ b/db/db.go @@ -1,7 +1,6 @@ package db import ( - "fmt" "log" "os" "path/filepath" @@ -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 { diff --git a/go.mod b/go.mod index 5cf3c33..eedddc7 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index f59d9fa..332c296 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= diff --git a/hypervisor/virtualbox/virtualbox.go b/hypervisor/virtualbox/virtualbox.go index 33b502d..04a98c2 100644 --- a/hypervisor/virtualbox/virtualbox.go +++ b/hypervisor/virtualbox/virtualbox.go @@ -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{} @@ -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 }