package proxy import ( "errors" "net/http" "strings" "github.com/fsouza/go-dockerclient" . "github.com/weaveworks/weave/common" ) type startContainerInterceptor struct{ proxy *Proxy } func (i *startContainerInterceptor) InterceptRequest(r *http.Request) error { return nil } func (i *startContainerInterceptor) InterceptResponse(r *http.Response) error { container, err := inspectContainerInPath(i.proxy.client, r.Request.URL.Path) if err != nil { return err } cidrs, ok := i.proxy.weaveCIDRsFromConfig(container.Config) if !ok { Log.Debug("No Weave CIDR, ignoring") return nil } Log.Infof("Attaching container %s with WEAVE_CIDR \"%s\" to weave network", container.ID, strings.Join(cidrs, " ")) args := []string{"attach"} args = append(args, cidrs...) args = append(args, "--or-die", container.ID) if _, stderr, err := callWeave(args...); err != nil { Log.Warningf("Attaching container %s to weave network failed: %s", container.ID, string(stderr)) return errors.New(string(stderr)) } else if len(stderr) > 0 { Log.Warningf("Attaching container %s to weave network: %s", container.ID, string(stderr)) } return i.proxy.client.KillContainer(docker.KillContainerOptions{ID: container.ID, Signal: docker.SIGUSR2}) }