use ID and names

This commit is contained in:
Victor Vieux 2014-11-20 19:03:55 +00:00
parent 725c03d799
commit 20319a5049
3 changed files with 8 additions and 6 deletions

View File

@ -32,8 +32,8 @@ type handler func(c *context, w http.ResponseWriter, r *http.Request)
func getInfo(c *context, w http.ResponseWriter, r *http.Request) {
driverStatus := [][2]string{{"\bNodes", fmt.Sprintf("%d", len(c.cluster.Nodes()))}}
for ID, node := range c.cluster.Nodes() {
driverStatus = append(driverStatus, [2]string{ID, node.Addr})
for _, node := range c.cluster.Nodes() {
driverStatus = append(driverStatus, [2]string{node.Name, node.Addr})
}
info := struct {
Containers int
@ -70,7 +70,7 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
// TODO remove the Node ID in the name when we have a good solution
tmp.Names = make([]string, len(container.Names))
for i, name := range container.Names {
tmp.Names[i] = "/" + container.Node().ID + name
tmp.Names[i] = "/" + container.Node().Name + name
}
tmp.Ports = make([]dockerclient.Port, len(container.Ports))
for i, port := range container.Ports {

View File

@ -17,9 +17,8 @@ const (
stateRefreshPeriod = 30 * time.Second
)
func NewNode(id string, addr string) *Node {
func NewNode(addr string) *Node {
e := &Node{
ID: id,
Addr: addr,
Labels: make(map[string]string),
ch: make(chan bool),
@ -34,6 +33,7 @@ type Node struct {
ID string
IP string
Addr string
Name string
Cpus int64
Memory int64
Labels map[string]string
@ -96,6 +96,8 @@ func (n *Node) updateSpecs() error {
if err != nil {
return err
}
n.ID = info.ID
n.Name = info.Name
n.Cpus = info.NCPU
n.Memory = info.MemTotal
n.Labels = map[string]string{

View File

@ -26,7 +26,7 @@ func manage(c *cli.Context) {
refresh := func(c *cluster.Cluster, nodes []string) error {
for _, addr := range nodes {
if c.Node(addr) == nil {
n := cluster.NewNode(addr, addr)
n := cluster.NewNode(addr)
if err := n.Connect(nil); err != nil {
return err
}