Merge pull request #235 from aluzzardi/public-node

Container: Make Node public instead of exposing it through Node().
This commit is contained in:
Victor Vieux 2015-01-12 11:14:48 -08:00
commit c76c29fd11
6 changed files with 14 additions and 19 deletions

View File

@ -92,20 +92,20 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
if !strings.Contains(tmp.Status, "Up") && !all {
continue
}
if !container.Node().IsHealthy() {
if !container.Node.IsHealthy() {
tmp.Status = "Pending"
}
// TODO remove the Node Name 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().Name + name
tmp.Names[i] = "/" + container.Node.Name + name
}
// insert node IP
tmp.Ports = make([]dockerclient.Port, len(container.Ports))
for i, port := range container.Ports {
tmp.Ports[i] = port
if port.IP == "0.0.0.0" {
tmp.Ports[i].IP = container.Node().IP
tmp.Ports[i].IP = container.Node.IP
}
}
out = append(out, &tmp)
@ -119,7 +119,7 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) {
func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
container := c.cluster.Container(mux.Vars(r)["name"])
if container != nil {
resp, err := http.Get(container.Node().Addr + "/containers/" + container.Id + "/json")
resp, err := http.Get(container.Node.Addr + "/containers/" + container.Id + "/json")
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
@ -130,7 +130,7 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
return
}
n, err := json.Marshal(container.Node())
n, err := json.Marshal(container.Node)
if err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
return
@ -140,9 +140,8 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
data = bytes.Replace(data, []byte("\"Name\":\"/"), []byte(fmt.Sprintf("\"Node\":%s,\"Name\":\"/", n)), -1)
// insert node IP
data = bytes.Replace(data, []byte("\"HostIp\":\"0.0.0.0\""), []byte(fmt.Sprintf("\"HostIp\":%q", container.Node().IP)), -1)
data = bytes.Replace(data, []byte("\"HostIp\":\"0.0.0.0\""), []byte(fmt.Sprintf("\"HostIp\":%q", container.Node.IP)), -1)
w.Write(data)
}
}
@ -225,7 +224,7 @@ func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Re
}
log.Debugf("[REFRESH CONTAINER] --> %s", container.Id)
container.Node().ForceRefreshContainer(container.Container)
container.Node.ForceRefreshContainer(container.Container)
}
// Proxy a request to the right node

View File

@ -45,7 +45,7 @@ func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseW
// RequestURI may not be sent to client
r.RequestURI = ""
parts := strings.SplitN(container.Node().Addr, "://", 2)
parts := strings.SplitN(container.Node.Addr, "://", 2)
if len(parts) == 2 {
r.URL.Scheme = parts[0]
r.URL.Host = parts[1]
@ -66,8 +66,8 @@ func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseW
}
func hijack(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseWriter, r *http.Request) error {
addr := container.Node().Addr
if parts := strings.SplitN(container.Node().Addr, "://", 2); len(parts) == 2 {
addr := container.Node.Addr
if parts := strings.SplitN(container.Node.Addr, "://", 2); len(parts) == 2 {
addr = parts[1]
}

View File

@ -107,7 +107,7 @@ func (c *Cluster) Container(IdOrName string) *Container {
// Match name, /name or engine/name.
for _, name := range container.Names {
if name == IdOrName || name == "/"+IdOrName || container.node.ID+name == IdOrName || container.node.Name+name == IdOrName {
if name == IdOrName || name == "/"+IdOrName || container.Node.ID+name == IdOrName || container.Node.Name+name == IdOrName {
return container
}
}

View File

@ -6,9 +6,5 @@ type Container struct {
dockerclient.Container
Info dockerclient.ContainerInfo
node *Node
}
func (c *Container) Node() *Node {
return c.node
Node *Node
}

View File

@ -185,7 +185,7 @@ func (n *Node) inspectContainer(c dockerclient.Container, containers map[string]
container := &Container{}
container.Container = c
container.node = n
container.Node = n
info, err := n.client.InspectContainer(c.Id)
if err != nil {

View File

@ -61,5 +61,5 @@ func (s *Scheduler) RemoveContainer(container *cluster.Container, force bool) er
s.Lock()
defer s.Unlock()
return container.Node().Destroy(container, force)
return container.Node.Destroy(container, force)
}