func waitFor(once *sync.Once, client *dockerclient.Client, endpoint string) { once.Do(func() { err := ClientOK(endpoint, func() bool { _, err := client.Info() return err == nil }) if err != nil { panic(err.Error()) } }) }
// Determines how many nodes are available in the swarm for use in getScale() func getNodes(client *dockerclient.Client) int { var env []interface{} info, _ := client.Info() envs := info.Map() json.Unmarshal([]byte(envs["DriverStatus"]), &env) for _, e := range env { v := e.([]interface{}) if v[0] == "\bNodes" { nodes, _ := strconv.Atoi(v[1].(string)) return nodes } } return 0 }
func New(endpoint, certPath string) (d Docker, err error) { var c *dockerclient.Client if certPath != "" { cert := fmt.Sprintf("%s/cert.pem", certPath) key := fmt.Sprintf("%s/key.pem", certPath) ca := fmt.Sprintf("%s/ca.pem", certPath) c, err = dockerclient.NewTLSClient(endpoint, cert, key, ca) } else { c, err = dockerclient.NewClient(endpoint) } if err != nil { return } log.Debugln("Connecting to Docker on:", endpoint) if _, err := c.Info(); err != nil { return d, err } d = Docker{client: c} return }
func GetConnection(dockerSocket string) (*DockerClient, error) { var ( client *gdocker.Client err error info *engine.Env executionDriver string ) client, err = gdocker.NewClient(dockerSocket) if err != nil { fmt.Println("Unable to connect to docker server:", err.Error()) return nil, err } if info, err = client.Info(); err != nil { return nil, err } executionDriver = info.Get("ExecutionDriver") return &DockerClient{client, executionDriver}, nil }