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

« back to all changes in this revision

Viewing changes to state/machine.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:
15
15
        "launchpad.net/juju-core/constraints"
16
16
        "launchpad.net/juju-core/errors"
17
17
        "launchpad.net/juju-core/instance"
 
18
        "launchpad.net/juju-core/names"
18
19
        "launchpad.net/juju-core/state/api/params"
19
20
        "launchpad.net/juju-core/state/presence"
20
21
        "launchpad.net/juju-core/utils"
148
149
        return instData, nil
149
150
}
150
151
 
151
 
const machineTagPrefix = "machine-"
152
 
 
153
 
// MachineTag returns the tag for the
154
 
// machine with the given id.
155
 
func MachineTag(id string) string {
156
 
        tag := fmt.Sprintf("%s%s", machineTagPrefix, id)
157
 
        // Containers require "/" to be replaced by "-".
158
 
        tag = strings.Replace(tag, "/", "-", -1)
159
 
        return tag
160
 
}
161
 
 
162
 
// MachineIdFromTag returns the machine id that was used to create the tag.
163
 
func MachineIdFromTag(tag string) string {
164
 
        // TODO(dimitern): Possibly change this to return (string, error),
165
 
        // so the case below can be reported.
166
 
        if !strings.HasPrefix(tag, machineTagPrefix) {
167
 
                return ""
168
 
        }
169
 
        // Strip off the "machine-" prefix.
170
 
        id := tag[len(machineTagPrefix):]
171
 
        // Put the slashes back.
172
 
        id = strings.Replace(id, "-", "/", -1)
173
 
        return id
174
 
}
175
 
 
176
152
// Tag returns a name identifying the machine that is safe to use
177
153
// as a file name.  The returned name will be different from other
178
154
// Tag values returned by any other entities from the same state.
179
155
func (m *Machine) Tag() string {
180
 
        return MachineTag(m.Id())
 
156
        return names.MachineTag(m.Id())
181
157
}
182
158
 
183
159
// Life returns whether the machine is Alive, Dying or Dead.