2
0
mirror of https://github.com/xcat2/confluent.git synced 2025-01-12 10:49:17 +00:00

Amend apiclient to support v4/v6

This commit is contained in:
Jarrod Johnson 2021-09-09 17:15:29 -04:00
parent 11796cda81
commit 35b74764bf

View File

@ -13,7 +13,7 @@ import time
class InvalidApiKey(Exception):
pass
def get_apikey(nodename, mgr):
def get_apikey(nodename, mgr, mgr6):
apikey = ""
if os.path.exists('/etc/confluent/confluent.apikey'):
apikey = open('/etc/confluent/confluent.apikey').read().strip()
@ -23,7 +23,10 @@ def get_apikey(nodename, mgr):
try:
apikey = subprocess.check_output(['/opt/confluent/bin/clortho', nodename, mgr])
except subprocess.CalledProcessError:
apikey = ''
try:
apikey = subprocess.check_output(['/opt/confluent/bin/clortho', nodename, mgr6])
except subprocess.CalledProcessError:
apikey = ''
if not isinstance(apikey, str):
apikey = apikey.decode('utf8')
if apikey.startswith('SEALED:'):
@ -68,26 +71,37 @@ class HTTPSClient(client.HTTPConnection, object):
info = open('/etc/confluent/confluent.deploycfg').read().split('\n')
except Exception:
info = None
v4srv = None
v6srv = None
if info:
for line in info:
if line.startswith('deploy_server: '):
host = line.split(': ', 1)[1]
break
self.stdheaders['CONFLUENT_APIKEY'] = get_apikey(node, host)
v4srv = line.split(': ', 1)[1]
if line.startswith('deploy_server_v6: '):
v6srv = line.split(': ', 1)[1]
self.stdheaders['CONFLUENT_APIKEY'] = get_apikey(node, v4srv, v6srv)
if mgtiface:
self.stdheaders['CONFLUENT_MGTIFACE'] = mgtiface
client.HTTPConnection.__init__(self, host, port)
self.host = host
self.node = node
self.v4srv = v4srv
self.v6srv = v6srv
self.connect()
client.HTTPConnection.__init__(self, host, port)
self.node = node
def set_header(self, key, val):
self.stdheaders[key] = val
def connect(self):
addrinf = socket.getaddrinfo(self.host, self.port)[0]
psock = socket.socket(addrinf[0])
psock.connect(addrinf[4])
try:
addrinf = socket.getaddrinfo(self.v4srv, self.port)[0]
psock = socket.socket(addrinf[0])
psock.connect(addrinf[4])
self.host = self.v4srv
except OSError:
addrinf = socket.getaddrinfo(self.v6srv, self.port)[0]
psock = socket.socket(addrinf[0])
psock.connect(addrinf[4])
self.host = self.v6srv
ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23)
ctx.load_verify_locations('/etc/confluent/ca.pem')
host = self.host.split('%', 1)[0]