github.com/rogpeppe/juju@v0.0.0-20140613142852-6337964b789e/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/environs/cloudinit"
     8  	"github.com/juju/juju/instance"
     9  )
    10  
    11  const (
    12  	ConfigName   = "name"
    13  	ConfigLogDir = "log-dir"
    14  )
    15  
    16  // ManagerConfig contains the initialization parameters for the ContainerManager.
    17  // The name of the manager is used to namespace the containers on the machine.
    18  type ManagerConfig map[string]string
    19  
    20  // Manager is responsible for starting containers, and stopping and listing
    21  // containers that it has started.
    22  type Manager interface {
    23  	// CreateContainer creates and starts a new container for the specified
    24  	// machine.
    25  	CreateContainer(
    26  		machineConfig *cloudinit.MachineConfig,
    27  		series string,
    28  		network *NetworkConfig) (instance.Instance, *instance.HardwareCharacteristics, error)
    29  
    30  	// DestroyContainer stops and destroyes the container identified by
    31  	// instance id.
    32  	DestroyContainer(instance.Id) error
    33  
    34  	// ListContainers return a list of containers that have been started by
    35  	// this manager.
    36  	ListContainers() ([]instance.Instance, error)
    37  }
    38  
    39  // Initialiser is responsible for performing the steps required to initialise
    40  // a host machine so it can run containers.
    41  type Initialiser interface {
    42  	// Initialise installs all required packages, sync any images etc so
    43  	// that the host machine can run containers.
    44  	Initialise() error
    45  }
    46  
    47  // PopValue returns the requested key from the config map. If the value
    48  // doesn't exist, the function returns the empty string. If the value does
    49  // exist, the value is returned, and the element removed from the map.
    50  func (m ManagerConfig) PopValue(key string) string {
    51  	value := m[key]
    52  	delete(m, key)
    53  	return value
    54  }
    55  
    56  // WarnAboutUnused emits a warning about each value in the map.
    57  func (m ManagerConfig) WarnAboutUnused() {
    58  	for key, value := range m {
    59  		logger.Warningf("unused config option: %q -> %q", key, value)
    60  	}
    61  }