registry.py 1.0 KB

12345678910111213141516171819202122232425262728293031
  1. from easyfl.registry import etcd_client
  2. from easyfl.registry import k8s
  3. from easyfl.registry.vclient import VirtualClient
  4. SOURCE_MANUAL = "manual"
  5. SOURCE_ETCD = "etcd"
  6. SOURCE_K8S = "kubernetes"
  7. SOURCES = [SOURCE_MANUAL, SOURCE_ETCD, SOURCE_K8S]
  8. CLIENT_DOCKER_IMAGE = "easyfl-client"
  9. def get_clients(source, etcd_addresses=None):
  10. """Get clients from registry.
  11. Args:
  12. source (str): Registry source, options: manual, etcd, kubernetes.
  13. etcd_addresses (str, optional): The addresses of etcd service.
  14. Returns:
  15. list[:obj:`VirtualClient`]: A list of clients with addresses.
  16. """
  17. if source == SOURCE_MANUAL:
  18. return [VirtualClient("1", "localhost:23400", 0), VirtualClient("2", "localhost:23401", 1)]
  19. elif source == SOURCE_ETCD:
  20. etcd = etcd_client.EtcdClient("server", etcd_addresses, "backends")
  21. return etcd.get_clients(CLIENT_DOCKER_IMAGE)
  22. elif source == SOURCE_K8S:
  23. return k8s.get_clients()
  24. else:
  25. raise ValueError("Not supported source type")