Merge lp://staging/~wallyworld/juju-core/add-machine-parent-getter into lp://staging/~juju/juju-core/trunk
Proposed by
Ian Booth
Status: | Merged |
---|---|
Merged at revision: | 1273 |
Proposed branch: | lp://staging/~wallyworld/juju-core/add-machine-parent-getter |
Merge into: | lp://staging/~juju/juju-core/trunk |
Diff against target: |
79 lines (+35/-3) 3 files modified
state/container.go (+12/-3) state/machine.go (+6/-0) state/machine_test.go (+17/-0) |
To merge this branch: | bzr merge lp://staging/~wallyworld/juju-core/add-machine-parent-getter |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Juju Engineering | Pending | ||
Review via email: mp+168827@code.staging.launchpad.net |
Description of the change
Add ParentId() to Machine
This branch provides the ability to ask a container for its parent machine's id.
To post a comment you must log in.
Reviewers: mp+168827_ code.launchpad. net,
Message:
Please take a look.
Description:
Add Parent() to Machine
This branch provides the ability to ask a container for its parent
machine.
https:/ /code.launchpad .net/~wallyworl d/juju- core/add- machine- parent- getter/ +merge/ 168827
(do not edit description out of merge proposal)
Please review this at https:/ /codereview. appspot. com/10203043/
Affected files: test.go
A [revision details]
M state/container.go
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/container.go container. go'
=== modified file 'state/
--- state/container.go 2013-06-11 20:56:00 +0000
+++ state/container.go 2013-06-11 22:40:34 +0000
@@ -88,6 +88,16 @@
return ops
}
+// parentId returns the id of the host machine if machineId a container Split(machineId , "/") Join(idParts[ :len(idParts) -2], "/") RefOps returns the txn.Op's necessary to remove a RefOps( st *State, machineId string) []txn.Op { Split(machineId , "/") removeRefOp} Join(idParts[ :len(idParts) -2], "/") RefOp := txn.Op{ s.Name,
id, or ""
+// if machineId is not for a container.
+func parentId(machineId string) string {
+ idParts := strings.
+ if len(idParts) < 3 {
+ return ""
+ }
+ return strings.
+}
+
// removeContainer
machine container record.
// These include removing the record itself and updating the host
machine's children property.
func removeContainer
@@ -98,11 +108,10 @@
Remove: true,
}
// If the machine is a container, figure out it's parent host.
- idParts := strings.
- if len(idParts) < 3 {
+ parentId := parentId(machineId)
+ if parentId == "" {
return []txn.Op{
}
- parentId := strings.
removeParent
C: st.containerRef
Id: parentId,
Index: state/machine.go
=== modified file 'state/machine.go'
--- state/machine.go 2013-06-11 20:56:00 +0000
+++ state/machine.go 2013-06-11 22:40:34 +0000
@@ -235,6 +235,14 @@
return nil, err
}
+func (m *Machine) Parent() (*Machine, error) { parentId)
+ parentId := parentId(m.Id())
+ if parentId == "" {
+ return nil, nil
+ }
+ return m.st.Machine(
+}
+
type HasContainersError struct {
MachineId string
ContainerIds []string
Index: state/machine_ test.go machine_ test.go' test.go 2013-06-11 02:15:31 +0000 test.go 2013-06-11 22:40:34 +0000 containers, DeepEquals, []string(nil))
=== modified file 'state/
--- state/machine_
+++ state/machine_
@@ -35,6 +35,23 @@
c.Assert(
}
+func (s *MachineSuite) TestParent(c *C) { eParams{ MachineJob{ state.JobHostUn its}, AddMachineWithC onstraints( ¶ms) parent. Id(...
+ parent, err := s.machine.Parent()
+ c.Assert(err, IsNil)
+ c.Assert(parent, IsNil)
+ params := state.AddMachin
+ ParentId: s.machine.Id(),
+ ContainerType: state.LXC,
+ Series: "series",
+ Jobs: []state.
+ }
+ container, err := s.State.
+ c.Assert(err, IsNil)
+ parent, err = container.Parent()
+ c.Assert(err, IsNil)
+ c.Assert(