Exemple #1
0
func NewDockerProxy(tlsConfig string) (*DockerProxy, error) {
	tlsFlagset := flag.NewFlagSet("tls-docker-machine", flag.ExitOnError)
	flTlsVerify := tlsFlagset.Bool("tlsverify", false, "Use TLS and verify the remote")
	flCa := tlsFlagset.String("tlscacert", "", "Trust certs signed only by this CA")
	flCert := tlsFlagset.String("tlscert", "", "Path to TLS certificate file")
	flKey := tlsFlagset.String("tlskey", "", "Path to TLS key file")
	host := tlsFlagset.String("H", "", "docker daemon host")
	err := tlsFlagset.Parse(strings.Split(tlsConfig, " "))
	if err != nil {
		fmt.Errorf("Fail to parse machine config, data: %s, error: %s", tlsConfig, err.Error())
		return nil, err
	}
	config, err := loadTLSConfig(normalizeString(*flCa), normalizeString(*flCert), normalizeString(*flKey), *flTlsVerify)
	if err != nil {
		fmt.Errorf("Fail to load tls config, error: %s", err.Error())
		return nil, err
	}

	client, err := dockerclient.NewDockerClientTimeout(*host, config, time.Duration(requestTimeout*time.Second))
	if err != nil {
		fmt.Errorf("Fail to build a docker client to %s, error: %s", *host, err.Error())
		return nil, err
	}
	return &DockerProxy{client}, nil
}
Exemple #2
0
func newDockerStressor(context *cli.Context) (ds *dockerStressor, err error) {
	ds = &dockerStressor{}

	client, err := dcli.NewDockerClientTimeout(
		"unix:///var/run/docker.sock", nil, time.Second*5)
	if err != nil {
		return
	}
	ds.dockerClient = client

	scfg, err := loadStressCfg(context.String("config"))
	if err != nil {
		return
	}
	ds.stressConfig = scfg

	if context.Int("count") <= 0 {
		return nil, errors.New("flag count must > 0")
	}
	ds.containerNum = context.Int("count")

	if context.Int("concurrent") <= 0 {
		return nil, errors.New("flag concurrent must > 0")
	}
	ds.containerConCurrent = context.Int("concurrent")

	ds.containerRunTime = context.Duration("runtime")
	return
}
Exemple #3
0
// Connect will initialize a connection to the Docker daemon running on the
// host, gather machine specs (memory, cpu, ...) and monitor state changes.
func (n *Node) Connect(config *tls.Config) error {
	c, err := dockerclient.NewDockerClientTimeout(n.Addr, config, time.Duration(requestTimeout))
	if err != nil {
		return err
	}

	addr, err := net.ResolveIPAddr("ip4", strings.Split(c.URL.Host, ":")[0])
	if err != nil {
		return err
	}
	n.IP = addr.IP.String()

	return n.connectClient(c)
}
Exemple #4
0
// Connect will initialize a connection to the Docker daemon running on the
// host, gather machine specs (memory, cpu, ...) and monitor state changes.
func (e *Engine) Connect(config *tls.Config) error {
	host, _, err := net.SplitHostPort(e.Addr)
	if err != nil {
		return err
	}

	addr, err := net.ResolveIPAddr("ip4", host)
	if err != nil {
		return err
	}
	e.IP = addr.IP.String()

	c, err := dockerclient.NewDockerClientTimeout("tcp://"+e.Addr, config, time.Duration(requestTimeout))
	if err != nil {
		return err
	}

	return e.ConnectWithClient(c)
}
Exemple #5
0
// Connect will initialize a connection to the Docker daemon running on the
// host, gather machine specs (memory, cpu, ...) and monitor state changes.
func (n *node) connect(config *tls.Config) error {
	host, _, err := net.SplitHostPort(n.addr)
	if err != nil {
		return err
	}

	addr, err := net.ResolveIPAddr("ip4", host)
	if err != nil {
		return err
	}
	n.ip = addr.IP.String()

	c, err := dockerclient.NewDockerClientTimeout("tcp://"+n.addr, config, time.Duration(requestTimeout))
	if err != nil {
		return err
	}

	return n.connectClient(c)
}
func waitForDockerDaemons(wait int, nodes []string) []string {
	var maxDockerPingAttemps int = wait/SecondsBetweenDockerPings + 1
	log.Infof("[bootstrap] Trying to reach docker daemons in %v attempts.", maxDockerPingAttemps)
	var nodesFound []string
	for i := 0; ; i++ {
		if i >= maxDockerPingAttemps {
			log.Infof("[bootstrap] Max attempts were reached, %v docker daemons are available.", len(nodesFound))
			return nodesFound
		}
		if len(nodesFound) == len(nodes) {
			log.Infof("[bootstrap] All docker daemons are available.")
			return nodesFound
		}
		time.Sleep(SecondsBetweenDockerPings * time.Second)
		log.Debugf("[bootstrap] Ping docker daemons, attempt %v", i+1)
		var wg sync.WaitGroup
		for _, node := range nodes {
			wg.Add(1)
			go func(node string) {
				defer wg.Done()
				time.Sleep(1 * time.Second)
				if contains(nodesFound, node) {
					log.Debugf("[bootstrap] Docker daemon on node %s has already responded, not pinging it again.", node)
					return
				}
				client, err := docker.NewDockerClientTimeout("http://"+node, nil, time.Duration(5*time.Second))
				if err != nil {
					log.Debugf("[bootstrap] Couldn't create client for docker daemon (%s): %s", node, err)
					return
				}
				if _, err := client.Info(); err != nil {
					log.Debugf("[bootstrap] Failed to retrieve info from docker daemon (%s): %s", node, err)
				} else {
					log.Debugf("[bootstrap] Docker daemon responded on node %s.", node)
					nodesFound = append(nodesFound, node)
				}
			}(node)
		}
		wg.Wait()
		log.Infof("[bootstrap] Attempt %v: %v docker daemons are available.", i+1, len(nodesFound))
	}
}
Exemple #7
0
// Connect will initialize a connection to the Docker daemon running on the
// host, gather machine specs (memory, cpu, ...) and monitor state changes.
func (e *Engine) Connect(config *tls.Config) error {
	host, _, err := net.SplitHostPort(e.Addr)
	if err != nil {
		return err
	}

	addr, err := net.ResolveIPAddr("ip4", host)
	if err != nil {
		return err
	}
	e.IP = addr.IP.String()

	c, err := dockerclient.NewDockerClientTimeout("tcp://"+e.Addr, config, time.Duration(requestTimeout), setTCPUserTimeout)
	if err != nil {
		return err
	}
	// Use HTTP Client used by dockerclient to create engine-api client
	apiClient, err := engineapi.NewClient("tcp://"+e.Addr, "", c.HTTPClient, nil)
	if err != nil {
		return err
	}

	return e.ConnectWithClient(c, apiClient)
}