当前位置: 首页>>代码示例>>Golang>>正文


Golang State.Unit方法代码示例

本文整理汇总了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
}
开发者ID:AlexisBruemmer,项目名称:juju,代码行数:47,代码来源:contextfactory.go

示例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
}
开发者ID:claudiu-coblis,项目名称:juju,代码行数:47,代码来源:factory.go

示例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
}
开发者ID:pmatulis,项目名称:juju,代码行数:19,代码来源:relations.go

示例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
}
开发者ID:Pankov404,项目名称:juju,代码行数:19,代码来源:relations.go


注:本文中的github.com/juju/juju/api/uniter.State.Unit方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。