Can update or delete domains

This commit is contained in:
2023-10-13 16:44:56 +02:00
parent 52d7e35d10
commit 6a3cf2e5c8
6 changed files with 111 additions and 22 deletions

View File

@ -113,6 +113,34 @@ impl Handler<DefineDomainReq> for LibVirtActor {
}
}
#[derive(Message)]
#[rtype(result = "anyhow::Result<()>")]
pub struct DeleteDomainReq {
pub id: DomainXMLUuid,
pub keep_files: bool,
}
impl Handler<DeleteDomainReq> for LibVirtActor {
type Result = anyhow::Result<()>;
fn handle(&mut self, msg: DeleteDomainReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!(
"Delete domain: {:?} (keep files: {})",
msg.id,
msg.keep_files
);
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.id.as_string())?;
domain.undefine_flags(match msg.keep_files {
true => sys::VIR_DOMAIN_UNDEFINE_KEEP_NVRAM,
false => sys::VIR_DOMAIN_UNDEFINE_NVRAM,
})?;
// TODO : delete files, if requested
Ok(())
}
}
#[derive(Message)]
#[rtype(result = "anyhow::Result<DomainState>")]
pub struct GetDomainStateReq(pub DomainXMLUuid);
@ -121,7 +149,7 @@ impl Handler<GetDomainStateReq> for LibVirtActor {
type Result = anyhow::Result<DomainState>;
fn handle(&mut self, msg: GetDomainStateReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Get domain state:\n{}", msg.0.as_string());
log::debug!("Get domain state: {}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
let (state, _) = domain.get_state()?;
Ok(match state {
@ -147,7 +175,7 @@ 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());
log::debug!("Start domain: {}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
domain.create()?;
Ok(())
@ -162,7 +190,7 @@ impl Handler<ShutdownDomainReq> for LibVirtActor {
type Result = anyhow::Result<()>;
fn handle(&mut self, msg: ShutdownDomainReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Shutdown domain:\n{}", msg.0.as_string());
log::debug!("Shutdown domain: {}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
domain.shutdown()?;
Ok(())
@ -177,7 +205,7 @@ impl Handler<KillDomainReq> for LibVirtActor {
type Result = anyhow::Result<()>;
fn handle(&mut self, msg: KillDomainReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Kill domain:\n{}", msg.0.as_string());
log::debug!("Kill domain: {}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
domain.destroy()?;
Ok(())
@ -192,7 +220,7 @@ impl Handler<ResetDomainReq> for LibVirtActor {
type Result = anyhow::Result<()>;
fn handle(&mut self, msg: ResetDomainReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Reset domain:\n{}", msg.0.as_string());
log::debug!("Reset domain: {}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
domain.reset()?;
Ok(())
@ -207,7 +235,7 @@ impl Handler<SuspendDomainReq> for LibVirtActor {
type Result = anyhow::Result<()>;
fn handle(&mut self, msg: SuspendDomainReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Suspend domain:\n{}", msg.0.as_string());
log::debug!("Suspend domain: {}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
domain.suspend()?;
Ok(())
@ -222,7 +250,7 @@ impl Handler<ResumeDomainReq> for LibVirtActor {
type Result = anyhow::Result<()>;
fn handle(&mut self, msg: ResumeDomainReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Resume domain:\n{}", msg.0.as_string());
log::debug!("Resume domain: {}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
domain.resume()?;
Ok(())
@ -237,7 +265,7 @@ impl Handler<ScreenshotDomainReq> for LibVirtActor {
type Result = anyhow::Result<Vec<u8>>;
fn handle(&mut self, msg: ScreenshotDomainReq, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Take screenshot of domain:\n{}", msg.0.as_string());
log::debug!("Take screenshot of domain: {}", msg.0.as_string());
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
let stream = Stream::new(&self.m, 0)?;