dnsdisc.py: support querying multiple services

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2022-09-15 12:49:46 +02:00
parent 3137f4bc88
commit 3545787b0a
No known key found for this signature in database
GPG Key ID: 09AA5403E54D9931
1 changed files with 17 additions and 11 deletions

View File

@ -38,9 +38,9 @@ def parse_opts():
help='Consul port.') help='Consul port.')
parser.add_option('-T', '--consul-token', default=os.environ.get('CONSUL_HTTP_TOKEN'), parser.add_option('-T', '--consul-token', default=os.environ.get('CONSUL_HTTP_TOKEN'),
help='Consul API 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.') 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.') help='Name of Consul service to query.')
parser.add_option('-s', '--query-stage', default='test', parser.add_option('-s', '--query-stage', default='test',
help='Name of Consul service to query.') help='Name of Consul service to query.')
@ -169,15 +169,21 @@ def main():
token=opts.consul_token, token=opts.consul_token,
) )
LOG.debug('Querying service: %s (%s.%s)', if len(opts.query_service) == 0:
opts.query_service, opts.query_env, opts.query_stage) LOG.error('No service names to query given!')
services = catalog.all_services( sys.exit(1)
opts.query_service,
meta={ services = []
'env': opts.query_env, for service_name in opts.query_service:
'stage': opts.query_stage 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: if len(services) == 0:
LOG.error('No services found!') LOG.error('No services found!')