本文整理汇总了Golang中github.com/juju/names.Tag.Id方法的典型用法代码示例。如果您正苦于以下问题:Golang Tag.Id方法的具体用法?Golang Tag.Id怎么用?Golang Tag.Id使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/juju/names.Tag
的用法示例。
在下文中一共展示了Tag.Id方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: parseTag
// parseTag, given an entity tag, returns the collection name and id
// of the entity document.
func (st *State) parseTag(tag names.Tag) (string, string, error) {
if tag == nil {
return "", "", errors.Errorf("tag is nil")
}
coll := ""
id := tag.Id()
switch tag := tag.(type) {
case names.MachineTag:
coll = st.machines.Name
case names.ServiceTag:
coll = st.services.Name
case names.UnitTag:
coll = st.units.Name
case names.UserTag:
coll = st.users.Name
case names.RelationTag:
coll = st.relations.Name
case names.EnvironTag:
coll = st.environments.Name
case names.NetworkTag:
coll = st.networks.Name
case names.ActionTag:
coll = st.actions.Name
id = actionIdFromTag(tag)
default:
return "", "", fmt.Errorf("%q is not a valid collection tag", tag)
}
return coll, id, nil
}
示例2: getAllUnits
// getAllUnits returns a list of all principal and subordinate units
// assigned to the given machine.
func getAllUnits(st *state.State, tag names.Tag) ([]string, error) {
machine, err := st.Machine(tag.Id())
if err != nil {
return nil, err
}
// Start a watcher on machine's units, read the initial event and stop it.
watch := machine.WatchUnits()
defer watch.Stop()
if units, ok := <-watch.Changes(); ok {
return units, nil
}
return nil, fmt.Errorf("cannot obtain units of machine %q: %v", tag, watch.Err())
}
示例3: testSetGetEntitiesAnnotations
func (s *annotationSuite) testSetGetEntitiesAnnotations(c *gc.C, tag names.Tag) {
entity := tag.String()
entities := []string{entity}
for i, t := range clientAnnotationsTests {
c.Logf("test %d. %s. entity %s", i, t.about, tag.Id())
s.setupEntity(c, entities, t.initial)
s.assertSetEntityAnnotations(c, entities, t.input, t.err)
if t.err != "" {
continue
}
aResult := s.assertGetEntityAnnotations(c, params.Entities{[]params.Entity{{entity}}}, entity, t.expected)
s.cleanupEntityAnnotations(c, entities, aResult)
}
}
示例4: matchingActionsByReceiverAndStatus
// matchingActionsByReceiverAndStatus finds actionNotifications that
// match ActionReceiver.
func (st *State) matchingActionsByReceiverAndStatus(tag names.Tag, statusCondition bson.D) ([]Action, error) {
var doc actionDoc
var actions []Action
actionsCollection, closer := st.getCollection(actionsC)
defer closer()
sel := append(bson.D{{"receiver", tag.Id()}}, statusCondition...)
iter := actionsCollection.Find(sel).Iter()
for iter.Next(&doc) {
actions = append(actions, newAction(st, doc))
}
return actions, errors.Trace(iter.Close())
}
示例5: getAssignedMachine
func (u *UnitUpgraderAPI) getAssignedMachine(tag names.Tag) (*state.Machine, error) {
// Check that we really have a unit tag.
switch tag := tag.(type) {
case names.UnitTag:
unit, err := u.st.Unit(tag.Id())
if err != nil {
return nil, common.ErrPerm
}
id, err := unit.AssignedMachineId()
if err != nil {
return nil, err
}
return u.st.Machine(id)
default:
return nil, common.ErrPerm
}
}
示例6: FindEntity
// FindEntity implements StateInterface.
func (m *mockState) FindEntity(tag names.Tag) (state.Entity, error) {
m.mu.Lock()
defer m.mu.Unlock()
m.MethodCall(m, "FindEntity", tag)
if err := m.NextErr(); err != nil {
return nil, err
}
if tag == nil {
return nil, errors.NotValidf("nil tag is") // +" not valid"
}
machine, found := m.machines[tag.Id()]
if !found {
return nil, errors.NotFoundf("machine %s", tag.Id())
}
return machine, nil
}
示例7: setEntityMeterStatus
func (api *MetricsDebugAPI) setEntityMeterStatus(entity names.Tag, status state.MeterStatus) error {
switch entity := entity.(type) {
case names.UnitTag:
unit, err := api.state.Unit(entity.Id())
if err != nil {
return errors.Trace(err)
}
chURL, found := unit.CharmURL()
if !found {
return errors.New("no charm url")
}
if chURL.Schema != "local" {
return errors.New("not a local charm")
}
err = unit.SetMeterStatus(status.Code.String(), status.Info)
if err != nil {
return errors.Trace(err)
}
case names.ServiceTag:
service, err := api.state.Service(entity.Id())
if err != nil {
return errors.Trace(err)
}
chURL, _ := service.CharmURL()
if chURL.Schema != "local" {
return errors.New("not a local charm")
}
units, err := service.AllUnits()
if err != nil {
return errors.Trace(err)
}
for _, unit := range units {
err := unit.SetMeterStatus(status.Code.String(), status.Info)
if err != nil {
return errors.Trace(err)
}
}
default:
return errors.Errorf("expected service or unit tag, got %T", entity)
}
return nil
}
示例8: MachineNetworkInfo
// Networks returns the list of networks with related interfaces for a given set of machines.
func (n *NetworkerAPI) MachineNetworkInfo(args params.Entities) (params.MachineNetworkInfoResults, error) {
result := params.MachineNetworkInfoResults{
Results: make([]params.MachineNetworkInfoResult, len(args.Entities)),
}
canAccess, err := n.getAuthFunc()
if err != nil {
return result, err
}
var tag names.Tag
for i, entity := range args.Entities {
if !canAccess(entity.Tag) {
err = common.ErrPerm
} else {
tag, err = names.ParseTag(entity.Tag, names.MachineTagKind)
if err == nil {
id := tag.Id()
result.Results[i].Info, err = n.oneMachineInfo(id)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例9: WatchInterfaces
// WatchInterfaces returns a NotifyWatcher for observing changes
// to each unit's service configuration settings.
func (n *NetworkerAPI) WatchInterfaces(args params.Entities) (params.NotifyWatchResults, error) {
result := params.NotifyWatchResults{
Results: make([]params.NotifyWatchResult, len(args.Entities)),
}
canAccess, err := n.getAuthFunc()
if err != nil {
return result, err
}
var tag names.Tag
for i, entity := range args.Entities {
if !canAccess(entity.Tag) {
err = common.ErrPerm
} else {
tag, err = names.ParseMachineTag(entity.Tag)
if err == nil {
id := tag.Id()
result.Results[i].NotifyWatcherId, err = n.watchOneMachineInterfaces(id)
}
}
result.Results[i].Error = common.ServerError(err)
}
return result, nil
}
示例10: newActionDoc
// newActionDoc builds the actionDoc with the given name and parameters.
func newActionDoc(st *State, receiverTag names.Tag, actionName string, parameters map[string]interface{}) (actionDoc, actionNotificationDoc, error) {
prefix := ensureActionMarker(receiverTag.Id())
actionId, err := NewUUID()
if err != nil {
return actionDoc{}, actionNotificationDoc{}, err
}
actionLogger.Debugf("newActionDoc name: '%s', receiver: '%s', actionId: '%s'", actionName, receiverTag, actionId)
modelUUID := st.ModelUUID()
return actionDoc{
DocId: st.docID(actionId.String()),
ModelUUID: modelUUID,
Receiver: receiverTag.Id(),
Name: actionName,
Parameters: parameters,
Enqueued: nowToTheSecond(),
Status: ActionPending,
}, actionNotificationDoc{
DocId: st.docID(prefix + actionId.String()),
ModelUUID: modelUUID,
Receiver: receiverTag.Id(),
ActionID: actionId.String(),
}, nil
}
示例11: FindEntity
func (m *mockState) FindEntity(tag names.Tag) (state.Entity, error) {
if tag.Kind() == names.ModelTagKind && tag.Id() == m.env.UUID() {
return m.env, nil
}
return nil, errors.NotFoundf("entity with tag %q", tag.String())
}