fix parent references

This commit is contained in:
Barak Michener 2015-02-13 16:54:15 -05:00
parent e9f4be498d
commit fdebf2b109

View File

@ -129,6 +129,7 @@ func fixEtcd(etcdref *node) *node {
ExpireTime: machines.ExpireTime, ExpireTime: machines.ExpireTime,
ACL: machines.ACL, ACL: machines.ACL,
Children: make(map[string]*node), Children: make(map[string]*node),
Parent: n,
} }
for name, c := range machines.Children { for name, c := range machines.Children {
q, err := url.ParseQuery(c.Value) q, err := url.ParseQuery(c.Value)
@ -153,25 +154,29 @@ func fixEtcd(etcdref *node) *node {
ModifiedIndex: c.ModifiedIndex, ModifiedIndex: c.ModifiedIndex,
ExpireTime: c.ExpireTime, ExpireTime: c.ExpireTime,
ACL: c.ACL, ACL: c.ACL,
Children: map[string]*node{ Children: make(map[string]*node),
"attributes": &node{ Parent: n.Children["members"],
Path: path.Join("/0/members", m.ID.String(), "attributes"),
CreatedIndex: c.CreatedIndex,
ModifiedIndex: c.ModifiedIndex,
ExpireTime: c.ExpireTime,
ACL: c.ACL,
Value: string(attrBytes),
},
"raftAttributes": &node{
Path: path.Join("/0/members", m.ID.String(), "raftAttributes"),
CreatedIndex: c.CreatedIndex,
ModifiedIndex: c.ModifiedIndex,
ExpireTime: c.ExpireTime,
ACL: c.ACL,
Value: string(raftBytes),
},
},
} }
attrs := &node{
Path: path.Join("/0/members", m.ID.String(), "attributes"),
CreatedIndex: c.CreatedIndex,
ModifiedIndex: c.ModifiedIndex,
ExpireTime: c.ExpireTime,
ACL: c.ACL,
Value: string(attrBytes),
Parent: newNode,
}
newNode.Children["attributes"] = attrs
raftAttrs := &node{
Path: path.Join("/0/members", m.ID.String(), "raftAttributes"),
CreatedIndex: c.CreatedIndex,
ModifiedIndex: c.ModifiedIndex,
ExpireTime: c.ExpireTime,
ACL: c.ACL,
Value: string(raftBytes),
Parent: newNode,
}
newNode.Children["raftAttributes"] = raftAttrs
n.Children["members"].Children[m.ID.String()] = newNode n.Children["members"].Children[m.ID.String()] = newNode
} }
return n return n
@ -190,6 +195,7 @@ func mangleRoot(n *node) *node {
etcd := n.Children["_etcd"] etcd := n.Children["_etcd"]
replacePathNames(n, "/", "/1/") replacePathNames(n, "/", "/1/")
newZero := fixEtcd(etcd) newZero := fixEtcd(etcd)
newZero.Parent = newRoot
newRoot.Children["0"] = newZero newRoot.Children["0"] = newZero
return newRoot return newRoot
} }