vm.go 1.1 KB

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