cluster

package
v0.0.0-...-b4cf141 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2016 License: Apache-2.0, CC-BY-SA-4.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

View Source
const SwarmLabelNamespace = "com.docker.swarm"

SwarmLabelNamespace defines the key prefix in all custom labels

Variables

This section is empty.

Functions

func ParseRepositoryTag

func ParseRepositoryTag(repos string) (string, string)

ParseRepositoryTag gets a repos name and returns the right reposName + tag|digest The tag can be confusing because of a port in a repository name.

Ex: localhost.localdomain:5000/samalba/hipache:latest
Digest ex: localhost:5000/foo/bar@sha256:bc8813ea7b3603864987522f02a76101c17ad122e1c46d790efc0fca78ca7bfb

Types

type Cluster

type Cluster interface {
	// Create a container
	CreateContainer(config *ContainerConfig, name string, authConfig *dockerclient.AuthConfig) (*Container, error)

	// Remove a container
	RemoveContainer(container *Container, force, volumes bool) error

	// Return all images
	Images() Images

	// Return one image matching `IDOrName`
	Image(IDOrName string) *Image

	// Remove images from the cluster
	RemoveImages(name string, force bool) ([]*dockerclient.ImageDelete, error)

	// Return all containers
	Containers() Containers

	// Return container the matching `IDOrName`
	// TODO: remove this method from the interface as we can use
	// cluster.Containers().Get(IDOrName)
	Container(IDOrName string) *Container

	// Return all networks
	Networks() Networks

	// Create a network
	CreateNetwork(request *dockerclient.NetworkCreate) (*dockerclient.NetworkCreateResponse, error)

	// Remove a network from the cluster
	RemoveNetwork(network *Network) error

	// Create a volume
	CreateVolume(request *dockerclient.VolumeCreateRequest) (*Volume, error)

	// Return all volumes
	Volumes() []*Volume

	// Return one volume from the cluster
	Volume(name string) *Volume

	// Remove volumes from the cluster
	RemoveVolumes(name string) (bool, error)

	// Pull images
	// `callback` can be called multiple time
	//  `where` is where it is being pulled
	//  `status` is the current status, like "", "in progress" or "downloaded
	Pull(name string, authConfig *dockerclient.AuthConfig, callback func(where, status string, err error))

	// Import image
	// `callback` can be called multiple time
	// `where` is where it is being imported
	// `status` is the current status, like "", "in progress" or "imported"
	Import(source string, repository string, tag string, imageReader io.Reader, callback func(where, status string, err error))

	// Load images
	// `callback` can be called multiple time
	// `what` is what is being loaded
	// `status` is the current status, like "", "in progress" or "loaded"
	Load(imageReader io.Reader, callback func(what, status string, err error))

	// Return some info about the cluster, like nb or containers / images
	// It is pretty open, so the implementation decides what to return.
	Info() [][]string

	// Return the total memory of the cluster
	TotalMemory() int64

	// Return the number of CPUs in the cluster
	TotalCpus() int64

	// Register an event handler for cluster-wide events.
	RegisterEventHandler(h EventHandler) error

	// Unregister an event handler.
	UnregisterEventHandler(h EventHandler)

	// FIXME: remove this method
	// Return a random engine
	RANDOMENGINE() (*Engine, error)

	// RenameContainer rename a container
	RenameContainer(container *Container, newName string) error

	// BuildImage build an image
	BuildImage(*dockerclient.BuildImage, io.Writer) error

	// TagImage tag an image
	TagImage(IDOrName string, repo string, tag string, force bool) error
}

Cluster is exported

type Container

type Container struct {
	dockerclient.Container

	Config *ContainerConfig
	Info   dockerclient.ContainerInfo
	Engine *Engine
}

Container is exported

func (*Container) Refresh

func (c *Container) Refresh() (*Container, error)

Refresh container

func (*Container) Start

func (c *Container) Start() error

Start a container

type ContainerConfig

type ContainerConfig struct {
	dockerclient.ContainerConfig
}

ContainerConfig is exported TODO store affinities and constraints in their own fields

func BuildContainerConfig

