command

package
v0.0.0-...-e2f5efa Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2020 License: BSD-3-Clause Imports: 25 Imported by: 10

Documentation

Index

Constants

View Source
const (
	// Createcontainer attempts to create a docker container
	Createcontainer = OrderType("createcontainer")
	// Startcontainer attempts to start an already created docker container
	Startcontainer = OrderType("startcontainer")
	// Removecontainer attempts to remove a container
	Removecontainer = OrderType("removecontainer")
	// Createnetwork attempts to create a network
	Createnetwork = OrderType("createnetwork")
	// Attachnetwork attempts to remove a network
	Attachnetwork = OrderType("attachnetwork")
	// Detachnetwork detaches network
	Detachnetwork = OrderType("detachnetwork")
	// Removenetwork removes network
	Removenetwork = OrderType("removenetwork")
	// Createvolume creates volume
	Createvolume = OrderType("createvolume")

	// Removevolume removes volume
	Removevolume = OrderType("removevolume")

	// Putfileincontainer puts file in container
	Putfileincontainer = OrderType("putfileincontainer")

	// Emulation emulates
	Emulation = OrderType("emulation")

	// SwarmInit sets up the docker swarm
	SwarmInit = OrderType("swarminit")

	// Pullimage pre-emptively pulls the given image
	Pullimage = OrderType("pullimage")

	// Volumeshare
	Volumeshare = OrderType("volumeshare")

	// Pauseexecution means wait a certain amount of time before continuing
	Pauseexecution = OrderType("pauseexecution") //Payload will be Duration

	// Resumeexecution contains the instructions for preparing for the next phase
	Resumeexecution = OrderType("resumeexecution")
)
View Source
const (
	// PhaseKey is the meta key for the phase name
	PhaseKey = "phase"

	// OrgIDKey is the location of the org id in meta
	OrgIDKey = "org"

	// TestIDKey is the location of the test id in the meta
	TestIDKey = "testRun"

	// TestNameKey is the location of the test name in the meta
	TestNameKey = "test"

	// DefinitionIDKey is the location of the definition in the meta
	DefinitionIDKey = "definition"
)

*

  • Note: changing any of these constants is a breaking change, so use caution.
View Source
const (
	// ServiceNumberSub is the magical value which gets replaced with the node number in pre-processing for inputs
	ServiceNumberSub = "$_n"

	// HostDomainSub is the magical value which gets replaced with the host's DNS for env vars
	HostDomainSub = "$_host"
)
View Source
const (
	InfiniteTimeTerm = "infinite"
	DefaultTimeout   = 2 * time.Minute
)
View Source
const KeySize = 4096
View Source
const OneYearDuration = time.Hour * 8760
View Source
const SerialRandSize = 8

Variables

View Source
var (

	// NoExpiration is the placeholder for the expiration to be ignored
	NoExpiration = time.Unix(0, 0)

	// NoTimeout indicates that there is no timeout duration provided
	NoTimeout time.Duration = -1

	// NoDuration indicates that duration is not set
	NoDuration time.Duration = 0

	// ErrNoCommands is when commands are needed but there are none
	ErrNoCommands = errors.New("there are no commands")

	// ErrNoPhase means that the commands meta doesn't include phase data
	ErrNoPhase = errors.New("phase not found")

	// ErrDone is given when isntructions is finished after this round
	ErrDone = errors.New("all done")

	// ErrTooManyFailed represents when given more failures than commands
	ErrTooManyFailed = errors.New("more commands failed than currently exist")

	// ErrNotAllFound is for when one or more commands where not matched up with the given ids
	ErrNotAllFound = errors.New("one or more commands where not matched up with the given ids")
)
View Source
var (
	InfiniteDuration = Duration{Time{/* contains filtered or unexported fields */}}
)

Functions

This section is empty.

Types

type Authentication

type Authentication struct {
	CAKey      *rsa.PrivateKey
	ServerKey  *rsa.PrivateKey
	ClientKey  *rsa.PrivateKey
	CACert     []byte
	ServerCert []byte
	ClientCert []byte
}

func GenerateAuth

func GenerateAuth() (out Authentication, err error)

func (Authentication) CACertPEM

func (auth Authentication) CACertPEM() []byte

func (Authentication) ClientCertPEM

func (auth Authentication) ClientCertPEM() []byte

func (Authentication) ClientPKPEM

func (auth Authentication) ClientPKPEM() []byte

func (Authentication) ClientPrivKeyPKCS1

func (auth Authentication) ClientPrivKeyPKCS1() []byte

