Created
June 27, 2018 18:32
-
-
Save danslapman/4289aa065979d3d092b1d666a9962439 to your computer and use it in GitHub Desktop.
Simple python consul client
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
class ConsulClient: | |
def __init__(self, consul_host, consul_port=8500): | |
self._service_url_template = "http://{host}:{port}/v1/catalog/service/{name}" | |
self._host = consul_host | |
self._port = consul_port | |
def get_service(self, service_name): | |
data = requests.get(self._service_url_template.format(host=self._host, port=self._port, name=service_name)) | |
return map(lambda item: {"host": item[u"ServiceAddress"], "port": item[u"ServicePort"]}, data.json()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment