本文整理汇总了Golang中github.com/wallyworld/core/state.Unit.AssignedMachineId方法的典型用法代码示例。如果您正苦于以下问题:Golang Unit.AssignedMachineId方法的具体用法?Golang Unit.AssignedMachineId怎么用?Golang Unit.AssignedMachineId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/wallyworld/core/state.Unit
的用法示例。
在下文中一共展示了Unit.AssignedMachineId方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: waitProvisioned
func (s *MachineSuite) waitProvisioned(c *gc.C, unit *state.Unit) (*state.Machine, instance.Id) {
c.Logf("waiting for unit %q to be provisioned", unit)
machineId, err := unit.AssignedMachineId()
c.Assert(err, gc.IsNil)
m, err := s.State.Machine(machineId)
c.Assert(err, gc.IsNil)
w := m.Watch()
defer w.Stop()
timeout := time.After(coretesting.LongWait)
for {
select {
case <-timeout:
c.Fatalf("timed out waiting for provisioning")
case _, ok := <-w.Changes():
c.Assert(ok, jc.IsTrue)
err := m.Refresh()
c.Assert(err, gc.IsNil)
if instId, err := m.InstanceId(); err == nil {
c.Logf("unit provisioned with instance %s", instId)
return m, instId
} else {
c.Check(err, jc.Satisfies, state.IsNotProvisionedError)
}
}
}
panic("watcher died")
}
示例2: processUnit
func (context *statusContext) processUnit(unit *state.Unit, serviceCharm string) (status api.UnitStatus) {
status.PublicAddress, _ = unit.PublicAddress()
for _, port := range unit.OpenedPorts() {
status.OpenedPorts = append(status.OpenedPorts, port.String())
}
if unit.IsPrincipal() {
status.Machine, _ = unit.AssignedMachineId()
}
curl, _ := unit.CharmURL()
if serviceCharm != "" && curl != nil && curl.String() != serviceCharm {
status.Charm = curl.String()
}
status.Life,
status.AgentVersion,
status.AgentState,
status.AgentStateInfo,
status.Err = processAgent(unit)
if subUnits := unit.SubordinateNames(); len(subUnits) > 0 {
status.Subordinates = make(map[string]api.UnitStatus)
for _, name := range subUnits {
subUnit := context.unitByName(name)
// subUnit may be nil if subordinate was filtered out.
if subUnit != nil {
status.Subordinates[name] = context.processUnit(subUnit, serviceCharm)
}
}
}
return
}
示例3: assertAssignedMachineRequestedNetworks
func (s *ConnSuite) assertAssignedMachineRequestedNetworks(c *gc.C, unit *state.Unit, expectInclude, expectExclude []string) {
machineId, err := unit.AssignedMachineId()
c.Assert(err, gc.IsNil)
machine, err := s.conn.State.Machine(machineId)
c.Assert(err, gc.IsNil)
include, exclude, err := machine.RequestedNetworks()
c.Assert(err, gc.IsNil)
c.Assert(include, jc.DeepEquals, expectInclude)
c.Assert(exclude, jc.DeepEquals, expectExclude)
}
示例4: setAssignedMachineAddresses
func (s *UnitSuite) setAssignedMachineAddresses(c *gc.C, u *state.Unit) {
err := u.AssignToNewMachine()
c.Assert(err, gc.IsNil)
mid, err := u.AssignedMachineId()
c.Assert(err, gc.IsNil)
machine, err := s.State.Machine(mid)
c.Assert(err, gc.IsNil)
err = machine.SetProvisioned("i-exist", "fake_nonce", nil)
c.Assert(err, gc.IsNil)
err = machine.SetAddresses(instance.Address{
Type: instance.Ipv4Address,
NetworkScope: instance.NetworkCloudLocal,
Value: "private.address.example.com",
}, instance.Address{
Type: instance.Ipv4Address,
NetworkScope: instance.NetworkPublic,
Value: "public.address.example.com",
})
c.Assert(err, gc.IsNil)
}
示例5: GetAssignedMachine
// GetAssignedMachine returns the assigned machine tag (if any) for
// each given unit.
func (f *FirewallerAPI) GetAssignedMachine(args params.Entities) (params.StringResults, error) {
result := params.StringResults{
Results: make([]params.StringResult, len(args.Entities)),
}
canAccess, err := f.accessUnit()
if err != nil {
return params.StringResults{}, err
}
for i, entity := range args.Entities {
var unit *state.Unit
unit, err = f.getUnit(canAccess, entity.Tag)
if err == nil {
var machineId string
machineId, err = unit.AssignedMachineId()
if err == nil {
result.Results[i].Result = names.MachineTag(machineId)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例6: assertAssignedUnit
func (s *AssignSuite) assertAssignedUnit(c *gc.C, unit *state.Unit) string {
// Get service networks.
service, err := unit.Service()
c.Assert(err, gc.IsNil)
includeNetworks, excludeNetworks, err := service.Networks()
c.Assert(err, gc.IsNil)
// Check the machine on the unit is set.
machineId, err := unit.AssignedMachineId()
c.Assert(err, gc.IsNil)
// Check that the principal is set on the machine.
machine, err := s.State.Machine(machineId)
c.Assert(err, gc.IsNil)
include, exclude, err := machine.RequestedNetworks()
c.Assert(err, gc.IsNil)
c.Assert(include, gc.DeepEquals, includeNetworks)
c.Assert(exclude, gc.DeepEquals, excludeNetworks)
machineUnits, err := machine.Units()
c.Assert(err, gc.IsNil)
c.Assert(machineUnits, gc.HasLen, 1)
// Make sure it is the right unit.
c.Assert(machineUnits[0].Name(), gc.Equals, unit.Name())
return machineId
}