[pbs-devel] [PATCH proxmox 3/3] network-api: add rename_interfaces method

Stefan Hanreich s.hanreich at proxmox.com
Tue Jul 29 18:56:49 CEST 2025


Used for batch renaming interfaces in the /e/n/i configuration file by
the proxmox-network-interface-pinning tool.

Signed-off-by: Stefan Hanreich <s.hanreich at proxmox.com>
---
 proxmox-network-api/src/config/mod.rs | 68 +++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/proxmox-network-api/src/config/mod.rs b/proxmox-network-api/src/config/mod.rs
index e8cb81d1..3b2ffdc2 100644
--- a/proxmox-network-api/src/config/mod.rs
+++ b/proxmox-network-api/src/config/mod.rs
@@ -267,6 +267,74 @@ impl NetworkConfig {
         Ok(interface)
     }
 
+    pub fn rename_interfaces(&mut self, mapping: &HashMap<String, String>) -> Result<(), Error> {
+        for (old_name, new_name) in mapping.iter() {
+            self.interfaces
+                .remove(old_name)
+                .map(|interface| self.interfaces.insert(new_name.to_string(), interface));
+
+            if let Some(idx) = self
+                .order
+                .iter()
+                .position(|elem| matches!(elem, NetworkOrderEntry::Iface(name) if name == new_name))
+            {
+                self.order[idx] = NetworkOrderEntry::Iface(new_name.to_string());
+            }
+        }
+
+        for interface in self.interfaces.values_mut() {
+            if let Some(new_name) = mapping.get(&interface.name) {
+                interface.name = new_name.to_string();
+            }
+
+            if let Some(bridge_ports) = interface.bridge_ports.take() {
+                interface.bridge_ports = Some(
+                    bridge_ports
+                        .into_iter()
+                        .map(|interface| {
+                            mapping
+                                .get(&interface)
+                                .map(String::from)
+                                .unwrap_or(interface)
+                        })
+                        .collect(),
+                )
+            }
+
+            if let Some(vlan_raw_device) = interface.vlan_raw_device.take() {
+                if let Some(new_name) = mapping.get(&vlan_raw_device) {
+                    interface.vlan_raw_device = Some(new_name.to_string());
+                } else {
+                    interface.vlan_raw_device = Some(vlan_raw_device);
+                }
+            }
+
+            if let Some(slaves) = interface.slaves.take() {
+                interface.slaves = Some(
+                    slaves
+                        .into_iter()
+                        .map(|interface| {
+                            mapping
+                                .get(&interface)
+                                .map(String::from)
+                                .unwrap_or(interface)
+                        })
+                        .collect(),
+                )
+            }
+
+            if let Some(bond_primary) = interface.bond_primary.take() {
+                if let Some(new_name) = mapping.get(&bond_primary) {
+                    interface.bond_primary = Some(new_name.to_string());
+                } else {
+                    interface.bond_primary = Some(bond_primary);
+                }
+            }
+        }
+
+        Ok(())
+    }
+
     /// Check that there is no other gateway.
     ///
     /// The gateway property is only allowed on passed 'iface'. This should be
-- 
2.47.2




More information about the pbs-devel mailing list