github.com/mwhudson/juju@v0.0.0-20160512215208-90ff01f3497f/container/interface.go (about)

     1  // Copyright 2013 Canonical Ltd.
     2  // Licensed under the AGPLv3, see LICENCE file for details.
     3  
     4  package container
     5  
     6  import (
     7  	"github.com/juju/juju/cloudconfig/instancecfg"
     8  	"github.com/juju/juju/instance"
     9  	"github.com/juju/juju/status"
    10  )
    11  
    12  const (
    13  	ConfigName   = "name"
    14  	ConfigLogDir = "log-dir"
    15  
    16  	// ConfigIPForwarding, if set to a non-empty value, instructs the
    17  	// container manager to enable IP forwarding as part of the
    18  	// container initialization. Will be enabled if the enviroment
    19  	// supports networking.
    20  	ConfigIPForwarding = "ip-forwarding"
    21  
    22  	// ConfigEnableNAT, if set to a non-empty value, instructs the
    23  	// container manager to enable NAT for hosted containers. NAT is
    24  	// required for AWS, but should be disabled for MAAS.
    25  	ConfigEnableNAT = "enable-nat"
    26  
    27  	// ConfigLXCDefaultMTU, if set to a positive integer (serialized
    28  	// as a string), will cause all network interfaces on all created
    29  	// LXC containers (not KVM instances) to use the given MTU
    30  	// setting.
    31  	ConfigLXCDefaultMTU = "lxc-default-mtu"
    32  
    33  	DefaultNamespace = "juju"
    34  )
    35  
    36  // ManagerConfig contains the initialization parameters for the ContainerManager.
    37  // The name of the manager is used to namespace the containers on the machine.
    38  type ManagerConfig map[string]string
    39  
    40  type StatusCallback func(settableStatus status.Status, info string, data map[string]interface{}) error
    41  
    42  // Manager is responsible for starting containers, and stopping and listing
    43  // containers that it has started.
    44  type Manager interface {
    45  	// CreateContainer creates and starts a new container for the specified
    46  	// machine.
    47  	CreateContainer(
    48  		instanceConfig *instancecfg.InstanceConfig,
    49  		series string,
    50  		network *NetworkConfig,
    51  		storage *StorageConfig,
    52  		callback StatusCallback) (instance.Instance, *instance.HardwareCharacteristics, error)
    53  
    54  	// DestroyContainer stops and destroyes the container identified by
    55  	// instance id.
    56  	DestroyContainer(instance.Id) error
    57  
    58  	// ListContainers return a list of containers that have been started by
    59  	// this manager.
    60  	ListContainers() ([]instance.Instance, error)
    61  
    62  	// IsInitialized check whether or not required packages have been installed
    63  	// to support this manager.
    64  	IsInitialized() bool
    65  }
    66  
    67  // Initialiser is responsible for performing the steps required to initialise
    68  // a host machine so it can run containers.
    69  type Initialiser interface {
    70  	// Initialise installs all required packages, sync any images etc so
    71  	// that the host machine can run containers.
    72  	Initialise() error
    73  }
    74  
    75  // PopValue returns the requested key from the config map. If the value
    76  // doesn't exist, the function returns the empty string. If the value does
    77  // exist, the value is returned, and the element removed from the map.
    78  func (m ManagerConfig) PopValue(key string) string {
    79  	value := m[key]
    80  	delete(m, key)
    81  	return value
    82  }
    83  
    84  // WarnAboutUnused emits a warning about each value in the map.
    85  func (m ManagerConfig) WarnAboutUnused() {
    86  	for key, value := range m {
    87  		logger.Warningf("unused config option: %q -> %q", key, value)
    88  	}
    89  }