1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Add implementation for lookupContainerID

Signed-off-by: Alessandro Boch <aboch@docker.com>
This commit is contained in:
Alessandro Boch 2015-06-15 02:27:24 -07:00
parent c83e31a761
commit 0969e192f2
2 changed files with 22 additions and 2 deletions

View file

@ -73,6 +73,8 @@ func setupMockHTTPCallback() {
rsp = string(mockServiceListJSON)
} else if strings.HasSuffix(path, "services/"+mockServiceID) {
rsp = string(mockServiceJSON)
} else if strings.Contains(path, "containers") {
return nopCloser{bytes.NewBufferString("")}, 400, fmt.Errorf("Bad Request")
}
case "POST":
var data []byte

View file

@ -92,8 +92,26 @@ func lookupServiceID(cli *NetworkCli, nwName, svNameID string) (string, error) {
}
func lookupContainerID(cli *NetworkCli, cnNameID string) (string, error) {
// TODO : containerID to sandbox-key ?
return cnNameID, nil
// Container is a Docker resource, ask docker about it.
// In case of connecton error, we assume we are running in dnet and return whatever was passed to us
obj, _, err := readBody(cli.call("GET", fmt.Sprintf("/containers/%s/json", cnNameID), nil, nil))
if err != nil {
// We are probably running outside of docker
return cnNameID, nil
}
var x map[string]interface{}
err = json.Unmarshal(obj, &x)
if err != nil {
return "", err
}
if iid, ok := x["Id"]; ok {
if id, ok := iid.(string); ok {
return id, nil
}
return "", fmt.Errorf("Unexpected data type for container ID in json response")
}
return "", fmt.Errorf("Cannot find container ID in json response")
}
// CmdService handles the service UI