github.com/kata-containers/runtime@v0.0.0-20210505125100-04f29832a923/virtcontainers/implementation.go (about)

     1  // Copyright (c) 2017 Intel Corporation
     2  //
     3  // SPDX-License-Identifier: Apache-2.0
     4  //
     5  
     6  // Description: The true virtcontainers function of the same name.
     7  // This indirection is required to allow an alternative implemenation to be
     8  // used for testing purposes.
     9  
    10  package virtcontainers
    11  
    12  import (
    13  	"context"
    14  	"syscall"
    15  
    16  	"github.com/kata-containers/runtime/virtcontainers/device/api"
    17  	"github.com/kata-containers/runtime/virtcontainers/device/config"
    18  	vcTypes "github.com/kata-containers/runtime/virtcontainers/pkg/types"
    19  	"github.com/kata-containers/runtime/virtcontainers/types"
    20  	specs "github.com/opencontainers/runtime-spec/specs-go"
    21  	"github.com/sirupsen/logrus"
    22  )
    23  
    24  // VCImpl is the official virtcontainers function of the same name.
    25  type VCImpl struct {
    26  	factory Factory
    27  }
    28  
    29  // SetLogger implements the VC function of the same name.
    30  func (impl *VCImpl) SetLogger(ctx context.Context, logger *logrus.Entry) {
    31  	SetLogger(ctx, logger)
    32  }
    33  
    34  // SetFactory implements the VC function of the same name.
    35  func (impl *VCImpl) SetFactory(ctx context.Context, factory Factory) {
    36  	impl.factory = factory
    37  }
    38  
    39  // CreateSandbox implements the VC function of the same name.
    40  func (impl *VCImpl) CreateSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error) {
    41  	return CreateSandbox(ctx, sandboxConfig, impl.factory)
    42  }
    43  
    44  // DeleteSandbox implements the VC function of the same name.
    45  func (impl *VCImpl) DeleteSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
    46  	return DeleteSandbox(ctx, sandboxID)
    47  }
    48  
    49  // StartSandbox implements the VC function of the same name.
    50  func (impl *VCImpl) StartSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
    51  	return StartSandbox(ctx, sandboxID)
    52  }
    53  
    54  // StopSandbox implements the VC function of the same name.
    55  func (impl *VCImpl) StopSandbox(ctx context.Context, sandboxID string, force bool) (VCSandbox, error) {
    56  	return StopSandbox(ctx, sandboxID, force)
    57  }
    58  
    59  // RunSandbox implements the VC function of the same name.
    60  func (impl *VCImpl) RunSandbox(ctx context.Context, sandboxConfig SandboxConfig) (VCSandbox, error) {
    61  	return RunSandbox(ctx, sandboxConfig, impl.factory)
    62  }
    63  
    64  // ListSandbox implements the VC function of the same name.
    65  func (impl *VCImpl) ListSandbox(ctx context.Context) ([]SandboxStatus, error) {
    66  	return ListSandbox(ctx)
    67  }
    68  
    69  // FetchSandbox will find out and connect to an existing sandbox and
    70  // return the sandbox structure.
    71  func (impl *VCImpl) FetchSandbox(ctx context.Context, sandboxID string) (VCSandbox, error) {
    72  	return FetchSandbox(ctx, sandboxID)
    73  }
    74  
    75  // StatusSandbox implements the VC function of the same name.
    76  func (impl *VCImpl) StatusSandbox(ctx context.Context, sandboxID string) (SandboxStatus, error) {
    77  	return StatusSandbox(ctx, sandboxID)
    78  }
    79  
    80  // CreateContainer implements the VC function of the same name.
    81  func (impl *VCImpl) CreateContainer(ctx context.Context, sandboxID string, containerConfig ContainerConfig) (VCSandbox, VCContainer, error) {
    82  	return CreateContainer(ctx, sandboxID, containerConfig)
    83  }
    84  
    85  // DeleteContainer implements the VC function of the same name.
    86  func (impl *VCImpl) DeleteContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error) {
    87  	return DeleteContainer(ctx, sandboxID, containerID)
    88  }
    89  
    90  // StartContainer implements the VC function of the same name.
    91  func (impl *VCImpl) StartContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error) {
    92  	return StartContainer(ctx, sandboxID, containerID)
    93  }
    94  
    95  // StopContainer implements the VC function of the same name.
    96  func (impl *VCImpl) StopContainer(ctx context.Context, sandboxID, containerID string) (VCContainer, error) {
    97  	return StopContainer(ctx, sandboxID, containerID)
    98  }
    99  
   100  // EnterContainer implements the VC function of the same name.
   101  func (impl *VCImpl) EnterContainer(ctx context.Context, sandboxID, containerID string, cmd types.Cmd) (VCSandbox, VCContainer, *Process, error) {
   102  	return EnterContainer(ctx, sandboxID, containerID, cmd)
   103  }
   104  
   105  // StatusContainer implements the VC function of the same name.
   106  func (impl *VCImpl) StatusContainer(ctx context.Context, sandboxID, containerID string) (ContainerStatus, error) {
   107  	return StatusContainer(ctx, sandboxID, containerID)
   108  }
   109  
   110  // StatsContainer implements the VC function of the same name.
   111  func (impl *VCImpl) StatsContainer(ctx context.Context, sandboxID, containerID string) (ContainerStats, error) {
   112  	return StatsContainer(ctx, sandboxID, containerID)
   113  }
   114  
   115  // StatsSandbox implements the VC function of the same name.
   116  func (impl *VCImpl) StatsSandbox(ctx context.Context, sandboxID string) (SandboxStats, []ContainerStats, error) {
   117  	return StatsSandbox(ctx, sandboxID)
   118  }
   119  
   120  // KillContainer implements the VC function of the same name.
   121  func (impl *VCImpl) KillContainer(ctx context.Context, sandboxID, containerID string, signal syscall.Signal, all bool) error {
   122  	return KillContainer(ctx, sandboxID, containerID, signal, all)
   123  }
   124  
   125  // ProcessListContainer implements the VC function of the same name.
   126  func (impl *VCImpl) ProcessListContainer(ctx context.Context, sandboxID, containerID string, options ProcessListOptions) (ProcessList, error) {
   127  	return ProcessListContainer(ctx, sandboxID, containerID, options)
   128  }
   129  
   130  // UpdateContainer implements the VC function of the same name.
   131  func (impl *VCImpl) UpdateContainer(ctx context.Context, sandboxID, containerID string, resources specs.LinuxResources) error {
   132  	return UpdateContainer(ctx, sandboxID, containerID, resources)
   133  }
   134  
   135  // PauseContainer implements the VC function of the same name.
   136  func (impl *VCImpl) PauseContainer(ctx context.Context, sandboxID, containerID string) error {
   137  	return PauseContainer(ctx, sandboxID, containerID)
   138  }
   139  
   140  // ResumeContainer implements the VC function of the same name.
   141  func (impl *VCImpl) ResumeContainer(ctx context.Context, sandboxID, containerID string) error {
   142  	return ResumeContainer(ctx, sandboxID, containerID)
   143  }
   144  
   145  // AddDevice will add a device to sandbox
   146  func (impl *VCImpl) AddDevice(ctx context.Context, sandboxID string, info config.DeviceInfo) (api.Device, error) {
   147  	return AddDevice(ctx, sandboxID, info)
   148  }
   149  
   150  // AddInterface implements the VC function of the same name.
   151  func (impl *VCImpl) AddInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
   152  	return AddInterface(ctx, sandboxID, inf)
   153  }
   154  
   155  // RemoveInterface implements the VC function of the same name.
   156  func (impl *VCImpl) RemoveInterface(ctx context.Context, sandboxID string, inf *vcTypes.Interface) (*vcTypes.Interface, error) {
   157  	return RemoveInterface(ctx, sandboxID, inf)
   158  }
   159  
   160  // ListInterfaces implements the VC function of the same name.
   161  func (impl *VCImpl) ListInterfaces(ctx context.Context, sandboxID string) ([]*vcTypes.Interface, error) {
   162  	return ListInterfaces(ctx, sandboxID)
   163  }
   164  
   165  // UpdateRoutes implements the VC function of the same name.
   166  func (impl *VCImpl) UpdateRoutes(ctx context.Context, sandboxID string, routes []*vcTypes.Route) ([]*vcTypes.Route, error) {
   167  	return UpdateRoutes(ctx, sandboxID, routes)
   168  }
   169  
   170  // ListRoutes implements the VC function of the same name.
   171  func (impl *VCImpl) ListRoutes(ctx context.Context, sandboxID string) ([]*vcTypes.Route, error) {
   172  	return ListRoutes(ctx, sandboxID)
   173  }
   174  
   175  // CleanupContaienr is used by shimv2 to stop and delete a container exclusively, once there is no container
   176  // in the sandbox left, do stop the sandbox and delete it. Those serial operations will be done exclusively by
   177  // locking the sandbox.
   178  func (impl *VCImpl) CleanupContainer(ctx context.Context, sandboxID, containerID string, force bool) error {
   179  	return CleanupContainer(ctx, sandboxID, containerID, force)
   180  }