Can view from web UI XML definition of domains

This commit is contained in:
2023-12-08 18:14:01 +01:00
parent 74b77be013
commit 82447a0018
13 changed files with 632 additions and 135 deletions

View File

@ -99,6 +99,20 @@ impl Handler<GetDomainXMLReq> for LibVirtActor {
}
}
#[derive(Message)]
#[rtype(result = "anyhow::Result<String>")]
pub struct GetSourceDomainXMLReq(pub XMLUuid);
impl Handler<GetSourceDomainXMLReq> for LibVirtActor {
type Result = anyhow::Result<String>;
fn handle(&mut self, msg: GetSourceDomainXMLReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Get domain source XML:\n{}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
Ok(domain.get_xml_desc(VIR_DOMAIN_XML_SECURE)?)
}
}
#[derive(Message)]
#[rtype(result = "anyhow::Result<XMLUuid>")]
pub struct DefineDomainReq(pub DomainXML);

View File

@ -73,6 +73,21 @@ pub async fn get_single(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> H
}))
}
/// Get the XML configuration of a VM
pub async fn get_single_src_def(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
let info = match client.get_single_domain_xml(id.uid).await {
Ok(i) => i,
Err(e) => {
log::error!("Failed to get domain source XML! {e}");
return Ok(HttpResponse::InternalServerError().json(e.to_string()));
}
};
Ok(HttpResponse::Ok()
.content_type("application/xml")
.body(info))
}
/// Update a VM information
pub async fn update(
client: LibVirtReq,

View File

@ -28,6 +28,13 @@ impl LibVirtClient {
self.0.send(libvirt_actor::GetDomainXMLReq(id)).await?
}
/// Get the source XML configuration of a single domain
pub async fn get_single_domain_xml(&self, id: XMLUuid) -> anyhow::Result<String> {
self.0
.send(libvirt_actor::GetSourceDomainXMLReq(id))
.await?
}
/// Update a domain
pub async fn update_domain(&self, xml: DomainXML) -> anyhow::Result<XMLUuid> {
self.0.send(libvirt_actor::DefineDomainReq(xml)).await?

View File

@ -153,6 +153,10 @@ async fn main() -> std::io::Result<()> {
.route("/api/vm/create", web::post().to(vm_controller::create))
.route("/api/vm/list", web::get().to(vm_controller::list_all))
.route("/api/vm/{uid}", web::get().to(vm_controller::get_single))
.route(
"/api/vm/{uid}/src",
web::get().to(vm_controller::get_single_src_def),
)
.route(
"/api/vm/{uid}/autostart",
web::get().to(vm_controller::get_autostart),