Return VM state
This commit is contained in:
@ -1,9 +1,10 @@
|
||||
use crate::app_config::AppConfig;
|
||||
use crate::libvirt_lib_structures::{DomainXML, DomainXMLUuid};
|
||||
use crate::libvirt_lib_structures::{DomainState, DomainXML, DomainXMLUuid};
|
||||
use crate::libvirt_rest_structures::*;
|
||||
use actix::{Actor, Context, Handler, Message};
|
||||
use virt::connect::Connect;
|
||||
use virt::domain::Domain;
|
||||
use virt::sys;
|
||||
use virt::sys::VIR_DOMAIN_XML_SECURE;
|
||||
|
||||
pub struct LibVirtActor {
|
||||
@ -88,3 +89,29 @@ impl Handler<DefineDomainReq> for LibVirtActor {
|
||||
DomainXMLUuid::parse_from_str(&domain.get_uuid_string()?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<DomainState>")]
|
||||
pub struct GetDomainStateReq(pub DomainXMLUuid);
|
||||
|
||||
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());
|
||||
let domain = Domain::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
|
||||
let (state, _) = domain.get_state()?;
|
||||
Ok(match state {
|
||||
sys::VIR_DOMAIN_NOSTATE => DomainState::NoState,
|
||||
sys::VIR_DOMAIN_RUNNING => DomainState::Running,
|
||||
sys::VIR_DOMAIN_BLOCKED => DomainState::Blocked,
|
||||
sys::VIR_DOMAIN_PAUSED => DomainState::Paused,
|
||||
sys::VIR_DOMAIN_SHUTDOWN => DomainState::Shutdown,
|
||||
sys::VIR_DOMAIN_SHUTOFF => DomainState::Shutoff,
|
||||
sys::VIR_DOMAIN_CRASHED => DomainState::Crashed,
|
||||
sys::VIR_DOMAIN_PMSUSPENDED => DomainState::PowerManagementSuspended,
|
||||
|
||||
_ => DomainState::Other,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user