Files
podman/vendor/github.com/containers/libhvee/pkg/wmiext/enum.go
Brent Baude 0dac214f56 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>
2023-03-17 16:02:28 -05:00

95 lines
2.2 KiB
Go

//go:build windows
// +build windows
package wmiext
import (
"fmt"
"syscall"
"unsafe"
"github.com/go-ole/go-ole"
)
type IEnumWbemClassObjectVtbl struct {
QueryInterface uintptr
AddRef uintptr
Release uintptr
Reset uintptr
Next uintptr
NextAsync uintptr
Clone uintptr
Skip uintptr
}
type Enum struct {
enum *ole.IUnknown
vTable *IEnumWbemClassObjectVtbl
service *Service
}
func (e *Enum) Close() {
if e != nil && e.enum != nil {
e.enum.Release()
}
}
func newEnum(enumerator *ole.IUnknown, service *Service) *Enum {
return &Enum{
enum: enumerator,
vTable: (*IEnumWbemClassObjectVtbl)(unsafe.Pointer(enumerator.RawVTable)),
service: service,
}
}
// NextObject obtains the next instance in an enumeration and sets all fields
// of the struct pointer passed through the target parameter. Otherwise, if
// the target parameter is not a struct pointer type, an error will be
// returned.
func NextObject(enum *Enum, target interface{}) (bool, error) {
var err error
var instance *Instance
if instance, err = enum.Next(); err != nil {
return false, err
}
if instance == nil {
return true, nil
}
defer instance.Close()
return false, instance.GetAll(target)
}
// Next returns the next object instance in this iteration
func (e *Enum) Next() (instance *Instance, err error) {
var res uintptr
var apObjects *ole.IUnknown
var uReturned uint32
res, _, _ = syscall.SyscallN(
e.vTable.Next, // IEnumWbemClassObject::Next()
uintptr(unsafe.Pointer(e.enum)), // IEnumWbemClassObject ptr
uintptr(WBEM_INFINITE), // [in] long lTimeout,
uintptr(1), // [in] ULONG uCount,
uintptr(unsafe.Pointer(&apObjects)), // [out] IWbemClassObject **apObjects,
uintptr(unsafe.Pointer(&uReturned))) // [out] ULONG *puReturned)
if res < 0 {
return nil, ole.NewError(res)
}
if uReturned < 1 {
switch res {
case WBEM_S_NO_ERROR, WBEM_S_FALSE:
// No more elements
return nil, nil
default:
return nil, fmt.Errorf("failure advancing enumeration (%d)", res)
}
}
return newInstance(apObjects, e.service), nil
}