Merge lp:~thumper/juju-core/machine-id-from-tag into lp:~go-bot/juju-core/trunk
Proposed by
Tim Penhey
Status: | Merged |
---|---|
Approved by: | Tim Penhey |
Approved revision: | no longer in the source branch. |
Merged at revision: | 1285 |
Proposed branch: | lp:~thumper/juju-core/machine-id-from-tag |
Merge into: | lp:~go-bot/juju-core/trunk |
Prerequisite: | lp:~thumper/juju-core/instance-instance |
Diff against target: |
51 lines (+21/-1) 2 files modified
state/machine.go (+12/-1) state/machine_test.go (+9/-0) |
To merge this branch: | bzr merge lp:~thumper/juju-core/machine-id-from-tag |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+169327@code.launchpad.net |
Commit message
Add a MachineIdFromTag function.
There are times (coming in future branches) where you want to be able to
reverse the MachineTag result back into a machineId.
Description of the change
Add a MachineIdFromTag function.
There are times (coming in future branches) where you want to be able to
reverse the MachineTag result back into a machineId.
To post a comment you must log in.
Reviewers: mp+169327_ code.launchpad. net,
Message:
Please take a look.
Description:
Add a MachineIdFromTag function.
There are times (coming in future branches) where you want to be able to
reverse the MachineTag result back into a machineId.
https:/ /code.launchpad .net/~thumper/ juju-core/ machine- id-from- tag/+merge/ 169327
Requires: /code.launchpad .net/~thumper/ juju-core/ instance- instance/ +merge/ 169325
https:/
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/10274044/
Affected files: test.go
A [revision details]
M state/machine.go
M state/machine_
Index: [revision details]
=== added file '[revision details]'
--- [revision details] 2012-01-01 00:00:00 +0000
+++ [revision details] 2012-01-01 00:00:00 +0000
@@ -0,0 +1,2 @@
+Old revision: <email address hidden>
+New revision: <email address hidden>
Index: state/machine.go y(m.doc. Id)
=== modified file 'state/machine.go'
--- state/machine.go 2013-06-12 00:05:50 +0000
+++ state/machine.go 2013-06-14 02:27:04 +0000
@@ -107,15 +107,26 @@
return machineGlobalKe
}
+const machineTagPrefix = "machine-" "machine- %s", id) Replace( tag, "/", "-", -1)
+
// MachineTag returns the tag for the
// machine with the given id.
func MachineTag(id string) string {
- tag := fmt.Sprintf(
+ tag := fmt.Sprintf("%s%s", machineTagPrefix, id)
// Containers require "/" to be replaced by "-".
tag = strings.
return tag
}
+// MachineIdFromTag returns the machine id that was used to create the tag. g(tag string) string { machineTagPrefi x):]
+func MachineIdFromTa
+ // Strip off the "machine-" prefix.
+ id := tag[len(
+ // Put the slashes back.
+ id = strings.Replace(id, "-", "/", -1)
+ return id
+}
+
// Tag returns a name identifying the machine that is safe to use
// as a file name. The returned name will be different from other
// Tag values returned by any other entities from the same state.
Index: state/machine_ test.go machine_ test.go' test.go 2013-06-12 00:01:40 +0000 test.go 2013-06-14 02:27:04 +0000 state.MachineTa g("10/lxc/ 1"), Equals, "machine-10-lxc-1")
=== modified file 'state/
--- state/machine_
+++ state/machine_
@@ -192,6 +192,15 @@
c.Assert(
}
+func (s *MachineSuite) TestMachineIdFr omTag(c *C) { state.MachineId FromTag( "machine- 10"), Equals, "10") state.MachineId FromTag( "machine- 10-lxc- 1"), Equals, "10/lxc/1") state.MachineId FromTag( state.MachineTa g(nested) ), Equals, nested) sword(c *C) { Password( c, func(st *state.State) (entity, error) { s.machine. Id())
+ c.Assert(
+ // Check a container id.
+ c.Assert(
+ // Check reversability.
+ nested := "2/kvm/0/lxc/3"
+ c.Assert(
+}
+
func (s *MachineSuite) TestSetMongoPas
testSetMongo
return st.Machine(