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


Golang state.State类代码示例

本文整理汇总了Golang中launchpad/net/juju-core/state.State的典型用法代码示例。如果您正苦于以下问题:Golang State类的具体用法?Golang State怎么用?Golang State使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了State类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: fetchMachines

// fetchMachines returns a map from top level machine id to machines, where machines[0] is the host
// machine and machines[1..n] are any containers (including nested ones).
//
// If machineIds is non-nil, only machines whose IDs are in the set are returned.
func fetchMachines(st *state.State, machineIds *set.Strings) (map[string][]*state.Machine, error) {
	v := make(map[string][]*state.Machine)
	machines, err := st.AllMachines()
	if err != nil {
		return nil, err
	}
	// AllMachines gives us machines sorted by id.
	for _, m := range machines {
		if machineIds != nil && !machineIds.Contains(m.Id()) {
			continue
		}
		parentId, ok := m.ParentId()
		if !ok {
			// Only top level host machines go directly into the machine map.
			v[m.Id()] = []*state.Machine{m}
		} else {
			topParentId := state.TopParentId(m.Id())
			machines, ok := v[topParentId]
			if !ok {
				panic(fmt.Errorf("unexpected machine id %q", parentId))
			}
			machines = append(machines, m)
			v[topParentId] = machines
		}
	}
	return v, nil
}
开发者ID:hivetech,项目名称:judo.legacy,代码行数:31,代码来源:status.go

示例2: fetchAllServicesAndUnits

// fetchAllServicesAndUnits returns a map from service name to service
// and a map from service name to unit name to unit.
func fetchAllServicesAndUnits(st *state.State, unitMatcher unitMatcher) (map[string]*state.Service, map[string]map[string]*state.Unit, error) {
	svcMap := make(map[string]*state.Service)
	unitMap := make(map[string]map[string]*state.Unit)
	services, err := st.AllServices()
	if err != nil {
		return nil, nil, err
	}
	for _, s := range services {
		units, err := s.AllUnits()
		if err != nil {
			return nil, nil, err
		}
		svcUnitMap := make(map[string]*state.Unit)
		for _, u := range units {
			if !unitMatcher.matchUnit(u) {
				continue
			}
			svcUnitMap[u.Name()] = u
		}
		if unitMatcher.matchesAny() || len(svcUnitMap) > 0 {
			unitMap[s.Name()] = svcUnitMap
			svcMap[s.Name()] = s
		}
	}
	return svcMap, unitMap, nil
}
开发者ID:hivetech,项目名称:judo.legacy,代码行数:28,代码来源:status.go

示例3: waitForUnitStarted

