juju: github.com/juju/juju/core/constraints Index | Files

package constraints

import "github.com/juju/juju/core/constraints"

Index

Package Files

constraints.go validation.go

Constants

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

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

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

func IsEmpty Uses

func IsEmpty(v *Value) bool

IsEmpty returns if the given constraints value has no constraints set

type ConstraintsValue Uses

type ConstraintsValue struct {
    Target *Value
}

Constraints implements gnuflag.Value for a Constraints.

func (ConstraintsValue) Set Uses

func (v ConstraintsValue) Set(s string) error

func (ConstraintsValue) String Uses

func (v ConstraintsValue) String() string

type Validator Uses

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 Uses

func NewValidator() Validator

NewValidator returns a new constraints Validator instance.

type Value Uses

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"`

    // RootDiskSource, if specified, determines what storage the root
    // disk should be allocated from. This will be provider specific -
    // in the case of vSphere it identifies the datastore the root
    // disk file should be created in.
    RootDiskSource *string `json:"root-disk-source,omitempty" yaml:"root-disk-source,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"`

    // Zones, if not nil, holds a list of availability zones limiting where
    // the machine can be located.
    Zones *[]string `json:"zones,omitempty" yaml:"zones,omitempty"`
}

Value describes a user's requirements of the hardware on which units of an application 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 Uses

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

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

func MustParse Uses

func MustParse(args ...string) Value

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

func Parse Uses

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 Uses

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 Uses

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 Uses

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 Uses

func (v *Value) HasArch() bool

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

func (*Value) HasContainer Uses

func (v *Value) HasContainer() bool

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

func (*Value) HasCpuCores Uses

func (v *Value) HasCpuCores() bool

HasCpuCores returns true if the constraints.Value specifies a minimum number of CPU cores.

func (*Value) HasCpuPower Uses

func (v *Value) HasCpuPower() bool

HasCpuPower returns true if the constraints.Value specifies a minimum amount of CPU power.

func (*Value) HasInstanceType Uses

func (v *Value) HasInstanceType() bool

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

func (*Value) HasMem Uses

func (v *Value) HasMem() bool

HasMem returns true if the constraints.Value specifies a minimum amount of memory.

func (*Value) HasRootDisk Uses

func (v *Value) HasRootDisk() bool

HasRootDisk returns true if the contraints.Value specifies a RootDisk size.

func (*Value) HasRootDiskSource Uses

func (v *Value) HasRootDiskSource() bool

HasRootDiskSource returns true if the constraints.Value specifies a source for its root disk.

func (*Value) HasSpaces Uses

func (v *Value) HasSpaces() bool

HasSpaces returns whether any spaces constraints were specified.

func (*Value) HasVirtType Uses

func (v *Value) HasVirtType() bool

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

func (*Value) HasZones Uses

func (v *Value) HasZones() bool

HasZones returns whether any zone constraints were specified.

func (*Value) IncludeSpaces Uses

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

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

func (Value) String Uses

func (v Value) String() string

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

func (*Value) UnmarshalYAML Uses

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.

Package constraints imports 11 packages (graph) and is imported by 154 packages. Updated 2019-08-23. Refresh now. Tools for package owners.