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:
Brent Baude
2023-02-25 15:02:16 -06:00
parent f1bcd0d781
commit 0dac214f56
106 changed files with 9552 additions and 33 deletions

View File

@@ -0,0 +1,72 @@
//go:build windows
// +build windows
package hypervctl
import (
"github.com/containers/libhvee/pkg/wmiext"
)
const SyntheticDiskDriveType = "Microsoft:Hyper-V:Synthetic Disk Drive"
type SyntheticDiskDriveSettings struct {
ResourceSettings
systemSettings *SystemSettings
controllerSettings *ScsiControllerSettings
}
type diskAssociation interface {
setParent(parent string)
setHostResource(resource []string)
Path() string
}
func (d *SyntheticDiskDriveSettings) DefineVirtualHardDisk(vhdxFile string, beforeAdd func(*VirtualHardDiskStorageSettings)) (*VirtualHardDiskStorageSettings, error) {
vhd := &VirtualHardDiskStorageSettings{}
var cb func()
if beforeAdd != nil {
cb = func() {
beforeAdd(vhd)
}
}
if err := createDiskResourceInternal(d.systemSettings.Path(), d.Path(), vhdxFile, vhd, VirtualHardDiskType, cb); err != nil {
return nil, err
}
vhd.driveSettings = d
vhd.systemSettings = d.systemSettings
return vhd, nil
}
func createDiskResourceInternal(systemPath string, drivePath string, file string, settings diskAssociation, resourceType string, cb func()) error {
var service *wmiext.Service
var err error
if service, err = wmiext.NewLocalService(HyperVNamespace); err != nil {
return err
}
defer service.Close()
if err = populateDefaults(resourceType, settings); err != nil {
return err
}
settings.setHostResource([]string{file})
settings.setParent(drivePath)
if cb != nil {
cb()
}
diskResource, err := createResourceSettingGeneric(settings, resourceType)
if err != nil {
return err
}
path, err := addResource(service, systemPath, diskResource)
if err != nil {
return err
}
return service.GetObjectAsObject(path, settings)
}