func waitForUnitStarted(stateConn *state.State, unit *state.Unit, c *C) {
	timeout := time.After(5 * time.Second)

	for {
		select {
		case <-timeout:
			c.Fatalf("no activity detected")
		case <-time.After(testing.ShortWait):
			err := unit.Refresh()
			c.Assert(err, IsNil)
			st, info, err := unit.Status()
			c.Assert(err, IsNil)
			switch st {
			case params.StatusPending, params.StatusInstalled:
				c.Logf("waiting...")
				continue
			case params.StatusStarted:
				c.Logf("started!")
				return
			case params.StatusDown:
				stateConn.StartSync()
				c.Logf("unit is still down")
			default:
				c.Fatalf("unexpected status %s %s", st, info)
			}
		}
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:28,代码来源:unit_test.go

示例4: SetServiceConstraints

// SetServiceContstraints sets the constraints for a given service
func SetServiceConstraints(st *state.State, args params.SetServiceConstraints) error {
	svc, err := st.Service(args.ServiceName)
	if err != nil {
		return err
	}
	return svc.SetConstraints(args.Constraints)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:8,代码来源:setconstraints.go

示例5: ServiceGet

// ServiceGet returns the configuration for the named service.
func ServiceGet(st *state.State, p params.ServiceGet) (params.ServiceGetResults, error) {
	service, err := st.Service(p.ServiceName)
	if err != nil {
		return params.ServiceGetResults{}, err
	}
	settings, err := service.ConfigSettings()
	if err != nil {
		return params.ServiceGetResults{}, err
	}
	charm, _, err := service.Charm()
	if err != nil {
		return params.ServiceGetResults{}, err
	}
	configInfo := describe(settings, charm.Config())
	var constraints constraints.Value
	if service.IsPrincipal() {
		constraints, err = service.Constraints()
		if err != nil {
			return params.ServiceGetResults{}, err
		}
	}
	return params.ServiceGetResults{
		Service:     p.ServiceName,
		Charm:       charm.Meta().Name,
		Config:      configInfo,
		Constraints: constraints,
	}, nil
}
开发者ID:rif,项目名称:golang-stuff,代码行数:29,代码来源:get.go

示例6: GetServiceConstraints

// GetServiceConstraints returns the constraints for a given service
func GetServiceConstraints(st *state.State, args params.GetServiceConstraints) (params.GetServiceConstraintsResults, error) {
	svc, err := st.Service(args.ServiceName)
	if err != nil {
		return params.GetServiceConstraintsResults{constraints.Value{}}, err
	}
	constraints, err := svc.Constraints()
	return params.GetServiceConstraintsResults{constraints}, err
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:9,代码来源:getconstraints.go

示例7: breakDummyProvider

// breakDummyProvider changes the environment config in state in a way
// that causes the given environMethod of the dummy provider to return
// an error, which is also returned as a message to be checked.
func breakDummyProvider(c *C, st *state.State, environMethod string) string {
	oldCfg, err := st.EnvironConfig()
	c.Assert(err, IsNil)
	cfg, err := oldCfg.Apply(map[string]interface{}{"broken": environMethod})
	c.Assert(err, IsNil)
	err = st.SetEnvironConfig(cfg)
	c.Assert(err, IsNil)
	return fmt.Sprintf("dummy.%s is broken", environMethod)
}
开发者ID:rayleyva,项目名称:gosf,代码行数:12,代码来源:provisioner_test.go

示例8: newDeployer

func newDeployer(st *state.State, w *state.UnitsWatcher, dataDir string) *deployer.Deployer {
	info := &state.Info{
		EntityName: w.EntityName(),
		Addrs:      st.Addrs(),
		CACert:     st.CACert(),
	}
	mgr := newDeployManager(st, info, dataDir)
	return deployer.NewDeployer(st, mgr, w)
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:9,代码来源:agent.go

示例9: isRemoved

func isRemoved(st *state.State, name string) func(*C) bool {
	return func(c *C) bool {
		_, err := st.Unit(name)
		if errors.IsNotFoundError(err) {
			return true
		}
		c.Assert(err, IsNil)
		return false
	}
}
开发者ID:rif,项目名称:golang-stuff,代码行数:10,代码来源:deployer_test.go

示例10: SetAgentVersion

// SetAgentVersion sets the current agent version in the state's
// environment configuration.
func SetAgentVersion(st *state.State, vers version.Number) error {
	cfg, err := st.EnvironConfig()
	if err != nil {
		return err
	}
	cfg, err = cfg.Apply(map[string]interface{}{"agent-version": vers.String()})
	if err != nil {
		return err
	}
	return st.SetEnvironConfig(cfg)
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:13,代码来源:agent.go

示例11: opClientServiceExpose

func opClientServiceExpose(c *C, st *api.State, mst *state.State) (func(), error) {
	err := st.Client().ServiceExpose("wordpress")
	if err != nil {
		return func() {}, err
	}
	return func() {
		svc, err := mst.Service("wordpress")
		c.Assert(err, IsNil)
		svc.ClearExposed()
	}, nil
}
开发者ID:johnvilsack,项目名称:golang-stuff,代码行数:11,代码来源:perm_test.go

示例12: fetchAllMachines

// fetchAllMachines returns a map[string]*state.Machine representing
// a mapping of machine ids to machines.
func fetchAllMachines(st *state.State) (map[string]*state.Machine, error) {
	v := make(map[string]*state.Machine)
	machines, err := st.AllMachines()
	if err != nil {
		return nil, err
	}
	for _, m := range machines {
		v[m.Id()] = m
	}
	return v, nil
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:13,代码来源:status.go

示例13: DestroyRelation

// DestroyRelation removes the relation between the specified endpoints.
func DestroyRelation(state *state.State, args params.DestroyRelation) error {
	eps, err := state.InferEndpoints(args.Endpoints)
	if err != nil {
		return err
	}
	rel, err := state.EndpointsRelation(eps...)
	if err != nil {
		return err
	}
	return rel.Destroy()
}
开发者ID:rif,项目名称:golang-stuff,代码行数:12,代码来源:destroyrelation.go

示例14: fetchAllServices

// fetchAllServices returns a map representing a mapping of service
// names to services.
func fetchAllServices(st *state.State) (map[string]*state.Service, error) {
	v := make(map[string]*state.Service)
	services, err := st.AllServices()
	if err != nil {
		return nil, err
	}
	for _, s := range services {
		v[s.Name()] = s
	}
	return v, nil
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:13,代码来源:status.go

示例15: setAgentVersion

// setAgentVersion sets the current agent version in the state's
// environment configuration.
func setAgentVersion(st *state.State, vers version.Number) error {
	cfg, err := st.EnvironConfig()
	if err != nil {
		return err
	}
	attrs := cfg.AllAttrs()
	attrs["agent-version"] = vers.String()
	cfg, err = config.New(attrs)
	if err != nil {
		panic(fmt.Errorf("config refused agent-version: %v", err))
	}
	return st.SetEnvironConfig(cfg)
}
开发者ID:prabhakhar,项目名称:juju-core,代码行数:15,代码来源:livetests.go


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