[pve-devel] [PATCH manager] ui: node summary: show repository configuration status

Fabian Ebner f.ebner at proxmox.com
Wed Jun 23 18:11:26 CEST 2021


I tried to use itemid and lookupreference for the nodeStatus item, but couldn't
get it to work, so I factored it out.

Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---

Depends on the APT repositories API/UI series.
https://lists.proxmox.com/pipermail/pve-devel/2021-June/048963.html

 www/manager6/node/StatusView.js | 102 ++++++++++++++++++++++++++++++++
 www/manager6/node/Summary.js    |  49 +++++++++++++--
 2 files changed, 145 insertions(+), 6 deletions(-)

diff --git a/www/manager6/node/StatusView.js b/www/manager6/node/StatusView.js
index 564658c4..f4a55d14 100644
--- a/www/manager6/node/StatusView.js
+++ b/www/manager6/node/StatusView.js
@@ -2,6 +2,69 @@ Ext.define('PVE.node.StatusView', {
     extend: 'Proxmox.panel.StatusView',
     alias: 'widget.pveNodeStatus',
 
+    viewModel: {
+	data: {
+	    subscriptionActive: '',
+	    noSubscriptionRepo: '',
+	    enterpriseRepo: '',
+	    testRepo: '',
+	},
+	formulas: {
+	    repoStatus: function(get) {
+		if (get('subscriptionActive') === '' ||
+		    get('enterpriseRepo') === '') {
+		    return '';
+		}
+
+		if (!get('subscriptionActive') && get('enterpriseRepo')) {
+		    return 'no-sub';
+		}
+
+		if (get('noSubscriptionRepo') || get('testRepo')) {
+		    return 'non-production';
+		}
+
+		if (!get('enterpriseRepo') || !get('noSubscriptionRepo') || !get('testRepo')) {
+		    return 'no-repo';
+		}
+
+		return 'ok';
+	    },
+	    repoStatusMessage: function(get) {
+		const status = get('repoStatus');
+
+		if (status === 'ok') {
+		    return gettext('Enterprise repository and subscription active');
+		} else if (status === 'no-sub') {
+		    return gettext('Enterprise repository enabled, but no active subscription');
+		} else if (status === 'non-production') {
+		    return gettext('No-subscription or test repository in use');
+		} else if (status === 'no-repo') {
+		    return gettext('No PVE repository is enabled!');
+		}
+
+		return Proxmox.Utils.unknownText;
+	    },
+	    repoStatusIconCls: function(get) {
+		const status = get('repoStatus');
+
+		let iconCls = (cls) => `fa fa-fw ${cls}`;
+
+		if (status === 'ok') {
+		    return iconCls('fa-check good');
+		} else if (status === 'no-sub') {
+		    return iconCls('fa-exclamation-triangle critical');
+		} else if (status === 'non-production') {
+		    return iconCls('fa-exclamation-triangle warning');
+		} else if (status === 'no-repo') {
+		    return iconCls('fa-exclamation-triangle critical');
+		}
+
+		return iconCls('fa-question-circle-o');
+	    },
+	},
+    },
+
     height: 300,
     bodyPadding: '20 15 20 15',
 
@@ -113,6 +176,21 @@ Ext.define('PVE.node.StatusView', {
 	    textField: 'pveversion',
 	    value: '',
 	},
+	{
+	    itemId: 'repositoryStatus',
+	    colspan: 2,
+	    printBar: false,
+	    title: gettext('Repository Configuration Status'),
+	    // for bind
+	    setValue: function(value) {
+		let me = this;
+		me.updateValue(value);
+	    },
+	    bind: {
+		iconCls: '{repoStatusIconCls}',
+		value: '{repoStatusMessage}',
+	    },
+	},
     ],
 
     updateTitle: function() {
@@ -121,4 +199,28 @@ Ext.define('PVE.node.StatusView', {
 	me.setTitle(me.pveSelNode.data.node + ' (' + gettext('Uptime') + ': ' + uptime + ')');
     },
 
+    setRepositoryInfo: function(standardRepos) {
+	let me = this;
+	let vm = me.getViewModel();
+
+	for (const standardRepo of standardRepos) {
+	    const handle = standardRepo.handle;
+	    const status = standardRepo.status;
+
+	    if (handle === "enterprise") {
+		vm.set('enterpriseRepo', status);
+	    } else if (handle === "no-subscription") {
+		vm.set('noSubscriptionRepo', status);
+	    } else if (handle === "test") {
+		vm.set('testRepo', status);
+	    }
+	}
+    },
+
+    setSubscriptionStatus: function(status) {
+	let me = this;
+	let vm = me.getViewModel();
+
+	vm.set('subscriptionActive', status);
+    },
 });
diff --git a/www/manager6/node/Summary.js b/www/manager6/node/Summary.js
index 1c93ef04..f3709dfc 100644
--- a/www/manager6/node/Summary.js
+++ b/www/manager6/node/Summary.js
@@ -83,6 +83,38 @@ Ext.define('PVE.node.Summary', {
 	});
     },
 
+    updateRepositoryStatus: function() {
+	let me = this;
+	let nodeStatus = me.nodeStatus;
+
+	let nodename = me.pveSelNode.data.node;
+
+	Proxmox.Utils.API2Request({
+	    url: `/nodes/${nodename}/apt/repositories`,
+	    method: 'GET',
+	    failure: function(response, opts) {
+		Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+	    },
+	    success: function(response, opts) {
+		nodeStatus.setRepositoryInfo(response.result.data['standard-repos']);
+	    },
+	});
+
+	Proxmox.Utils.API2Request({
+	    url: `/nodes/${nodename}/subscription`,
+	    method: 'GET',
+	    failure: function(response, opts) {
+		Ext.Msg.alert(gettext('Error'), response.htmlStatus);
+	    },
+	    success: function(response, opts) {
+		const res = response.result;
+		const subscription = !(res === null || res === undefined ||
+		    !res || res.data.status.toLowerCase() !== 'active');
+		nodeStatus.setSubscriptionStatus(subscription);
+	    },
+	});
+    },
+
     initComponent: function() {
         var me = this;
 
@@ -109,8 +141,16 @@ Ext.define('PVE.node.Summary', {
 	    model: 'pve-rrd-node',
 	});
 
+	let nodeStatus = Ext.create('PVE.node.StatusView', {
+	    xtype: 'pveNodeStatus',
+	    rstore: rstore,
+	    width: 770,
+	    pveSelNode: me.pveSelNode,
+	});
+
 	Ext.apply(me, {
 	    tbar: [version_btn, '->', { xtype: 'proxmoxRRDTypeSelector' }],
+	    nodeStatus: nodeStatus,
 	    items: [
 		{
 		    xtype: 'container',
@@ -123,12 +163,7 @@ Ext.define('PVE.node.Summary', {
 			columnWidth: 1,
 		    },
 		    items: [
-			{
-			    xtype: 'pveNodeStatus',
-			    rstore: rstore,
-			    width: 770,
-			    pveSelNode: me.pveSelNode,
-			},
+			nodeStatus,
 			{
 			    xtype: 'proxmoxRRDChart',
 			    title: gettext('CPU usage'),
@@ -179,6 +214,8 @@ Ext.define('PVE.node.Summary', {
 	    },
 	});
 
+	me.updateRepositoryStatus();
+
 	me.callParent();
 
 	let sp = Ext.state.Manager.getProvider();
-- 
2.30.2






More information about the pve-devel mailing list