Add basic NAT structures

This commit is contained in:
2024-01-08 21:03:39 +01:00
parent 80ecb3c5d2
commit 672e866897
9 changed files with 190 additions and 30 deletions

View File

@ -7,6 +7,7 @@ use crate::libvirt_rest_structures::hypervisor::*;
use crate::libvirt_rest_structures::net::*;
use crate::libvirt_rest_structures::nw_filter::{NetworkFilter, NetworkFilterName};
use crate::libvirt_rest_structures::vm::*;
use crate::nat::nat_lib;
use actix::{Actor, Context, Handler, Message};
use image::ImageOutputFormat;
use std::io::Cursor;
@ -395,6 +396,9 @@ impl Handler<DefineNetwork> for LibVirtActor {
let network = Network::define_xml(&self.m, &network_xml)?;
let uuid = XMLUuid::parse_from_str(&network.get_uuid_string()?)?;
// Save NAT definition
nat_lib::save_nat_def(&msg.0)?;
// Save a copy of the source definition
msg.0.uuid = Some(uuid);
let json = serde_json::to_string(&msg.0)?;
@ -464,9 +468,12 @@ impl Handler<DeleteNetwork> for LibVirtActor {
fn handle(&mut self, msg: DeleteNetwork, _ctx: &mut Self::Context) -> Self::Result {
log::debug!("Delete network: {}\n", msg.0.as_string());
let network = Network::lookup_by_uuid_string(&self.m, &msg.0.as_string())?;
let network_name = network.get_name()?;
let network_name = NetworkName(network.get_name()?);
network.undefine()?;
// Remove NAT definition, if any
nat_lib::remove_nat_def(&network_name)?;
// Remove backup definition
let backup_definition = AppConfig::get().net_definition_path(&network_name);
if backup_definition.exists() {