2
0
mirror of https://github.com/linka-cloud/d2vm.git synced 2025-12-14 15:03:12 +00:00

remove -O option, use output extension instead

add run command to execute vm in qemu or virtualbox

Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
2022-05-20 16:36:36 +02:00
parent 29d953c14d
commit 62d8a1019d
17 changed files with 1320 additions and 38 deletions

View File

@@ -20,6 +20,7 @@ import (
"io"
"os"
"path/filepath"
"strings"
"github.com/google/uuid"
"github.com/sirupsen/logrus"
@@ -27,7 +28,7 @@ import (
"go.linka.cloud/d2vm/pkg/docker"
)
func Convert(ctx context.Context, img string, size int64, password string, output string, format string) error {
func Convert(ctx context.Context, img string, size int64, password string, output string) error {
imgUUID := uuid.New().String()
tmpPath := filepath.Join(os.TempDir(), "d2vm", imgUUID)
if err := os.MkdirAll(tmpPath, os.ModePerm); err != nil {
@@ -62,6 +63,7 @@ func Convert(ctx context.Context, img string, size int64, password string, outpu
defer docker.Remove(ctx, imgUUID)
logrus.Infof("creating vm image")
format := strings.TrimPrefix(filepath.Ext(output), ".")
b, err := NewBuilder(ctx, tmpPath, imgUUID, "", size, r, format)
if err != nil {
return err
@@ -73,7 +75,7 @@ func Convert(ctx context.Context, img string, size int64, password string, outpu
if err := os.RemoveAll(output); err != nil {
return err
}
if err := MoveFile(filepath.Join(tmpPath, "disk0.qcow2"), output); err != nil {
if err := MoveFile(filepath.Join(tmpPath, "disk0."+format), output); err != nil {
return err
}
return nil