public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Guillaume via pve-devel <pve-devel@lists.proxmox.com>
To: pve-devel@lists.proxmox.com
Cc: Guillaume <09couplet.bitmap@icloud.com>
Subject: [pve-devel] [PATCH container v2 2/4] setup: add support of el10 and implementing NetworkManager instead fo network-scripts
Date: Mon,  1 Sep 2025 18:20:34 +0200	[thread overview]
Message-ID: <mailman.102.1756744126.418.pve-devel@lists.proxmox.com> (raw)
In-Reply-To: <20250901162036.2651-1-09couplet.bitmap@icloud.com>

[-- Attachment #1: Type: message/rfc822, Size: 9866 bytes --]

From: Guillaume <09couplet.bitmap@icloud.com>
To: pve-devel@lists.proxmox.com
Cc: Guillaume <09couplet.bitmap@icloud.com>
Subject: [PATCH container v2 2/4] setup: add support of el10 and implementing NetworkManager instead fo network-scripts
Date: Mon,  1 Sep 2025 18:20:34 +0200
Message-ID: <20250901162036.2651-3-09couplet.bitmap@icloud.com>

Red Hat remove support for network configuration files in the ifcfg format until version 10.

Signed-off-by: Guillaume <09couplet.bitmap@icloud.com>
---
 src/PVE/LXC/Setup/CentOS.pm | 108 +++++++++++++++++++++++++++++++++---
 1 file changed, 101 insertions(+), 7 deletions(-)

diff --git a/src/PVE/LXC/Setup/CentOS.pm b/src/PVE/LXC/Setup/CentOS.pm
index 446b49b..06b4dac 100644
--- a/src/PVE/LXC/Setup/CentOS.pm
+++ b/src/PVE/LXC/Setup/CentOS.pm
@@ -4,6 +4,7 @@ use strict;
 use warnings;
 
 use UUID;
+use Net::IP;
 
 use PVE::Tools;
 use PVE::Network;
@@ -19,16 +20,13 @@ sub new {
     my $release = PVE::Tools::file_read_firstline("$rootdir/etc/redhat-release");
     die "unable to read version info\n" if !defined($release);
 
-    my $version;
+    my $version = get_centos_version($release);
 
-    if (($release =~ m/release\s+(\d+\.\d+)(\.\d+)?/) || ($release =~ m/release\s+(\d+)/)) {
-        if ($1 >= 5 && $1 < 10) {
-            $version = $1;
-        }
+    # check compatibility
+    if (!($version >= 5 && $version < 11)) {
+        die "unsupported centos version '$version'\n";
     }
 
-    die "unsupported centos release '$release'\n" if !$version;
-
     my $self = { conf => $conf, rootdir => $rootdir, version => $version };
 
     $conf->{ostype} = "centos";
@@ -36,6 +34,16 @@ sub new {
     return bless $self, $class;
 }
 
+sub get_centos_version {
+    my ($release) = @_;
+
+    if (($release =~ m/release\s+(\d+\.\d+)(\.\d+)?/) || ($release =~ m/release\s+(\d+)/)) {
+        return $1;
+    }
+
+    die "unable to parse centos version '$release'\n";
+}
+
 my $tty_conf = <<__EOD__;
 # tty - getty
 #
@@ -182,6 +190,92 @@ sub set_hostname {
 sub setup_network {
     my ($self, $conf) = @_;
 
+    my $release = $self->ct_file_get_contents('/etc/redhat-release');
+    my $version = get_centos_version($release);
+
+    if ($version >= 10) {
+        # Use NetworkManager files
+        setup_netork_with_networkmanager($self, $conf)
+    } else {
+        # Use network-scripts files
+        setup_netork_with_network_scripts($self, $conf)
+    }
+}
+
+sub setup_netork_with_networkmanager {
+    my ($self, $conf) = @_;
+
+    $self->ct_make_path('/etc/NetworkManager/system-connections');
+
+    foreach my $k (keys %$conf) {
+        next if $k !~ m/^net(\d+)$/;
+        my $d = PVE::LXC::Config->parse_lxc_network($conf->{$k});
+        next if !$d->{name};
+
+        my $filename = "/etc/NetworkManager/system-connections/$d->{name}.nmconnection";
+
+        my ($searchdomains, $nameserver) = $self->lookup_dns_conf($conf);
+        my @nameservers = PVE::Tools::split_list($nameserver);
+        my @nameserversv4 = grep {
+            my $ip = Net::IP->new($_);
+            $ip && $ip->version == 4;
+        } @nameservers;
+        my @nameserversv6 = grep {
+            my $ip = Net::IP->new($_);
+            $ip && $ip->version == 6;
+        } @nameservers;
+
+
+        my $header = "[connection]\nid=$d->{name}\nuuid=" . UUID::uuid() . "\ntype=ethernet\ninterface-name=$d->{name}\n";
+        my $data = '';
+
+        if ($d->{ip} && $d->{ip} ne 'manual') {
+            $data .= "[ipv4]\n";
+            if ($d->{ip} eq 'dhcp') {
+                $data .= "method=auto\n";
+            } else {
+                $data .= "method=manual\n";
+                $data .= "addresses=$d->{ip}\n";
+                if (defined($d->{gw})) {
+                    $data .= "gateway=$d->{gw}\n";
+                    if (!PVE::Network::is_ip_in_cidr($d->{gw}, $d->{ip}, 4)) {
+                        $data .= "routes=$d->{gw}\n";
+                    }
+                }
+            }
+            $data .= "dns=" . join(',', @nameserversv4) . "\n" if @nameserversv4;
+            $data .= "dns-search=" . join(' ', PVE::Tools::split_list($searchdomains)) . "\n" if @nameserversv4 && $searchdomains;
+        }
+
+        if ($d->{ip6} && $d->{ip6} ne 'manual') {
+            $data .= "[ipv6]\n";
+            if ($d->{ip6} eq 'auto' || $d->{ip6} eq 'dhcp') {
+                $data .= "method=auto\n";
+            } else {
+                $data .= "method=manual\naddress=$d->{ip6}\n";
+                if (defined($d->{gw6})) {
+                    if (
+                        !PVE::Network::is_ip_in_cidr($d->{gw6}, $d->{ip6}, 6)
+                        && !PVE::Network::is_ip_in_cidr($d->{gw6}, 'fe80::/10', 6)
+                    ) {
+                        $data .= "routes=$d->{gw6}\n";
+                    } else {
+                        $data .= "gateway=$d->{gw6}\n";
+                    }
+                }
+            }
+            $data .= "dns=" . join(',', @nameserversv6) . "\n" if @nameserversv6;
+            $data .= "dns-search=" . join(' ', PVE::Tools::split_list($searchdomains)) . "\n" if @nameserversv6 && $searchdomains;
+        }
+
+        next unless $data;
+        $self->ct_file_set_contents($filename, $header . $data, 0600);
+    }
+}
+
+sub setup_netork_with_network_scripts {
+    my ($self, $conf) = @_;
+
     my ($gw, $gw6);
 
     $self->ct_make_path('/etc/sysconfig/network-scripts');
-- 
2.47.2



[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel

  parent reply	other threads:[~2025-09-01 16:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20250901162036.2651-1-09couplet.bitmap@icloud.com>
2025-09-01 16:20 ` [pve-devel] SPAM: [PATCH container v2 1/4] setup: add underscore in regex to parse systemd version Guillaume via pve-devel
2025-09-01 16:20 ` Guillaume via pve-devel [this message]
2025-09-01 16:20 ` [pve-devel] SPAM: [PATCH container v2 3/4] tests: add tests for centos 10 Guillaume via pve-devel
2025-09-01 16:20 ` [pve-devel] [PATCH container v2 4/4] setup: disabled ipv4 or ipv6 if not used in NetworkManager files Guillaume via pve-devel

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=mailman.102.1756744126.418.pve-devel@lists.proxmox.com \
    --to=pve-devel@lists.proxmox.com \
    --cc=09couplet.bitmap@icloud.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