本文整理汇总了Golang中github.com/juju/names.UnitTag类的典型用法代码示例。如果您正苦于以下问题:Golang UnitTag类的具体用法?Golang UnitTag怎么用?Golang UnitTag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了UnitTag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: NewPaths
// NewPaths returns the set of filesystem paths that the supplied unit should
// use, given the supplied root juju data directory path.
func NewPaths(dataDir string, unitTag names.UnitTag) Paths {
join := filepath.Join
baseDir := join(dataDir, "agents", unitTag.String())
stateDir := join(baseDir, "state")
socket := func(name string, abstract bool) string {
if version.Current.OS == version.Windows {
return fmt.Sprintf(`\\.\pipe\%s-%s`, unitTag, name)
}
path := join(baseDir, name+".socket")
if abstract {
path = "@" + path
}
return path
}
toolsDir := tools.ToolsDir(dataDir, unitTag.String())
return Paths{
ToolsDir: filepath.FromSlash(toolsDir),
Runtime: RuntimePaths{
JujuRunSocket: socket("run", false),
JujucServerSocket: socket("agent", true),
},
State: StatePaths{
CharmDir: join(baseDir, "charm"),
OperationsFile: join(stateDir, "uniter"),
RelationsDir: join(stateDir, "relations"),
BundlesDir: join(stateDir, "bundles"),
DeployerDir: join(stateDir, "deployer"),
StorageDir: join(stateDir, "storage"),
MetricsSpoolDir: join(stateDir, "spool", "metrics"),
},
}
}
示例2: FormatDetailResource
// FormatDetailResource converts the arguments into a FormattedServiceResource.
func FormatDetailResource(tag names.UnitTag, svc, unit resource.Resource, progress int64) (FormattedDetailResource, error) {
// note that the unit resource can be a zero value here, to indicate that
// the unit has not downloaded that resource yet.
unitNum, err := unitNum(tag)
if err != nil {
return FormattedDetailResource{}, errors.Trace(err)
}
progressStr := ""
fUnit := FormatSvcResource(unit)
expected := FormatSvcResource(svc)
revProgress := expected.combinedRevision
if progress >= 0 {
progressStr = "100%"
if expected.Size > 0 {
progressStr = fmt.Sprintf("%.f%%", float64(progress)*100.0/float64(expected.Size))
}
if fUnit.combinedRevision != expected.combinedRevision {
revProgress = fmt.Sprintf("%s (fetching: %s)", expected.combinedRevision, progressStr)
}
}
return FormattedDetailResource{
UnitID: tag.Id(),
unitNumber: unitNum,
Unit: fUnit,
Expected: expected,
Progress: progress,
progress: progressStr,
revProgress: revProgress,
}, nil
}
示例3: WatchRelationUnits
// WatchRelationUnits returns a watcher that notifies of changes to the
// counterpart units in the relation for the given unit.
func (st *State) WatchRelationUnits(
relationTag names.RelationTag,
unitTag names.UnitTag,
) (watcher.RelationUnitsWatcher, error) {
var results params.RelationUnitsWatchResults
args := params.RelationUnits{
RelationUnits: []params.RelationUnit{{
Relation: relationTag.String(),
Unit: unitTag.String(),
}},
}
err := st.facade.FacadeCall("WatchRelationUnits", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, fmt.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewRelationUnitsWatcher(st.facade.RawAPICaller(), result)
return w, nil
}
示例4: UnitStorageAttachments
// UnitStorageAttachments returns the StorageAttachments for the specified unit.
func (st *State) UnitStorageAttachments(unit names.UnitTag) ([]StorageAttachment, error) {
query := bson.D{{"unitid", unit.Id()}}
attachments, err := st.storageAttachments(query)
if err != nil {
return nil, errors.Annotatef(err, "cannot get storage attachments for unit %s", unit.Id())
}
return attachments, nil
}
示例5: tryClosePorts
func tryClosePorts(
protocol string,
fromPort, toPort int,
unitTag names.UnitTag,
machinePorts map[network.PortRange]params.RelationUnit,
pendingPorts map[PortRange]PortRangeInfo,
) error {
// TODO(dimitern) Once port ranges are linked to relations in
// addition to networks, refactor this functions and test it
// better to ensure it handles relations properly.
relationId := -1
// Validate the given range.
newRange, err := validatePortRange(protocol, fromPort, toPort)
if err != nil {
return err
}
rangeKey := PortRange{
Ports: newRange,
RelationId: relationId,
}
rangeInfo, isKnown := pendingPorts[rangeKey]
if isKnown {
if rangeInfo.ShouldOpen {
// If the same range is already pending to be opened, just
// remove it from pending.
delete(pendingPorts, rangeKey)
}
return nil
}
// Ensure the range we're trying to close is opened on the
// machine.
relUnit, found := machinePorts[newRange]
if !found {
// Trying to close a range which is not open is ignored.
return nil
} else if relUnit.Unit != unitTag.String() {
relUnitTag, err := names.ParseUnitTag(relUnit.Unit)
if err != nil {
return errors.Annotatef(
err,
"machine ports %v contain invalid unit tag",
newRange,
)
}
return errors.Errorf(
"cannot close %v (opened by %q) from %q",
newRange, relUnitTag.Id(), unitTag.Id(),
)
}
rangeInfo = pendingPorts[rangeKey]
rangeInfo.ShouldOpen = false
pendingPorts[rangeKey] = rangeInfo
return nil
}
示例6: destroyStorageAttachmentOps
func destroyStorageAttachmentOps(storage names.StorageTag, unit names.UnitTag) []txn.Op {
ops := []txn.Op{{
C: storageAttachmentsC,
Id: storageAttachmentId(unit.Id(), storage.Id()),
Assert: isAliveDoc,
Update: bson.D{{"$set", bson.D{{"life", Dying}}}},
}}
return ops
}
示例7: createStorageAttachmentOp
// createStorageAttachmentOps returns a txn.Op for creating a storage attachment.
// The caller is responsible for updating the attachmentcount field of the storage
// instance.
func createStorageAttachmentOp(storage names.StorageTag, unit names.UnitTag) txn.Op {
return txn.Op{
C: storageAttachmentsC,
Id: storageAttachmentId(unit.Id(), storage.Id()),
Assert: txn.DocMissing,
Insert: &storageAttachmentDoc{
Unit: unit.Id(),
StorageInstance: storage.Id(),
},
}
}
示例8: UnitAssignedMachine
// UnitAssignedMachine returns the tag of the machine that the unit
// is assigned to, or an error if the unit cannot be obtained or is
// not assigned to a machine.
func (s stateShim) UnitAssignedMachine(tag names.UnitTag) (names.MachineTag, error) {
unit, err := s.Unit(tag.Id())
if err != nil {
return names.MachineTag{}, errors.Trace(err)
}
mid, err := unit.AssignedMachineId()
if err != nil {
return names.MachineTag{}, errors.Trace(err)
}
return names.NewMachineTag(mid), nil
}
示例9: watchOneUnitMeterStatus
func (m *MeterStatusAPI) watchOneUnitMeterStatus(tag names.UnitTag) (string, error) {
unit, err := m.state.Unit(tag.Id())
if err != nil {
return "", err
}
watch := unit.WatchMeterStatus()
if _, ok := <-watch.Changes(); ok {
return m.resources.Register(watch), nil
}
return "", watcher.EnsureErr(watch)
}
示例10: obliterateUnit
func (s *StorageStateSuiteBase) obliterateUnit(c *gc.C, tag names.UnitTag) {
u, err := s.State.Unit(tag.Id())
c.Assert(err, jc.ErrorIsNil)
err = u.Destroy()
c.Assert(err, jc.ErrorIsNil)
s.obliterateUnitStorage(c, tag)
err = u.EnsureDead()
c.Assert(err, jc.ErrorIsNil)
err = u.Remove()
c.Assert(err, jc.ErrorIsNil)
}
示例11: storageAttachment
func (st *State) storageAttachment(storage names.StorageTag, unit names.UnitTag) (*storageAttachment, error) {
coll, closer := st.getCollection(storageAttachmentsC)
defer closer()
var s storageAttachment
err := coll.FindId(storageAttachmentId(unit.Id(), storage.Id())).One(&s.doc)
if err == mgo.ErrNotFound {
return nil, errors.NotFoundf("storage attachment %s:%s", storage.Id(), unit.Id())
} else if err != nil {
return nil, errors.Annotatef(err, "cannot get storage attachment %s:%s", storage.Id(), unit.Id())
}
return &s, nil
}
示例12: UnitStorageConstraints
// UnitStorageConstraints returns storage constraints for this unit,
// or an error if the unit or its constraints cannot be obtained.
func (s storageStateShim) UnitStorageConstraints(u names.UnitTag) (map[string]state.StorageConstraints, error) {
unit, err := s.Unit(u.Id())
if err != nil {
return nil, errors.Trace(err)
}
cons, err := unit.StorageConstraints()
if err != nil {
return nil, errors.Trace(err)
}
return cons, nil
}
示例13: FormatDetailResource
// FormatDetailResource converts the arguments into a FormattedServiceResource.
func FormatDetailResource(tag names.UnitTag, svc, unit resource.Resource) (FormattedDetailResource, error) {
// note that the unit resource can be a zero value here, to indicate that
// the unit has not downloaded that resource yet.
unitNum, err := unitNum(tag)
if err != nil {
return FormattedDetailResource{}, errors.Trace(err)
}
return FormattedDetailResource{
UnitID: tag.Id(),
unitNumber: unitNum,
Unit: FormatSvcResource(unit),
Expected: FormatSvcResource(svc),
}, nil
}
示例14: StorageAttachment
func (st *mockState) StorageAttachment(
storageTag names.StorageTag, unitTag names.UnitTag,
) (params.StorageAttachment, error) {
if unitTag != st.unit.tag {
return params.StorageAttachment{}, ¶ms.Error{Code: params.CodeNotFound}
}
attachment, ok := st.storageAttachment[params.StorageAttachmentId{
UnitTag: unitTag.String(),
StorageTag: storageTag.String(),
}]
if !ok {
return params.StorageAttachment{}, ¶ms.Error{Code: params.CodeNotFound}
}
if attachment.Kind == params.StorageKindUnknown {
return params.StorageAttachment{}, ¶ms.Error{Code: params.CodeNotProvisioned}
}
return attachment, nil
}
示例15: WatchUnitStorageAttachments
// WatchUnitStorageAttachments starts a watcher for changes to storage
// attachments related to the unit. The watcher will return the
// IDs of the corresponding storage instances.
func (sa *StorageAccessor) WatchUnitStorageAttachments(unitTag names.UnitTag) (watcher.StringsWatcher, error) {
var results params.StringsWatchResults
args := params.Entities{
Entities: []params.Entity{{Tag: unitTag.String()}},
}
err := sa.facade.FacadeCall("WatchUnitStorageAttachments", args, &results)
if err != nil {
return nil, err
}
if len(results.Results) != 1 {
return nil, errors.Errorf("expected 1 result, got %d", len(results.Results))
}
result := results.Results[0]
if result.Error != nil {
return nil, result.Error
}
w := apiwatcher.NewStringsWatcher(sa.facade.RawAPICaller(), result)
return w, nil
}