func BuildContainerConfig(c dockerclient.ContainerConfig) *ContainerConfig

BuildContainerConfig creates a cluster.ContainerConfig from a dockerclient.ContainerConfig

func (*ContainerConfig) AddAffinity

func (c *ContainerConfig) AddAffinity(affinity string) error

AddAffinity to config

func (*ContainerConfig) Affinities

func (c *ContainerConfig) Affinities() []string

Affinities returns all the affinities from the ContainerConfig

func (*ContainerConfig) Constraints

func (c *ContainerConfig) Constraints() []string

Constraints returns all the constraints from the ContainerConfig

func (*ContainerConfig) HasReschedulePolicy

func (c *ContainerConfig) HasReschedulePolicy(p string) bool

HasReschedulePolicy returns true if the specified policy is part of the config

func (*ContainerConfig) HaveNodeConstraint

func (c *ContainerConfig) HaveNodeConstraint() bool

HaveNodeConstraint in config

func (*ContainerConfig) RemoveAffinity

func (c *ContainerConfig) RemoveAffinity(affinity string) error

RemoveAffinity from config

func (*ContainerConfig) SetSwarmID

func (c *ContainerConfig) SetSwarmID(id string)

SetSwarmID sets or overrides the Swarm ID in the Config.

func (*ContainerConfig) SwarmID

func (c *ContainerConfig) SwarmID() string

SwarmID extracts the Swarm ID from the Config. May return an empty string if not set.

func (*ContainerConfig) Validate

func (c *ContainerConfig) Validate() error

Validate returns an error if the config isn't valid

type Containers

type Containers []*Container

Containers represents a list a containers

func (Containers) Get

func (containers Containers) Get(IDOrName string) *Container

Get returns a container using it's ID or Name

type DriverOpts

type DriverOpts []string

DriverOpts are key=values options

func (DriverOpts) Bool

func (do DriverOpts) Bool(key, env string) (bool, bool)

Bool returns a boolean from the driver options

func (DriverOpts) Float

func (do DriverOpts) Float(key, env string) (float64, bool)

Float returns a float64 from the driver options

func (DriverOpts) IP

func (do DriverOpts) IP(key, env string) (net.IP, bool)

IP returns an IP address from the driver options

func (DriverOpts) Int

func (do DriverOpts) Int(key, env string) (int64, bool)

Int returns an int64 from the driver options

func (DriverOpts) String

func (do DriverOpts) String(key, env string) (string, bool)

String returns a string from the driver options

func (DriverOpts) Uint

func (do DriverOpts) Uint(key, env string) (uint64, bool)

Uint returns an int64 from the driver options

type Engine

type Engine struct {
	sync.RWMutex

	ID     string
	IP     string
	Addr   string
	Name   string
	Cpus   int64
	Memory int64
	Labels map[string]string
	// contains filtered or unexported fields
}

Engine represents a docker engine

func NewEngine

func NewEngine(addr string, overcommitRatio float64, opts *EngineOpts) *Engine

NewEngine is exported

func (*Engine) AddContainer

func (e *Engine) AddContainer(container *Container) error

AddContainer inject a container into the internal state.

func (*Engine) BuildImage

func (e *Engine) BuildImage(buildImage *dockerclient.BuildImage) (io.ReadCloser, error)

BuildImage build an image

func (*Engine) CheckConnectionErr

func (e *Engine) CheckConnectionErr(err error)

CheckConnectionErr checks error from client response and adjusts engine healthy indicators

func (*Engine) Connect

func (e *Engine) Connect(config *tls.Config) error

Connect will initialize a connection to the Docker daemon running on the host, gather machine specs (memory, cpu, ...) and monitor state changes.

func (*Engine) ConnectWithClient

func (e *Engine) ConnectWithClient(client dockerclient.Client) error

ConnectWithClient is exported

func (*Engine) Containers

func (e *Engine) Containers() Containers

Containers returns all the containers in the engine.

func (*Engine) Create

func (e *Engine) Create(config *ContainerConfig, name string, pullImage bool, authConfig *dockerclient.AuthConfig) (*Container, error)

