all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pve-devel] [PATCH cluster 1/5 v2] Close #1295: Add notifications to datacenter schema
@ 2021-07-14 10:09 Dominic Jäger
  2021-07-14 10:09 ` [pve-devel] [PATCH manager 2/5 v2] apt update: Inform users about missing subscriptions Dominic Jäger
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Dominic Jäger @ 2021-07-14 10:09 UTC (permalink / raw)
  To: pve-devel

Permits controlling email notifications about package updates.
Use property string for extensibility to more notification types.

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
---
v2: Use property string

 data/PVE/DataCenterConfig.pm | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

diff --git a/data/PVE/DataCenterConfig.pm b/data/PVE/DataCenterConfig.pm
index 24ebf3f..336f68a 100644
--- a/data/PVE/DataCenterConfig.pm
+++ b/data/PVE/DataCenterConfig.pm
@@ -25,6 +25,15 @@ my $migration_format = {
     },
 };
 
+my $notify_format = {
+    package_updates => {
+	type => 'boolean',
+	description => 'Control notifications about available package updates',
+	format_description => 'boolean',
+	optional => 1,
+    },
+};
+
 my $ha_format = {
     shutdown_policy => {
 	type => 'string',
@@ -146,6 +155,12 @@ my $datacenter_schema = {
 	    format => 'email-opt',
 	    description => "Specify email address to send notification from (default is root@\$hostname)",
 	},
+	notify => {
+	    optional => 1,
+	    type => 'string',
+	    format => $notify_format,
+	    description => 'Control email notifications',
+	},
 	max_workers => {
 	    optional => 1,
 	    type => 'integer',
@@ -196,6 +211,10 @@ sub parse_datacenter_config {
 	$res->{migration} = PVE::JSONSchema::parse_property_string($migration_format, $migration);
     }
 
+    if (my $notify = $res->{notify}) {
+	$res->{notify} = PVE::JSONSchema::parse_property_string($notify_format, $notify);
+    }
+
     if (my $ha = $res->{ha}) {
 	$res->{ha} = PVE::JSONSchema::parse_property_string($ha_format, $ha);
     }
@@ -241,6 +260,11 @@ sub write_datacenter_config {
 	$cfg->{migration} = PVE::JSONSchema::print_property_string($migration, $migration_format);
     }
 
+    if (ref($cfg->{notify})) {
+	my $notify = $cfg->{notify};
+	$cfg->{notify} = PVE::JSONSchema::print_property_string($notify, $notify_format);
+    }
+
     if (ref($cfg->{ha})) {
 	my $ha = $cfg->{ha};
 	$cfg->{ha} = PVE::JSONSchema::print_property_string($ha, $ha_format);
-- 
2.30.2





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

* [pve-devel] [PATCH manager 2/5 v2] apt update: Inform users about missing subscriptions
  2021-07-14 10:09 [pve-devel] [PATCH cluster 1/5 v2] Close #1295: Add notifications to datacenter schema Dominic Jäger
@ 2021-07-14 10:09 ` Dominic Jäger
  2021-07-14 10:09 ` [pve-devel] [PATCH manager 3/5 v2] Close #1295: Make apt notifications configurable Dominic Jäger
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Dominic Jäger @ 2021-07-14 10:09 UTC (permalink / raw)
  To: pve-devel

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@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





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

* [pve-devel] [PATCH manager 3/5 v2] Close #1295: Make apt notifications configurable
  2021-07-14 10:09 [pve-devel] [PATCH cluster 1/5 v2] Close #1295: Add notifications to datacenter schema Dominic Jäger
  2021-07-14 10:09 ` [pve-devel] [PATCH manager 2/5 v2] apt update: Inform users about missing subscriptions Dominic Jäger
