From 03e632b630d556120ac979d9da0b9fd11ac91b5b Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 14 Nov 2022 09:42:59 -0500 Subject: [PATCH] Add register to nodediscover command This connects the remote registration api to the usual CLI usage --- confluent_client/bin/nodediscover | 12 +++++++++++- confluent_server/confluent/discovery/core.py | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/confluent_client/bin/nodediscover b/confluent_client/bin/nodediscover index 1b0f6fe9..995e6f3a 100755 --- a/confluent_client/bin/nodediscover +++ b/confluent_client/bin/nodediscover @@ -50,6 +50,14 @@ columnmapping = { } #TODO: add chassis uuid +def register_endpoint(options, session, addr): + for rsp in session.update('/discovery/register', {'addresses': addr}): + if 'created' in rsp: + print('Registered: {0}'.format(rsp['created'])) + else: + sys.stderr.write(repr(rsp)) + sys.stderr.write('\n') + def subscribe_discovery(options, session, subscribe): keyn = 'subscribe' if subscribe else 'unsubscribe' payload = {keyn: options.node} @@ -372,7 +380,7 @@ def main(): parser.add_option('-o', '--order', dest='order', help='Order output by given field', metavar='ORDER') (options, args) = parser.parse_args() - if len(args) == 0 or args[0] not in ('list', 'assign', 'reassign', 'rescan', 'clear', 'subscribe', 'unsubscribe'): + if len(args) == 0 or args[0] not in ('list', 'assign', 'reassign', 'rescan', 'clear', 'subscribe', 'unsubscribe', 'register'): parser.print_help() sys.exit(1) session = client.Command() @@ -384,6 +392,8 @@ def main(): assign_discovery(options, session) if args[0] == 'reassign': assign_discovery(options, session, False) + if args[0] == 'register': + register_endpoint(options, session, args[1]) if args[0] == 'subscribe': subscribe_discovery(options, session, True) if args[0] == 'unsubscribe': diff --git a/confluent_server/confluent/discovery/core.py b/confluent_server/confluent/discovery/core.py index 34690db1..2a3d1267 100644 --- a/confluent_server/confluent/discovery/core.py +++ b/confluent_server/confluent/discovery/core.py @@ -475,10 +475,10 @@ def handle_api_request(configmanager, inputdata, operation, pathcomponents): return (msg.KeyValueData({'status': 'unsubscribed'}),) elif operation in ('update', 'create'): if pathcomponents == ['discovery', 'register']: - if 'address' not in inputdata: + if 'addresses' not in inputdata: raise exc.InvalidArgumentException('Missing address in input') nd = { - 'addresses': [(inputdata['address'], 443)] + 'addresses': [(inputdata['addresses'], 443)] } sd = ssdp.check_fish(('/DeviceDescription.json', nd)) if not sd: