From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pbs-devel@lists.proxmox.com
Subject: [pbs-devel] [PATCH proxmox v5 3/3] network-api: add rename_interfaces method
Date: Mon, 4 Aug 2025 18:24:38 +0200 [thread overview]
Message-ID: <20250804162448.607184-5-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20250804162448.607184-1-s.hanreich@proxmox.com>
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@proxmox.com>
---
proxmox-network-api/src/config/mod.rs | 80 +++++++++++++++++++++++++++
1 file changed, 80 insertions(+)
diff --git a/proxmox-network-api/src/config/mod.rs b/proxmox-network-api/src/config/mod.rs
index e8cb81d1..bc80fb8d 100644
--- a/proxmox-network-api/src/config/mod.rs
+++ b/proxmox-network-api/src/config/mod.rs
@@ -267,6 +267,86 @@ impl NetworkConfig {
Ok(interface)
}
+ fn map_interface_name(iface_name: String, mapping: &HashMap<String, String>) -> String {
+ if let Some(mapping) = mapping.get(&iface_name) {
+ return mapping.clone();
+ }
+
+ if let (Some(name), Some(id)) = (
+ parse_vlan_raw_device_from_name(&iface_name),
+ parse_vlan_id_from_name(&iface_name),
+ ) {
+ if let Some(mapping) = mapping.get(name) {
+ return format!("{mapping}.{id}");
+ }
+ }
+
+ iface_name
+ }
+
+ fn handle_interface(mut interface: Interface, mapping: &HashMap<String, String>) -> Interface {
+ interface.bridge_ports = interface.bridge_ports.map(|bridge_ports| {
+ bridge_ports
+ .into_iter()
+ .map(|interface| Self::map_interface_name(interface, mapping))
+ .collect::<Vec<String>>()
+ });
+
+ interface.vlan_raw_device = interface
+ .vlan_raw_device
+ .map(|interface| Self::map_interface_name(interface, mapping));
+
+ interface.slaves = interface.slaves.map(|slaves| {
+ slaves
+ .into_iter()
+ .map(|interface| Self::map_interface_name(interface, mapping))
+ .collect::<Vec<String>>()
+ });
+
+ interface.bond_primary = interface
+ .bond_primary
+ .map(|interface| Self::map_interface_name(interface, mapping));
+
+ interface
+ }
+
+ pub fn rename_interfaces(
+ mut self,
+ mapping: &HashMap<String, String>,
+ ) -> Result<NetworkConfig, Error> {
+ let mut new_config = NetworkConfig::new();
+
+ for entry in self.order {
+ match entry {
+ NetworkOrderEntry::Iface(ref iface_name) => {
+ if let Some(mut interface) = self.interfaces.remove(iface_name) {
+ interface.name = Self::map_interface_name(interface.name, mapping);
+
+ interface = Self::handle_interface(interface, mapping);
+
+ new_config.order.push(entry);
+ new_config
+ .interfaces
+ .insert(interface.name.clone(), interface);
+ }
+ }
+ _ => new_config.order.push(entry),
+ }
+ }
+
+ for (name, mut interface) in self.interfaces.into_iter() {
+ interface.name = Self::map_interface_name(name, mapping);
+
+ interface = Self::handle_interface(interface, mapping);
+
+ new_config
+ .interfaces
+ .insert(interface.name.clone(), interface);
+ }
+
+ Ok(new_config)
+ }
+
/// Check that there is no other gateway.
///
/// The gateway property is only allowed on passed 'iface'. This should be
--
2.47.2
_______________________________________________
pbs-devel mailing list
pbs-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pbs-devel
next prev parent reply other threads:[~2025-08-04 16:23 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-08-04 16:24 [pbs-devel] [PATCH proxmox{-ve-rs, , -backup, -firewall, -network-interface-pinning} v5 00/10] proxmox-network-interface-pinning Stefan Hanreich
2025-08-04 16:24 ` [pbs-devel] [PATCH proxmox-ve-rs v5 1/1] host: network: move to proxmox-network-api Stefan Hanreich
2025-08-04 16:24 ` [pbs-devel] [PATCH proxmox v5 1/3] pbs-api-types: use proxmox-network-api types Stefan Hanreich
2025-08-04 16:24 ` [pbs-devel] [PATCH proxmox v5 2/3] proxmox-network-api: use ip link for querying interface information Stefan Hanreich
2025-08-04 16:24 ` Stefan Hanreich [this message]
2025-08-04 16:24 ` [pbs-devel] [PATCH proxmox-backup v5 1/4] config: network: move to proxmox-network-api Stefan Hanreich
2025-08-04 16:24 ` [pbs-devel] [PATCH proxmox-backup v5 2/4] metric_collection: use ip link for determining the type of interfaces Stefan Hanreich
2025-08-04 16:24 ` [pbs-devel] [PATCH proxmox-backup v5 3/4] docs: add documentation for proxmox-network-interface-pinning Stefan Hanreich
2025-08-04 16:24 ` [pbs-devel] [PATCH proxmox-backup v5 4/4] ui: show altnames Stefan Hanreich
2025-08-04 16:24 ` [pbs-devel] [PATCH proxmox-firewall v5 1/1] firewall: config: use proxmox-network-api Stefan Hanreich
2025-08-04 16:24 ` [pbs-devel] [PATCH proxmox-network-interface-pinning v5 1/1] initial commit Stefan Hanreich
2025-08-05 10:34 ` [pbs-devel] applied-series: [PATCH proxmox{-ve-rs, , -backup, -firewall, -network-interface-pinning} v5 00/10] proxmox-network-interface-pinning Wolfgang Bumiller
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20250804162448.607184-5-s.hanreich@proxmox.com \
--to=s.hanreich@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox