From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) by lore.proxmox.com (Postfix) with ESMTPS id 8A53A1FF146 for ; Tue, 23 Jun 2026 11:45:06 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 685E41D995; Tue, 23 Jun 2026 11:45:06 +0200 (CEST) From: Christoph Heiss 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 Message-ID: <20260623094419.330174-7-c.heiss@proxmox.com> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260623094419.330174-1-c.heiss@proxmox.com> References: <20260623094419.330174-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1782207890317 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.077 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [proxmox.com] Message-ID-Hash: NFEKBMRJ2EYWM4DYMKXJAFD7TZRCPWKK X-Message-ID-Hash: NFEKBMRJ2EYWM4DYMKXJAFD7TZRCPWKK X-MailFrom: c.heiss@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: 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 --- 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 = ; + 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