當前位置: 首頁>>代碼示例>>Golang>>正文


Golang state.RelationUnit類代碼示例

本文整理匯總了Golang中github.com/juju/juju/state.RelationUnit的典型用法代碼示例。如果您正苦於以下問題:Golang RelationUnit類的具體用法?Golang RelationUnit怎麽用?Golang RelationUnit使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了RelationUnit類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: checkRemoteUnit

func (u *UniterAPIV3) checkRemoteUnit(relUnit *state.RelationUnit, remoteUnitTag string) (string, error) {
	// Make sure the unit is indeed remote.
	if remoteUnitTag == u.auth.GetAuthTag().String() {
		return "", common.ErrPerm
	}
	// Check remoteUnit is indeed related. Note that we don't want to actually get
	// the *Unit, because it might have been removed; but its relation settings will
	// persist until the relation itself has been removed (and must remain accessible
	// because the local unit's view of reality may be time-shifted).
	tag, err := names.ParseUnitTag(remoteUnitTag)
	if err != nil {
		return "", common.ErrPerm
	}
	remoteUnitName := tag.Id()
	remoteServiceName, err := names.UnitApplication(remoteUnitName)
	if err != nil {
		return "", common.ErrPerm
	}
	rel := relUnit.Relation()
	_, err = rel.RelatedEndpoints(remoteServiceName)
	if err != nil {
		return "", common.ErrPerm
	}
	return remoteUnitName, nil
}
開發者ID:bac,項目名稱:juju,代碼行數:25,代碼來源:uniter.go

示例2: changeSettings

func changeSettings(c *gc.C, ru *state.RelationUnit) {
	node, err := ru.Settings()
	c.Assert(err, jc.ErrorIsNil)
	value, _ := node.Get("value")
	v, _ := value.(int)
	node.Set("value", v+1)
	_, err = node.Write()
	c.Assert(err, jc.ErrorIsNil)
}
開發者ID:claudiu-coblis,項目名稱:juju,代碼行數:9,代碼來源:relationunit_test.go

示例3: setSettings

func setSettings(c *gc.C, ru *state.RelationUnit, settings map[string]interface{}) {
	node, err := ru.Settings()
	c.Assert(err, gc.IsNil)
	for _, k := range node.Keys() {
		node.Delete(k)
	}
	node.Update(settings)
	_, err = node.Write()
	c.Assert(err, gc.IsNil)
}
開發者ID:jiasir,項目名稱:juju,代碼行數:10,代碼來源:util_test.go

示例4: watchOneRelationUnit

func (u *UniterAPIV3) watchOneRelationUnit(relUnit *state.RelationUnit) (params.RelationUnitsWatchResult, error) {
	watch := relUnit.Watch()
	// Consume the initial event and forward it to the result.
	if changes, ok := <-watch.Changes(); ok {
		return params.RelationUnitsWatchResult{
			RelationUnitsWatcherId: u.resources.Register(watch),
			Changes:                changes,
		}, nil
	}
	return params.RelationUnitsWatchResult{}, watcher.EnsureErr(watch)
}
開發者ID:bac,項目名稱:juju,代碼行數:11,代碼來源:uniter.go

示例5: assertInScope

func (s *uniterSuite) assertInScope(c *gc.C, relUnit *state.RelationUnit, inScope bool) {
	ok, err := relUnit.InScope()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ok, gc.Equals, inScope)
}
開發者ID:imoapps,項目名稱:juju,代碼行數:5,代碼來源:uniter_test.go

示例6: assertNotJoined

func assertNotJoined(c *gc.C, ru *state.RelationUnit) {
	ok, err := ru.Joined()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ok, jc.IsFalse)
}
開發者ID:claudiu-coblis,項目名稱:juju,代碼行數:5,代碼來源:relationunit_test.go

示例7: assertJoined

func assertJoined(c *gc.C, ru *state.RelationUnit) {
	assertInScope(c, ru)
	ok, err := ru.Joined()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ok, jc.IsTrue)
}
開發者ID:claudiu-coblis,項目名稱:juju,代碼行數:6,代碼來源:relationunit_test.go

示例8: assertInScope

func assertInScope(c *gc.C, ru *state.RelationUnit) {
	ok, err := ru.InScope()
	c.Assert(err, jc.ErrorIsNil)
	c.Assert(ok, jc.IsTrue)
}
開發者ID:claudiu-coblis,項目名稱:juju,代碼行數:5,代碼來源:relationunit_test.go

示例9: assertNotInScope

func assertNotInScope(c *gc.C, ru *state.RelationUnit) {
	assertNotJoined(c, ru)
	ok, err := ru.InScope()
	c.Assert(err, gc.IsNil)
	c.Assert(ok, jc.IsFalse)
}
開發者ID:jiasir,項目名稱:juju,代碼行數:6,代碼來源:relationunit_test.go


注:本文中的github.com/juju/juju/state.RelationUnit類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。