[pve-devel] [PATCH proxmox-ve-rs 4/6] ve-config: add optional tag property to vnet
Stefan Hanreich
s.hanreich at proxmox.com
Thu Oct 30 16:48:13 CET 2025
From: Gabriel Goller <g.goller at proxmox.com>
When parsing the vnet.cfg config file we also want to get the tag
(vni or vlan). We need this so that we can lookup the vni of the passed
vnet on the status api call. We need the vni so that we can filter the
frr output.
In the future we would probably want to do this better with an enum per
vnet type and parse all possible options.
Signed-off-by: Gabriel Goller <g.goller at proxmox.com>
Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
---
proxmox-ve-config/src/sdn/config.rs | 27 ++++++++++++++++---
proxmox-ve-config/tests/sdn/main.rs | 5 ++--
.../tests/sdn/resources/running-config.json | 1 +
3 files changed, 28 insertions(+), 5 deletions(-)
diff --git a/proxmox-ve-config/src/sdn/config.rs b/proxmox-ve-config/src/sdn/config.rs
index 031fedc..afc5175 100644
--- a/proxmox-ve-config/src/sdn/config.rs
+++ b/proxmox-ve-config/src/sdn/config.rs
@@ -196,6 +196,7 @@ pub struct SubnetsRunningConfig {
/// Struct for deserializing a vnet entry of the SDN running config
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct VnetRunningConfig {
+ tag: Option<u32>,
zone: ZoneName,
}
@@ -295,14 +296,16 @@ impl SubnetConfig {
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub struct VnetConfig {
name: VnetName,
+ tag: Option<u32>,
subnets: BTreeMap<Cidr, SubnetConfig>,
}
impl VnetConfig {
- pub fn new(name: VnetName) -> Self {
+ pub fn new(name: VnetName, tag: Option<u32>) -> Self {
Self {
name,
subnets: BTreeMap::default(),
+ tag,
}
}
@@ -310,7 +313,18 @@ impl VnetConfig {
name: VnetName,
subnets: impl IntoIterator<Item = SubnetConfig>,
) -> Result<Self, SdnConfigError> {
- let mut config = Self::new(name);
+ let mut config = Self::new(name, None);
+ config.add_subnets(subnets)?;
+ Ok(config)
+ }
+
+ pub fn from_subnets_and_tag(
+ name: VnetName,
+ tag: Option<u32>,
+ subnets: impl IntoIterator<Item = SubnetConfig>,
+ ) -> Result<Self, SdnConfigError> {
+ let mut config = Self::new(name, None);
+ config.tag = tag;
config.add_subnets(subnets)?;
Ok(config)
}
@@ -342,6 +356,10 @@ impl VnetConfig {
pub fn name(&self) -> &VnetName {
&self.name
}
+
+ pub fn tag(&self) -> &Option<u32> {
+ &self.tag
+ }
}
#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Hash, PartialOrd, Ord)]
@@ -617,7 +635,10 @@ impl TryFrom<RunningConfig> for SdnConfig {
if let Some(running_vnets) = value.vnets.take() {
for (name, running_config) in running_vnets.ids {
- config.add_vnet(&running_config.zone, VnetConfig::new(name))?;
+ config.add_vnet(
+ &running_config.zone,
+ VnetConfig::new(name, running_config.tag),
+ )?;
}
}
diff --git a/proxmox-ve-config/tests/sdn/main.rs b/proxmox-ve-config/tests/sdn/main.rs
index 94039ad..bd38bbf 100644
--- a/proxmox-ve-config/tests/sdn/main.rs
+++ b/proxmox-ve-config/tests/sdn/main.rs
@@ -25,8 +25,9 @@ fn parse_running_config() {
ZoneName::from_str("zone0").unwrap(),
ZoneType::Simple,
[
- VnetConfig::from_subnets(
+ VnetConfig::from_subnets_and_tag(
VnetName::from_str("vnet0").unwrap(),
+ Some(100),
[
SubnetConfig::new(
SubnetName::from_str("zone0-fd80::-64").unwrap(),
@@ -84,7 +85,7 @@ fn sdn_config() {
let zone0 = ZoneConfig::new(zone0_name.clone(), ZoneType::Qinq);
sdn_config.add_zone(zone0).unwrap();
- let vnet0 = VnetConfig::new(vnet0_name.clone());
+ let vnet0 = VnetConfig::new(vnet0_name.clone(), None);
assert_eq!(
sdn_config.add_vnet(&zone1_name, vnet0.clone()),
Err(SdnConfigError::ZoneNotFound)
diff --git a/proxmox-ve-config/tests/sdn/resources/running-config.json b/proxmox-ve-config/tests/sdn/resources/running-config.json
index b03c20f..d6054ba 100644
--- a/proxmox-ve-config/tests/sdn/resources/running-config.json
+++ b/proxmox-ve-config/tests/sdn/resources/running-config.json
@@ -43,6 +43,7 @@
"ids": {
"vnet0": {
"type": "vnet",
+ "tag": 100,
"zone": "zone0"
},
"vnet1": {
--
2.47.3
More information about the pve-devel
mailing list