當前位置: 首頁>>代碼示例>>Golang>>正文


Golang dockerclient.NewDockerClientTimeout函數代碼示例

本文整理匯總了Golang中github.com/samalba/dockerclient.NewDockerClientTimeout函數的典型用法代碼示例。如果您正苦於以下問題:Golang NewDockerClientTimeout函數的具體用法?Golang NewDockerClientTimeout怎麽用?Golang NewDockerClientTimeout使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了NewDockerClientTimeout函數的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: NewDockerProxy

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
}
開發者ID:sdgdsffdsfff,項目名稱:dockerf,代碼行數:25,代碼來源:docker_proxy.go

示例2: newDockerStressor

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
}
開發者ID:zhang0137,項目名稱:costest,代碼行數:29,代碼來源:stress.go

示例3: Connect

// 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)
}
開發者ID:abhishekamralkar,項目名稱:swarm,代碼行數:16,代碼來源:node.go

示例4: Connect

// 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)
}
開發者ID:jennifer42104,項目名稱:swarm,代碼行數:21,代碼來源:engine.go

示例5: connect

// 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)
}
開發者ID:marsmensch,項目名稱:swarm,代碼行數:21,代碼來源:node.go

示例6: waitForDockerDaemons

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))
	}
}
開發者ID:sequenceiq,項目名稱:cb-experimental,代碼行數:42,代碼來源:bootstrap.go

示例7: Connect

// 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)
}
開發者ID:yingkitw,項目名稱:swarm,代碼行數:26,代碼來源:engine.go


注:本文中的github.com/samalba/dockerclient.NewDockerClientTimeout函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。