vm.go 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //go:build windows
  2. package runhcs
  3. import (
  4. "encoding/json"
  5. "github.com/Microsoft/go-winio"
  6. )
  7. // VMRequestOp is an operation that can be issued to a VM shim.
  8. type VMRequestOp string
  9. const (
  10. // OpCreateContainer is a create container request.
  11. OpCreateContainer VMRequestOp = "create"
  12. // OpSyncNamespace is a `cni.NamespaceTypeGuest` sync request with the UVM.
  13. OpSyncNamespace VMRequestOp = "sync"
  14. // OpUnmountContainer is a container unmount request.
  15. OpUnmountContainer VMRequestOp = "unmount"
  16. // OpUnmountContainerDiskOnly is a container unmount disk request.
  17. OpUnmountContainerDiskOnly VMRequestOp = "unmount-disk"
  18. )
  19. // VMRequest is an operation request that is issued to a VM shim.
  20. type VMRequest struct {
  21. ID string
  22. Op VMRequestOp
  23. }
  24. // IssueVMRequest issues a request to a shim at the given pipe.
  25. func IssueVMRequest(pipepath string, req *VMRequest) error {
  26. pipe, err := winio.DialPipe(pipepath, nil)
  27. if err != nil {
  28. return err
  29. }
  30. defer pipe.Close()
  31. if err := json.NewEncoder(pipe).Encode(req); err != nil {
  32. return err
  33. }
  34. if err := GetErrorFromPipe(pipe, nil); err != nil {
  35. return err
  36. }
  37. return nil
  38. }