mirror of
https://github.com/moby/moby.git
synced 2026-08-05 23:51:18 +00:00
Merge pull request #296 from aboch/dn
Add implementation for lookupContainerID
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user