From 7dcad26002eaab1ef48f805e17bf05ba61e00f97 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Wed, 13 May 2020 16:29:10 -0400 Subject: [PATCH] Add hook for registering install completion This will allow watching the profile for changes to know when install is utterly complete. --- .../confluent/config/attributes.py | 7 ++++++ confluent_server/confluent/selfservice.py | 22 +++++++++++++++++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/confluent_server/confluent/config/attributes.py b/confluent_server/confluent/config/attributes.py index e9d2a56d..d8ccadac 100644 --- a/confluent_server/confluent/config/attributes.py +++ b/confluent_server/confluent/config/attributes.py @@ -175,6 +175,13 @@ node = { 'the network boot subsystem what should be offered when a potential ' 'network boot request comes in') }, + 'deployment.profile': { + 'description': ('The profile that has most recently reported ' + 'completion of deployment. Note that an image may opt ' + 'to leave itself both current and pending, for example ' + 'a stateless profile would be both after first boot.') + + }, 'deployment.useinsecureprotocols': { 'description': ('What phase(s) of boot are permitted to use insecure protocols ' '(TFTP and HTTP without TLS. By default, HTTPS is allowed. However ' diff --git a/confluent_server/confluent/selfservice.py b/confluent_server/confluent/selfservice.py index ee9f8f33..4e1a2648 100644 --- a/confluent_server/confluent/selfservice.py +++ b/confluent_server/confluent/selfservice.py @@ -106,13 +106,31 @@ def handle_request(env, start_response): nodes.add(mgr) nodes.add(collective.get_myname()) if isgeneric: - start_response('200 OK', (('Contennt-Type', 'text/plain'),)) + start_response('200 OK', (('Content-Type', 'text/plain'),)) for node in util.natural_sort(nodes): yield node + '\n' else: start_response('200 OK', (('Content-Type', retype),)) yield dumper(sorted(nodes)) - + elif env['PATH_INFO'] == '/self/updatestatus': + update = yaml.safe_load(reqbody) + if update['status'] != 'complete': + raise Exception('Unknown update status request') + currattr = cfg.get_node_attributes(nodename, 'deployment.*').get( + nodename, {}) + pending = currattr.get('deployment.pendingprofile', {}).get('value', '') + updates = {} + if pending: + updates['deployment.pendingprofile'] = {'value': ''} + currprof = currattr.get('deployment.profile', {}).get('value', '') + if currprof != pending: + updates['deployment.profile'] = {'value': pending} + cfg.set_node_attributes({nodename: updates}) + start_response('200 OK', ('Content-Type', 'text/plain')) + yield 'OK' + else: + start_response('500 Error', ('Content-Type', 'text/plain')) + yield 'No pending profile detected, unable to accept status update' else: start_response('404 Not Found', ()) yield 'Not found' \ No newline at end of file