func (Authentication) MarshalJSON

func (auth Authentication) MarshalJSON() ([]byte, error)

func (Authentication) ServerCertPEM

func (auth Authentication) ServerCertPEM() []byte

func (Authentication) ServerPKPEM

func (auth Authentication) ServerPKPEM() []byte

func (Authentication) ServerPrivKeyPKCS1

func (auth Authentication) ServerPrivKeyPKCS1() []byte

func (*Authentication) UnmarshalJSON

func (auth *Authentication) UnmarshalJSON(data []byte) error

func (Authentication) Validate

func (auth Authentication) Validate() bool

type Command

type Command struct {
	// ID is the unique id of this command
	ID string `json:"id"`

	// Target represents the target of this command
	Target Target `json:"target"`

	// Order is the action of the command, it represents what needs to be done
	Order Order `json:"order"`

	// Meta is extra informative data to be passed with the command
	Meta map[string]string `json:"meta"`
	// contains filtered or unexported fields
}

Command is the command sent to Definition.

func NewCommand

func NewCommand(order Order, endpoint string) (Command, error)

NewCommand properly creates a new command

func (Command) Parent

func (cmd Command) Parent() *Instructions

Parent function exists to prevent parent from showing up when a command is marshal with any marshaller

func (Command) ParseOrderPayloadInto

func (cmd Command) ParseOrderPayloadInto(out interface{}) error

ParseOrderPayloadInto attempts to Marshal the payload into the object pointed to by out

func (Command) TestID

func (cmd Command) TestID() string

type Container

type Container struct {
	// BoundCpus are the cpus which the container will be set with an affinity for.
	BoundCPUs []int `json:"boundCPUs,omitonempty"`

	// EntryPoint overrides the docker containers entrypoint if non-empty
	EntryPoint string `json:"entrypoint"`

	// Environment represents the environment kv which will be provided to the container
	Environment map[string]string `json:"environment"`

	// Labels are any identifier which are to be attached to the container
	Labels map[string]string `json:"labels"`

	// Name is the unique name of the docker container
	Name string `json:"name"`

	// Network is the primary network(s) for this container to be attached to
	Network string `json:"network"`

	// TCPPorts to be opened for each container, each port associated.
	TCPPorts map[int]int `json:"tcpPorts"`

	// UDPPorts to be opened for each container, each port associated.
	UDPPorts map[int]int `json:"udpPorts"`

	// Volumes are the docker volumes to be mounted on this container
	Volumes []Mount `json:"volumes"`

	// HostVolumes contains the host filesystem volumes. Mounts on /var/lib/docker/genesis/{key}/{container}:{value}
	HostVolumes map[string]string `json:"hostVolumes"`

	// Cpus should be a floating point value represented as a string, and
	// is  equivalent to the percentage of a single cores time which can be used
	// by a node. Can be more than 1.0, meaning the node can use multiple cores at
	// a time.
	Cpus string `json:"cpus"`

	// Memory supports values up to Terrabytes (tb). If the unit is omitted, then it
	// is assumed to be bytes. This is not case sensitive.
	Memory string `json:"memory"`

	// Image is the docker image
	Image string `json:"image"`

	// Args are the arguments passed to the containers entrypoint
	Args []string `json:"args"`

	// IP is the IP address on the primary network
	IP string `json:"ip"`

	// AutoRemove flags a container to be automatically removed
	AutoRemove bool `json:"autoremove"`

	User string `json:"user"`

	Credentials
}

Container represents a docker container, this is calculated from the payload of the Run command

func (Container) GetCPUSet

func (c Container) GetCPUSet() string

func (Container) GetCmd

func (c Container) GetCmd() strslice.StrSlice

GetCmd gets the commands

func (Container) GetEntryPoint

func (c Container) GetEntryPoint() strslice.StrSlice

GetEntryPoint returns the properly formatted entrypoint if this container has one, otherwise returns nil

func (Container) GetEnv

func (c Container) GetEnv() (envVars []string)

GetEnv gets the environment variables in the format which is expected by docker

func (Container) GetMemory

func (c Container) GetMemory() (int64, error)

GetMemory gets the memory value as an integer.

func (Container) GetMounts

func (c Container) GetMounts() []mount.Mount

GetMounts gets the docker mounts for the docker container

func (Container) GetPortBindings

func (c Container) GetPortBindings() (nat.PortSet, nat.PortMap, error)

GetPortBindings gets the port bindings in the proper docker container types

type ContainerNetwork

