chore: remove terminal ssh code
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@ -696,10 +696,7 @@ async fn v1_terminal_proxy(
|
||||
match msg {
|
||||
Ok(m) => {
|
||||
let m_up = match m {
|
||||
Message::Text(t) => {
|
||||
info!("Got msg: {}", t);
|
||||
t.as_bytes().to_vec()
|
||||
}
|
||||
Message::Text(t) => t.as_bytes().to_vec(),
|
||||
_ => panic!("todo"),
|
||||
};
|
||||
if let Err(e) = ws_upstream.send(m_up).await {
|
||||
@ -723,7 +720,6 @@ async fn v1_terminal_proxy(
|
||||
match msg {
|
||||
Ok(m) => {
|
||||
let down = String::from_utf8_lossy(&m).into_owned();
|
||||
info!("Got down msg: {}", &down);
|
||||
let m_down = Message::Text(down);
|
||||
if let Err(e) = tx_client.send(m_down).await {
|
||||
bail!("Failed to msg to client: {}", e);
|
||||
|
@ -19,8 +19,8 @@ use std::io::{Read, Write};
|
||||
use std::net::IpAddr;
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use std::sync::Arc;
|
||||
use std::sync::atomic::{AtomicBool, Ordering};
|
||||
use std::sync::Arc;
|
||||
use std::time::Duration;
|
||||
use tokio::io::{AsyncRead, AsyncReadExt, AsyncWrite, AsyncWriteExt};
|
||||
use tokio::sync::mpsc::channel;
|
||||
@ -664,67 +664,30 @@ impl VmHostClient for ProxmoxClient {
|
||||
}
|
||||
|
||||
async fn connect_terminal(&self, vm: &Vm) -> Result<TerminalStream> {
|
||||
// the proxmox api for terminal connection is weird and doesn't work
|
||||
// when I tested it, using ssh instead to run qm terminal command
|
||||
|
||||
if let Some(ssh_config) = &self.ssh {
|
||||
let mut ses = SshClient::new()?;
|
||||
ses.connect(
|
||||
(self.api.base.host().unwrap().to_string(), 22),
|
||||
&ssh_config.user,
|
||||
&ssh_config.key,
|
||||
)
|
||||
.await?;
|
||||
|
||||
let vm_id: ProxmoxVmId = vm.id.into();
|
||||
let sock_path = PathBuf::from(&format!("/var/run/qemu-server/{}.serial0", vm_id));
|
||||
let mut chan = ses.tunnel_unix_socket(&sock_path)?;
|
||||
|
||||
let (mut client_tx, client_rx) = channel::<Vec<u8>>(1024);
|
||||
let (server_tx, mut server_rx) = channel::<Vec<u8>>(1024);
|
||||
let shutdown = Arc::new(AtomicBool::new(false));
|
||||
let shut_chan = shutdown.clone();
|
||||
tokio::spawn(async move {
|
||||
let mut w_buf = vec![0; 4096];
|
||||
|
||||
// fire calls to read every 100ms
|
||||
let mut chan_timer = time::interval(Duration::from_millis(100));
|
||||
loop {
|
||||
tokio::select! {
|
||||
Some(buf) = server_rx.recv() => {
|
||||
if let Err(e) = chan.write_all(&buf) {
|
||||
error!("Failed to send data: {}", e);
|
||||
}
|
||||
}
|
||||
_ = chan_timer.tick() => {
|
||||
if chan.eof() {
|
||||
info!("SSH connection terminated!");
|
||||
shut_chan.store(true, Ordering::Relaxed);
|
||||
break;
|
||||
}
|
||||
let r_window = chan.read_window();
|
||||
|
||||
let mut stream = chan.stream(0);
|
||||
if let Ok(r) = stream.read(w_buf.as_mut_slice()) {
|
||||
if r > 0 {
|
||||
if let Err(e) = client_tx.send(w_buf[..r].to_vec()).await {
|
||||
error!("Failed to write data: {}", e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// echo
|
||||
client_tx.send(buf).await?;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
info!("SSH connection terminated!");
|
||||
Ok::<(), anyhow::Error>(())
|
||||
});
|
||||
return Ok(TerminalStream{
|
||||
Ok(TerminalStream {
|
||||
shutdown,
|
||||
rx: client_rx,
|
||||
tx: server_tx,
|
||||
});
|
||||
}
|
||||
bail!("Cannot use terminal proxy without ssh")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user