etcd.tmpl 718 B

12345678910111213141516171819202122232425262728293031323334353637
  1. #!/usr/bin/python
  2. import etcd3
  3. import sys
  4. etcd_host = "{{ .Env.ETCD_HOST }}"
  5. if not etcd_host:
  6. print("ETCD_HOST not set")
  7. sys.exit(1)
  8. port = 2379
  9. host = etcd_host
  10. if ":" in etcd_host:
  11. host, port = etcd_host.split(":")
  12. print("{}:{}".format(host, port))
  13. client = etcd3.client(host=host, port=int(port))
  14. {{ $local := . }}
  15. {{ range $key, $value := . }}
  16. {{ $addrLen := len $value.Addresses }}
  17. {{ if gt $addrLen 0 }}
  18. {{ with $address := index $value.Addresses 0 }}
  19. {{ if $address.HostPort}}
  20. client.put("/backends/{{ $value.Image.Repository }}/{{ $local.Env.HOST_IP }}:{{ $address.HostPort }}", "{{ $value.Name }}")
  21. {{end}}
  22. {{end}}
  23. {{end}}
  24. {{end}}