Example #1
0
File: proxy.go Project: brb/weave
func NewProxy(c Config) (*Proxy, error) {
	p := &Proxy{
		Config:     c,
		waiters:    make(map[*http.Request]*wait),
		attachJobs: make(map[string]*attachJob),
		quit:       make(chan struct{}),
	}

	if err := p.TLSConfig.LoadCerts(); err != nil {
		Log.Fatalf("Could not configure tls for proxy: %s", err)
	}

	// We pin the protocol version to 1.18 (which corresponds to
	// Docker 1.6.x; the earliest version supported by weave) in order
	// to insulate ourselves from breaking changes to the API, as
	// happened in 1.20 (Docker 1.8.0) when the presentation of
	// volumes changed in `inspect`.
	client, err := weavedocker.NewVersionedClient(c.DockerHost, "1.18")
	if err != nil {
		return nil, err
	}
	Log.Info(client.Info())

	p.client = client.Client

	if !p.WithoutDNS {
		netDevs, err := GetBridgeNetDev(c.ProcPath, c.DockerBridge)
		if err != nil {
			return nil, err
		}
		if len(netDevs) != 1 || len(netDevs[0].CIDRs) != 1 {
			return nil, fmt.Errorf("Could not obtain address of %s", c.DockerBridge)
		}
		p.dockerBridgeIP = netDevs[0].CIDRs[0].IP.String()
	}

	p.hostnameMatchRegexp, err = regexp.Compile(c.HostnameMatch)
	if err != nil {
		err := fmt.Errorf("Incorrect hostname match '%s': %s", c.HostnameMatch, err.Error())
		return nil, err
	}

	if err = p.findWeaveWaitVolumes(); err != nil {
		return nil, err
	}

	client.AddObserver(p)

	return p, nil
}
Example #2
0
func NewProxy(c Config) (*Proxy, error) {
	p := &Proxy{Config: c, waiters: make(map[*http.Request]*wait)}

	if err := p.TLSConfig.LoadCerts(); err != nil {
		Log.Fatalf("Could not configure tls for proxy: %s", err)
	}

	// We pin the protocol version to 1.18 (which corresponds to
	// Docker 1.6.x; the earliest version supported by weave) in order
	// to insulate ourselves from breaking changes to the API, as
	// happened in 1.20 (Docker 1.8.0) when the presentation of
	// volumes changed in `inspect`.
	client, err := weavedocker.NewVersionedClient(c.DockerHost, "1.18")
	if err != nil {
		return nil, err
	}
	Log.Info(client.Info())

	p.client = client.Client

	if !p.WithoutDNS {
		dockerBridgeIP, stderr, err := callWeave("docker-bridge-ip")
		if err != nil {
			return nil, fmt.Errorf(string(stderr))
		}
		p.dockerBridgeIP = string(dockerBridgeIP)
	}

	p.hostnameMatchRegexp, err = regexp.Compile(c.HostnameMatch)
	if err != nil {
		err := fmt.Errorf("Incorrect hostname match '%s': %s", c.HostnameMatch, err.Error())
		return nil, err
	}

	if err = p.findWeaveWaitVolumes(); err != nil {
		return nil, err
	}

	client.AddObserver(p)

	return p, nil
}