]> git.proxmox.com Git - pve-manager.git/commitdiff
ui: node summary: show repository configuration status
authorFabian Ebner <f.ebner@proxmox.com>
Wed, 23 Jun 2021 16:11:26 +0000 (18:11 +0200)
committerThomas Lamprecht <t.lamprecht@proxmox.com>
Sun, 4 Jul 2021 18:58:33 +0000 (20:58 +0200)
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@proxmox.com>
www/manager6/node/StatusView.js
www/manager6/node/Summary.js

index 564658c4ab7b5d4126c161b1bdcbee6fe567e95f..f4a55d14658e61b40c26401e21eb63d7752aae1b 100644 (file)
@@ -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);
+    },
 });
index 1c93ef04533ab8d44a9c50a1036b980e37de90e0..f3709dfca8af9a0beca73b96f57b869c1f39f74a 100644 (file)
@@ -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();