mirror of
https://github.com/containers/podman.git
synced 2025-05-20 16:47:39 +08:00
basic hypverv machine implementation
with libhvee, we are able to do the basics of podman machine management on hyperv. The basic functions like init, rm, stop, and start are all functional. Start and stop will periodically throw a benign error processing the hyperv message being returned from the action. The error is described in the todo's below. notable items: * no podman commands will work (like ps, images, etc) * the machine must be initialized with --image-path and fed a custom image. * disk size is set to 100GB statically. * the vm joins the default hyperv network which is TCP/IP network based. * podman machine ssh does not work * podman machine set does not work * you can grab the ip address from hyperv and fake a machine connection with `podman system connection`. * when booting, use the hyperv console to know the boot is complete. TODOs: * podman machine ssh * podman machine set * podman machine rm needs force bool * disk size in NewMachine is set to 100GB * podman start needs to wait until fully booted * establish a boot complete signal from guest * implement gvproxy like user networking * fix benign failures in stop/start -> Error: error 2147749890 (FormatMessage failed with: The system cannot find message text for message number 0x%1 in the message file for %2.) [NO NEW TESTS NEEDED] Signed-off-by: Brent Baude <bbaude@redhat.com>
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
package machine
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bufio"
|
||||
"errors"
|
||||
"fmt"
|
||||
@ -13,6 +14,7 @@ import (
|
||||
"os"
|
||||
"os/exec"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@ -31,7 +33,7 @@ type GenericDownload struct {
|
||||
}
|
||||
|
||||
// NewGenericDownloader is used when the disk image is provided by the user
|
||||
func NewGenericDownloader(vmType, vmName, pullPath string) (DistributionDownload, error) {
|
||||
func NewGenericDownloader(vmType VMType, vmName, pullPath string) (DistributionDownload, error) {
|
||||
var (
|
||||
imageName string
|
||||
)
|
||||
@ -57,7 +59,7 @@ func NewGenericDownloader(vmType, vmName, pullPath string) (DistributionDownload
|
||||
}
|
||||
dl.VMName = vmName
|
||||
dl.ImageName = imageName
|
||||
dl.LocalUncompressedFile = filepath.Join(dataDir, imageName)
|
||||
dl.LocalUncompressedFile = dl.GetLocalUncompressedFile(dataDir)
|
||||
// The download needs to be pulled into the datadir
|
||||
|
||||
gd := GenericDownload{Download: dl}
|
||||
@ -86,9 +88,11 @@ func supportedURL(path string) (url *url2.URL) {
|
||||
}
|
||||
|
||||
func (d Download) GetLocalUncompressedFile(dataDir string) string {
|
||||
extension := compressionFromFile(dataDir)
|
||||
uncompressedFilename := d.VMName + "_" + d.ImageName
|
||||
return filepath.Join(dataDir, strings.TrimSuffix(uncompressedFilename, extension.String()))
|
||||
compressedFilename := d.VMName + "_" + d.ImageName
|
||||
extension := compressionFromFile(compressedFilename)
|
||||
uncompressedFile := strings.TrimSuffix(compressedFilename, fmt.Sprintf(".%s", extension.String()))
|
||||
d.LocalUncompressedFile = filepath.Join(dataDir, uncompressedFile)
|
||||
return d.LocalUncompressedFile
|
||||
}
|
||||
|
||||
func (g GenericDownload) Get() *Download {
|
||||
@ -193,6 +197,7 @@ func DownloadVMImage(downloadURL *url2.URL, imageName string, localImagePath str
|
||||
}
|
||||
|
||||
func Decompress(localPath, uncompressedPath string) error {
|
||||
var isZip bool
|
||||
uncompressedFileWriter, err := os.OpenFile(uncompressedPath, os.O_CREATE|os.O_RDWR, 0600)
|
||||
if err != nil {
|
||||
return err
|
||||
@ -201,14 +206,19 @@ func Decompress(localPath, uncompressedPath string) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if strings.HasSuffix(localPath, ".zip") {
|
||||
isZip = true
|
||||
}
|
||||
compressionType := archive.DetectCompression(sourceFile)
|
||||
if compressionType != archive.Uncompressed {
|
||||
if compressionType != archive.Uncompressed || isZip {
|
||||
fmt.Println("Extracting compressed file")
|
||||
}
|
||||
if compressionType == archive.Xz {
|
||||
return decompressXZ(localPath, uncompressedFileWriter)
|
||||
}
|
||||
if isZip && runtime.GOOS == "windows" {
|
||||
return decompressZip(localPath, uncompressedFileWriter)
|
||||
}
|
||||
return decompressEverythingElse(localPath, uncompressedFileWriter)
|
||||
}
|
||||
|
||||
@ -280,6 +290,32 @@ func decompressEverythingElse(src string, output io.WriteCloser) error {
|
||||
return err
|
||||
}
|
||||
|
||||
func decompressZip(src string, output io.WriteCloser) error {
|
||||
zipReader, err := zip.OpenReader(src)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if len(zipReader.File) != 1 {
|
||||
return errors.New("machine image files should consist of a single compressed file")
|
||||
}
|
||||
f, err := zipReader.File[0].Open()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer func() {
|
||||
if err := f.Close(); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}()
|
||||
defer func() {
|
||||
if err := output.Close(); err != nil {
|
||||
logrus.Error(err)
|
||||
}
|
||||
}()
|
||||
_, err = io.Copy(output, f)
|
||||
return err
|
||||
}
|
||||
|
||||
func RemoveImageAfterExpire(dir string, expire time.Duration) error {
|
||||
now := time.Now()
|
||||
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
|
||||
|
Reference in New Issue
Block a user