@ 2021-07-14 10:09 ` Dominic Jäger
  2021-07-14 10:09 ` [pve-devel] [PATCH manager 4/5 v2] dc options: Add apt notifications GUI checkbox Dominic Jäger
  2021-07-14 10:09 ` [pve-devel] [PATCH manager 5/5 v2] dc options: Allow both package_update options Dominic Jäger
  3 siblings, 0 replies; 5+ messages in thread
From: Dominic Jäger @ 2021-07-14 10:09 UTC (permalink / raw)
  To: pve-devel

Users may want turn off update notifications.
Depends on pve-cluster patch.

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
---
v2: Keep defaults. I hope that I understood the idea correctly.

 bin/pveupdate | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/bin/pveupdate b/bin/pveupdate
index 99b52fe9..5981b82c 100755
--- a/bin/pveupdate
+++ b/bin/pveupdate
@@ -50,9 +50,14 @@ if (my $err = $@) {
 }
 
 my $info = PVE::INotify::read_file('subscription');
-# We assume that users with subscriptions want informations
-# about new packages.
-my $notify = ($info && $info->{status} eq 'Active') ? 1 : 0;
+my $has_subscription = $info && $info->{status} eq 'Active';
+
+my $notification_settings = $dccfg && $dccfg->{notify};
+my $notify_package_updates = $notification_settings->{package_updates}
+    if $notification_settings;
+
+# We assume that users with subscriptions want information about new packages
+my $notify = $notify_package_updates // $has_subscription;
 eval { PVE::API2::APT->update_database({ node => $nodename, notify => $notify, quiet => 1 }); };
 if (my $err = $@) {
     syslog ('err', "update apt database failed: $err");
-- 
2.30.2





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

* [pve-devel] [PATCH manager 4/5 v2] dc options: Add apt notifications GUI checkbox
  2021-07-14 10:09 [pve-devel] [PATCH cluster 1/5 v2] Close #1295: Add notifications to datacenter schema Dominic Jäger
  2021-07-14 10:09 ` [pve-devel] [PATCH manager 2/5 v2] apt update: Inform users about missing subscriptions Dominic Jäger
  2021-07-14 10:09 ` [pve-devel] [PATCH manager 3/5 v2] Close #1295: Make apt notifications configurable Dominic Jäger
@ 2021-07-14 10:09 ` Dominic Jäger
  2021-07-14 10:09 ` [pve-devel] [PATCH manager 5/5 v2] dc options: Allow both package_update options Dominic Jäger
  3 siblings, 0 replies; 5+ messages in thread
From: Dominic Jäger @ 2021-07-14 10:09 UTC (permalink / raw)
  To: pve-devel

Default value like pveupdate: Assume users with subscriptions want
notifications

Signed-off-by: Dominic Jäger <d.jaeger@proxmox.com>
---
v2: default depends on subscription status

 www/manager6/dc/OptionView.js | 37 +++++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)

diff --git a/www/manager6/dc/OptionView.js b/www/manager6/dc/OptionView.js
index edae97ea..ec6ff1a3 100644
--- a/www/manager6/dc/OptionView.js
+++ b/www/manager6/dc/OptionView.js
@@ -90,6 +90,43 @@ Ext.define('PVE.dc.OptionView', {
 	    vtype: 'proxmoxMail',
 	    defaultValue: 'root@$hostname',
 	});
+	me.add_inputpanel_row('notify', gettext('Notification settings'), {
+	    renderer: PVE.Utils.render_dc_ha_opts,
+	    labelWidth: 120,
+	    url: "/api2/extjs/cluster/options",
+	    items: [
+		{
+		    xtype: 'checkbox',
+		    name: 'package_updates',
+		    fieldLabel: gettext('Package updates'),
+		    inputValue: 1,
+		    uncheckedValue: 0, // behavior for undefined is different
+		    listeners: {
+			added: function(checkbox) {
+			    Proxmox.Utils.API2Request({
+				url: '/nodes/localhost/subscription',
+				method: 'GET',
+				failure: function(response) {
+				    console.warn('Unable to load subscription status: '
+					+ response.htmlStatus);
+				},
+				success: function(response) {
+				    const data = response.result.data;
+				    // This happens after the row is clicked and the edit window
+				    // opens but before the setValue from add_inputpanel_row sets
+				    // the value that is (potentially) saved in datacenter.cfg. If
+				    // no value is in datacenter.cfg then the setValue from
+				    // add_inputpanel_row does nothing. Then this setValue uses the
+				    // subscription status as default like pveupdate.
+				    checkbox.setValue(data.status ==='Active');
+				},
+			    });
+			},
+		    },
+		},
+	    ],
+	});
+
 	me.add_text_row('mac_prefix', gettext('MAC address prefix'), {
 	    deleteEmpty: true,
 	    vtype: 'MacPrefix',
-- 
2.30.2





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

* [pve-devel] [PATCH manager 5/5 v2] dc options: Allow both package_update options
  2021-07-14 10:09 [pve-devel] [PATCH cluster 1/5 v2] Close #1295: Add notifications to datacenter schema Dominic Jäger
                   ` (2 preceding siblings ...)
  2021-07-14 10:09 ` [pve-devel] [PATCH manager 4/5 v2] dc options: Add apt notifications GUI checkbox Dominic Jäger
@ 2021-07-14 10:09 ` Dominic Jäger
  3 siblings, 0 replies; 5+ messages in thread
From: Dominic Jäger @ 2021-07-14 10:09 UTC (permalink / raw)
  To: pve-devel

When opened for the first time (undefined value in datacenter.cfg) we should
allow setting both options yes and no for the package_update checkbox.

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

 www/manager6/dc/OptionView.js | 11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/www/manager6/dc/OptionView.js b/www/manager6/dc/OptionView.js
index ec6ff1a3..de7cbce9 100644
--- a/www/manager6/dc/OptionView.js
+++ b/www/manager6/dc/OptionView.js
@@ -35,6 +35,17 @@ Ext.define('PVE.dc.OptionView', {
 
 		    Ext.Array.each(this.query('inputpanel'), function(panel) {
 			panel.setValues(edit_value);
+
+			if (name === 'notify') {
+			    // Default depends on subscription status.
+			    // Therefore, when datacenter.cfg contains nothing
+			    // about package updates then allow setting both yes
+			    // and no for it.
+			    if (!edit_value || typeof edit_value.package_updates === 'undefined') {
+				const field = panel.down('field[name=package_updates]');
+				field.isDirty = () => true;
+			    }
+			}
 		    });
 		},
 		url: opts.url,
-- 
2.30.2





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

end of thread, other threads:[~2021-07-14 10:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-14 10:09 [pve-devel] [PATCH cluster 1/5 v2] Close #1295: Add notifications to datacenter schema Dominic Jäger
2021-07-14 10:09 ` [pve-devel] [PATCH manager 2/5 v2] apt update: Inform users about missing subscriptions Dominic Jäger
2021-07-14 10:09 ` [pve-devel] [PATCH manager 3/5 v2] Close #1295: Make apt notifications configurable Dominic Jäger
2021-07-14 10:09 ` [pve-devel] [PATCH manager 4/5 v2] dc options: Add apt notifications GUI checkbox Dominic Jäger
2021-07-14 10:09 ` [pve-devel] [PATCH manager 5/5 v2] dc options: Allow both package_update options Dominic Jäger

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal