[pve-devel] [PATCH manager 2/5 v2] apt update: Inform users about missing subscriptions

Dominic Jäger d.jaeger at proxmox.com
Wed Jul 14 12:09:30 CEST 2021


We assume that users want update notifications for production systems.
Those systems should also have an active subscription.

Signed-off-by: Dominic Jäger <d.jaeger at proxmox.com>
---
v2: new

 PVE/API2/APT.pm | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm
index bd60db33..b6a86595 100644
--- a/PVE/API2/APT.pm
+++ b/PVE/API2/APT.pm
@@ -36,6 +36,15 @@ my $get_apt_cache = sub {
     return $apt_cache;
 };
 
+# avoid a wall of text in the code
+my $get_subscription_message = sub {
+    my $hostname = shift;
+    return "You do not have a valid subscription for the server '$hostname'.\n\n" .
+    "A subscription gives access to the Proxmox VE Enterprise Repository.\n" .
+    "This repository contains the most stable packages and is recommended for production use.\n" .
+    "Please visit www.proxmox.com to get a list of available options.\n\n\n"
+};
+
 use base qw(PVE::RESTHandler);
 
 __PACKAGE__->register_method({
@@ -345,7 +354,12 @@ __PACKAGE__->register_method({
 		    my $mailfrom = $dcconf->{email_from} || "root";
 		    my $subject = "New software packages available ($hostname)";
 
-		    my $data = "The following updates are available:\n\n";
+		    my $info = PVE::INotify::read_file('subscription');
+		    my $has_subscription = $info && $info->{status} eq 'Active';
+
+		    my $data = "";
+		    $data .= $get_subscription_message->($hostname) if !$has_subscription;
+		    $data .= "The following updates are available:\n\n";
 
 		    my $count = 0;
 		    foreach my $p (sort {$a->{Package} cmp $b->{Package} } @$pkglist) {
-- 
2.30.2






More information about the pve-devel mailing list