...

Source file src/github.com/Microsoft/hcsshim/internal/runhcs/vm.go

Documentation: github.com/Microsoft/hcsshim/internal/runhcs

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

View as plain text