Documentation ¶
Index ¶
Constants ¶
const ( Arch = "arch" Container = "container" CpuCores = "cpu-cores" CpuPower = "cpu-power" Mem = "mem" RootDisk = "root-disk" Tags = "tags" InstanceType = "instance-type" Networks = "networks" )
The following constants list the supported constraint attribute names, as defined by the fields in the Value struct.
Variables ¶
This section is empty.
Functions ¶
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) }
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:"cpu-cores,omitempty" yaml:"cpu-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"` // Networks, if not nil, holds a list of juju network names 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. Networks *[]string `json:"networks,omitempty" yaml:"networks,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 MustParse ¶
MustParse constructs a constraints.Value from the supplied arguments, as Parse, but panics on failure.
func Parse ¶
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 (*Value) ExcludeNetworks ¶
ExcludeNetworks returns a list of networks to exclude when starting a machine, if specified. They are given in the networks constraint with a "^" prefix to the name, which is stripped before returning.
func (*Value) HasContainer ¶
HasContainer returns true if the constraints.Value specifies a container.
func (*Value) HasInstanceType ¶
HasInstanceType returns true if the constraints.Value specifies an instance type.
func (*Value) HaveNetworks ¶
HaveNetworks returns whether any network constraints were specified.
func (*Value) IncludeNetworks ¶
IncludeNetworks returns a list of networks to include when starting a machine, if specified.
func (*Value) SetYAML ¶
SetYAML is required to unmarshall 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.