Create a new container

func (*Engine) CreateNetwork

CreateNetwork creates a network in the engine

func (*Engine) CreateVolume

func (e *Engine) CreateVolume(request *dockerclient.VolumeCreateRequest) (*Volume, error)

CreateVolume creates a volume in the engine

func (*Engine) Disconnect

func (e *Engine) Disconnect()

Disconnect will stop all monitoring of the engine. The Engine object cannot be further used without reconnecting it first.

func (*Engine) ErrMsg

func (e *Engine) ErrMsg() string

ErrMsg returns error message for the engine

func (*Engine) HandleIDConflict

func (e *Engine) HandleIDConflict(otherAddr string)

HandleIDConflict handles ID duplicate with existing engine

func (*Engine) HealthIndicator

func (e *Engine) HealthIndicator() int64

HealthIndicator returns degree of healthiness between 0 and 100. 0 means node is not healthy (unhealthy, pending), 100 means last connectivity was successful other values indicate recent failures but haven't moved engine out of healthy state

func (*Engine) Image

func (e *Engine) Image(IDOrName string) *Image

Image returns the image with IDOrName in the engine

func (*Engine) Images

func (e *Engine) Images() Images

Images returns all the images in the engine

func (*Engine) Import

func (e *Engine) Import(source string, repository string, tag string, imageReader io.Reader) error

Import image

func (*Engine) IsHealthy

func (e *Engine) IsHealthy() bool

IsHealthy returns true if the engine is healthy

func (*Engine) Load

func (e *Engine) Load(reader io.Reader) error

Load an image on the engine

func (*Engine) Networks

func (e *Engine) Networks() Networks

Networks returns all the networks in the engine

func (*Engine) Pull

func (e *Engine) Pull(image string, authConfig *dockerclient.AuthConfig) error

Pull an image on the engine

func (*Engine) RefreshContainers

func (e *Engine) RefreshContainers(full bool) error

RefreshContainers will refresh the list and status of containers running on the engine. If `full` is true, each container will be inspected. FIXME: unexport this method after mesos scheduler stops using it directly

func (*Engine) RefreshImages

func (e *Engine) RefreshImages() error

RefreshImages refreshes the list of images on the engine.

func (*Engine) RefreshNetworks

func (e *Engine) RefreshNetworks() error

RefreshNetworks refreshes the list of networks on the engine.

func (*Engine) RefreshVolumes

func (e *Engine) RefreshVolumes() error

RefreshVolumes refreshes the list of volumes on the engine.

func (*Engine) RegisterEventHandler

func (e *Engine) RegisterEventHandler(h EventHandler) error

RegisterEventHandler registers an event handler.

func (*Engine) RemoveContainer

func (e *Engine) RemoveContainer(container *Container, force, volumes bool) error

RemoveContainer a container from the engine.

func (*Engine) RemoveImage

func (e *Engine) RemoveImage(image *Image, name string, force bool) ([]*dockerclient.ImageDelete, error)

RemoveImage deletes an image from the engine.

func (*Engine) RemoveNetwork

func (e *Engine) RemoveNetwork(network *Network) error

RemoveNetwork deletes a network from the engine.

func (*Engine) RemoveVolume

func (e *Engine) RemoveVolume(name string) error

RemoveVolume deletes a volume from the engine.

func (*Engine) RenameContainer

func (e *Engine) RenameContainer(container *Container, newName string) error

RenameContainer rename a container

func (*Engine) Status

func (e *Engine) Status() string

Status returns the health status of the Engine: Healthy or Unhealthy

func (*Engine) String

func (e *Engine) String() string

func (*Engine) TagImage

func (e *Engine) TagImage(IDOrName string, repo string, tag string, force bool) error

TagImage tag an image

func (*Engine) TimeToValidate

func (e *Engine) TimeToValidate() bool

TimeToValidate returns true if a pending node is up for validation

func (*Engine) TotalCpus

func (e *Engine) TotalCpus() int64

TotalCpus returns the total cpus + overcommit

func (*Engine) TotalMemory

func (e *Engine) TotalMemory() int64

