19
18
"launchpad.net/juju-core/constraints"
20
19
"launchpad.net/juju-core/errors"
21
20
"launchpad.net/juju-core/instance"
21
"launchpad.net/juju-core/names"
22
22
"launchpad.net/juju-core/state/api/params"
23
23
"launchpad.net/juju-core/state/presence"
24
24
"launchpad.net/juju-core/utils"
433
433
// the unit. If no such entity can be determined, false is returned.
434
434
func (u *Unit) DeployerTag() (string, bool) {
435
435
if u.doc.Principal != "" {
436
return UnitTag(u.doc.Principal), true
436
return names.UnitTag(u.doc.Principal), true
437
437
} else if u.doc.MachineId != "" {
438
return MachineTag(u.doc.MachineId), true
438
return names.MachineTag(u.doc.MachineId), true
628
628
return u.st.pwatcher.Alive(u.globalKey())
631
const unitTagPrefix = "unit-"
633
// UnitTag returns the tag for the
634
// unit with the given name.
635
func UnitTag(unitName string) string {
636
return unitTagPrefix + strings.Replace(unitName, "/", "-", -1)
639
// UnitNameFromTag returns the unit name that was used to create the tag.
640
func UnitNameFromTag(tag string) string {
641
// TODO(dimitern): Possibly change this to return (string, error),
642
// so the case below can be reported.
643
if !strings.HasPrefix(tag, unitTagPrefix) {
646
// Strip off the "unit-" prefix.
647
name := tag[len(unitTagPrefix):]
648
// Put the slashes back.
649
name = strings.Replace(name, "-", "/", -1)
653
631
// Tag returns a name identifying the unit that is safe to use
654
632
// as a file name. The returned name will be different from other
655
633
// Tag values returned by any other entities from the same state.
656
634
func (u *Unit) Tag() string {
657
return UnitTag(u.Name())
635
return names.UnitTag(u.Name())
660
638
// WaitAgentAlive blocks until the respective agent is alive.