constraints

package
v0.0.0-...-4bd6544 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2016 License: AGPL-3.0 Imports: 11 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Arch      = "arch"
	Container = "container"

	Cores        = "cores"
	CpuPower     = "cpu-power"
	Mem          = "mem"
	RootDisk     = "root-disk"
	Tags         = "tags"
	InstanceType = "instance-type"
	Spaces       = "spaces"
	VirtType     = "virt-type"
)

The following constants list the supported constraint attribute names, as defined by the fields in the Value struct.

Variables

This section is empty.

Functions

func IsEmpty

func IsEmpty(v *Value) bool

IsEmpty returns if the given constraints value has no constraints set

Types

type ConstraintsValue

type ConstraintsValue struct {
	Target *Value
}

Constraints implements gnuflag.Value for a Constraints.

func (ConstraintsValue) Set

func (v ConstraintsValue) Set(s string) error

func (ConstraintsValue) String

func (v ConstraintsValue) String() string

type Validator

type Validator interface {

	// RegisterConflicts is used to define cross-constraint override behaviour.
	// The red and blue attribute lists contain attribute names which conflict
	// with those in the other list.
	// When two constraints conflict:
	//  it is an error to set both constraints in the same constraints Value.
	//  when a constraints Value overrides another which specifies a conflicting
	//   attribute, the attribute in the overridden Value is cleared.
	RegisterConflicts(reds, blues []string)

	// RegisterUnsupported records attributes which are not supported by a constraints Value.
	RegisterUnsupported(unsupported []string)

	// RegisterVocabulary records allowed values for the specified constraint attribute.
	// allowedValues is expected to be a slice/array but is declared as interface{} so
	// that vocabs of different types can be passed in.
	RegisterVocabulary(attributeName string, allowedValues interface{})

	// Validate returns an error if the given constraints are not valid, and also
	// any unsupported attributes.
	Validate(cons Value) ([]string, error)

	// Merge merges cons into consFallback, with any conflicting attributes from cons
	// overriding those from consFallback.
	Merge(consFallback, cons Value) (Value, error)

	// UpdateVocabulary merges new attribute values with existing values.
	// This method does not overwrite or delete values, i.e.
	//     if existing values are {a, b}
	//     and new values are {c, d},
	//     then the merge result would be {a, b, c, d}.
	UpdateVocabulary(attributeName string, newValues interface{})
}

Validator defines operations on constraints attributes which are used to ensure a constraints value is valid, as well as being able to handle overridden attributes.

func NewValidator

func NewValidator() Validator

NewValidator returns a new constraints Validator instance.

type Value

type Value struct {

	// Arch, if not nil or empty, indicates that a machine must run the named
	// architecture.
	Arch *string `json:"arch,omitempty" yaml:"arch,omitempty"`

	// Container, if not nil, indicates that a machine must be the specified container type.
	Container *instance.ContainerType `json:"container,omitempty" yaml:"container,omitempty"`

	// CpuCores, if not nil, indicates that a machine must have at least that
	// number of effective cores available.
	CpuCores *uint64 `json:"cores,omitempty" yaml:"cores,omitempty"`

	// CpuPower, if not nil, indicates that a machine must have at least that
	// amount of CPU power available, where 100 CpuPower is considered to be
	// equivalent to 1 Amazon ECU (or, roughly, a single 2007-era Xeon).
	CpuPower *uint64 `json:"cpu-power,omitempty" yaml:"cpu-power,omitempty"`

	// Mem, if not nil, indicates that a machine must have at least that many
	// megabytes of RAM.
	Mem *uint64 `json:"mem,omitempty" yaml:"mem,omitempty"`

	// RootDisk, if not nil, indicates that a machine must have at least
	// that many megabytes of disk space available in the root disk. In
	// providers where the root disk is configurable at instance startup
	// time, an instance with the specified amount of disk space in the OS
	// disk might be requested.
	RootDisk *uint64 `json:"root-disk,omitempty" yaml:"root-disk,omitempty"`

	// Tags, if not nil, indicates tags that the machine must have applied to it.
	// An empty list is treated the same as a nil (unspecified) list, except an
	// empty list will override any default tags, where a nil list will not.
	Tags *[]string `json:"tags,omitempty" yaml:"tags,omitempty"`

	// InstanceType, if not nil, indicates that the specified cloud instance type
	// be used. Only valid for clouds which support instance types.
	InstanceType *string `json:"instance-type,omitempty" yaml:"instance-type,omitempty"`

	// Spaces, if not nil, holds a list of juju network spaces that
	// should be available (or not) on the machine. Positive and
	// negative values are accepted, and the difference is the latter
	// have a "^" prefix to the name.
	Spaces *[]string `json:"spaces,omitempty" yaml:"spaces,omitempty"`

	// VirtType, if not nil or empty, indicates that a machine must run the named
	// virtual type. Only valid for clouds with multi-hypervisor support.
	VirtType *string `json:"virt-type,omitempty" yaml:"virt-type,omitempty"`
}

Value describes a user's requirements of the hardware on which units of a service will run. Constraints are used to choose an existing machine onto which a unit will be deployed, or to provision a new machine if no existing one satisfies the requirements.

func Merge

func Merge(values ...Value) (Value, error)

Merge returns the effective constraints after merging any given existing values.

func MustParse

func MustParse(args ...string) Value

MustParse constructs a constraints.Value from the supplied arguments, as Parse, but panics on failure.

func Parse

func Parse(args ...string) (Value, error)

Parse constructs a constraints.Value from the supplied arguments, each of which must contain only spaces and name=value pairs. If any name is specified more than once, an error is returned.

func ParseWithAliases

func ParseWithAliases(args ...string) (cons Value, aliases map[string]string, err error)

ParseWithAliases constructs a constraints.Value from the supplied arguments, each of which must contain only spaces and name=value pairs. If any name is specified more than once, an error is returned. The aliases map returned contains a map of aliases used, and their canonical values.

func (*Value) ExcludeSpaces

func (v *Value) ExcludeSpaces() []string

ExcludeSpaces returns a list of spaces to exclude when starting a machine, if specified. They are given in the spaces constraint with a "^" prefix to the name, which is stripped before returning.

func (Value) GoString

func (v Value) GoString() string

GoString allows printing a constraints.Value nicely with the fmt package, especially when nested inside other types.

func (*Value) HasArch

func (v *Value) HasArch() bool

HasArch returns true if the constraints.Value specifies an architecture.

func (*Value) HasContainer

func (v *Value) HasContainer() bool

HasContainer returns true if the constraints.Value specifies a container.

func (*Value) HasInstanceType

func (v *Value) HasInstanceType() bool

HasInstanceType returns true if the constraints.Value specifies an instance type.

func (*Value) HasVirtType

func (v *Value) HasVirtType() bool

HasVirtType returns true if the constraints.Value specifies an virtual type.

func (*Value) HaveSpaces

func (v *Value) HaveSpaces() bool

HaveSpaces returns whether any spaces constraints were specified.

func (*Value) IncludeSpaces

func (v *Value) IncludeSpaces() []string

IncludeSpaces returns a list of spaces to include when starting a machine, if specified.

func (Value) String

func (v Value) String() string

String expresses a constraints.Value in the language in which it was specified.

func (*Value) UnmarshalYAML

func (v *Value) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML is required to unmarshal a constraints.Value object to ensure the container attribute is correctly handled when it is empty. Because ContainerType is an alias for string, Go's reflect logic used in the YAML decode determines that *string and *ContainerType are not assignable so the container value of "" in the YAML is ignored.

Jump to

Keyboard shortcuts

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