Fix:#748 add refresh container

Signed-off-by: Xian Chaobo <xianchaobo@huawei.com>
This commit is contained in:
Xian Chaobo 2015-05-15 04:46:02 -04:00
parent 77884de123
commit 4af3e30f64
3 changed files with 33 additions and 7 deletions

View File

@ -532,6 +532,27 @@ func proxyContainer(c *context, w http.ResponseWriter, r *http.Request) {
}
}
// Proxy a request to the right node and force refresh container
func proxyContainerAndForceRefresh(c *context, w http.ResponseWriter, r *http.Request) {
name, container, err := getContainerFromVars(c, mux.Vars(r))
if err != nil {
httpError(w, err.Error(), http.StatusNotFound)
return
}
// Set the full container ID in the proxied URL path.
if name != "" {
r.URL.Path = strings.Replace(r.URL.Path, name, container.Id, 1)
}
if err := proxy(c.tlsConfig, container.Engine.Addr, w, r); err != nil {
httpError(w, err.Error(), http.StatusInternalServerError)
}
// force fresh container
container.Refresh()
}
// Proxy a request to the right node
func proxyImage(c *context, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]

View File

@ -52,14 +52,14 @@ var routes = map[string]map[string]handler{
"/images/{name:.*}/push": proxyImage,
"/images/{name:.*}/tag": proxyImageAndForceRefresh,
"/containers/create": postContainersCreate,
"/containers/{name:.*}/kill": proxyContainer,
"/containers/{name:.*}/pause": proxyContainer,
"/containers/{name:.*}/unpause": proxyContainer,
"/containers/{name:.*}/kill": proxyContainerAndForceRefresh,
"/containers/{name:.*}/pause": proxyContainerAndForceRefresh,
"/containers/{name:.*}/unpause": proxyContainerAndForceRefresh,
"/containers/{name:.*}/rename": postRenameContainer,
"/containers/{name:.*}/restart": proxyContainer,
"/containers/{name:.*}/start": proxyContainer,
"/containers/{name:.*}/stop": proxyContainer,
"/containers/{name:.*}/wait": proxyContainer,
"/containers/{name:.*}/restart": proxyContainerAndForceRefresh,
"/containers/{name:.*}/start": proxyContainerAndForceRefresh,
"/containers/{name:.*}/stop": proxyContainerAndForceRefresh,
"/containers/{name:.*}/wait": proxyContainerAndForceRefresh,
"/containers/{name:.*}/resize": proxyContainer,
"/containers/{name:.*}/attach": proxyHijack,
"/containers/{name:.*}/copy": proxyContainer,

View File

@ -10,3 +10,8 @@ type Container struct {
Info dockerclient.ContainerInfo
Engine *Engine
}
// Refresh container
func (c *Container) Refresh() error {
return c.Engine.refreshContainer(c.Id, true)
}