本文整理汇总了Golang中github.com/wallyworld/core/state.State.Unit方法的典型用法代码示例。如果您正苦于以下问题:Golang State.Unit方法的具体用法?Golang State.Unit怎么用?Golang State.Unit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/state.State
的用法示例。
在下文中一共展示了State.Unit方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getAllUnitNames
// getAllUnitNames returns a sequence of valid Unit objects from state. If any
// of the service names or unit names are not found, an error is returned.
func getAllUnitNames(st *state.State, units, services []string) (result []*state.Unit, err error) {
unitsSet := set.NewStrings(units...)
for _, name := range services {
service, err := st.Service(name)
if err != nil {
return nil, err
}
units, err := service.AllUnits()
if err != nil {
return nil, err
}
for _, unit := range units {
unitsSet.Add(unit.Name())
}
}
for _, unitName := range unitsSet.Values() {
unit, err := st.Unit(unitName)
if err != nil {
return nil, err
}
// We only operate on principal units, and only thise that have an
// assigned machines.
if unit.IsPrincipal() {
if _, err := unit.AssignedMachineId(); err != nil {
return nil, err
}
} else {
return nil, fmt.Errorf("%s is not a principal unit", unit)
}
result = append(result, unit)
}
return result, nil
}
示例2: isRemoved
func isRemoved(st *state.State, name string) func(*gc.C) bool {
return func(c *gc.C) bool {
_, err := st.Unit(name)
if errors.IsNotFound(err) {
return true
}
c.Assert(err, gc.IsNil)
return false
}
}