Ready to implement network routes contents
This commit is contained in:
@ -367,10 +367,12 @@ impl Handler<DefineNetwork> for LibVirtActor {
|
||||
msg.0.ips = vec![];
|
||||
|
||||
let mut network_xml = serde_xml_rs::to_string(&msg.0)?;
|
||||
log::trace!("Serialize network XML start: {network_xml}");
|
||||
|
||||
let ips_xml = ips_xml.join("\n");
|
||||
network_xml = network_xml.replacen("</network>", &format!("{ips_xml}</network>"), 1);
|
||||
|
||||
log::debug!("Source network structure: {:#?}", msg.0);
|
||||
log::debug!("Define network XML: {network_xml}");
|
||||
|
||||
let network = Network::define_xml(&self.m, &network_xml)?;
|
||||
@ -428,3 +430,83 @@ impl Handler<DeleteNetwork> for LibVirtActor {
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<bool>")]
|
||||
pub struct IsNetworkAutostart(pub XMLUuid);
|
||||
|
||||
impl Handler<IsNetworkAutostart> for LibVirtActor {
|
||||
type Result = anyhow::Result<bool>;
|
||||
|
||||
fn handle(&mut self, msg: IsNetworkAutostart, _ctx: &mut Self::Context) -> Self::Result {
|
||||
log::debug!(
|
||||
"Check if autostart is enabled for a network: {}",
|
||||
msg.0.as_string()
|
||||
);
|
||||
let network = Network::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
|
||||
Ok(network.get_autostart()?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<()>")]
|
||||
pub struct SetNetworkAutostart(pub XMLUuid, pub bool);
|
||||
|
||||
impl Handler<SetNetworkAutostart> for LibVirtActor {
|
||||
type Result = anyhow::Result<()>;
|
||||
|
||||
fn handle(&mut self, msg: SetNetworkAutostart, _ctx: &mut Self::Context) -> Self::Result {
|
||||
log::debug!(
|
||||
"Set autostart enabled={} for a network: {}",
|
||||
msg.1,
|
||||
msg.0.as_string()
|
||||
);
|
||||
let network = Network::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
|
||||
network.set_autostart(msg.1)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<bool>")]
|
||||
pub struct IsNetworkStarted(pub XMLUuid);
|
||||
|
||||
impl Handler<IsNetworkStarted> for LibVirtActor {
|
||||
type Result = anyhow::Result<bool>;
|
||||
|
||||
fn handle(&mut self, msg: IsNetworkStarted, _ctx: &mut Self::Context) -> Self::Result {
|
||||
log::debug!("Check if a network is started: {}", msg.0.as_string());
|
||||
let network = Network::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
|
||||
Ok(network.is_active()?)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<()>")]
|
||||
pub struct StartNetwork(pub XMLUuid);
|
||||
|
||||
impl Handler<StartNetwork> for LibVirtActor {
|
||||
type Result = anyhow::Result<()>;
|
||||
|
||||
fn handle(&mut self, msg: StartNetwork, _ctx: &mut Self::Context) -> Self::Result {
|
||||
log::debug!("Start a network: {}", msg.0.as_string());
|
||||
let network = Network::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
|
||||
network.create()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Message)]
|
||||
#[rtype(result = "anyhow::Result<()>")]
|
||||
pub struct StopNetwork(pub XMLUuid);
|
||||
|
||||
impl Handler<StopNetwork> for LibVirtActor {
|
||||
type Result = anyhow::Result<()>;
|
||||
|
||||
fn handle(&mut self, msg: StopNetwork, _ctx: &mut Self::Context) -> Self::Result {
|
||||
log::debug!("Stop a network: {}", msg.0.as_string());
|
||||
let network = Network::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
|
||||
network.destroy()?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user