Documentation ¶
Overview ¶
The state package enables reading, observing, and changing the state stored in MongoDB of a whole environment managed by juju.
Index ¶
- Constants
- Variables
- func ContainerTypeFromId(machineId string) instance.ContainerType
- func IsHasAssignedUnitsError(err error) bool
- func IsHasContainersError(err error) bool
- func IsMachineId(name string) bool
- func IsNotAssigned(err error) bool
- func IsNotProvisionedError(err error) bool
- func IsServiceName(name string) bool
- func IsUnitName(name string) bool
- func MachineIdFromTag(tag string) string
- func MachineTag(id string) string
- func NestingLevel(machineId string) int
- func ParentId(machineId string) string
- func SortPorts(ports []instance.Port)
- func TopParentId(machineId string) string
- func UnitTag(unitName string) string
- type AddMachineParams
- type Annotator
- type AssignmentPolicy
- type Authenticator
- type Charm
- type D
- type DialOpts
- type Endpoint
- type EnvironConfigWatcher
- type Environment
- type HasAssignedUnitsError
- type HasContainersError
- type Info
- type ItemChange
- type Life
- type Lifer
- type Living
- type Machine
- func (m *Machine) AgentAlive() (bool, error)
- func (m *Machine) AgentTools() (*Tools, error)
- func (a *Machine) Annotation(key string) (string, error)
- func (a *Machine) Annotations() (map[string]string, error)
- func (m *Machine) CheckProvisioned(nonce string) bool
- func (m *Machine) Clean() bool
- func (m *Machine) Constraints() (constraints.Value, error)
- func (m *Machine) ContainerType() instance.ContainerType
- func (m *Machine) Containers() ([]string, error)
- func (m *Machine) Destroy() error
- func (m *Machine) EnsureDead() error
- func (m *Machine) HardwareCharacteristics() (*instance.HardwareCharacteristics, error)
- func (m *Machine) Id() string
- func (m *Machine) InstanceId() (instance.Id, error)
- func (m *Machine) Jobs() []MachineJob
- func (m *Machine) Life() Life
- func (m *Machine) ParentId() (string, bool)
- func (m *Machine) PasswordValid(password string) bool
- func (m *Machine) Refresh() error
- func (m *Machine) Remove() (err error)
- func (m *Machine) Series() string
- func (m *Machine) SetAgentAlive() (*presence.Pinger, error)
- func (m *Machine) SetAgentTools(t *Tools) (err error)
- func (a *Machine) SetAnnotations(pairs map[string]string) (err error)
- func (m *Machine) SetConstraints(cons constraints.Value) (err error)
- func (m *Machine) SetMongoPassword(password string) error
- func (m *Machine) SetPassword(password string) error
- func (m *Machine) SetProvisioned(id instance.Id, nonce string, ...) (err error)
- func (m *Machine) SetStatus(status params.Status, info string) error
- func (m *Machine) Status() (status params.Status, info string, err error)
- func (m *Machine) String() string
- func (m *Machine) Tag() string
- func (m *Machine) Units() (units []*Unit, err error)
- func (m *Machine) WaitAgentAlive(timeout time.Duration) (err error)
- func (m *Machine) Watch() NotifyWatcher
- func (m *Machine) WatchContainers(ctype instance.ContainerType) StringsWatcher
- func (m *Machine) WatchHardwareCharacteristics() NotifyWatcher
- func (m *Machine) WatchPrincipalUnits() StringsWatcher
- func (m *Machine) WatchUnits() StringsWatcher
- type MachineJob
- type NotAssignedError
- type NotProvisionedError
- type NotifyWatcher
- type Relation
- func (r *Relation) Destroy() (err error)
- func (r *Relation) Endpoint(serviceName string) (Endpoint, error)
- func (r *Relation) Id() int
- func (r *Relation) Life() Life
- func (r *Relation) Refresh() error
- func (r *Relation) RelatedEndpoints(serviceName string) ([]Endpoint, error)
- func (r *Relation) String() string
- func (r *Relation) Unit(u *Unit) (*RelationUnit, error)
- type RelationScopeChange
- type RelationScopeWatcher
- type RelationUnit
- func (ru *RelationUnit) Endpoint() Endpoint
- func (ru *RelationUnit) EnterScope(settings map[string]interface{}) error
- func (ru *RelationUnit) LeaveScope() error
- func (ru *RelationUnit) PrivateAddress() (string, bool)
- func (ru *RelationUnit) ReadSettings(uname string) (m map[string]interface{}, err error)
- func (ru *RelationUnit) Relation() *Relation
- func (ru *RelationUnit) Settings() (*Settings, error)
- func (ru *RelationUnit) Watch() *RelationUnitsWatcher
- func (ru *RelationUnit) WatchScope() *RelationScopeWatcher
- type RelationUnitsChange
- type RelationUnitsWatcher
- type Remover
- type ResolvedMode
- type Service
- func (s *Service) AddUnit() (unit *Unit, err error)
- func (s *Service) AllUnits() (units []*Unit, err error)
- func (a *Service) Annotation(key string) (string, error)
- func (a *Service) Annotations() (map[string]string, error)
- func (s *Service) Charm() (ch *Charm, force bool, err error)
- func (s *Service) CharmURL() (curl *charm.URL, force bool)
- func (s *Service) ClearExposed() error
- func (s *Service) ConfigSettings() (charm.Settings, error)
- func (s *Service) Constraints() (constraints.Value, error)
- func (s *Service) Destroy() (err error)
- func (s *Service) Endpoint(relationName string) (Endpoint, error)
- func (s *Service) Endpoints() (eps []Endpoint, err error)
- func (s *Service) IsExposed() bool
- func (s *Service) IsPrincipal() bool
- func (s *Service) Life() Life
- func (s *Service) MinUnits() int
- func (s *Service) Name() string
- func (s *Service) Refresh() error
- func (s *Service) Relations() (relations []*Relation, err error)
- func (a *Service) SetAnnotations(pairs map[string]string) (err error)
- func (s *Service) SetCharm(ch *Charm, force bool) (err error)
- func (s *Service) SetConstraints(cons constraints.Value) (err error)
- func (s *Service) SetExposed() error
- func (s *Service) SetMinUnits(minUnits int) (err error)
- func (s *Service) String() string
- func (s *Service) Tag() string
- func (s *Service) Unit(name string) (*Unit, error)
- func (s *Service) UpdateConfigSettings(changes charm.Settings) error
- func (s *Service) Watch() NotifyWatcher
- func (s *Service) WatchRelations() StringsWatcher
- func (s *Service) WatchUnits() StringsWatcher
- type Settings
- func (c *Settings) Delete(key string)
- func (c *Settings) Get(key string) (value interface{}, found bool)
- func (c *Settings) Keys() []string
- func (c *Settings) Map() map[string]interface{}
- func (c *Settings) Read() error
- func (c *Settings) Set(key string, value interface{})
- func (c *Settings) Update(kv map[string]interface{})
- func (c *Settings) Write() ([]ItemChange, error)
- type State
- func (st *State) APIAddresses() ([]string, error)
- func (st *State) AddCharm(ch charm.Charm, curl *charm.URL, bundleURL *url.URL, bundleSha256 string) (stch *Charm, err error)
- func (st *State) AddMachine(series string, jobs ...MachineJob) (m *Machine, err error)
- func (st *State) AddMachineWithConstraints(params *AddMachineParams) (m *Machine, err error)
- func (st *State) AddRelation(eps ...Endpoint) (r *Relation, err error)
- func (st *State) AddService(name string, ch *Charm) (service *Service, err error)
- func (st *State) AddUser(name, password string) (*User, error)
- func (st *State) Addresses() ([]string, error)
- func (st *State) AllMachines() (machines []*Machine, err error)
- func (st *State) AllServices() (services []*Service, err error)
- func (st *State) Annotator(tag string) (TaggedAnnotator, error)
- func (st *State) AssignUnit(u *Unit, policy AssignmentPolicy) (err error)
- func (st *State) Authenticator(tag string) (TaggedAuthenticator, error)
- func (st *State) CACert() (cert []byte)
- func (st *State) Charm(curl *charm.URL) (*Charm, error)
- func (st *State) Cleanup() error
- func (st *State) Close() error
- func (st *State) DestroyMachines(ids ...string) (err error)
- func (st *State) DestroyUnits(names ...string) (err error)
- func (st *State) EndpointsRelation(endpoints ...Endpoint) (*Relation, error)
- func (st *State) EnvironConfig() (*config.Config, error)
- func (st *State) EnvironConstraints() (constraints.Value, error)
- func (st *State) Environment() (*Environment, error)
- func (st *State) InferEndpoints(names []string) ([]Endpoint, error)
- func (st *State) InjectMachine(series string, cons constraints.Value, instanceId instance.Id, ...) (m *Machine, err error)
- func (st *State) KeyRelation(key string) (*Relation, error)
- func (st *State) Lifer(tag string) (Lifer, error)
- func (st *State) Machine(id string) (*Machine, error)
- func (st *State) NeedsCleanup() (bool, error)
- func (st *State) ParseTag(tag string) (string, string, error)
- func (st *State) Relation(id int) (*Relation, error)
- func (st *State) ResumeTransactions() error
- func (st *State) Service(name string) (service *Service, err error)
- func (st *State) SetAdminMongoPassword(password string) error
- func (st *State) SetEnvironConfig(cfg *config.Config) error
- func (st *State) SetEnvironConstraints(cons constraints.Value) error
- func (st *State) StartSync()
- func (st *State) Sync()
- func (st *State) Unit(name string) (*Unit, error)
- func (st *State) User(name string) (*User, error)
- func (st *State) Watch() *multiwatcher.Watcher
- func (st *State) WatchCleanups() NotifyWatcher
- func (s *State) WatchEnvironConfig() *EnvironConfigWatcher
- func (st *State) WatchEnvironMachines() StringsWatcher
- func (st *State) WatchForEnvironConfigChanges() NotifyWatcher
- func (st *State) WatchMinUnits() StringsWatcher
- func (st *State) WatchServices() StringsWatcher
- type StringsWatcher
- type TaggedAnnotator
- type TaggedAuthenticator
- type Tagger
- type Tools
- type Unit
- func (u *Unit) AgentAlive() (bool, error)
- func (u *Unit) AgentTools() (*Tools, error)
- func (a *Unit) Annotation(key string) (string, error)
- func (a *Unit) Annotations() (map[string]string, error)
- func (u *Unit) AssignToCleanEmptyMachine() (m *Machine, err error)
- func (u *Unit) AssignToCleanMachine() (m *Machine, err error)
- func (u *Unit) AssignToMachine(m *Machine) (err error)
- func (u *Unit) AssignToNewMachine() (err error)
- func (u *Unit) AssignedMachineId() (id string, err error)
- func (u *Unit) CharmURL() (*charm.URL, bool)
- func (u *Unit) ClearResolved() error
- func (u *Unit) ClosePort(protocol string, number int) (err error)
- func (u *Unit) ConfigSettings() (charm.Settings, error)
- func (u *Unit) DeployerTag() (string, bool)
- func (u *Unit) Destroy() (err error)
- func (u *Unit) EnsureDead() (err error)
- func (u *Unit) IsPrincipal() bool
- func (u *Unit) Life() Life
- func (u *Unit) Name() string
- func (u *Unit) OpenPort(protocol string, number int) (err error)
- func (u *Unit) OpenedPorts() []instance.Port
- func (u *Unit) PasswordValid(password string) bool
- func (u *Unit) PrivateAddress() (string, bool)
- func (u *Unit) PublicAddress() (string, bool)
- func (u *Unit) Refresh() error
- func (u *Unit) Remove() (err error)
- func (u *Unit) Resolve(retryHooks bool) error
- func (u *Unit) Resolved() ResolvedMode
- func (u *Unit) Service() (*Service, error)
- func (u *Unit) ServiceName() string
- func (u *Unit) SetAgentAlive() (*presence.Pinger, error)
- func (u *Unit) SetAgentTools(t *Tools) (err error)
- func (a *Unit) SetAnnotations(pairs map[string]string) (err error)
- func (u *Unit) SetCharmURL(curl *charm.URL) (err error)
- func (u *Unit) SetMongoPassword(password string) error
- func (u *Unit) SetPassword(password string) error
- func (u *Unit) SetPrivateAddress(address string) error
- func (u *Unit) SetPublicAddress(address string) (err error)
- func (u *Unit) SetResolved(mode ResolvedMode) (err error)
- func (u *Unit) SetStatus(status params.Status, info string) error
- func (u *Unit) Status() (status params.Status, info string, err error)
- func (u *Unit) String() string
- func (u *Unit) SubordinateNames() []string
- func (u *Unit) Tag() string
- func (u *Unit) UnassignFromMachine() (err error)
- func (u *Unit) WaitAgentAlive(timeout time.Duration) (err error)
- func (u *Unit) Watch() NotifyWatcher
- func (u *Unit) WatchConfigSettings() (NotifyWatcher, error)
- func (u *Unit) WatchSubordinateUnits() StringsWatcher
- type UnitSettings
- type User
Constants ¶
const ( ItemAdded = iota ItemModified ItemDeleted )
const BootstrapNonce = "user-admin:bootstrap"
BootstrapNonce is used as a nonce for the state server machine.
Variables ¶
var ErrCannotEnterScope = stderrors.New("cannot enter scope: unit or relation is not alive")
ErrCannotEnterScope indicates that a relation unit failed to enter its scope due to either the unit or the relation not being Alive.
var ErrCannotEnterScopeYet = stderrors.New("cannot enter scope yet: non-alive subordinate unit has not been removed")
ErrCannotEnterScopeYet indicates that a relation unit failed to enter its scope due to a required and pre-existing subordinate unit that is not Alive. Once that subordinate has been removed, a new one can be created.
var ErrExcessiveContention = stderrors.New("state changing too quickly; try again soon")
var ErrSubordinateConstraints = stderrors.New("constraints do not apply to subordinate services")
var ErrUnitHasSubordinates = stderrors.New("unit has subordinates")
Functions ¶
func ContainerTypeFromId ¶
func ContainerTypeFromId(machineId string) instance.ContainerType
ContainerTypeFromId returns the container type if machineId is a container id, or "" if machineId is not for a container.
func IsHasAssignedUnitsError ¶
func IsHasContainersError ¶
func IsMachineId ¶
IsMachineId returns whether id is a valid machine id.
func IsNotAssigned ¶
func IsNotProvisionedError ¶
IsNotProvisionedError returns true if err is a NotProvisionedError.
func IsServiceName ¶
IsServiceName returns whether name is a valid service name.
func IsUnitName ¶
IsUnitName returns whether name is a valid unit name.
func MachineIdFromTag ¶
MachineIdFromTag returns the machine id that was used to create the tag.
func MachineTag ¶
MachineTag returns the tag for the machine with the given id.
func NestingLevel ¶
NestingLevel returns how many levels of nesting exist for a machine id.
func ParentId ¶
ParentId returns the id of the host machine if machineId a container id, or "" if machineId is not for a container.
func TopParentId ¶
TopParentId returns the id of the top level host machine for a container id.
Types ¶
type AddMachineParams ¶
type AddMachineParams struct { Series string Constraints constraints.Value ParentId string ContainerType instance.ContainerType Jobs []MachineJob // contains filtered or unexported fields }
AddMachineParams encapsulates the parameters used to create a new machine.
type Annotator ¶
type Annotator interface { Annotation(key string) (string, error) Annotations() (map[string]string, error) SetAnnotations(pairs map[string]string) error }
Annotator represents entities capable of handling annotations.
type AssignmentPolicy ¶
type AssignmentPolicy string
AssignmentPolicy controls what machine a unit will be assigned to.
const ( // AssignLocal indicates that all service units should be assigned // to machine 0. AssignLocal AssignmentPolicy = "local" // AssignClean indicates that every service unit should be assigned // to a machine which never previously has hosted any units, and that // new machines should be launched if required. AssignClean AssignmentPolicy = "clean" // AssignCleanEmpty indicates that every service unit should be assigned // to a machine which never previously has hosted any units, and which is not // currently hosting any containers, and that new machines should be launched if required. AssignCleanEmpty AssignmentPolicy = "clean-empty" // AssignNew indicates that every service unit should be assigned to a new // dedicated machine. A new machine will be launched for each new unit. AssignNew AssignmentPolicy = "new" )
type Authenticator ¶
type Authenticator interface { Refresh() error SetPassword(pass string) error PasswordValid(pass string) bool }
Authenticator represents entites capable of handling password authentication.
type Charm ¶
type Charm struct {
// contains filtered or unexported fields
}
Charm represents the state of a charm in the environment.
func (*Charm) BundleSha256 ¶
BundleSha256 returns the SHA256 digest of the charm bundle bytes.
type DialOpts ¶
type DialOpts struct { // Timeout is the amount of time to wait contacting // a state server. Timeout time.Duration }
DialOpts holds configuration parameters that control the Dialing behavior when connecting to a state server.
func DefaultDialOpts ¶
func DefaultDialOpts() DialOpts
DefaultDialOpts returns a DialOpts representing the default parameters for contacting a state server.
type Endpoint ¶
Endpoint represents one endpoint of a relation.
func (Endpoint) CanRelateTo ¶
CanRelateTo returns whether a relation may be established between e and other.
func (Endpoint) ImplementedBy ¶
ImplementedBy returns whether the endpoint is implemented by the supplied charm.
func (Endpoint) IsImplicit ¶
IsImplicit returns whether the endpoint is supplied by juju itself, rather than by a charm.
type EnvironConfigWatcher ¶
type EnvironConfigWatcher struct {
// contains filtered or unexported fields
}
EnvironConfigWatcher observes changes to the environment configuration.
func (*EnvironConfigWatcher) Changes ¶
func (w *EnvironConfigWatcher) Changes() <-chan *config.Config
Changes returns a channel that will receive the new environment configuration when a change is detected. Note that multiple changes may be observed as a single event in the channel.
type Environment ¶
type Environment struct {
// contains filtered or unexported fields
}
Environment represents the state of an environment.
func (*Environment) Annotation ¶
Annotation returns the annotation value corresponding to the given key. If the requested annotation is not found, an empty string is returned.
func (*Environment) Annotations ¶
Annotations returns all the annotations corresponding to an entity.
func (*Environment) SetAnnotations ¶
SetAnnotations adds key/value pairs to annotations in MongoDB.
func (Environment) Tag ¶
func (e Environment) Tag() string
Tag returns a name identifying the environment. The returned name will be different from other Tag values returned by any other entities from the same state.
func (Environment) UUID ¶
func (e Environment) UUID() string
UUID returns the universally unique identifier of the environment.
type HasAssignedUnitsError ¶
func (*HasAssignedUnitsError) Error ¶
func (e *HasAssignedUnitsError) Error() string
type HasContainersError ¶
func (*HasContainersError) Error ¶
func (e *HasContainersError) Error() string
type Info ¶
type Info struct { // Addrs gives the addresses of the MongoDB servers for the state. // Each address should be in the form address:port. Addrs []string // CACert holds the CA certificate that will be used // to validate the state server's certificate, in PEM format. CACert []byte // Tag holds the name of the entity that is connecting. // It should be empty when connecting as an administrator. Tag string // Password holds the password for the connecting entity. Password string }
Info encapsulates information about cluster of servers holding juju state and can be used to make a connection to that cluster.
type ItemChange ¶
ItemChange represents the change of an item in a settings.
func (*ItemChange) String ¶
func (ic *ItemChange) String() string
String returns the item change in a readable format.
type Life ¶
type Life int8
Life represents the lifecycle state of the entities Relation, Unit, Service and Machine.
type Machine ¶
type Machine struct {
// contains filtered or unexported fields
}
Machine represents the state of a machine.
func (*Machine) AgentAlive ¶
AgentAlive returns whether the respective remote agent is alive.
func (*Machine) AgentTools ¶
AgentTools returns the tools that the agent is currently running. It returns an error that satisfies IsNotFound if the tools have not yet been set.
func (*Machine) Annotation ¶
Annotation returns the annotation value corresponding to the given key. If the requested annotation is not found, an empty string is returned.
func (*Machine) Annotations ¶
Annotations returns all the annotations corresponding to an entity.
func (*Machine) CheckProvisioned ¶
CheckProvisioned returns true if the machine was provisioned with the given nonce.
func (*Machine) Clean ¶
Clean returns true if the machine does not have any deployed units or containers.
func (*Machine) Constraints ¶
func (m *Machine) Constraints() (constraints.Value, error)
Constraints returns the exact constraints that should apply when provisioning an instance for the machine.
func (*Machine) ContainerType ¶
func (m *Machine) ContainerType() instance.ContainerType
ContainerType returns the type of container hosting this machine.
func (*Machine) Containers ¶
Containers returns the container ids belonging to a parent machine. TODO(wallyworld): move this method to a service
func (*Machine) Destroy ¶
Destroy sets the machine lifecycle to Dying if it is Alive. It does nothing otherwise. Destroy will fail if the machine has principal units assigned, or if the machine has JobManageEnviron. If the machine has assigned units, Destroy will return a HasAssignedUnitsError.
func (*Machine) EnsureDead ¶
EnsureDead sets the machine lifecycle to Dead if it is Alive or Dying. It does nothing otherwise. EnsureDead will fail if the machine has principal units assigned, or if the machine has JobManageEnviron. If the machine has assigned units, EnsureDead will return a HasAssignedUnitsError.
func (*Machine) HardwareCharacteristics ¶
func (m *Machine) HardwareCharacteristics() (*instance.HardwareCharacteristics, error)
TODO(wallyworld): move this method to a service.
func (*Machine) InstanceId ¶
InstanceId returns the provider specific instance id for this machine and whether it has been set.
func (*Machine) Jobs ¶
func (m *Machine) Jobs() []MachineJob
Jobs returns the responsibilities that must be fulfilled by m's agent.
func (*Machine) ParentId ¶
ParentId returns the Id of the host machine if this machine is a container.
func (*Machine) PasswordValid ¶
PasswordValid returns whether the given password is valid for the given machine.
func (*Machine) Refresh ¶
Refresh refreshes the contents of the machine from the underlying state. It returns an error that satisfies IsNotFound if the machine has been removed.
func (*Machine) Remove ¶
Remove removes the machine from state. It will fail if the machine is not Dead.
func (*Machine) SetAgentAlive ¶
SetAgentAlive signals that the agent for machine m is alive. It returns the started pinger.
func (*Machine) SetAgentTools ¶
SetAgentTools sets the tools that the agent is currently running.
func (*Machine) SetAnnotations ¶
SetAnnotations adds key/value pairs to annotations in MongoDB.
func (*Machine) SetConstraints ¶
func (m *Machine) SetConstraints(cons constraints.Value) (err error)
SetConstraints sets the exact constraints to apply when provisioning an instance for the machine. It will fail if the machine is Dead, or if it is already provisioned.
func (*Machine) SetMongoPassword ¶
SetMongoPassword sets the password the agent responsible for the machine should use to communicate with the state servers. Previous passwords are invalidated.
func (*Machine) SetPassword ¶
SetPassword sets the password for the machine's agent.
func (*Machine) SetProvisioned ¶
func (m *Machine) SetProvisioned(id instance.Id, nonce string, characteristics *instance.HardwareCharacteristics) (err error)
SetProvisioned sets the provider specific machine id, nonce and also metadata for this machine. Once set, the instance id cannot be changed.
func (*Machine) Tag ¶
Tag returns a name identifying the machine that is safe to use as a file name. The returned name will be different from other Tag values returned by any other entities from the same state.
func (*Machine) WaitAgentAlive ¶
WaitAgentAlive blocks until the respective agent is alive.
func (*Machine) Watch ¶
func (m *Machine) Watch() NotifyWatcher
Watch returns a watcher for observing changes to a machine.
func (*Machine) WatchContainers ¶
func (m *Machine) WatchContainers(ctype instance.ContainerType) StringsWatcher
WatchContainers returns a StringsWatcher that notifies of changes to the lifecycles of containers on a machine.
func (*Machine) WatchHardwareCharacteristics ¶
func (m *Machine) WatchHardwareCharacteristics() NotifyWatcher
WatchHardwareCharacteristics returns a watcher for observing changes to a machine's hardware characteristics.
func (*Machine) WatchPrincipalUnits ¶
func (m *Machine) WatchPrincipalUnits() StringsWatcher
WatchPrincipalUnits returns a StringsWatcher tracking the machine's principal units.
func (*Machine) WatchUnits ¶
func (m *Machine) WatchUnits() StringsWatcher
WatchUnits returns a new StringsWatcher watching m's units.
type MachineJob ¶
type MachineJob int
MachineJob values define responsibilities that machines may be expected to fulfil.
const ( JobHostUnits MachineJob JobManageEnviron JobManageState )
func (MachineJob) String ¶
func (job MachineJob) String() string
type NotAssignedError ¶
type NotAssignedError struct{ Unit *Unit }
NotAssignedError indicates that a unit is not assigned to a machine (and, in the case of subordinate units, that the unit's principal is not assigned).
func (*NotAssignedError) Error ¶
func (e *NotAssignedError) Error() string
type NotProvisionedError ¶
type NotProvisionedError struct {
// contains filtered or unexported fields
}
NotProvisionedError records an error when a machine is not provisioned.
func (*NotProvisionedError) Error ¶
func (e *NotProvisionedError) Error() string
type NotifyWatcher ¶
NotifyWatcher generates signals when something changes, but it does not return any content for those changes
type Relation ¶
type Relation struct {
// contains filtered or unexported fields
}
Relation represents a relation between one or two service endpoints.
func (*Relation) Destroy ¶
Destroy ensures that the relation will be removed at some point; if no units are currently in scope, it will be removed immediately.
func (*Relation) Endpoint ¶
Endpoint returns the endpoint of the relation for the named service. If the service is not part of the relation, an error will be returned.
func (*Relation) Id ¶
Id returns the integer internal relation key. This is exposed because the unit agent needs to expose a value derived from this (as JUJU_RELATION_ID) to allow relation hooks to differentiate between relations with different services.
func (*Relation) Refresh ¶
Refresh refreshes the contents of the relation from the underlying state. It returns an error that satisfies IsNotFound if the relation has been removed.
func (*Relation) RelatedEndpoints ¶
RelatedEndpoints returns the endpoints of the relation r with which units of the named service will establish relations. If the service is not part of the relation r, an error will be returned.
type RelationScopeChange ¶
RelationScopeChange contains information about units that have entered or left a particular scope.
type RelationScopeWatcher ¶
type RelationScopeWatcher struct {
// contains filtered or unexported fields
}
RelationScopeWatcher observes changes to the set of units in a particular relation scope.
func (*RelationScopeWatcher) Changes ¶
func (w *RelationScopeWatcher) Changes() <-chan *RelationScopeChange
Changes returns a channel that will receive changes when units enter and leave a relation scope. The Entered field in the first event on the channel holds the initial state.
type RelationUnit ¶
type RelationUnit struct {
// contains filtered or unexported fields
}
RelationUnit holds information about a single unit in a relation, and allows clients to conveniently access unit-specific functionality.
func (*RelationUnit) Endpoint ¶
func (ru *RelationUnit) Endpoint() Endpoint
Endpoint returns the relation endpoint that defines the unit's participation in the relation.
func (*RelationUnit) EnterScope ¶
func (ru *RelationUnit) EnterScope(settings map[string]interface{}) error
EnterScope ensures that the unit has entered its scope in the relation. When the unit has already entered its relation scope, EnterScope will report success but make no changes to state.
Otherwise, assuming both the relation and the unit are alive, it will enter scope and create or overwrite the unit's settings in the relation according to the supplied map.
If the unit is a principal and the relation has container scope, EnterScope will also create the required subordinate unit, if it does not already exist; this is because there's no point having a principal in scope if there is no corresponding subordinate to join it.
Once a unit has entered a scope, it stays in scope without further intervention; the relation will not be able to become Dead until all units have departed its scopes.
func (*RelationUnit) LeaveScope ¶
func (ru *RelationUnit) LeaveScope() error
LeaveScope signals that the unit has left its scope in the relation. After the unit has left its relation scope, it is no longer a member of the relation; if the relation is dying when its last member unit leaves, it is removed immediately. It is not an error to leave a scope that the unit is not, or never was, a member of.
func (*RelationUnit) PrivateAddress ¶
func (ru *RelationUnit) PrivateAddress() (string, bool)
PrivateAddress returns the private address of the unit and whether it is valid.
func (*RelationUnit) ReadSettings ¶
func (ru *RelationUnit) ReadSettings(uname string) (m map[string]interface{}, err error)
ReadSettings returns a map holding the settings of the unit with the supplied name within this relation. An error will be returned if the relation no longer exists, or if the unit's service is not part of the relation, or the settings are invalid; but mere non-existence of the unit is not grounds for an error, because the unit settings are guaranteed to persist for the lifetime of the relation, regardless of the lifetime of the unit.
func (*RelationUnit) Relation ¶
func (ru *RelationUnit) Relation() *Relation
Relation returns the relation associated with the unit.
func (*RelationUnit) Settings ¶
func (ru *RelationUnit) Settings() (*Settings, error)
Settings returns a Settings which allows access to the unit's settings within the relation.
func (*RelationUnit) Watch ¶
func (ru *RelationUnit) Watch() *RelationUnitsWatcher
Watch returns a watcher that notifies of changes to conterpart units in the relation.
func (*RelationUnit) WatchScope ¶
func (ru *RelationUnit) WatchScope() *RelationScopeWatcher
WatchScope returns a watcher which notifies of counterpart units entering and leaving the unit's scope.
type RelationUnitsChange ¶
type RelationUnitsChange struct { Joined []string Changed map[string]UnitSettings Departed []string }
RelationUnitsChange holds notifications of units entering and leaving the scope of a RelationUnit, and changes to the settings of those units known to have entered.
When a counterpart first enters scope, it is/ noted in the Joined field, and its settings are noted in the Changed field. Subsequently, settings changes will be noted in the Changed field alone, until the couterpart leaves the scope; at that point, it will be noted in the Departed field, and no further events will be sent for that counterpart unit.
type RelationUnitsWatcher ¶
type RelationUnitsWatcher struct {
// contains filtered or unexported fields
}
RelationUnitsWatcher sends notifications of units entering and leaving the scope of a RelationUnit, and changes to the settings of those units known to have entered.
func (*RelationUnitsWatcher) Changes ¶
func (w *RelationUnitsWatcher) Changes() <-chan RelationUnitsChange
Changes returns a channel that will receive the changes to counterpart units in a relation. The first event on the channel holds the initial state of the relation in its Joined and Changed fields.
type ResolvedMode ¶
type ResolvedMode string
ResolvedMode describes the way state transition errors are resolved.
const ( ResolvedNone ResolvedMode = "" ResolvedRetryHooks ResolvedMode = "retry-hooks" ResolvedNoHooks ResolvedMode = "no-hooks" )
type Service ¶
type Service struct {
// contains filtered or unexported fields
}
Service represents the state of a service.
func (*Service) Annotation ¶
Annotation returns the annotation value corresponding to the given key. If the requested annotation is not found, an empty string is returned.
func (*Service) Annotations ¶
Annotations returns all the annotations corresponding to an entity.
func (*Service) Charm ¶
Charm returns the service's charm and whether units should upgrade to that charm even if they are in an error state.
func (*Service) CharmURL ¶
CharmURL returns the service's charm URL, and whether units should upgrade to the charm with that URL even if they are in an error state.
func (*Service) ClearExposed ¶
ClearExposed removes the exposed flag from the service. See SetExposed and IsExposed.
func (*Service) ConfigSettings ¶
ConfigSettings returns the raw user configuration for the service's charm. Unset values are omitted.
func (*Service) Constraints ¶
func (s *Service) Constraints() (constraints.Value, error)
Constraints returns the current service constraints.
func (*Service) Destroy ¶
Destroy ensures that the service and all its relations will be removed at some point; if the service has no units, and no relation involving the service has any units in scope, they are all removed immediately.
func (*Service) Endpoint ¶
Endpoint returns the relation endpoint with the supplied name, if it exists.
func (*Service) IsExposed ¶
IsExposed returns whether this service is exposed. The explicitly open ports (with open-port) for exposed services may be accessed from machines outside of the local deployment network. See SetExposed and ClearExposed.
func (*Service) IsPrincipal ¶
IsPrincipal returns whether units of the service can have subordinate units.
func (*Service) Refresh ¶
Refresh refreshes the contents of the Service from the underlying state. It returns an error that satisfies IsNotFound if the service has been removed.
func (*Service) SetAnnotations ¶
SetAnnotations adds key/value pairs to annotations in MongoDB.
func (*Service) SetCharm ¶
SetCharm changes the charm for the service. New units will be started with this charm, and existing units will be upgraded to use it. If force is true, units will be upgraded even if they are in an error state.
func (*Service) SetConstraints ¶
func (s *Service) SetConstraints(cons constraints.Value) (err error)
SetConstraints replaces the current service constraints.
func (*Service) SetExposed ¶
SetExposed marks the service as exposed. See ClearExposed and IsExposed.
func (*Service) SetMinUnits ¶
SetMinUnits changes the number of minimum units required by the service.
func (*Service) Tag ¶
Tag returns a name identifying the service that is safe to use as a file name. The returned name will be different from other Tag values returned by any other entities from the same state.
func (*Service) UpdateConfigSettings ¶
UpdateConfigSettings changes a service's charm config settings. Values set to nil will be deleted; unknown and invalid values will return an error.
func (*Service) Watch ¶
func (s *Service) Watch() NotifyWatcher
Watch returns a watcher for observing changes to a service.
func (*Service) WatchRelations ¶
func (s *Service) WatchRelations() StringsWatcher
WatchRelations returns a StringsWatcher that notifies of changes to the lifecycles of relations involving s.
func (*Service) WatchUnits ¶
func (s *Service) WatchUnits() StringsWatcher
WatchUnits returns a StringsWatcher that notifies of changes to the lifecycles of units of s.
type Settings ¶
type Settings struct {
// contains filtered or unexported fields
}
A Settings manages changes to settings as a delta in memory and merges them back in the database when explicitly requested.
func (*Settings) Write ¶
func (c *Settings) Write() ([]ItemChange, error)
Write writes changes made to c back onto its node. Changes are written as a delta applied on top of the latest version of the node, to prevent overwriting unrelated changes made to the node since it was last read.
type State ¶
type State struct {
// contains filtered or unexported fields
}
State represents the state of an environment managed by juju.
func Initialize ¶
Initialize sets up an initial empty state and returns it. This needs to be performed only once for a given environment. It returns unauthorizedError if access is unauthorized.
func Open ¶
Open connects to the server described by the given info, waits for it to be initialized, and returns a new State representing the environment connected to. It returns unauthorizedError if access is unauthorized.
func (*State) APIAddresses ¶
APIAddresses returns the list of addresses used to connect to the API.
func (*State) AddCharm ¶
func (st *State) AddCharm(ch charm.Charm, curl *charm.URL, bundleURL *url.URL, bundleSha256 string) (stch *Charm, err error)
AddCharm adds the ch charm with curl to the state. bundleUrl must be set to a URL where the bundle for ch may be downloaded from. On success the newly added charm state is returned.
func (*State) AddMachine ¶
func (st *State) AddMachine(series string, jobs ...MachineJob) (m *Machine, err error)
AddMachine adds a new machine configured to run the supplied jobs on the supplied series. The machine's constraints will be taken from the environment constraints.
func (*State) AddMachineWithConstraints ¶
func (st *State) AddMachineWithConstraints(params *AddMachineParams) (m *Machine, err error)
AddMachineWithConstraints adds a new machine configured to run the supplied jobs on the supplied series. The machine's constraints and other configuration will be taken from the supplied params struct.
func (*State) AddRelation ¶
AddRelation creates a new relation with the given endpoints.
func (*State) AddService ¶
AddService creates a new service, running the supplied charm, with the supplied name (which must be unique). If the charm defines peer relations, they will be created automatically.
func (*State) AllMachines ¶
AllMachines returns all machines in the environment ordered by id.
func (*State) AllServices ¶
AllServices returns all deployed services in the environment.
func (*State) Annotator ¶
func (st *State) Annotator(tag string) (TaggedAnnotator, error)
Annotator attempts to return aa TaggedAnnotator with the given tag.
func (*State) AssignUnit ¶
func (st *State) AssignUnit(u *Unit, policy AssignmentPolicy) (err error)
AssignUnit places the unit on a machine. Depending on the policy, and the state of the environment, this may lead to new instances being launched within the environment.
func (*State) Authenticator ¶
func (st *State) Authenticator(tag string) (TaggedAuthenticator, error)
Authenticator attempts to return a TaggedAuthenticator with the given tag.
func (*State) Cleanup ¶
Cleanup removes all documents that were previously marked for removal, if any such exist. It should be called periodically by at least one element of the system.
func (*State) DestroyMachines ¶
DestroyMachines destroys the machines with the specified ids.
func (*State) DestroyUnits ¶
DestroyUnits destroys the units with the specified names.
func (*State) EndpointsRelation ¶
EndpointsRelation returns the existing relation with the given endpoints.
func (*State) EnvironConstraints ¶
func (st *State) EnvironConstraints() (constraints.Value, error)
EnvironConstraints returns the current environment constraints.
func (*State) Environment ¶
func (st *State) Environment() (*Environment, error)
Environment returns the environment entity.
func (*State) InferEndpoints ¶
InferEndpoints returns the endpoints corresponding to the supplied names. There must be 1 or 2 supplied names, of the form <service>[:<relation>]. If the supplied names uniquely specify a possible relation, or if they uniquely specify a possible relation once all implicit relations have been filtered, the endpoints corresponding to that relation will be returned.
func (*State) InjectMachine ¶
func (st *State) InjectMachine(series string, cons constraints.Value, instanceId instance.Id, jobs ...MachineJob) (m *Machine, err error)
InjectMachine adds a new machine, corresponding to an existing provider instance, configured to run the supplied jobs on the supplied series, using the specified constraints.
func (*State) KeyRelation ¶
KeyRelation returns the existing relation with the given key (which can be derived unambiguously from the relation's endpoints).
func (*State) NeedsCleanup ¶
NeedsCleanup returns true if documents previously marked for removal exist.
func (*State) ParseTag ¶
ParseTag, given an entity tag, returns the collection name and id of the entity document.
func (*State) ResumeTransactions ¶
ResumeTransactions resumes all pending transactions.
func (*State) SetAdminMongoPassword ¶
SetAdminMongoPassword sets the administrative password to access the state. If the password is non-empty, all subsequent attempts to access the state must be authorized; otherwise no authorization is required.
func (*State) SetEnvironConfig ¶
SetEnvironConfig replaces the current configuration of the environment with the provided configuration.
func (*State) SetEnvironConstraints ¶
func (st *State) SetEnvironConstraints(cons constraints.Value) error
SetEnvironConstraints replaces the current environment constraints.
func (*State) StartSync ¶
func (st *State) StartSync()
StartSync forces watchers to resynchronize their state with the database immediately. This will happen periodically automatically.
func (*State) Sync ¶
func (st *State) Sync()
Sync forces watchers to resynchronize their state with the database immediately, and waits until all events are known.
func (*State) Watch ¶
func (st *State) Watch() *multiwatcher.Watcher
func (*State) WatchCleanups ¶
func (st *State) WatchCleanups() NotifyWatcher
WatchCleanups starts and returns a CleanupWatcher.
func (*State) WatchEnvironConfig ¶
func (s *State) WatchEnvironConfig() *EnvironConfigWatcher
WatchEnvironConfig returns a watcher for observing changes to the environment configuration.
func (*State) WatchEnvironMachines ¶
func (st *State) WatchEnvironMachines() StringsWatcher
WatchEnvironMachines returns a StringsWatcher that notifies of changes to the lifecycles of the machines (but not containers) in the environment.
func (*State) WatchForEnvironConfigChanges ¶
func (st *State) WatchForEnvironConfigChanges() NotifyWatcher
WatchForEnvironConfigChanges return a NotifyWatcher waiting for the Environ Config to change. This differs from WatchEnvironConfig in that the watcher is a NotifyWatcher that does not give content during Changes()
func (*State) WatchMinUnits ¶
func (st *State) WatchMinUnits() StringsWatcher
func (*State) WatchServices ¶
func (st *State) WatchServices() StringsWatcher
WatchServices returns a StringsWatcher that notifies of changes to the lifecycles of the services in the environment.
type StringsWatcher ¶
StringsWatcher generates signals when something changes, returning the changes as a list of strings.
type TaggedAnnotator ¶
TaggedAnnotator represents tagged entities capable of handling annotations.
type TaggedAuthenticator ¶
type TaggedAuthenticator interface { Authenticator Tagger }
TaggedAuthenticator represents tagged entities capable of authentication.
type Unit ¶
type Unit struct {
// contains filtered or unexported fields
}
Unit represents the state of a service unit.
func (*Unit) AgentAlive ¶
AgentAlive returns whether the respective remote agent is alive.
func (*Unit) AgentTools ¶
AgentTools returns the tools that the agent is currently running. It an error that satisfies IsNotFound if the tools have not yet been set.
func (*Unit) Annotation ¶
Annotation returns the annotation value corresponding to the given key. If the requested annotation is not found, an empty string is returned.
func (*Unit) Annotations ¶
Annotations returns all the annotations corresponding to an entity.
func (*Unit) AssignToCleanEmptyMachine ¶
AssignToCleanMachine assigns u to a machine which is marked as clean and is also not hosting any containers. A machine is clean if it has never had any principal units assigned to it. If there are no clean machines besides any machine(s) running JobHostEnviron, an error is returned. This method does not take constraints into consideration when choosing a machine (lp:1161919).
func (*Unit) AssignToCleanMachine ¶
AssignToCleanMachine assigns u to a machine which is marked as clean. A machine is clean if it has never had any principal units assigned to it. If there are no clean machines besides any machine(s) running JobHostEnviron, an error is returned. This method does not take constraints into consideration when choosing a machine (lp:1161919).
func (*Unit) AssignToMachine ¶
AssignToMachine assigns this unit to a given machine.
func (*Unit) AssignToNewMachine ¶
AssignToNewMachine assigns the unit to a new machine, with constraints determined according to the service and environment constraints at the time of unit creation.
func (*Unit) AssignedMachineId ¶
AssignedMachineId returns the id of the assigned machine.
func (*Unit) ClearResolved ¶
ClearResolved removes any resolved setting on the unit.
func (*Unit) ClosePort ¶
ClosePort sets the policy of the port with protocol and number to be closed.
func (*Unit) ConfigSettings ¶
ConfigSettings returns the complete set of service charm config settings available to the unit. Unset values will be replaced with the default value for the associated option, and may thus be nil when no default is specified.
func (*Unit) DeployerTag ¶
DeployerTag returns the tag of the agent responsible for deploying the unit. If no such entity can be determined, false is returned.
func (*Unit) Destroy ¶
Destroy, when called on a Alive unit, advances its lifecycle as far as possible; it otherwise has no effect. In most situations, the unit's life is just set to Dying; but if a principal unit that is not assigned to a provisioned machine is Destroyed, it will be removed from state directly.
func (*Unit) EnsureDead ¶
EnsureDead sets the unit lifecycle to Dead if it is Alive or Dying. It does nothing otherwise. If the unit has subordinates, it will return ErrUnitHasSubordinates.
func (*Unit) IsPrincipal ¶
IsPrincipal returns whether the unit is deployed in its own container, and can therefore have subordinate services deployed alongside it.
func (*Unit) OpenedPorts ¶
OpenedPorts returns a slice containing the open ports of the unit.
func (*Unit) PasswordValid ¶
PasswordValid returns whether the given password is valid for the given unit.
func (*Unit) PrivateAddress ¶
PrivateAddress returns the private address of the unit and whether it is valid.
func (*Unit) PublicAddress ¶
PublicAddress returns the public address of the unit and whether it is valid.
func (*Unit) Refresh ¶
Refresh refreshes the contents of the Unit from the underlying state. It an error that satisfies IsNotFound if the unit has been removed.
func (*Unit) Remove ¶
Remove removes the unit from state, and may remove its service as well, if the service is Dying and no other references to it exist. It will fail if the unit is not Dead.
func (*Unit) Resolve ¶
Resolve marks the unit as having had any previous state transition problems resolved, and informs the unit that it may attempt to reestablish normal workflow. The retryHooks parameter informs whether to attempt to reexecute previous failed hooks or to continue as if they had succeeded before.
func (*Unit) Resolved ¶
func (u *Unit) Resolved() ResolvedMode
Resolved returns the resolved mode for the unit.
func (*Unit) ServiceName ¶
ServiceName returns the service name.
func (*Unit) SetAgentAlive ¶
SetAgentAlive signals that the agent for unit u is alive. It returns the started pinger.
func (*Unit) SetAgentTools ¶
SetAgentTools sets the tools that the agent is currently running.
func (*Unit) SetAnnotations ¶
SetAnnotations adds key/value pairs to annotations in MongoDB.
func (*Unit) SetCharmURL ¶
SetCharmURL marks the unit as currently using the supplied charm URL. An error will be returned if the unit is dead, or the charm URL not known.
func (*Unit) SetMongoPassword ¶
SetMongoPassword sets the password the agent responsible for the unit should use to communicate with the state servers. Previous passwords are invalidated.
func (*Unit) SetPassword ¶
SetPassword sets the password for the machine's agent.
func (*Unit) SetPrivateAddress ¶
SetPrivateAddress sets the private address of the unit.
func (*Unit) SetPublicAddress ¶
SetPublicAddress sets the public address of the unit.
func (*Unit) SetResolved ¶
func (u *Unit) SetResolved(mode ResolvedMode) (err error)
SetResolved marks the unit as having had any previous state transition problems resolved, and informs the unit that it may attempt to reestablish normal workflow. The resolved mode parameter informs whether to attempt to reexecute previous failed hooks or to continue as if they had succeeded before.
func (*Unit) SubordinateNames ¶
SubordinateNames returns the names of any subordinate units.
func (*Unit) Tag ¶
Tag returns a name identifying the unit that is safe to use as a file name. The returned name will be different from other Tag values returned by any other entities from the same state.
func (*Unit) UnassignFromMachine ¶
UnassignFromMachine removes the assignment between this unit and the machine it's assigned to.
func (*Unit) WaitAgentAlive ¶
WaitAgentAlive blocks until the respective agent is alive.
func (*Unit) Watch ¶
func (u *Unit) Watch() NotifyWatcher
Watch returns a watcher for observing changes to a unit.
func (*Unit) WatchConfigSettings ¶
func (u *Unit) WatchConfigSettings() (NotifyWatcher, error)
WatchConfigSettings returns a watcher for observing changes to the unit's service configuration settings. The unit must have a charm URL set before this method is called, and the returned watcher will be valid only while the unit's charm URL is not changed. TODO(fwereade): this could be much smarter; if it were, uniter.Filter could be somewhat simpler.
func (*Unit) WatchSubordinateUnits ¶
func (u *Unit) WatchSubordinateUnits() StringsWatcher
WatchSubordinateUnits returns a StringsWatcher tracking the unit's subordinate units.
type UnitSettings ¶
UnitSettings holds information about a service unit's settings within a relation.
type User ¶
type User struct {
// contains filtered or unexported fields
}
User represents a juju client user.
func (*User) PasswordValid ¶
PasswordValid returns whether the given password is valid for the user.
func (*User) SetPassword ¶
SetPassword sets the password associated with the user.
func (*User) SetPasswordHash ¶
SetPasswordHash sets the password to the inverse of utils.PasswordHash(pwHash). It can be used when we know only the hash of the password, but not the clear text.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
machine
The machine package implements the API interfaces used by the machine agent.
|
The machine package implements the API interfaces used by the machine agent. |
The presence package implements an interface for observing liveness of arbitrary keys (agents, processes, etc) on top of MongoDB.
|
The presence package implements an interface for observing liveness of arbitrary keys (agents, processes, etc) on top of MongoDB. |
The statecmd package is a temporary package to put code that's used by both cmd/juju and state/api.
|
The statecmd package is a temporary package to put code that's used by both cmd/juju and state/api. |
The watcher package provides an interface for observing changes to arbitrary MongoDB documents that are maintained via the mgo/txn transaction package.
|
The watcher package provides an interface for observing changes to arbitrary MongoDB documents that are maintained via the mgo/txn transaction package. |