2
0
mirror of https://github.com/xcat2/confluent.git synced 2026-11-22 10:22:27 +00:00

Add ssh://' support for CONFLUENT_HOST

This handles Unix domain forwarding over ssh on behalf of the user.

Extends to the nodeconsole -tv, which is particularly handy for faster video (VNC over ssh instead of base64 whole screen updates).
This commit is contained in:
Jarrod Johnson
2026-10-26 13:28:36 -04:00
parent 6426a081c0
commit c00230384f
3 changed files with 73 additions and 4 deletions
+21
View File
@@ -1213,6 +1213,27 @@ async def do_vnc(node, url, outputfile=None):
global streaming
keeprunning = True
retries = 5
if os.path.abspath(url) and 'ssh://' in os.environ.get('CONFLUENT_HOST', ''):
if not os.path.exists(url):
localpath = os.path.join(os.environ['XDG_RUNTIME_DIR'], 'confluent', 'vinz', os.path.basename(url))
os.makedirs(os.path.dirname(localpath), exist_ok=True, mode=0o700)
if os.path.exists(localpath):
try:
rdr, writer = await asyncio.open_unix_connection(localpath)
writer.close()
except Exception:
os.unlink(localpath)
if not os.path.exists(localpath):
sshhost = os.environ.get('CONFLUENT_HOST')[6:].split('/', 1)[0]
# would do '-fNT' like elsewhere, but the video tunnel exiting on close
# is nice, since we end up with another port forward for each node
sshproc = await asyncio.create_subprocess_exec(
'ssh', '-fT', '-o', 'StreamLocalBindUnlink=yes',
'-L', localpath + ':' + url, sshhost, 'sleep', '30',
stdout=asyncio.subprocess.DEVNULL,
stderr=asyncio.subprocess.DEVNULL)
await sshproc.wait()
url = localpath
while keeprunning:
try:
async with await vnc.VNCClient.create(url, outputfile=outputfile) as client:
+26 -2
View File
@@ -27,6 +27,7 @@ import os
import shlex
import socket
import ssl
import subprocess
import sys
import confluent.asynctlvdata as tlvdata
import confluent.sortutil as sortutil
@@ -194,14 +195,37 @@ class Command(object):
self.serverloc = '/var/run/confluent/api.sock'
else:
self.serverloc = server
if self.serverloc.startswith('ssh://'):
if '/' not in self.serverloc[6:]:
self.serverloc += '/var/run/confluent/api.sock'
userhost, apipath = self.serverloc[6:].split('/', 1)
if apipath[0] != '/':
apipath = '/' + apipath
serverpath = os.path.join(os.environ['XDG_RUNTIME_DIR'], 'confluent')
serverpath = os.path.join(serverpath, userhost)
localsock = os.path.join(serverpath, 'api.sock')
self.serverloc = localsock
os.makedirs(serverpath, exist_ok=True, mode=0o700)
if os.path.exists(localsock):
try:
self._connect_unix()
self.unixdomain = True
except Exception as e:
os.remove(localsock)
if not os.path.exists(localsock):
subprocess.check_call([
'ssh', '-fNT', '-o', 'StreamLocalBindUnlink=yes',
'-L', localsock + ':' + apipath,
userhost])
self.connected = False
async def ensure_connected(self):
if self.connected:
return True
if os.path.isabs(self.serverloc) and os.path.exists(self.serverloc):
self._connect_unix()
self.unixdomain = True
if not self.unixdomain:
self._connect_unix()
self.unixdomain = True
elif self.serverloc == '/var/run/confluent/api.sock':
raise Exception('Confluent service is not available')
else:
+26 -2
View File
@@ -27,6 +27,7 @@ import os
import shlex
import socket
import ssl
import subprocess
import sys
import confluent.tlvdata as tlvdata
import confluent.sortutil as sortutil
@@ -169,9 +170,32 @@ class Command(object):
self.serverloc = '/var/run/confluent/api.sock'
else:
self.serverloc = server
if self.serverloc.startswith('ssh://'):
if '/' not in self.serverloc[6:]:
self.serverloc += '/var/run/confluent/api.sock'
userhost, apipath = self.serverloc[6:].split('/', 1)
if apipath[0] != '/':
apipath = '/' + apipath
serverpath = os.path.join(os.environ['XDG_RUNTIME_DIR'], 'confluent')
serverpath = os.path.join(serverpath, userhost)
os.makedirs(serverpath, exist_ok=True, mode=0o700)
localsock = os.path.join(serverpath, 'api.sock')
self.serverloc = localsock
if os.path.exists(localsock):
try:
self._connect_unix()
self.unixdomain = True
except Exception:
os.remove(localsock)
if not os.path.exists(localsock):
subprocess.check_call([
'ssh', '-fNT', '-o', 'StreamLocalBindUnlink=yes',
'-L', localsock + ':' + apipath,
userhost])
if os.path.isabs(self.serverloc) and os.path.exists(self.serverloc):
self._connect_unix()
self.unixdomain = True
if not self.unixdomain:
self._connect_unix()
self.unixdomain = True
elif self.serverloc == '/var/run/confluent/api.sock':
raise Exception('Confluent service is not available')
else: