First successful VNC connection

This commit is contained in:
2023-10-18 18:00:25 +02:00
parent 4f75cd918d
commit b87306f8ea
14 changed files with 422 additions and 5 deletions

View File

@ -83,6 +83,12 @@ impl From<reqwest::header::ToStrError> for HttpErr {
}
}
impl From<actix_web::Error> for HttpErr {
fn from(value: actix_web::Error) -> Self {
HttpErr::Err(std::io::Error::new(ErrorKind::Other, value.to_string()).into())
}
}
impl From<HttpResponse> for HttpErr {
fn from(value: HttpResponse) -> Self {
HttpErr::HTTPResponse(value)

View File

@ -1,8 +1,10 @@
use crate::actors::vnc_actor::VNCActor;
use crate::actors::vnc_tokens_actor::VNCTokensManager;
use crate::controllers::{HttpResult, LibVirtReq};
use crate::libvirt_lib_structures::{DomainState, DomainXMLUuid};
use crate::libvirt_rest_structures::VMInfo;
use actix_web::{web, HttpResponse};
use actix_web::{web, HttpRequest, HttpResponse};
use actix_web_actors::ws;
#[derive(serde::Serialize)]
struct VMInfoAndState {
@ -231,3 +233,31 @@ pub async fn vnc_token(
}
})
}
#[derive(serde::Deserialize)]
pub struct VNCTokenQuery {
token: String,
}
/// Start a VNC connection
pub async fn vnc(
client: LibVirtReq,
manager: web::Data<VNCTokensManager>,
token: web::Query<VNCTokenQuery>,
req: HttpRequest,
stream: web::Payload,
) -> HttpResult {
let domain_id = manager.consume_token(token.0.token).await?;
let domain = client.get_single_domain(domain_id).await?;
let socket_path = match domain.devices.graphics {
None => {
log::error!("Attempted to open VNC for a domain where VNC is disabled!");
return Ok(HttpResponse::ServiceUnavailable().json("VNC is not enabled!"));
}
Some(g) => g.socket,
};
log::info!("Start VNC connection on socket {socket_path}");
Ok(ws::start(VNCActor::new(&socket_path).await?, &req, stream)?)
}