本文整理汇总了Golang中github.com/juju/juju/api/uniter.State.Unit方法的典型用法代码示例。如果您正苦于以下问题:Golang State.Unit方法的具体用法?Golang State.Unit怎么用?Golang State.Unit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/api/uniter.State
的用法示例。
在下文中一共展示了State.Unit方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewContextFactory
// NewContextFactory returns a ContextFactory capable of creating execution contexts backed
// by the supplied unit's supplied API connection.
func NewContextFactory(
state *uniter.State,
unitTag names.UnitTag,
tracker leadership.Tracker,
getRelationInfos RelationsFunc,
storage StorageContextAccessor,
paths Paths,
clock clock.Clock,
) (
ContextFactory, error,
) {
unit, err := state.Unit(unitTag)
if err != nil {
return nil, errors.Trace(err)
}
machineTag, err := unit.AssignedMachine()
if err != nil {
return nil, errors.Trace(err)
}
model, err := state.Model()
if err != nil {
return nil, errors.Trace(err)
}
zone, err := unit.AvailabilityZone()
if err != nil {
return nil, errors.Trace(err)
}
f := &contextFactory{
unit: unit,
state: state,
tracker: tracker,
paths: paths,
modelUUID: model.UUID(),
envName: model.Name(),
machineTag: machineTag,
getRelationInfos: getRelationInfos,
relationCaches: map[int]*RelationCache{},
storage: storage,
rand: rand.New(rand.NewSource(time.Now().Unix())),
clock: clock,
zone: zone,
}
return f, nil
}
示例2: NewFactory
// NewFactory returns a Factory capable of creating execution contexts backed
// by the supplied unit's supplied API connection.
func NewFactory(
state *uniter.State,
unitTag names.UnitTag,
tracker leadership.Tracker,
getRelationInfos RelationsFunc,
storage StorageContextAccessor,
paths Paths,
) (
Factory, error,
) {
unit, err := state.Unit(unitTag)
if err != nil {
return nil, errors.Trace(err)
}
service, err := state.Service(unit.ServiceTag())
if err != nil {
return nil, errors.Trace(err)
}
ownerTag, err := service.OwnerTag()
if err != nil {
return nil, errors.Trace(err)
}
machineTag, err := unit.AssignedMachine()
if err != nil {
return nil, errors.Trace(err)
}
environment, err := state.Environment()
if err != nil {
return nil, errors.Trace(err)
}
return &factory{
unit: unit,
state: state,
tracker: tracker,
paths: paths,
envUUID: environment.UUID(),
envName: environment.Name(),
machineTag: machineTag,
ownerTag: ownerTag,
getRelationInfos: getRelationInfos,
relationCaches: map[int]*RelationCache{},
storage: storage,
rand: rand.New(rand.NewSource(time.Now().Unix())),
}, nil
}
示例3: NewRelations
// NewRelations returns a new Relations instance.
func NewRelations(st *uniter.State, tag names.UnitTag, charmDir, relationsDir string, abort <-chan struct{}) (Relations, error) {
unit, err := st.Unit(tag)
if err != nil {
return nil, errors.Trace(err)
}
r := &relations{
st: st,
unit: unit,
charmDir: charmDir,
relationsDir: relationsDir,
relationers: make(map[int]*Relationer),
abort: abort,
}
if err := r.init(); err != nil {
return nil, errors.Trace(err)
}
return r, nil
}
示例4: newRelations
func newRelations(st *uniter.State, tag names.UnitTag, paths Paths, abort <-chan struct{}) (*relations, error) {
unit, err := st.Unit(tag)
if err != nil {
return nil, errors.Trace(err)
}
r := &relations{
st: st,
unit: unit,
charmDir: paths.State.CharmDir,
relationsDir: paths.State.RelationsDir,
relationers: make(map[int]*Relationer),
relationHooks: make(chan hook.Info),
abort: abort,
}
if err := r.init(); err != nil {
return nil, errors.Trace(err)
}
return r, nil
}