From 49a523ca5ec5ac0bd5beb8fc6999746d901e8e73 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Fri, 17 Apr 2020 13:21:15 -0400 Subject: [PATCH] Add timezone to deploycfg This is generally needed to install an operating system. --- confluent_server/confluent/selfservice.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/confluent_server/confluent/selfservice.py b/confluent_server/confluent/selfservice.py index fd45349f..d17b5d64 100644 --- a/confluent_server/confluent/selfservice.py +++ b/confluent_server/confluent/selfservice.py @@ -1,16 +1,23 @@ import confluent.config.configmanager as configmanager import confluent.netutil as netutil import confluent.sshutil as sshutil +import eventlet.green.subprocess as subprocess import crypt import json +import time import yaml +currtz = None +currtzvintage = None + def yamldump(input): return yaml.safe_dump(input, default_flow_style=False) def handle_request(env, start_response): + global currtz + global currtzvintage nodename = env.get('HTTP_CONFLUENT_NODENAME', None) apikey = env.get('HTTP_CONFLUENT_APIKEY', None) if not (nodename and apikey): @@ -61,6 +68,19 @@ def handle_request(env, start_response): ncfg['protocol'] = 'https' ncfg['rootpassword'] = deployinfo.get('crypted.rootpassword', {}).get( 'hashvalue', None) + if currtzvintage and currtzvintage > (time.time() - 30.0): + ncfg['timezone'] = currtz + else: + tdc = subprocess.check_output(['timedatectl']).split(b'\n') + for ent in tdc: + ent = ent.strip() + if ent.startswith(b'Time zone:'): + currtz = ent.split(b': ', 1)[1].split(b'(', 1)[0].strip() + if not isinstance(currtz, str): + currtz = currtz.decode('utf8') + currtzvintage = time.time() + ncfg['timezone'] = currtz + break start_response('200 OK', (('Content-Type', retype),)) yield dumper(ncfg) elif env['PATH_INFO'] == '/self/sshcert':