From 924f679f797ddf3cdf804f4db622c4dbdf2a1b53 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Tue, 23 Jan 2018 13:27:20 -0500 Subject: [PATCH] Add ability to delete discovery entry This allows a full purge without restarting confluent. --- confluent_server/confluent/discovery/core.py | 24 +++++++++++++------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/confluent_server/confluent/discovery/core.py b/confluent_server/confluent/discovery/core.py index 62337458..f25519ae 100644 --- a/confluent_server/confluent/discovery/core.py +++ b/confluent_server/confluent/discovery/core.py @@ -359,15 +359,10 @@ def handle_api_request(configmanager, inputdata, operation, pathcomponents): raise exc.InvalidArgumentException() rescan() return (msg.KeyValueData({'rescan': 'started'}),) - elif (operation in ('update', 'create')): + elif operation in ('update', 'create'): if 'node' not in inputdata: raise exc.InvalidArgumentException('Missing node name in input') - _, queryparms, _, _ = _parameterize_path(pathcomponents[1:]) - if 'by-mac' not in queryparms: - raise exc.InvalidArgumentException('Must target using "by-mac"') - mac = queryparms['by-mac'].replace('-', ':') - if mac not in known_info: - raise exc.NotFoundException('{0} not found'.format(mac)) + mac = _get_mac_from_query(pathcomponents) info = known_info[mac] if info['handler'] is None: raise exc.NotImplementedException( @@ -377,10 +372,24 @@ def handle_api_request(configmanager, inputdata, operation, pathcomponents): eval_node(configmanager, handler, info, inputdata['node'], manual=True) return [msg.AssignedResource(inputdata['node'])] + elif operation == 'delete': + mac = _get_mac_from_query(pathcomponents) + del known_info[mac] + return [msg.DeletedResource(mac)] raise exc.NotImplementedException( 'Unable to {0} to {1}'.format(operation, '/'.join(pathcomponents))) +def _get_mac_from_query(pathcomponents): + _, queryparms, _, _ = _parameterize_path(pathcomponents[1:]) + if 'by-mac' not in queryparms: + raise exc.InvalidArgumentException('Must target using "by-mac"') + mac = queryparms['by-mac'].replace('-', ':') + if mac not in known_info: + raise exc.NotFoundException('{0} not found'.format(mac)) + return mac + + def handle_read_api_request(pathcomponents): # TODO(jjohnson2): This should be more generalized... # odd indexes into components are 'by-'*, even indexes @@ -812,7 +821,6 @@ def get_nodename_from_enclosures(cfg, info): def eval_node(cfg, handler, info, nodename, manual=False): try: handler.probe() # unicast interrogation as possible to get more data - # for now, we search switch only, ideally we search cmm, smm, and # switch concurrently # do some preconfig, for example, to bring a SMM online if applicable errorstr = handler.preconfig()