type ContainerNetwork struct {
	// Name of the container.
	Container string `json:"container"`
	// Name of the network.
	Network string `json:"network"`
	// IP is the IP address of the container in this network
	IP string `json:"ip,omitempty"`
}

ContainerNetwork is a container and network order payload.

type Credentials

type Credentials struct {
	Username      string `json:"username,omitempty"`
	Password      string `json:"password,omitempty"`
	RegistryToken string `json:"registrytoken,omitempty"`
}

func (Credentials) Empty

func (cred Credentials) Empty() bool

type Duration

type Duration struct {
	Time
}

func (Duration) Empty

func (to Duration) Empty() bool

func (*Duration) UnmarshalJSON

func (to *Duration) UnmarshalJSON(data []byte) error

func (*Duration) UnmarshalYAML

func (to *Duration) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML converts from yaml into this object

type File

type File struct {
	// Mode is permission and mode bits
	Mode int64 `json:"mode"`
	// Destination is the mount point of the file
	Destination string `json:"destination"`
	// ID is the UUID of the file
	ID string `json:"id"`

	// Meta data on the file
	Meta common.Metadata `json:"meta"`
}

File represents a file which will be placed inside either a docker container or volume

type FileAndContainer

type FileAndContainer struct {
	// Name of the container.
	ContainerName string `json:"container"`
	// Name of the file.
	File File `json:"file"`
}

FileAndContainer is a file and container order payload.

type Instructions

type Instructions struct {
	ID           string      `json:"id,omitempty"`
	OrgID        string      `json:"orgID,omitempty"`
	DefinitionID string      `json:"definitionID,omitempty"`
	Timestamp    time.Time   `json:"timestamp,omitempty"`
	Commands     [][]Command `json:"commands,omitempty"`

	Round            int                    `json:"round,omitempty"`
	GlobalTimeout    Timeout                `json:"globalTimeout,omitempty"`
	GlobalExpiration time.Time              `json:"globalExpiration,omitempty"`
	PhaseTimeouts    map[string]Timeout     `json:"phaseTimeouts,omitempty"`
	PhaseExpirations map[string]time.Time   `json:"phaseExpirations,omitempty"`
	Meta             map[string]interface{} `json:"meta,omitempty"`
	Auth             Authentication         `json:"auth"`
	TeardownCmd      biome.DestroyBiome     `json:"teardownCmd"`
}

Instructions contains all of the execution based information, for use in anything that executes the Commands

func (Instructions) GetTimeRemaining

func (instruct Instructions) GetTimeRemaining() (time.Duration, error)

func (*Instructions) InsertHostInfo

func (instruct *Instructions) InsertHostInfo(domains, ips []string) error

func (*Instructions) MetaTo

func (instruct *Instructions) MetaTo(out interface{}) error

MetaTo takes the given meta fields and puts them into the given struct ptr. Should be easier than having to do lots of type conversions directly on the meta. This uses json marshalling to accomplish it

func (Instructions) NeverTerminate

func (instruct Instructions) NeverTerminate() bool

func (*Instructions) Next

func (instruct *Instructions) Next() ([]Command, error)

Next pops the first element off of Commands. If this results in Commands being empty, it returns ErrDone.

func (*Instructions) PartialCompletion

func (instruct *Instructions) PartialCompletion(failed []string) error

func (Instructions) Peek

func (instruct Instructions) Peek() ([]Command, error)

Peek is like Next, but does not make any state changes

func (Instructions) Phase

func (instruct Instructions) Phase() (string, error)

func (*Instructions) PlaceInCredentials

func (instruct *Instructions) PlaceInCredentials(log logrus.Ext1FieldLogger, auth Credentials)

func (*Instructions) PlaceInProperIDs

func (instruct *Instructions) PlaceInProperIDs(log logrus.Ext1FieldLogger, files []common.Metadata)

func (Instructions) Status

func (instruct Instructions) Status() common.Status

func (*Instructions) UnmarshalJSON

func (instruct *Instructions) UnmarshalJSON(data []byte) error

UnmarshalJSON creates Instructions from JSON, and also handles creating the links back this object

type Mount

type Mount struct {
	Name      string `json:"name"`
	Directory string `json:"directory"`
	ReadOnly  bool   `json:"readOnly"`
}

Mount represents the information needed for the mounting of a volume

type Netconf

type Netconf struct {
	// Container is the target container
	Container string `json:"container"`
	// Network is the target network
	Network string `json:"network"`
	// Limit is the max number of packets to hold the in queue
	Limit int `json:"limit"`
	// Loss represents packet loss % ie 100% = 100
	Loss float64 `json:"loss"`
	// Delay represents the latency to be applied in microseconds
	Delay int `json:"delay"`
	// Rate represents the bandwidth constraint to be applied to the network
	Rate string `json:"rate"`
	// Duplication represents the percentage of packets to duplicate
	Duplication float64 `json:"duplicate"`
	// Corrupt represents the percentage of packets to corrupt
	Corrupt float64 `json:"corrupt"`
	// Reorder represents the percentage of packets that get reordered
	Reorder float64 `json:"reorder"`
}

Netconf represents network impairments which are to be applied to a network

type Network

type Network struct {
	//Name is the name of the network
	Name    string            `json:"name"`
	Subnet  string            `json:"subnet"`
	Gateway string            `json:"gateway"`
	Global  bool              `json:"global"`
	Labels  map[string]string `json:"labels"`
}

Network represents a logic network on which containers exist

type Order

type Order struct {
	// Type is the type of the order
	Type OrderType `json:"type"`
	// Payload is the payload object of the order
	Payload OrderPayload `json:"payload"`
}

Order to be executed by Definition

type OrderPayload

type OrderPayload interface {
}

OrderPayload is a pointer interface for order payloads.

type OrderType

type OrderType string

OrderType is the type of order

type PullImage

type PullImage struct {
	Image string `json:"image"`
	Credentials
}

PullImage contains the information necessary to pull a docker image from a registry

type ResumeExecution

type ResumeExecution struct {
	Tasks []string `json:"tasks,omitempty"`
}

ResumeExecution contains the tasks to kill before resuming execution if there are any

type SetupSwarm

type SetupSwarm struct {
	//Hosts is an array of the hosts to be setup with docker swarm
	Hosts []string `json:"hosts"`
}

SetupSwarm is the payload to setup a docker swarm

type SimpleName

type SimpleName struct {
	// Name of the container.
	Name string `json:"name"`
}

SimpleName is a simple order payload with just the container name

type StartContainer

type StartContainer struct {
	Name           string `json:"name"`
	IgnoreExitCode bool   `json:"ignoreExitCode"`
	Attach         bool   `json:"attach"`
	// Timeout is the maximum amount of time to wait for the task before terminating it.
	// This is ignored if attach is false
	Timeout Timeout `json:"timeout"`
}

StartContainer is the command for starting a container

type Target

type Target struct {
	IP string `json:"ip"`
}

Target sets the target of a command - which testnet, instance to hit

type Test

type Test struct {
	Instructions
	ProvisionCommand biome.CreateBiome `json:"provisionCommand"`
}

Test contains the instructions necessary for the execution of a single test

func (Test) GetDestroyCommand

func (t Test) GetDestroyCommand() biome.DestroyBiome

func (Test) GuessSteps

func (t Test) GuessSteps() int64

func (Test) Status

func (t Test) Status(cnt int) common.Status

func (*Test) UnmarshalJSON

func (instruct *Test) UnmarshalJSON(data []byte) error

UnmarshalJSON prevents Instructions from taking this over

type Time

type Time struct {
	time.Duration
	// contains filtered or unexported fields
}

Time represents the frame of time which can be infinite

func (Time) IsInfinite

func (to Time) IsInfinite() bool

func (Time) MarshalJSON

func (to Time) MarshalJSON() ([]byte, error)

func (Time) MarshalYAML

func (to Time) MarshalYAML() (interface{}, error)

type Timeout

type Timeout struct {
	Time
}

func (Timeout) SetInfinite

func (to Timeout) SetInfinite() Timeout

func (*Timeout) UnmarshalJSON

func (to *Timeout) UnmarshalJSON(data []byte) error

func (*Timeout) UnmarshalYAML

func (to *Timeout) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML converts from yaml into this object

type Volume

type Volume struct {
	// Name is the name of the docker volume
	Name string `json:"name"`
	// Labels to be attached to the volume
	Labels map[string]string `json:"labels"`

	Global bool `json:"global"`

	Hosts []string `json:"hosts,omitempty"`
}

Volume represents a docker volume which may be shared among multiple containers

type VolumeShare

type VolumeShare struct {
	Hosts []string `json:"hosts"`
}

VolumeShare prepares the environment for global volumes

Directories

Path Synopsis
Package biome messages used to perform commands, transiting over RabbitMQ.
Package biome messages used to perform commands, transiting over RabbitMQ.

Jump to

Keyboard shortcuts

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