...

Source file src/github.com/Microsoft/hcsshim/internal/guest/runtime/runtime.go

Documentation: github.com/Microsoft/hcsshim/internal/guest/runtime

     1  //go:build linux
     2  // +build linux
     3  
     4  package runtime
     5  
     6  import (
     7  	"errors"
     8  	"io"
     9  	"syscall"
    10  
    11  	"github.com/Microsoft/hcsshim/internal/guest/gcserr"
    12  	"github.com/Microsoft/hcsshim/internal/guest/stdio"
    13  	oci "github.com/opencontainers/runtime-spec/specs-go"
    14  )
    15  
    16  var (
    17  	ErrContainerAlreadyExists = gcserr.WrapHresult(errors.New("container already exist"), gcserr.HrVmcomputeSystemAlreadyExists)
    18  	ErrContainerDoesNotExist  = gcserr.WrapHresult(errors.New("container does not exist"), gcserr.HrVmcomputeSystemNotFound)
    19  	ErrContainerStillRunning  = gcserr.WrapHresult(errors.New("container still running"), gcserr.HrVmcomputeInvalidState)
    20  	ErrContainerNotRunning    = gcserr.WrapHresult(errors.New("container not running"), gcserr.HrVmcomputeSystemAlreadyStopped)
    21  	ErrContainerNotStopped    = gcserr.WrapHresult(errors.New("container not stopped"), gcserr.HrVmcomputeInvalidState)
    22  	ErrInvalidContainerID     = gcserr.WrapHresult(errors.New("invalid container ID"), gcserr.HrErrInvalidArg)
    23  )
    24  
    25  // ContainerState gives information about a container created by a Runtime.
    26  type ContainerState struct {
    27  	OCIVersion string
    28  	ID         string
    29  	Pid        int
    30  	BundlePath string
    31  	RootfsPath string
    32  	Status     string
    33  	Created    string
    34  }
    35  
    36  // ContainerProcessState gives information about a process created by a
    37  // Runtime.
    38  type ContainerProcessState struct {
    39  	Pid              int
    40  	Command          []string
    41  	CreatedByRuntime bool
    42  	IsZombie         bool
    43  }
    44  
    45  // StdioPipes contain the interfaces for reading from and writing to a
    46  // process's stdio.
    47  type StdioPipes struct {
    48  	In  io.WriteCloser
    49  	Out io.ReadCloser
    50  	Err io.ReadCloser
    51  }
    52  
    53  // Process is an interface to manipulate process state.
    54  type Process interface {
    55  	Wait() (int, error)
    56  	Pid() int
    57  	Delete() error
    58  	Tty() *stdio.TtyRelay
    59  	PipeRelay() *stdio.PipeRelay
    60  }
    61  
    62  // Container is an interface to manipulate container state.
    63  type Container interface {
    64  	Process
    65  	ID() string
    66  	Exists() (bool, error)
    67  	Start() error
    68  	ExecProcess(process *oci.Process, stdioSet *stdio.ConnectionSet) (p Process, err error)
    69  	Kill(signal syscall.Signal) error
    70  	Pause() error
    71  	Resume() error
    72  	GetState() (*ContainerState, error)
    73  	GetRunningProcesses() ([]ContainerProcessState, error)
    74  	GetAllProcesses() ([]ContainerProcessState, error)
    75  	GetInitProcess() (Process, error)
    76  	Update(resources interface{}) error
    77  }
    78  
    79  // Runtime is the interface defining commands over an OCI container runtime,
    80  // such as runC.
    81  type Runtime interface {
    82  	CreateContainer(id string, bundlePath string, stdioSet *stdio.ConnectionSet) (c Container, err error)
    83  	ListContainerStates() ([]ContainerState, error)
    84  }
    85  

View as plain text