Skip to content
This repository was archived by the owner on May 30, 2024. It is now read-only.

feat: add tag filter to Catalog.services #40

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion consul/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1930,6 +1930,7 @@ def services(self,
index=None,
wait=None,
consistency=None,
tag=None,
dc=None,
token=None,
node_meta=None):
Expand All @@ -1949,6 +1950,9 @@ def services(self,
not specified *consistency* will the consistency level this client
was configured with.

If *tag* is provided, the list of services returned will be filtered
by that tag.

*token* is an optional `ACL token`_ to apply to this request.

*node_meta* is an optional meta data used for filtering, a
Expand All @@ -1969,6 +1973,7 @@ def services(self,
known tags for a given service.
"""
params = []
results = {}
headers = {}
dc = dc or self.agent.dc
if dc:
Expand All @@ -1987,9 +1992,16 @@ def services(self,
for nodemeta_name, nodemeta_value in node_meta.items():
params.append(('node-meta', '{0}:{1}'.
format(nodemeta_name, nodemeta_value)))
return self.agent.http.get(
index, consul_services = self.agent.http.get(
CB.json(index=True), path='/v1/catalog/services',
params=params, headers=headers)
if tag:
for key in consul_services:
for consul_tag in consul_services[key]:
if consul_tag == tag:
results[key] = consul_services[key]
return (index, results)
return (index, consul_services)

def node(self,
node,
Expand Down