TotalMemory returns the total memory + overcommit

func (*Engine) UpdatedAt

func (e *Engine) UpdatedAt() time.Time

UpdatedAt returns the previous updatedAt time

func (*Engine) UsedCpus

func (e *Engine) UsedCpus() int64

UsedCpus returns the sum of CPUs reserved by containers.

func (*Engine) UsedMemory

func (e *Engine) UsedMemory() int64

UsedMemory returns the sum of memory reserved by containers.

func (*Engine) ValidationComplete

func (e *Engine) ValidationComplete()

ValidationComplete transitions engine state from statePending to stateHealthy

func (*Engine) Volumes

func (e *Engine) Volumes() []*Volume

Volumes returns all the volumes in the engine

type EngineOpts

type EngineOpts struct {
	RefreshMinInterval time.Duration
	RefreshMaxInterval time.Duration
	FailureRetry       int
}

EngineOpts represents the options for an engine

type EngineSorter

type EngineSorter []*Engine

EngineSorter implements the Sort interface to sort Cluster.Engine. It is not guaranteed to be a stable sort.

func (EngineSorter) Len

func (s EngineSorter) Len() int

Len returns the number of engines to be sorted.

func (EngineSorter) Less

func (s EngineSorter) Less(i, j int) bool

Less reports whether the engine with index i should sort before the engine with index j. Engines are sorted chronologically by name.

func (EngineSorter) Swap

func (s EngineSorter) Swap(i, j int)

Swap exchanges the engine elements with indices i and j.

type Event

type Event struct {
	dockerclient.Event
	Engine *Engine `json:"-"`
}

Event is exported

type EventHandler

type EventHandler interface {
	Handle(*Event) error
}

EventHandler is exported

type EventHandlers

type EventHandlers struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

EventHandlers is a map of EventHandler

func NewEventHandlers

func NewEventHandlers() *EventHandlers

NewEventHandlers returns a EventHandlers

func (*EventHandlers) Handle

func (eh *EventHandlers) Handle(e *Event)

Handle callbacks for the events

func (*EventHandlers) RegisterEventHandler

func (eh *EventHandlers) RegisterEventHandler(h EventHandler) error

RegisterEventHandler registers an event handler.

func (*EventHandlers) UnregisterEventHandler

func (eh *EventHandlers) UnregisterEventHandler(h EventHandler)

UnregisterEventHandler unregisters a previously registered event handler.

type Image

type Image struct {
	dockerclient.Image

	Engine *Engine
}

Image is exported

func (*Image) Match

func (image *Image) Match(IDOrName string, matchTag bool) bool

Match is exported

type ImageFilterOptions

type ImageFilterOptions struct {
	All        bool
	NameFilter string
	Filters    dockerfilters.Args
}

ImageFilterOptions are the set of filtering options supported by Images.Filter()

type Images

type Images []*Image

Images is a collection of Image objects that can be filtered

func (Images) Filter

func (images Images) Filter(opts ImageFilterOptions) Images

Filter returns a new sequence of Images filtered to only the images that matched the filtering paramters

type Network

type Network struct {
	dockerclient.NetworkResource

	Engine *Engine
}

Network is exported

type Networks

type Networks []*Network

Networks represents a map of networks

func (Networks) Filter

func (networks Networks) Filter(names []string, ids []string) Networks

Filter returns networks filtered by names or ids

func (Networks) Get

func (networks Networks) Get(IDOrName string) *Network

Get returns a network using it's ID or Name

func (Networks) Uniq

func (networks Networks) Uniq() Networks

Uniq returns all uniq networks

type Volume

type Volume struct {
	dockerclient.Volume

	Engine *Engine
}

Volume is exported

type Watchdog

type Watchdog struct {
	sync.Mutex
	// contains filtered or unexported fields
}

Watchdog listen to cluster events ans handle container rescheduling

func NewWatchdog

func NewWatchdog(cluster Cluster) *Watchdog

NewWatchdog creates a new watchdog

func (*Watchdog) Handle

func (w *Watchdog) Handle(e *Event) error

Handle cluster callbacks

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL