github.com/juju/juju@v0.0.0-20240327075706-a90865de2538/container/kvm/interface.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package kvm
     5  
     6  import (
     7  	"github.com/juju/juju/container"
     8  	"github.com/juju/juju/core/status"
     9  )
    10  
    11  // StartParams is a simple parameter struct for Container.Start.
    12  type StartParams struct {
    13  	Version           string
    14  	Arch              string
    15  	Stream            string
    16  	UserDataFile      string
    17  	NetworkConfigData string
    18  	Network           *container.NetworkConfig
    19  	Memory            uint64 // MB
    20  	CpuCores          uint64
    21  	RootDisk          uint64 // GB
    22  	ImageDownloadURL  string
    23  	StatusCallback    func(status status.Status, info string, data map[string]interface{}) error
    24  }
    25  
    26  // Container represents a virtualized container instance and provides
    27  // operations to create, maintain and destroy the container.
    28  type Container interface {
    29  
    30  	// Name returns the name of the container.
    31  	Name() string
    32  
    33  	// EnsureCachedImage ensures that a container image suitable for satisfying
    34  	// the input start parameters has been cached on disk.
    35  	EnsureCachedImage(params StartParams) error
    36  
    37  	// Start runs the container as a daemon.
    38  	Start(params StartParams) error
    39  
    40  	// Stop terminates the running container.
    41  	Stop() error
    42  
    43  	// IsRunning returns whether or not the container is running and active.
    44  	IsRunning() bool
    45  
    46  	// String returns information about the container, like the name, state,
    47  	// and process id.
    48  	String() string
    49  }
    50  
    51  // ContainerFactory represents the methods used to create Containers.  This
    52  // wraps the low level OS functions for dealing with the containers.
    53  type ContainerFactory interface {
    54  	// New returns a container instance which can then be used for operations
    55  	// like Start() and Stop()
    56  	New(string) Container
    57  
    58  	// List returns all the existing containers on the system.
    59  	List() ([]Container, error)
    60  }