本文整理汇总了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
}
示例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
}
示例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)
}
示例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)
}
示例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)
}
示例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))
}
}
示例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)
}