Can start a domain
This commit is contained in:
parent
908b0f4c56
commit
0c7128e6eb
@ -135,3 +135,18 @@ impl Handler<GetDomainStateReq> for LibVirtActor {
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<()>")]
|
||||
pub struct StartDomainReq(pub DomainXMLUuid);
|
||||
|
||||
impl Handler<StartDomainReq> for LibVirtActor {
|
||||
type Result = anyhow::Result<()>;
|
||||
|
||||
fn handle(&mut self, msg: StartDomainReq, _ctx: &mut Self::Context) -> Self::Result {
|
||||
log::debug!("Start domain:\n{}", msg.0.as_string());
|
||||
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
|
||||
domain.create()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
@ -64,3 +64,14 @@ pub async fn get_single(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> H
|
||||
state,
|
||||
}))
|
||||
}
|
||||
|
||||
/// Start a VM
|
||||
pub async fn start(client: LibVirtReq, id: web::Path<SingleVMUUidReq>) -> HttpResult {
|
||||
Ok(match client.start_domain(id.uid).await {
|
||||
Ok(_) => HttpResponse::Ok().json("Domain started"),
|
||||
Err(e) => {
|
||||
log::error!("Failed to start domain {:?} ! {e}", id.uid);
|
||||
HttpResponse::InternalServerError().json("Failed to start domain!")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -37,4 +37,9 @@ impl LibVirtClient {
|
||||
pub async fn get_domain_state(&self, id: DomainXMLUuid) -> anyhow::Result<DomainState> {
|
||||
self.0.send(libvirt_actor::GetDomainStateReq(id)).await?
|
||||
}
|
||||
|
||||
/// Start a domain
|
||||
pub async fn start_domain(&self, id: DomainXMLUuid) -> anyhow::Result<()> {
|
||||
self.0.send(libvirt_actor::StartDomainReq(id)).await?
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy)]
|
||||
#[derive(serde::Serialize, serde::Deserialize, Clone, Copy, Debug)]
|
||||
pub struct DomainXMLUuid(pub uuid::Uuid);
|
||||
|
||||
impl DomainXMLUuid {
|
||||
|
@ -66,6 +66,11 @@ pub struct VMInfo {
|
||||
pub architecture: VMArchitecture,
|
||||
/// VM allocated memory, in megabytes
|
||||
pub memory: usize,
|
||||
// TODO : storage
|
||||
// TODO : iso
|
||||
// TODO : autostart
|
||||
// TODO : vnc
|
||||
// TODO : interface
|
||||
}
|
||||
|
||||
impl VMInfo {
|
||||
|
@ -138,6 +138,7 @@ 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}/start", web::get().to(vm_controller::start))
|
||||
})
|
||||
.bind(&AppConfig::get().listen_address)?
|
||||
.run()
|
||||
|
Loading…
Reference in New Issue
Block a user