From 2aed973a8bda901bff60075cbbf6d775fbbf75d4 Mon Sep 17 00:00:00 2001 From: Jarrod Johnson Date: Mon, 8 Aug 2022 11:18:35 -0400 Subject: [PATCH] Have apiclient check all hosts for connectivity Further allow it to output the result and feed that to esxi startup. --- .../initramfs/opt/confluent/bin/apiclient | 25 +++++++++++++------ .../esxi7/initramfs/bin/dcuiweasel | 2 +- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient b/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient index 9c345c38..c5c92034 100644 --- a/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient +++ b/confluent_osdeploy/common/initramfs/opt/confluent/bin/apiclient @@ -245,6 +245,7 @@ class HTTPSClient(client.HTTPConnection, object): info = open('/etc/confluent/confluent.info').read().split('\n') havedefault = '0' for line in info: + host = '' if line.startswith('NODENAME:'): node = line.split(' ')[1] self.stdheaders['CONFLUENT_NODENAME'] = node @@ -257,11 +258,12 @@ class HTTPSClient(client.HTTPConnection, object): host, mgtiface, havedefault = extinfo[:3] if havedefault == '0' and extinfo[2] == '1': host, mgtiface, havedefault = extinfo[:3] - if '%' in host: - ifidx = host.split('%', 1)[1] - with open('/tmp/confluent.ifidx', 'w+') as ifout: - ifout.write(ifidx) - self.hosts.append(host) + if '%' in host: + ifidx = host.split('%', 1)[1] + with open('/tmp/confluent.ifidx', 'w+') as ifout: + ifout.write(ifidx) + if host: + self.hosts.append(host) try: info = open('/etc/confluent/confluent.deploycfg').read().split('\n') except Exception: @@ -417,6 +419,13 @@ if __name__ == '__main__': phmac = sys.argv.pop(phmac) except ValueError: phmac = None + try: + checkonly = False + idxit = sys.argv.index('-c') + sys.argv.pop(idxit) + checkonly = True + except Exception: + pass if len(sys.argv) > 2 and os.path.exists(sys.argv[-1]): data = open(sys.argv[-1]).read() if outbin: @@ -428,11 +437,13 @@ if __name__ == '__main__': outf.write(chunk) chunk = reader.read(16384) sys.exit(0) + client = HTTPSClient(usejson, errout=errout, phmac=phmac) if waitfor: - client = HTTPSClient(usejson, errout=errout) status = 201 while status != waitfor: status, rsp = client.grab_url_with_status(sys.argv[1], data) sys.stdout.write(rsp.decode()) + elif checkonly: + sys.stdout.write(client.check_connections()) else: - sys.stdout.write(HTTPSClient(usejson, errout=errout, phmac=phmac).grab_url(sys.argv[1], data).decode()) + sys.stdout.write(client.grab_url(sys.argv[1], data).decode()) diff --git a/confluent_osdeploy/esxi7/initramfs/bin/dcuiweasel b/confluent_osdeploy/esxi7/initramfs/bin/dcuiweasel index 07d0fac0..075497c8 100644 --- a/confluent_osdeploy/esxi7/initramfs/bin/dcuiweasel +++ b/confluent_osdeploy/esxi7/initramfs/bin/dcuiweasel @@ -75,7 +75,7 @@ while ! grep NODENAME /etc/confluent/confluent.info; do fi done node=$(grep NODENAME: /etc/confluent/confluent.info|head -n 1|awk '{print $2}') -mgr=$(grep MANAGER: /etc/confluent/confluent.info|head -n 1|awk '{print $2}') +mgr=$(python /opt/confluent/bin/apiclient -c) APIKEY=$(cat /etc/confluent/confluent.apikey) if [ -z "$APIKEY" ]; then