~themue/juju-core/053-env-more-script-friendly

« back to all changes in this revision

Viewing changes to state/api/deployer/unit.go

  • Committer: Dimiter Naydenov
  • Date: 2013-07-29 15:15:41 UTC
  • mto: This revision was merged to the branch mainline in revision 1565.
  • Revision ID: dimiter.naydenov@canonical.com-20130729151541-zm8murwo9u7mtsdu
names: new package

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
package deployer
5
5
 
6
6
import (
7
 
        "strings"
8
 
 
 
7
        "launchpad.net/juju-core/names"
9
8
        "launchpad.net/juju-core/state/api/params"
10
9
)
11
10
 
21
20
        return u.tag
22
21
}
23
22
 
24
 
const unitTagPrefix = "unit-"
25
 
 
26
 
// UnitTag returns the tag for the
27
 
// unit with the given name.
28
 
func UnitTag(unitName string) string {
29
 
        return unitTagPrefix + strings.Replace(unitName, "/", "-", -1)
30
 
}
31
 
 
32
23
// Name returns the unit's name.
33
24
func (u *Unit) Name() string {
34
 
        if !strings.HasPrefix(u.tag, unitTagPrefix) {
 
25
        name, err := names.UnitNameFromTag(u.tag)
 
26
        if err != nil {
35
27
                return ""
36
28
        }
37
 
        // Strip off the "unit-" prefix.
38
 
        name := u.tag[len(unitTagPrefix):]
39
 
        // Put the slashes back.
40
 
        name = strings.Replace(name, "-", "/", -1)
41
29
        return name
42
30
}
43
31