From 3545787b0ac2b50998a66a9282f8e80a3f5b6b6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Soko=C5=82owski?= Date: Thu, 15 Sep 2022 12:49:46 +0200 Subject: [PATCH] dnsdisc.py: support querying multiple services MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Jakub SokoĊ‚owski --- consul/dnsdisc.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/consul/dnsdisc.py b/consul/dnsdisc.py index 00fc66b..22c3546 100755 --- a/consul/dnsdisc.py +++ b/consul/dnsdisc.py @@ -38,9 +38,9 @@ def parse_opts(): help='Consul port.') parser.add_option('-T', '--consul-token', default=os.environ.get('CONSUL_HTTP_TOKEN'), help='Consul API token.') - parser.add_option('-n', '--query-service', default='nim-waku-v2-enr', + parser.add_option('-n', '--query-service', type='string', action="append", default=[], help='Name of Consul service to query.') - parser.add_option('-e', '--query-env', default='wakuv2', + parser.add_option('-e', '--query-env', default='status', help='Name of Consul service to query.') parser.add_option('-s', '--query-stage', default='test', help='Name of Consul service to query.') @@ -169,15 +169,21 @@ def main(): token=opts.consul_token, ) - LOG.debug('Querying service: %s (%s.%s)', - opts.query_service, opts.query_env, opts.query_stage) - services = catalog.all_services( - opts.query_service, - meta={ - 'env': opts.query_env, - 'stage': opts.query_stage - } - ) + if len(opts.query_service) == 0: + LOG.error('No service names to query given!') + sys.exit(1) + + services = [] + for service_name in opts.query_service: + LOG.debug('Querying service: %s (%s.%s)', + service_name, opts.query_env, opts.query_stage) + services.extend(catalog.all_services( + service_name, + meta={ + 'env': opts.query_env, + 'stage': opts.query_stage + } + )) if len(services) == 0: LOG.error('No services found!')