本文整理匯總了Golang中github.com/juju/juju/state.Application.AddUnit方法的典型用法代碼示例。如果您正苦於以下問題:Golang Application.AddUnit方法的具體用法?Golang Application.AddUnit怎麽用?Golang Application.AddUnit使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/juju/juju/state.Application
的用法示例。
在下文中一共展示了Application.AddUnit方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: addUnit
func (s *runSuite) addUnit(c *gc.C, service *state.Application) *state.Unit {
unit, err := service.AddUnit()
c.Assert(err, jc.ErrorIsNil)
err = unit.AssignToNewMachine()
c.Assert(err, jc.ErrorIsNil)
return unit
}
示例2: AddUnit
func (s *ContextSuite) AddUnit(c *gc.C, svc *state.Application) *state.Unit {
unit, err := svc.AddUnit()
c.Assert(err, jc.ErrorIsNil)
if s.machine != nil {
err = unit.AssignToMachine(s.machine)
c.Assert(err, jc.ErrorIsNil)
return unit
}
err = s.State.AssignUnit(unit, state.AssignCleanEmpty)
c.Assert(err, jc.ErrorIsNil)
machineId, err := unit.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
s.machine, err = s.State.Machine(machineId)
c.Assert(err, jc.ErrorIsNil)
zone := "a-zone"
hwc := instance.HardwareCharacteristics{
AvailabilityZone: &zone,
}
err = s.machine.SetProvisioned("i-exist", "fake_nonce", &hwc)
c.Assert(err, jc.ErrorIsNil)
name := strings.Replace(unit.Name(), "/", "-", 1)
privateAddr := network.NewScopedAddress(name+".testing.invalid", network.ScopeCloudLocal)
err = s.machine.SetProviderAddresses(privateAddr)
c.Assert(err, jc.ErrorIsNil)
return unit
}
示例3: addUnitWithVersion
func addUnitWithVersion(c *gc.C, application *state.Application, version string) *state.Unit {
unit, err := application.AddUnit()
c.Assert(err, jc.ErrorIsNil)
// Ensure that the timestamp on this version record is different
// from the previous one.
// TODO(babbageclunk): when Application and Unit have clocks, change
// that instead of sleeping (lp:1558657)
time.Sleep(time.Millisecond * 1)
err = unit.SetWorkloadVersion(version)
c.Assert(err, jc.ErrorIsNil)
return unit
}
示例4: addRU
func addRU(c *gc.C, svc *state.Application, 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, jc.ErrorIsNil)
u = unit
} else {
origUnits, err := svc.AllUnits()
c.Assert(err, jc.ErrorIsNil)
pru, err := rel.Unit(principal)
c.Assert(err, jc.ErrorIsNil)
err = pru.EnterScope(nil) // to create the subordinate
c.Assert(err, jc.ErrorIsNil)
err = pru.LeaveScope() // to reset to initial expected state
c.Assert(err, jc.ErrorIsNil)
newUnits, err := svc.AllUnits()
c.Assert(err, jc.ErrorIsNil)
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, gc.NotNil)
}
preventUnitDestroyRemove(c, u)
ru, err := rel.Unit(u)
c.Assert(err, jc.ErrorIsNil)
return u, ru
}
示例5: addUnit
func (s *HookContextSuite) addUnit(c *gc.C, svc *state.Application) *state.Unit {
unit, err := svc.AddUnit()
c.Assert(err, jc.ErrorIsNil)
if s.machine != nil {
err = unit.AssignToMachine(s.machine)
c.Assert(err, jc.ErrorIsNil)
return unit
}
err = s.State.AssignUnit(unit, state.AssignCleanEmpty)
c.Assert(err, jc.ErrorIsNil)
machineId, err := unit.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
s.machine, err = s.State.Machine(machineId)
c.Assert(err, jc.ErrorIsNil)
zone := "a-zone"
hwc := instance.HardwareCharacteristics{
AvailabilityZone: &zone,
}
err = s.machine.SetProvisioned("i-exist", "fake_nonce", &hwc)
c.Assert(err, jc.ErrorIsNil)
return unit
}