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


Golang Service.AddUnit方法代碼示例

本文整理匯總了Golang中launchpad/net/juju-core/state.Service.AddUnit方法的典型用法代碼示例。如果您正苦於以下問題:Golang Service.AddUnit方法的具體用法?Golang Service.AddUnit怎麽用?Golang Service.AddUnit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在launchpad/net/juju-core/state.Service的用法示例。


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

示例1: AddUnit

func (s *HookContextSuite) AddUnit(c *C, svc *state.Service) *state.Unit {
	unit, err := svc.AddUnit()
	c.Assert(err, IsNil)
	name := strings.Replace(unit.Name(), "/", "-", 1)
	err = unit.SetPrivateAddress(name + ".testing.invalid")
	c.Assert(err, IsNil)
	return unit
}
開發者ID:johnvilsack,項目名稱:golang-stuff,代碼行數:8,代碼來源:context_test.go

示例2: addUnit

func (s *SSHCommonSuite) addUnit(srv *state.Service, m *state.Machine, c *C) {
	u, err := srv.AddUnit()
	c.Assert(err, IsNil)
	err = u.AssignToMachine(m)
	c.Assert(err, IsNil)
	// fudge unit.SetPublicAddress
	id, err := m.InstanceId()
	c.Assert(err, IsNil)
	insts, err := s.Conn.Environ.Instances([]state.InstanceId{id})
	c.Assert(err, IsNil)
	addr, err := insts[0].WaitDNSName()
	c.Assert(err, IsNil)
	err = u.SetPublicAddress(addr)
	c.Assert(err, IsNil)
}
開發者ID:prabhakhar,項目名稱:juju-core,代碼行數:15,代碼來源:ssh_test.go

示例3: AddUnits

// AddUnits starts n units of the given service and allocates machines
// to them as necessary.
func (conn *Conn) AddUnits(svc *state.Service, n int) ([]*state.Unit, error) {
	units := make([]*state.Unit, n)
	// TODO what do we do if we fail half-way through this process?
	for i := 0; i < n; i++ {
		policy := conn.Environ.AssignmentPolicy()
		unit, err := svc.AddUnit()
		if err != nil {
			return nil, fmt.Errorf("cannot add unit %d/%d to service %q: %v", i+1, n, svc.Name(), err)
		}
		if err := conn.State.AssignUnit(unit, policy); err != nil {
			return nil, err
		}
		units[i] = unit
	}
	return units, nil
}
開發者ID:prabhakhar,項目名稱:juju-core,代碼行數:18,代碼來源:conn.go

示例4: addRU

func addRU(c *C, svc *state.Service, rel *state.Relation, principal *state.Unit) (*state.Unit, *state.RelationUnit) {
	// Given the service svc in the relation rel, add a unit of svc and create
	// a RelationUnit with rel. If principal is supplied, svc is assumed to be
	// subordinate and the unit will be created by temporarily entering the
	// relation's scope as the principal.
	var u *state.Unit
	if principal == nil {
		unit, err := svc.AddUnit()
		c.Assert(err, IsNil)
		u = unit
	} else {
		origUnits, err := svc.AllUnits()
		c.Assert(err, IsNil)
		pru, err := rel.Unit(principal)
		c.Assert(err, IsNil)
		err = pru.EnterScope(nil) // to create the subordinate
		c.Assert(err, IsNil)
		err = pru.LeaveScope() // to reset to initial expected state
		c.Assert(err, IsNil)
		newUnits, err := svc.AllUnits()
		c.Assert(err, IsNil)
		for _, unit := range newUnits {
			found := false
			for _, old := range origUnits {
				if unit.Name() == old.Name() {
					found = true
					break
				}
			}
			if !found {
				u = unit
				break
			}
		}
		c.Assert(u, NotNil)
	}
	preventUnitDestroyRemove(c, u)
	ru, err := rel.Unit(u)
	c.Assert(err, IsNil)
	return u, ru
}
開發者ID:rif,項目名稱:golang-stuff,代碼行數:41,代碼來源:relationunit_test.go

示例5: AddUnits

// AddUnits starts n units of the given service and allocates machines
// to them as necessary.
func (conn *Conn) AddUnits(svc *state.Service, n int, machineIdSpec string) ([]*state.Unit, error) {
	units := make([]*state.Unit, n)
	// Hard code for now till we implement a different approach.
	policy := state.AssignCleanEmpty
	// TODO what do we do if we fail half-way through this process?
	for i := 0; i < n; i++ {
		unit, err := svc.AddUnit()
		if err != nil {
			return nil, fmt.Errorf("cannot add unit %d/%d to service %q: %v", i+1, n, svc.Name(), err)
		}
		if machineIdSpec != "" {
			if n != 1 {
				return nil, fmt.Errorf("cannot add multiple units of service %q to a single machine", svc.Name())
			}
			// machineIdSpec may be an existing machine or container, eg 3/lxc/2
			// or a new container on a machine, eg lxc:3
			mid := machineIdSpec
			var containerType instance.ContainerType
			specParts := strings.Split(machineIdSpec, ":")
			if len(specParts) > 1 {
				firstPart := specParts[0]
				var err error
				if containerType, err = instance.ParseSupportedContainerType(firstPart); err == nil {
					mid = strings.Join(specParts[1:], "/")
				} else {
					mid = machineIdSpec
				}
			}
			if !names.IsMachine(mid) {
				return nil, fmt.Errorf("invalid force machine id %q", mid)
			}

			var err error
			var m *state.Machine
			// If a container is to be used, create it.
			if containerType != "" {
				params := state.AddMachineParams{
					Series:        unit.Series(),
					ParentId:      mid,
					ContainerType: containerType,
					Jobs:          []state.MachineJob{state.JobHostUnits},
				}
				m, err = conn.State.AddMachineWithConstraints(&params)

			} else {
				m, err = conn.State.Machine(mid)
			}
			if err != nil {
				return nil, fmt.Errorf("cannot assign unit %q to machine: %v", unit.Name(), err)
			}
			err = unit.AssignToMachine(m)

			if err != nil {
				return nil, err
			}
		} else if err := conn.State.AssignUnit(unit, policy); err != nil {
			return nil, err
		}
		units[i] = unit
	}
	return units, nil
}
開發者ID:hivetech,項目名稱:judo.legacy,代碼行數:64,代碼來源:conn.go


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