Add backend bridge support

This commit is contained in:
2025-05-26 19:12:18 +02:00
parent aac05b7faf
commit ff372800bd
3 changed files with 89 additions and 4 deletions

View File

@ -80,7 +80,9 @@ pub struct NetMacAddress {
#[serde(rename = "source")]
pub struct NetIntSourceXML {
#[serde(rename = "@network")]
pub network: String,
pub network: Option<String>,
#[serde(rename = "@bridge")]
pub bridge: Option<String>,
}
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]

View File

@ -53,7 +53,8 @@ pub struct Network {
#[serde(tag = "type")]
pub enum NetworkType {
UserspaceSLIRPStack,
DefinedNetwork { network: String }, // TODO : complete network types
DefinedNetwork { network: String },
Bridge { bridge: String },
}
#[derive(serde::Serialize, serde::Deserialize)]
@ -240,7 +241,18 @@ impl VMInfo {
mac,
r#type: "network".to_string(),
source: Some(NetIntSourceXML {
network: network.to_string(),
network: Some(network.to_string()),
bridge: None,
}),
model,
filterref,
},
NetworkType::Bridge { bridge } => DomainNetInterfaceXML {
r#type: "bridge".to_string(),
mac,
source: Some(NetIntSourceXML {
network: None,
bridge: Some(bridge.to_string()),
}),
model,
filterref,
@ -468,7 +480,34 @@ impl VMInfo {
r#type: match d.r#type.as_str() {
"user" => NetworkType::UserspaceSLIRPStack,
"network" => NetworkType::DefinedNetwork {
network: d.source.as_ref().unwrap().network.to_string(),
network: d
.source
.as_ref()
.unwrap()
.network
.as_deref()
.ok_or_else(|| {
LibVirtStructError::DomainExtraction(
"Missing source network for defined network!"
.to_string(),
)
})?
.to_string(),
},
"bridge" => NetworkType::Bridge {
bridge: d
.source
.as_ref()
.unwrap()
.bridge
.as_deref()
.ok_or_else(|| {
LibVirtStructError::DomainExtraction(
"Missing bridge name for bridge connection!"
.to_string(),
)
})?
.to_string(),
},
a => {
return Err(LibVirtStructError::DomainExtraction(format!(