diff --git a/confluent_osdeploy/common/opt/confluent/bin/apiclient b/confluent_osdeploy/common/opt/confluent/bin/apiclient index bcb2fae4..488c61a2 100644 --- a/confluent_osdeploy/common/opt/confluent/bin/apiclient +++ b/confluent_osdeploy/common/opt/confluent/bin/apiclient @@ -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]