Skip to content

Instantly share code, notes, and snippets.

@danslapman
Created June 27, 2018 18:32
Show Gist options
  • Save danslapman/4289aa065979d3d092b1d666a9962439 to your computer and use it in GitHub Desktop.
Save danslapman/4289aa065979d3d092b1d666a9962439 to your computer and use it in GitHub Desktop.
Simple python consul client
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