本文整理汇总了Golang中github.com/juju/juju/state.State.StateServerInfo方法的典型用法代码示例。如果您正苦于以下问题:Golang State.StateServerInfo方法的具体用法?Golang State.StateServerInfo怎么用?Golang State.StateServerInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/state.State
的用法示例。
在下文中一共展示了State.StateServerInfo方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: EnsureAvailabilitySingle
// EnsureAvailabilitySingle applies a single StateServersSpec specification to the current environment.
// Exported so it can be called by the legacy client API in the client package.
func EnsureAvailabilitySingle(st *state.State, spec params.StateServersSpec) (params.StateServersChanges, error) {
if !st.IsStateServer() {
return params.StateServersChanges{}, errors.New("unsupported with hosted environments")
}
// Check if changes are allowed and the command may proceed.
blockChecker := common.NewBlockChecker(st)
if err := blockChecker.ChangeAllowed(); err != nil {
return params.StateServersChanges{}, errors.Trace(err)
}
// Validate the environment tag if present.
if spec.EnvironTag != "" {
tag, err := names.ParseEnvironTag(spec.EnvironTag)
if err != nil {
return params.StateServersChanges{}, errors.Errorf("invalid environment tag: %v", err)
}
if _, err := st.FindEntity(tag); err != nil {
return params.StateServersChanges{}, err
}
}
series := spec.Series
if series == "" {
ssi, err := st.StateServerInfo()
if err != nil {
return params.StateServersChanges{}, err
}
// We should always have at least one voting machine
// If we *really* wanted we could just pick whatever series is
// in the majority, but really, if we always copy the value of
// the first one, then they'll stay in sync.
if len(ssi.VotingMachineIds) == 0 {
// Better than a panic()?
return params.StateServersChanges{}, fmt.Errorf("internal error, failed to find any voting machines")
}
templateMachine, err := st.Machine(ssi.VotingMachineIds[0])
if err != nil {
return params.StateServersChanges{}, err
}
series = templateMachine.Series()
}
changes, err := st.EnsureAvailability(spec.NumStateServers, spec.Constraints, series, spec.Placement)
if err != nil {
return params.StateServersChanges{}, err
}
return stateServersChanges(changes), nil
}
示例2: environManagerInstances
// environManagerInstances returns all environ manager instances.
func environManagerInstances(st *state.State) ([]instance.Id, error) {
info, err := st.StateServerInfo()
if err != nil {
return nil, err
}
instances := make([]instance.Id, 0, len(info.MachineIds))
for _, id := range info.MachineIds {
machine, err := st.Machine(id)
if err != nil {
return nil, err
}
instanceId, err := machine.InstanceId()
if err == nil {
instances = append(instances, instanceId)
} else if !state.IsNotProvisionedError(err) {
return nil, err
}
}
return instances, nil
}