public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Christoph Heiss <c.heiss@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH manager 6/7] network-interface-pinning: add method for renaming existing pins
Date: Tue, 23 Jun 2026 11:43:23 +0200	[thread overview]
Message-ID: <20260623094419.330174-7-c.heiss@proxmox.com> (raw)
In-Reply-To: <20260623094419.330174-1-c.heiss@proxmox.com>

Enables easily renaming of already pinned network interfaces, e.g. for
further customization later on.

It essentially runs the normal "generate" step, then removes the old
link file.

Can be invoked as e.g.:

  pve-network-interface-pinning rename nic1 port1

Came up in the forum in the past [0][1].

[0] https://forum.proxmox.com/threads/renaming-of-pinned-nic-names.184257
[1] https://forum.proxmox.com/threads/edit-pinned-network-interface-names.182305

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
---
Shortly talked to Stefan about this; seemed like a small but worthwhile
improvement to our tooling.

Tangentially also addresses [2], since that also asks for
recreating/renaming.

[2] https://bugzilla.proxmox.com/show_bug.cgi?id=6928

 PVE/CLI/pve_network_interface_pinning.pm | 153 +++++++++++++++++------
 1 file changed, 117 insertions(+), 36 deletions(-)

diff --git a/PVE/CLI/pve_network_interface_pinning.pm b/PVE/CLI/pve_network_interface_pinning.pm
index 19e358cd9..72515b164 100644
--- a/PVE/CLI/pve_network_interface_pinning.pm
+++ b/PVE/CLI/pve_network_interface_pinning.pm
@@ -364,6 +364,47 @@ sub resolve_pinned {
     return $resolved;
 }
 
