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