machines.go 504 B

123456789101112131415161718192021222324252627
  1. package main
  2. import (
  3. "fmt"
  4. "path"
  5. "strings"
  6. )
  7. func getClientAddr(name string) (string, bool) {
  8. response, _ := etcdStore.RawGet(path.Join("_etcd/machines", name))
  9. values := strings.Split(response[0].Value, ",")
  10. hostname := values[0]
  11. clientPort := values[2]
  12. addr := fmt.Sprintf("%s:%s", hostname, clientPort)
  13. return addr, true
  14. }
  15. // machineNum returns the number of machines in the cluster
  16. func machineNum() int {
  17. response, _ := etcdStore.RawGet("_etcd/machines")
  18. return len(response)
  19. }