public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [PATCH pve-manager v2 0/2] fix #8031: Write APT proxy config on http_proxy change
@ 2026-09-14 15:24 Jonas Theisen
  2026-09-14 15:24 ` [PATCH pve-manager v2 1/2] fix #8031: factor out APT proxy write from update_database call Jonas Theisen
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Jonas Theisen @ 2026-09-14 15:24 UTC (permalink / raw)
  To: pve-devel

To allow reuse of the same code this patch series factors out
the relevant function inside the APT part of the API and reuses
the function on change of the http_proxy variable in the Cluster API.

This is to ensure a consistent state after a change of the HTTP proxy
without having to run a Refresh / apt update through the PVE tooling.

https://bugzilla.proxmox.com/show_bug.cgi?id=8031

Changes from v1:
 * renamed APT function to update_apt_proxy_config for more clarity
 * considered that $delete is a list and not a single string
 * fixed the import of the API2::APT package in Cluster.pm

Thanks for the feedback off-list @m.sandoval

Jonas Theisen (2):
  fix #8031: factor out APT proxy write from update_database call
  fix #8031: write APT proxy config on http_proxy change

 PVE/API2/APT.pm     | 23 ++++++++++++++---------
 PVE/API2/Cluster.pm |  9 +++++++++
 2 files changed, 23 insertions(+), 9 deletions(-)

-- 
2.47.3





^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH pve-manager v2 1/2] fix #8031: factor out APT proxy write from update_database call
  2026-09-14 15:24 [PATCH pve-manager v2 0/2] fix #8031: Write APT proxy config on http_proxy change Jonas Theisen
@ 2026-09-14 15:24 ` Jonas Theisen
  2026-09-14 15:24 ` [PATCH pve-manager v2 2/2] fix #8031: write APT proxy config on http_proxy change Jonas Theisen
  2026-09-15  9:18 ` [PATCH pve-manager v2 0/2] fix #8031: Write " Jonas Theisen
  2 siblings, 0 replies; 5+ messages in thread
From: Jonas Theisen @ 2026-09-14 15:24 UTC (permalink / raw)
  To: pve-devel

To allow reuse of the same function for the Cluster set_options call
this commit factors the function to write the APT proxy config file
out of the update_database call into a sub function.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 PVE/API2/APT.pm | 23 ++++++++++++++---------
 1 file changed, 14 insertions(+), 9 deletions(-)

diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm
index 6dd4c261..87928e58 100644
--- a/PVE/API2/APT.pm
+++ b/PVE/API2/APT.pm
@@ -290,6 +290,19 @@ __PACKAGE__->register_method({
     },
 });
 
+sub update_apt_proxy_config {
+    my $dcconf = PVE::Cluster::cfs_read_file('datacenter.cfg');
+    my $aptconf = "// no proxy configured\n";
+
+    if (my $http_proxy = $dcconf->{http_proxy}) {
+        my $http_proxy_uri = URI->new($http_proxy);
+        $aptconf = "Acquire::http::Proxy \"${http_proxy_uri}\";\n";
+    }
+    my $aptcfn = "/etc/apt/apt.conf.d/76pveproxy";
+
+    PVE::Tools::file_set_contents($aptcfn, $aptconf);
+}
+
 __PACKAGE__->register_method({
     name => 'update_database',
     path => 'update',
@@ -334,15 +347,7 @@ __PACKAGE__->register_method({
         my $realcmd = sub {
             my $upid = shift;
 
-            # setup proxy for apt
-
-            my $aptconf = "// no proxy configured\n";
-            if (my $http_proxy = $dcconf->{http_proxy}) {
-                my $http_proxy_uri = URI->new($http_proxy);
-                $aptconf = "Acquire::http::Proxy \"${http_proxy_uri}\";\n";
-            }
-            my $aptcfn = "/etc/apt/apt.conf.d/76pveproxy";
-            PVE::Tools::file_set_contents($aptcfn, $aptconf);
+            update_apt_proxy_config();
 
             my $cmd = ['apt-get', 'update'];
 
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH pve-manager v2 2/2] fix #8031: write APT proxy config on http_proxy change
  2026-09-14 15:24 [PATCH pve-manager v2 0/2] fix #8031: Write APT proxy config on http_proxy change Jonas Theisen
  2026-09-14 15:24 ` [PATCH pve-manager v2 1/2] fix #8031: factor out APT proxy write from update_database call Jonas Theisen
@ 2026-09-14 15:24 ` Jonas Theisen
  2026-09-15  8:03   ` Maximiliano Sandoval
  2026-09-15  9:18 ` [PATCH pve-manager v2 0/2] fix #8031: Write " Jonas Theisen
  2 siblings, 1 reply; 5+ messages in thread
From: Jonas Theisen @ 2026-09-14 15:24 UTC (permalink / raw)
  To: pve-devel

Writes the necessary file for APT if the http_proxy variable
on the datacenter level is changed.

This reuses the same function from the APT API for a regular
database update.

Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
---
 PVE/API2/Cluster.pm | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
index 4e5efbfd..8529c026 100644
--- a/PVE/API2/Cluster.pm
+++ b/PVE/API2/Cluster.pm
@@ -36,6 +36,7 @@ use PVE::API2::ClusterConfig;
 use PVE::API2::Firewall::Cluster;
 use PVE::API2::HAConfig;
 use PVE::API2::ReplicationConfig;
+use PVE::API2::APT;
 
 my $have_sdn;
 eval {
@@ -842,7 +843,11 @@ __PACKAGE__->register_method({
     code => sub {
         my ($param) = @_;
 
+        my $http_proxy_change = 0;
+
         my $delete = extract_param($param, 'delete');
+        $http_proxy_change = 1
+            if ((defined($param->{http_proxy})) || (defined($delete) && $delete =~ m/\bhttp_proxy\b/ ));
 
         cfs_lock_file(
             'datacenter.cfg',
@@ -859,6 +864,10 @@ __PACKAGE__->register_method({
         );
         die $@ if $@;
 
+        if ($http_proxy_change) {
+            PVE::API2::APT::update_apt_proxy_config();
+        }
+
         return undef;
     },
 });
-- 
2.47.3





^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH pve-manager v2 2/2] fix #8031: write APT proxy config on http_proxy change
  2026-09-14 15:24 ` [PATCH pve-manager v2 2/2] fix #8031: write APT proxy config on http_proxy change Jonas Theisen
@ 2026-09-15  8:03   ` Maximiliano Sandoval
  0 siblings, 0 replies; 5+ messages in thread
From: Maximiliano Sandoval @ 2026-09-15  8:03 UTC (permalink / raw)
  To: Jonas Theisen; +Cc: pve-devel

Jonas Theisen <j.theisen@proxmox.com> writes:

> Writes the necessary file for APT if the http_proxy variable
> on the datacenter level is changed.
>
> This reuses the same function from the APT API for a regular
> database update.
>
> Signed-off-by: Jonas Theisen <j.theisen@proxmox.com>
> ---
>  PVE/API2/Cluster.pm | 9 +++++++++
>  1 file changed, 9 insertions(+)
>
> diff --git a/PVE/API2/Cluster.pm b/PVE/API2/Cluster.pm
> index 4e5efbfd..8529c026 100644
> --- a/PVE/API2/Cluster.pm
> +++ b/PVE/API2/Cluster.pm
> @@ -36,6 +36,7 @@ use PVE::API2::ClusterConfig;
>  use PVE::API2::Firewall::Cluster;
>  use PVE::API2::HAConfig;
>  use PVE::API2::ReplicationConfig;
> +use PVE::API2::APT;
>  
>  my $have_sdn;
>  eval {
> @@ -842,7 +843,11 @@ __PACKAGE__->register_method({
>      code => sub {
>          my ($param) = @_;
>  
> +        my $http_proxy_change = 0;
> +
>          my $delete = extract_param($param, 'delete');
> +        $http_proxy_change = 1
> +            if ((defined($param->{http_proxy})) || (defined($delete) && $delete =~ m/\bhttp_proxy\b/ ));

Cosmetic stuff: Please run a 'make tidy' to format this file. the
whitespace before the '))' at the end will probably trigger the
formatter. I don't think you need to use two levels of parenthesis
either on the defined($param->{http_proxy} part, but the formatter won't
fix that automatically.

Regarding the '\b', they look correct to me but I am not sure if this is
necessary. This is not a blocked in any case.

>  
>          cfs_lock_file(
>              'datacenter.cfg',
> @@ -859,6 +864,10 @@ __PACKAGE__->register_method({
>          );
>          die $@ if $@;
>  
> +        if ($http_proxy_change) {
> +            PVE::API2::APT::update_apt_proxy_config();
> +        }
> +
>          return undef;
>      },
>  });

Other than that, the patch looks good to me.

Reviewed-by: Maximiliano Sandoval <m.sandoval@proxmox.com>

-- 
Maximiliano




^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH pve-manager v2 0/2] fix #8031: Write APT proxy config on http_proxy change
  2026-09-14 15:24 [PATCH pve-manager v2 0/2] fix #8031: Write APT proxy config on http_proxy change Jonas Theisen
  2026-09-14 15:24 ` [PATCH pve-manager v2 1/2] fix #8031: factor out APT proxy write from update_database call Jonas Theisen
  2026-09-14 15:24 ` [PATCH pve-manager v2 2/2] fix #8031: write APT proxy config on http_proxy change Jonas Theisen
@ 2026-09-15  9:18 ` Jonas Theisen
  2 siblings, 0 replies; 5+ messages in thread
From: Jonas Theisen @ 2026-09-15  9:18 UTC (permalink / raw)
  To: pve-devel

Superseded by 
https://lore.proxmox.com/pve-devel/20260915091758.85522-1-j.theisen@proxmox.com/T/#t 





^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2026-09-15  9:19 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-14 15:24 [PATCH pve-manager v2 0/2] fix #8031: Write APT proxy config on http_proxy change Jonas Theisen
2026-09-14 15:24 ` [PATCH pve-manager v2 1/2] fix #8031: factor out APT proxy write from update_database call Jonas Theisen
2026-09-14 15:24 ` [PATCH pve-manager v2 2/2] fix #8031: write APT proxy config on http_proxy change Jonas Theisen
2026-09-15  8:03   ` Maximiliano Sandoval
2026-09-15  9:18 ` [PATCH pve-manager v2 0/2] fix #8031: Write " Jonas Theisen

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