mirror of https://github.com/docker/docs.git
Merge pull request #456 from vieux/fix_inspect_node
add Node back to inspect
This commit is contained in:
commit
75275f4bd9
|
@ -32,18 +32,10 @@ DELETE "/images/{name:.*}"
|
|||
|
||||
```json
|
||||
"Node": {
|
||||
"ID": "ODAI:IC6Q:MSBL:TPB5:HIEE:6IKC:VCAM:QRNH:PRGX:ERZT:OK46:PMFX",
|
||||
"IP": "0.0.0.0",
|
||||
"Id": "ODAI:IC6Q:MSBL:TPB5:HIEE:6IKC:VCAM:QRNH:PRGX:ERZT:OK46:PMFX",
|
||||
"Ip": "0.0.0.0",
|
||||
"Addr": "http://0.0.0.0:4243",
|
||||
"Name": "vagrant-ubuntu-saucy-64",
|
||||
"Cpus": 1,
|
||||
"Memory": 2099654656,
|
||||
"Labels": {
|
||||
"executiondriver": "native-0.2",
|
||||
"kernelversion": "3.11.0-15-generic",
|
||||
"operatingsystem": "Ubuntu 13.10",
|
||||
"storagedriver": "aufs"
|
||||
}
|
||||
},
|
||||
```
|
||||
* `GET "/containers/{name:.*}/json"`: `HostIP` replaced by the the actual Node's IP if `HostIP` is `0.0.0.0`
|
||||
|
|
|
@ -180,14 +180,8 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
|
||||
n, err := json.Marshal(container.Node)
|
||||
if err != nil {
|
||||
httpError(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
// insert Node field
|
||||
data = bytes.Replace(data, []byte("\"Name\":\"/"), []byte(fmt.Sprintf("\"Node\":%s,\"Name\":\"/", n)), -1)
|
||||
data = bytes.Replace(data, []byte("\"Name\":\"/"), []byte(fmt.Sprintf("\"Node\":%s,\"Name\":\"/", cluster.SerializeNode(container.Node))), -1)
|
||||
|
||||
// insert node IP
|
||||
data = bytes.Replace(data, []byte("\"HostIp\":\"0.0.0.0\""), []byte(fmt.Sprintf("\"HostIp\":%q", container.Node.IP())), -1)
|
||||
|
|
|
@ -36,15 +36,12 @@ func (eh *eventsHandler) Wait(remoteAddr string) {
|
|||
func (eh *eventsHandler) Handle(e *cluster.Event) error {
|
||||
eh.RLock()
|
||||
|
||||
str := fmt.Sprintf("{%q:%q,%q:%q,%q:%q,%q:%d,%q:%q,%q:%q,%q:%q,%q:%q}",
|
||||
str := fmt.Sprintf("{%q:%q,%q:%q,%q:%q,%q:%d,%q:%s}",
|
||||
"status", e.Status,
|
||||
"id", e.Id,
|
||||
"from", e.From+" node:"+e.Node.Name(),
|
||||
"time", e.Time,
|
||||
"node_name", e.Node.Name(),
|
||||
"node_id", e.Node.ID(),
|
||||
"node_addr", e.Node.Addr(),
|
||||
"node_ip", e.Node.IP())
|
||||
"node", cluster.SerializeNode(e.Node))
|
||||
|
||||
for key, w := range eh.ws {
|
||||
if _, err := fmt.Fprintf(w, str); err != nil {
|
||||
|
|
|
@ -54,15 +54,16 @@ func TestHandle(t *testing.T) {
|
|||
|
||||
assert.NoError(t, eh.Handle(event))
|
||||
|
||||
str := fmt.Sprintf("{%q:%q,%q:%q,%q:%q,%q:%d,%q:%q,%q:%q,%q:%q,%q:%q}",
|
||||
str := fmt.Sprintf("{%q:%q,%q:%q,%q:%q,%q:%d,%q:{%q:%q,%q:%q,%q:%q,%q:%q}}",
|
||||
"status", "status",
|
||||
"id", "id",
|
||||
"from", "from node:node_name",
|
||||
"time", 0,
|
||||
"node_name", "node_name",
|
||||
"node_id", "node_id",
|
||||
"node_addr", "node_addr",
|
||||
"node_ip", "node_ip")
|
||||
"node",
|
||||
"Name", "node_name",
|
||||
"Id", "node_id",
|
||||
"Addr", "node_addr",
|
||||
"Ip", "node_ip")
|
||||
|
||||
assert.Equal(t, str, string(fw.Tmp))
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package cluster
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Node interface {
|
||||
ID() string
|
||||
Name() string
|
||||
|
@ -21,3 +23,11 @@ type Node interface {
|
|||
|
||||
IsHealthy() bool
|
||||
}
|
||||
|
||||
func SerializeNode(node Node) string {
|
||||
return fmt.Sprintf("{%q:%q,%q:%q,%q:%q,%q:%q}",
|
||||
"Name", node.Name(),
|
||||
"Id", node.ID(),
|
||||
"Addr", node.Addr(),
|
||||
"Ip", node.IP())
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue