mirror of
https://github.com/linka-cloud/d2vm.git
synced 2024-11-22 15:56:24 +00:00
d2vm/run: hetzner: convert image to raw if needed
Signed-off-by: Adphi <philippe.adrien.nousse@gmail.com>
This commit is contained in:
parent
0192f32905
commit
4720b1cd17
@ -22,6 +22,7 @@ import (
|
|||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
|
"path/filepath"
|
||||||
"runtime"
|
"runtime"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@ -31,6 +32,8 @@ import (
|
|||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"github.com/spf13/cobra"
|
"github.com/spf13/cobra"
|
||||||
"github.com/svenwiltink/sparsecat"
|
"github.com/svenwiltink/sparsecat"
|
||||||
|
|
||||||
|
exec2 "go.linka.cloud/d2vm/pkg/exec"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@ -80,7 +83,21 @@ func runHetzner(ctx context.Context, imgPath string, stdin io.Reader, stderr io.
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
if i.Format != "raw" {
|
if i.Format != "raw" {
|
||||||
return fmt.Errorf("image format must be raw")
|
logrus.Warnf("image format is %s, expected raw", i.Format)
|
||||||
|
rawPath := filepath.Join(os.TempDir(), "d2vm", "run", filepath.Base(imgPath)+".raw")
|
||||||
|
if err := os.MkdirAll(filepath.Dir(rawPath), 0755); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
defer os.RemoveAll(rawPath)
|
||||||
|
logrus.Infof("converting image to raw: %s", rawPath)
|
||||||
|
if err := exec2.Run(ctx, "qemu-img", "convert", "-O", "raw", imgPath, rawPath); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
imgPath = rawPath
|
||||||
|
i, err = ImgInfo(ctx, imgPath)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
src, err := os.Open(imgPath)
|
src, err := os.Open(imgPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user