+sub setup_mappings {
+    my ($ip_links, $existing_pins, $mapping) = @_;
+
+    if (!$mapping->%*) {
+        print "Nothing to do, aborting.\n";
+        exit 0;
+    }
+
+    my $altnames = PVE::Network::altname_mapping($ip_links);
+
+    my @sorted_links = sort {
+        my $a_name = $altnames->{$a} // $a;
+        my $b_name = $altnames->{$b} // $b;
+
+        $ip_links->{$a_name}->{ifindex} <=> $ip_links->{$b_name}->{ifindex};
+        } grep {
+            $ip_links->{$_}
+        } keys $mapping->%*;
+
+    for my $old_name (@sorted_links) {
+        my $altname_string = '';
+
+        if (my $interface_altnames = $ip_links->{$old_name}->{altnames}) {
+            $altname_string = join(', ', $interface_altnames->@*);
+        }
+
+        print "Name for link '$old_name' ";
+        print "($altname_string) " if $altname_string;
+        print "will change to '$mapping->{$old_name}'\n";
+
+    }
+
+    generate_link_files($ip_links, $mapping);
+    print "Successfully generated .link files in '/usr/local/lib/systemd/network/'\n";
+
+    update_host_fw_config($mapping);
+    update_etc_network_interfaces($mapping, $existing_pins);
+    update_sdn_controllers($mapping);
+    update_sdn_fabrics($mapping);
+}
+
 __PACKAGE__->register_method({
     name => 'generate',
     path => 'generate',
@@ -453,42 +494,7 @@ __PACKAGE__->register_method({
                 );
             }
 
-            if (!$mapping->%*) {
-                print "Nothing to do, aborting.\n";
-                exit 0;
-            }
-
-            my $altnames = PVE::Network::altname_mapping($ip_links);
-
-            my @sorted_links = sort {
-                my $a_name = $altnames->{$a} // $a;
-                my $b_name = $altnames->{$b} // $b;
-
-                $ip_links->{$a_name}->{ifindex} <=> $ip_links->{$b_name}->{ifindex};
-                } grep {
-                    $ip_links->{$_}
-                } keys $mapping->%*;
-
-            for my $old_name (@sorted_links) {
-                my $altname_string = '';
-
-                if (my $interface_altnames = $ip_links->{$old_name}->{altnames}) {
-                    $altname_string = join(', ', $interface_altnames->@*);
-                }
-
-                print "Name for link '$old_name' ";
-                print "($altname_string) " if $altname_string;
-                print "will change to '$mapping->{$old_name}'\n";
-
-            }
-
-            generate_link_files($ip_links, $mapping);
-            print "Successfully generated .link files in '/usr/local/lib/systemd/network/'\n";
-
-            update_host_fw_config($mapping);
-            update_etc_network_interfaces($mapping, $existing_pins);
-            update_sdn_controllers($mapping);
-            update_sdn_fabrics($mapping);
+            setup_mappings($ip_links, $existing_pins, $mapping);
 
             print "Successfully updated Proxmox VE configuration files.\n";
             print "\nPlease reboot to apply the changes to your configuration\n\n";
@@ -501,8 +507,83 @@ __PACKAGE__->register_method({
     },
 });
 
+__PACKAGE__->register_method({
+    name => 'rename',
+    path => 'rename',
+    method => 'POST',
+    description => 'Rename an existing pin for a network interface to a specific name.',
+    parameters => {
+        additionalProperties => 0,
+        properties => {
+            interface => {
+                description => 'The interface to rename.',
+                type => 'string',
+                format => 'pve-iface',
+            },
+            'target-name' => {
+                description => 'The new pinned interface name.',
+                type => 'string',
+                format => 'pve-iface',
+            },
+        },
+    },
+    returns => {
+        type => 'null',
+    },
+    code => sub {
+        my ($params) = @_;
+
+        my $iface = $params->{interface};
+        my $target_name = $params->{'target-name'};
+
+        if (-t STDOUT) {
+            say
+                "This will rename the existing pin '$iface' to '$target_name' - continue (y/N)? ";
+
+            my $answer = <STDIN>;
+            my $continue = defined($answer) && $answer =~ m/^\s*y(?:es)?\s*$/i;
+
+            die "Aborting renaming as requested\n" if !$continue;
+        }
+
+        my $code = sub {
+            my $ip_links = get_ip_links();
+            my $pinned = get_pinned();
+            my $existing_pins = resolve_pinned($ip_links, $pinned);
+
+            die "Could not find existing link with name '$iface'!\n" if !$ip_links->{$iface};
+
+            if (!defined($existing_pins->{$iface})) {
+                die "No existing pin found for NIC '$iface' - aborting.\n"
+                    . "Use the 'generate' subcommand for first time setup.\n";
+            }
+
+            die "target-name '$target_name' already exists as link or pin!\n"
+                if $ip_links->{$target_name} || grep { $target_name eq $_ } values $pinned->%*;
+
+            my $mapping = PVE::CLI::pve_network_interface_pinning::InterfaceMapping->new({
+                $iface => $target_name,
+            });
+
+            setup_mappings($ip_links, $existing_pins, $mapping);
+
+            delete_link_files({ $target_name => $iface });
+            print "Removed old .link file for '$iface'.\n";
+
+            print "Successfully updated Proxmox VE configuration files.\n";
+            print "\nPlease reboot to apply the changes to your configuration.\n\n";
+        };
+
+        PVE::Tools::lock_file($PVEETH_LOCK, 10, $code);
+        die $@ if $@;
+
+        return;
+    },
+});
+
 our $cmddef = {
     generate => [__PACKAGE__, 'generate', [], {}],
+    rename => [__PACKAGE__, 'rename', ['interface', 'target-name'], {}],
 };
 
 1;
-- 
2.54.0





  parent reply	other threads:[~2026-06-23  9:45 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-23  9:43 [PATCH docs/manager 0/7] interface-pinning: add rename subcommand and man(1) page Christoph Heiss
2026-06-23  9:43 ` [PATCH docs 1/7] network: fix typo occurences -> occurrences Christoph Heiss
2026-06-23  9:43 ` [PATCH docs 2/7] pve-doc-generator: handle CLI tools/services with dashes in their name Christoph Heiss
2026-06-23  9:43 ` [PATCH docs 3/7] pve-network-interface-pinning: init man(1) page Christoph Heiss
2026-06-23  9:43 ` [PATCH docs 4/7] network: pinning: mention how to rename an interface Christoph Heiss
2026-06-23  9:43 ` [PATCH manager 5/7] network-interface-pinning: avoid warning if `bond-primary` is unset Christoph Heiss
2026-06-23  9:43 ` Christoph Heiss [this message]
2026-06-23  9:43 ` [PATCH manager 7/7] network-interface-pinning: generate proper manpage from docs Christoph Heiss

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=20260623094419.330174-7-c.heiss@proxmox.com \
    --to=c.heiss@proxmox.com \
    --cc=pve-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
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal