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
151
const machineTagPrefix = "machine-"
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)
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) {
169
// Strip off the "machine-" prefix.
170
id := tag[len(machineTagPrefix):]
171
// Put the slashes back.
172
id = strings.Replace(id, "-", "/", -1)
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())
183
159
// Life returns whether the machine is Alive, Dying or Dead.