本文整理汇总了Golang中github.com/juju/juju/state.Unit.AssignedMachineId方法的典型用法代码示例。如果您正苦于以下问题:Golang Unit.AssignedMachineId方法的具体用法?Golang Unit.AssignedMachineId怎么用?Golang Unit.AssignedMachineId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/juju/state.Unit
的用法示例。
在下文中一共展示了Unit.AssignedMachineId方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: processUnit
func (context *statusContext) processUnit(unit *state.Unit, serviceCharm string) params.UnitStatus {
var result params.UnitStatus
addr, err := unit.PublicAddress()
if err != nil {
// Usually this indicates that no addresses have been set on the
// machine yet.
addr = network.Address{}
logger.Debugf("error fetching public address: %v", err)
}
result.PublicAddress = addr.Value
unitPorts, _ := unit.OpenedPorts()
for _, port := range unitPorts {
result.OpenedPorts = append(result.OpenedPorts, port.String())
}
if unit.IsPrincipal() {
result.Machine, _ = unit.AssignedMachineId()
}
curl, _ := unit.CharmURL()
if serviceCharm != "" && curl != nil && curl.String() != serviceCharm {
result.Charm = curl.String()
}
processUnitAndAgentStatus(unit, &result)
if subUnits := unit.SubordinateNames(); len(subUnits) > 0 {
result.Subordinates = make(map[string]params.UnitStatus)
for _, name := range subUnits {
subUnit := context.unitByName(name)
// subUnit may be nil if subordinate was filtered out.
if subUnit != nil {
result.Subordinates[name] = context.processUnit(subUnit, serviceCharm)
}
}
}
return result
}
示例2: 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)
}
}
}
}
示例3: assertAssignedUnit
func (s *AssignSuite) assertAssignedUnit(c *gc.C, unit *state.Unit) string {
// Get service networks.
service, err := unit.Service()
c.Assert(err, jc.ErrorIsNil)
serviceNetworks, err := service.Networks()
c.Assert(err, jc.ErrorIsNil)
serviceCons, err := service.Constraints()
c.Assert(err, jc.ErrorIsNil)
// Check the machine on the unit is set.
machineId, err := unit.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
// Check that the principal is set on the machine.
machine, err := s.State.Machine(machineId)
c.Assert(err, jc.ErrorIsNil)
machineCons, err := machine.Constraints()
c.Assert(err, jc.ErrorIsNil)
machineNetworks, err := machine.RequestedNetworks()
c.Assert(err, jc.ErrorIsNil)
c.Assert(machineNetworks, gc.DeepEquals, serviceNetworks)
c.Assert(serviceCons.IncludeNetworks(), gc.DeepEquals, machineCons.IncludeNetworks())
c.Assert(serviceCons.ExcludeNetworks(), gc.DeepEquals, machineCons.ExcludeNetworks())
machineUnits, err := machine.Units()
c.Assert(err, jc.ErrorIsNil)
c.Assert(machineUnits, gc.HasLen, 1)
// Make sure it is the right unit.
c.Assert(machineUnits[0].Name(), gc.Equals, unit.Name())
return machineId
}
示例4: processUnit
func (context *statusContext) processUnit(unit *state.Unit, serviceCharm string) api.UnitStatus {
var result api.UnitStatus
result.PublicAddress, _ = unit.PublicAddress()
unitPorts, _ := unit.OpenedPorts()
for _, port := range unitPorts {
result.OpenedPorts = append(result.OpenedPorts, port.String())
}
if unit.IsPrincipal() {
result.Machine, _ = unit.AssignedMachineId()
}
curl, _ := unit.CharmURL()
if serviceCharm != "" && curl != nil && curl.String() != serviceCharm {
result.Charm = curl.String()
}
processUnitAndAgentStatus(unit, &result)
if subUnits := unit.SubordinateNames(); len(subUnits) > 0 {
result.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 {
result.Subordinates[name] = context.processUnit(subUnit, serviceCharm)
}
}
}
return result
}
示例5: getMachineForUnit
func (s *SSHCommonSuite) getMachineForUnit(c *gc.C, u *state.Unit) *state.Machine {
machineId, err := u.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
m, err := s.State.Machine(machineId)
c.Assert(err, jc.ErrorIsNil)
return m
}
示例6: assertAssignedUnit
func (s *DeployLocalSuite) assertAssignedUnit(c *gc.C, u *state.Unit, mId string, cons constraints.Value) {
id, err := u.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
machine, err := s.State.Machine(id)
c.Assert(err, jc.ErrorIsNil)
machineCons, err := machine.Constraints()
c.Assert(err, jc.ErrorIsNil)
c.Assert(machineCons, gc.DeepEquals, cons)
}
示例7: assertAssignedMachineRequestedNetworks
func (s *ConnSuite) assertAssignedMachineRequestedNetworks(c *gc.C, unit *state.Unit, includeNets, excludeNets []string) {
machineId, err := unit.AssignedMachineId()
c.Assert(err, gc.IsNil)
machine, err := s.conn.State.Machine(machineId)
c.Assert(err, gc.IsNil)
networks, err := machine.RequestedNetworks()
c.Assert(err, gc.IsNil)
c.Assert(networks, jc.DeepEquals, includeNets)
cons, err := machine.Constraints()
c.Assert(err, gc.IsNil)
c.Assert(cons.ExcludeNetworks(), jc.DeepEquals, excludeNets)
}
示例8: assertAssignedUnit
func (s *AssignSuite) assertAssignedUnit(c *gc.C, unit *state.Unit) string {
// Check the machine on the unit is set.
machineId, err := unit.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
// Check that the principal is set on the machine.
machine, err := s.State.Machine(machineId)
c.Assert(err, jc.ErrorIsNil)
machineUnits, err := machine.Units()
c.Assert(err, jc.ErrorIsNil)
c.Assert(machineUnits, gc.HasLen, 1)
// Make sure it is the right unit.
c.Assert(machineUnits[0].Name(), gc.Equals, unit.Name())
return machineId
}
示例9: assignUnit
func (s *storageAddSuite) assignUnit(c *gc.C, u *state.Unit) {
// Assign unit to machine to get volumes and filesystems
err := s.State.AssignUnit(u, state.AssignCleanEmpty)
c.Assert(err, jc.ErrorIsNil)
machineId, err := u.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
m, err := s.State.Machine(machineId)
c.Assert(err, jc.ErrorIsNil)
s.machineTag = m.MachineTag()
volumes, err := s.State.AllVolumes()
c.Assert(err, jc.ErrorIsNil)
s.originalVolumeCount = len(volumes)
filesystems, err := s.State.MachineFilesystemAttachments(s.machineTag)
c.Assert(err, jc.ErrorIsNil)
s.originalFilesystemCount = len(filesystems)
}
示例10: setAssignedMachineAddresses
func (s *UnitSuite) setAssignedMachineAddresses(c *gc.C, u *state.Unit) {
err := u.AssignToNewMachine()
c.Assert(err, jc.ErrorIsNil)
mid, err := u.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
machine, err := s.State.Machine(mid)
c.Assert(err, jc.ErrorIsNil)
err = machine.SetProvisioned("i-exist", "fake_nonce", nil)
c.Assert(err, jc.ErrorIsNil)
err = machine.SetProviderAddresses(network.Address{
Type: network.IPv4Address,
Scope: network.ScopeCloudLocal,
Value: "private.address.example.com",
}, network.Address{
Type: network.IPv4Address,
Scope: network.ScopePublic,
Value: "public.address.example.com",
})
c.Assert(err, jc.ErrorIsNil)
}
示例11: 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.NewMachineTag(machineId).String()
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例12: assertMachineVolume
func (s *VolumeStateSuite) assertMachineVolume(c *gc.C, unit *state.Unit) {
assignedMachineId, err := unit.AssignedMachineId()
c.Assert(err, jc.ErrorIsNil)
storageAttachments, err := s.State.UnitStorageAttachments(unit.UnitTag())
c.Assert(err, jc.ErrorIsNil)
c.Assert(storageAttachments, gc.HasLen, 1)
storageInstance, err := s.State.StorageInstance(storageAttachments[0].StorageInstance())
c.Assert(err, jc.ErrorIsNil)
volume := s.storageInstanceVolume(c, storageInstance.StorageTag())
c.Assert(volume.VolumeTag(), gc.Equals, names.NewVolumeTag("0/0"))
volumeStorageTag, err := volume.StorageInstance()
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumeStorageTag, gc.Equals, storageInstance.StorageTag())
_, err = volume.Info()
c.Assert(err, jc.Satisfies, errors.IsNotProvisioned)
_, ok := volume.Params()
c.Assert(ok, jc.IsTrue)
machine, err := s.State.Machine(assignedMachineId)
c.Assert(err, jc.ErrorIsNil)
volumeAttachments, err := s.State.MachineVolumeAttachments(machine.MachineTag())
c.Assert(err, jc.ErrorIsNil)
c.Assert(volumeAttachments, gc.HasLen, 1)
c.Assert(volumeAttachments[0].Volume(), gc.Equals, volume.VolumeTag())
c.Assert(volumeAttachments[0].Machine(), gc.Equals, machine.MachineTag())
_, err = volumeAttachments[0].Info()
c.Assert(err, jc.Satisfies, errors.IsNotProvisioned)
_, ok = volumeAttachments[0].Params()
c.Assert(ok, jc.IsTrue)
_, err = s.State.VolumeAttachment(machine.MachineTag(), volume.VolumeTag())
c.Assert(err, jc.ErrorIsNil)
assertMachineStorageRefs(c, s.State, machine.MachineTag())
}
示例13: newUniterBaseAPI
// newUniterBaseAPI creates a new instance of the uniter base API.
func newUniterBaseAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*uniterBaseAPI, error) {
if !authorizer.AuthUnitAgent() {
return nil, common.ErrPerm
}
var unit *state.Unit
var err error
switch tag := authorizer.GetAuthTag().(type) {
case names.UnitTag:
unit, err = st.Unit(tag.Id())
if err != nil {
return nil, errors.Trace(err)
}
default:
return nil, errors.Errorf("expected names.UnitTag, got %T", tag)
}
accessUnit := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
accessService := func() (common.AuthFunc, error) {
switch tag := authorizer.GetAuthTag().(type) {
case names.UnitTag:
entity, err := st.Unit(tag.Id())
if err != nil {
return nil, errors.Trace(err)
}
serviceName := entity.ServiceName()
serviceTag := names.NewServiceTag(serviceName)
return func(tag names.Tag) bool {
return tag == serviceTag
}, nil
default:
return nil, errors.Errorf("expected names.UnitTag, got %T", tag)
}
}
accessMachine := func() (common.AuthFunc, error) {
machineId, err := unit.AssignedMachineId()
if err != nil {
return nil, errors.Trace(err)
}
machine, err := st.Machine(machineId)
if err != nil {
return nil, errors.Trace(err)
}
return func(tag names.Tag) bool {
return tag == machine.Tag()
}, nil
}
msAPI, err := meterstatus.NewMeterStatusAPI(st, resources, authorizer)
if err != nil {
return nil, errors.Annotate(err, "could not create meter status API handler")
}
accessUnitOrService := common.AuthEither(accessUnit, accessService)
return &uniterBaseAPI{
LifeGetter: common.NewLifeGetter(st, accessUnitOrService),
DeadEnsurer: common.NewDeadEnsurer(st, accessUnit),
AgentEntityWatcher: common.NewAgentEntityWatcher(st, resources, accessUnitOrService),
APIAddresser: common.NewAPIAddresser(st, resources),
EnvironWatcher: common.NewEnvironWatcher(st, resources, authorizer),
RebootRequester: common.NewRebootRequester(st, accessMachine),
LeadershipSettingsAccessor: leadershipSettingsAccessorFactory(st, resources, authorizer),
MeterStatus: msAPI,
// TODO(fwereade): so *every* unit should be allowed to get/set its
// own status *and* its service's? This is not a pleasing arrangement.
StatusAPI: NewStatusAPI(st, accessUnitOrService),
st: st,
auth: authorizer,
resources: resources,
accessUnit: accessUnit,
accessService: accessService,
unit: unit,
}, nil
}
示例14: newUniterBaseAPI
// newUniterBaseAPI creates a new instance of the uniter base API.
func newUniterBaseAPI(st *state.State, resources *common.Resources, authorizer common.Authorizer) (*uniterBaseAPI, error) {
if !authorizer.AuthUnitAgent() {
return nil, common.ErrPerm
}
var unit *state.Unit
var err error
switch tag := authorizer.GetAuthTag().(type) {
case names.UnitTag:
unit, err = st.Unit(tag.Id())
if err != nil {
return nil, errors.Trace(err)
}
default:
return nil, errors.Errorf("expected names.UnitTag, got %T", tag)
}
accessUnit := func() (common.AuthFunc, error) {
return authorizer.AuthOwner, nil
}
accessService := func() (common.AuthFunc, error) {
switch tag := authorizer.GetAuthTag().(type) {
case names.UnitTag:
entity, err := st.Unit(tag.Id())
if err != nil {
return nil, errors.Trace(err)
}
serviceName := entity.ServiceName()
serviceTag := names.NewServiceTag(serviceName)
return func(tag names.Tag) bool {
return tag == serviceTag
}, nil
default:
return nil, errors.Errorf("expected names.UnitTag, got %T", tag)
}
}
accessMachine := func() (common.AuthFunc, error) {
machineId, err := unit.AssignedMachineId()
if err != nil {
return nil, errors.Trace(err)
}
machine, err := st.Machine(machineId)
if err != nil {
return nil, errors.Trace(err)
}
return func(tag names.Tag) bool {
return tag == machine.Tag()
}, nil
}
accessUnitOrService := common.AuthEither(accessUnit, accessService)
return &uniterBaseAPI{
LifeGetter: common.NewLifeGetter(st, accessUnitOrService),
StatusAPI: NewStatusAPI(st, accessUnitOrService),
DeadEnsurer: common.NewDeadEnsurer(st, accessUnit),
AgentEntityWatcher: common.NewAgentEntityWatcher(st, resources, accessUnitOrService),
APIAddresser: common.NewAPIAddresser(st, resources),
EnvironWatcher: common.NewEnvironWatcher(st, resources, authorizer),
RebootRequester: common.NewRebootRequester(st, accessMachine),
LeadershipSettingsAccessor: leadershipSettingsAccessorFactory(st, resources, authorizer),
st: st,
auth: authorizer,
resources: resources,
accessUnit: accessUnit,
accessService: accessService,
unit: unit,
}, nil
}