]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
ui: lxc: pass full property name to for-each dev & mountpoint helpers
[pve-manager.git] / www / manager6 / Utils.js
index 6ce22ded5b22bb0ade2e50f4ba8a242b72c94476..54aa8bacae5e2f91b210f627c987b6cac31e80b6 100644 (file)
@@ -34,12 +34,20 @@ Ext.define('PVE.Utils', {
     },
 
     noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit '
-      +'<a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">'
+      +'<a target="_blank" href="https://www.proxmox.com/en/proxmox-virtual-environment/pricing">'
       +'www.proxmox.com</a> to get a list of available options.',
 
+    getClusterSubscriptionLevel: async function() {
+       let { result } = await Proxmox.Async.api2({ url: '/cluster/status' });
+       let levelMap = Object.fromEntries(
+         result.data.filter(v => v.type === 'node').map(v => [v.name, v.level]),
+       );
+       return levelMap;
+    },
+
     kvm_ostypes: {
        'Linux': [
-           { desc: '5.x - 2.6 Kernel', val: 'l26' },
+           { desc: '6.x - 2.6 Kernel', val: 'l26' },
            { desc: '2.4 Kernel', val: 'l24' },
        ],
        'Microsoft Windows': [
@@ -393,6 +401,8 @@ Ext.define('PVE.Utils', {
        'efidisk but no OMVF BIOS': gettext('EFI Disk without OMVF BIOS'),
     },
 
+    renderNotFound: what => Ext.String.format(gettext("No {0} found"), what),
+
     get_kvm_osinfo: function(value) {
        var info = { base: 'Other' }; // default
        if (value) {
@@ -473,6 +483,8 @@ Ext.define('PVE.Utils', {
                    virtio: "VirtIO",
                };
                displayText = map[value] || Proxmox.Utils.unknownText;
+           } else if (key === 'freeze-fs-on-backup' && PVE.Parser.parseBoolean(value)) {
+               continue;
            } else if (PVE.Parser.parseBoolean(value)) {
                displayText = Proxmox.Utils.enabledText;
            }
@@ -827,6 +839,12 @@ Ext.define('PVE.Utils', {
            hideAdd: true,
            backups: false,
        },
+       esxi: {
+           name: 'ESXi',
+           ipanel: 'ESXIInputPanel',
+           faIcon: 'cloud-download',
+           backups: false,
+       },
     },
 
     sdnvnetSchema: {
@@ -883,6 +901,11 @@ Ext.define('PVE.Utils', {
            ipanel: 'BgpInputPanel',
            faIcon: 'crosshairs',
        },
+       isis: {
+           name: 'isis',
+           ipanel: 'IsisInputPanel',
+           faIcon: 'crosshairs',
+       },
     },
 
     sdnipamSchema: {
@@ -991,15 +1014,20 @@ Ext.define('PVE.Utils', {
     },
 
     render_storage_content: function(value, metaData, record) {
-       var data = record.data;
+       let data = record.data;
+       let result;
        if (Ext.isNumber(data.channel) &&
            Ext.isNumber(data.id) &&
            Ext.isNumber(data.lun)) {
-           return "CH " +
+           result = "CH " +
                Ext.String.leftPad(data.channel, 2, '0') +
                " ID " + data.id + " LUN " + data.lun;
+       } else if (data.content === 'import') {
+           result = data.volid.replace(/^.*?:/, '');
+       } else {
+           result = data.volid.replace(/^.*?:(.*?\/)?/, '');
        }
-       return data.volid.replace(/^.*?:(.*?\/)?/, '');
+       return Ext.String.htmlEncode(result);
     },
 
     render_serverity: function(value) {
@@ -1216,6 +1244,8 @@ Ext.define('PVE.Utils', {
            // templates
            objType = 'template';
            status = type;
+       } else if (type === 'storage' && record.content.indexOf('import') !== -1) {
+           return 'fa fa-cloud-download';
        } else {
            // everything else
            status = record.status + ' ha-' + record.hastate;
@@ -1278,6 +1308,21 @@ Ext.define('PVE.Utils', {
        return Ext.htmlEncode(first + " " + last);
     },
 
+    // expecting the following format:
+    // [v2:10.10.10.1:6802/2008,v1:10.10.10.1:6803/2008]
+    render_ceph_osd_addr: function(value) {
+       value = value.trim();
+       if (value.startsWith('[') && value.endsWith(']')) {
+           value = value.slice(1, -1); // remove []
+       }
+       value = value.replaceAll(',', '\n'); // split IPs in lines
+       let retVal = '';
+       for (const i of value.matchAll(/^(v[0-9]):(.*):([0-9]*)\/([0-9]*)$/gm)) {
+           retVal += `${i[1]}: ${i[2]}:${i[3]}<br>`;
+       }
+       return retVal.length < 1 ? value : retVal;
+    },
+
     windowHostname: function() {
        return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
             function(m, addr, offset, original) { return addr; });
@@ -1332,7 +1377,7 @@ Ext.define('PVE.Utils', {
            allowSpice = consoles.spice;
            allowXtermjs = !!consoles.xtermjs;
        }
-       let dv = PVE.UIOptions.console || (type === 'kvm' ? 'vv' : 'xtermjs');
+       let dv = PVE.UIOptions.options.console || (type === 'kvm' ? 'vv' : 'xtermjs');
        if (dv === 'vv' && !allowSpice) {
            dv = allowXtermjs ? 'xtermjs' : 'html5';
        } else if (dv === 'xtermjs' && !allowXtermjs) {
@@ -1371,10 +1416,11 @@ Ext.define('PVE.Utils', {
                css: 'display:none;visibility:hidden;height:0px;',
            });
 
-           // Note: we need to tell Android and Chrome the correct file name extension
+           // Note: we need to tell Android, AppleWebKit and Chrome
+           // the correct file name extension
            // but we do not set 'download' tag for other environments, because
            // It can have strange side effects (additional user prompt on firefox)
-           if (navigator.userAgent.match(/Android|Chrome/i)) {
+           if (navigator.userAgent.match(/Android|AppleWebKit|Chrome/i)) {
                link.download = name;
            }
 
@@ -1544,14 +1590,14 @@ Ext.define('PVE.Utils', {
        }
     },
 
-    mp_counts: {
+    lxc_mp_counts: {
        mp: 256,
        unused: 256,
     },
 
-    forEachMP: function(func, includeUnused) {
-       for (let i = 0; i < PVE.Utils.mp_counts.mp; i++) {
-           let cont = func('mp', i);
+    forEachLxcMP: function(func, includeUnused) {
+       for (let i = 0; i < PVE.Utils.lxc_mp_counts.mp; i++) {
+           let cont = func('mp', i, `mp${i}`);
            if (!cont && cont !== undefined) {
                return;
            }
@@ -1561,8 +1607,19 @@ Ext.define('PVE.Utils', {
            return;
        }
 
-       for (let i = 0; i < PVE.Utils.mp_counts.unused; i++) {
-           let cont = func('unused', i);
+       for (let i = 0; i < PVE.Utils.lxc_mp_counts.unused; i++) {
+           let cont = func('unused', i, `unused${i}`);
+           if (!cont && cont !== undefined) {
+               return;
+           }
+       }
+    },
+
+    lxc_dev_count: 256,
+
+    forEachLxcDev: function(func) {
+       for (let i = 0; i < PVE.Utils.lxc_dev_count; i++) {
+           let cont = func(i, `dev${i}`);
            if (!cont && cont !== undefined) {
                return;
            }
@@ -1683,6 +1740,9 @@ Ext.define('PVE.Utils', {
                    });
                    win.getViewModel().set('isInstalled', isInstalled);
                    container.add(win);
+                   win.on('close', () => {
+                       container.el.unmask();
+                   });
                    win.show();
                    callback(win);
                }
@@ -1702,7 +1762,7 @@ Ext.define('PVE.Utils', {
            rstore,
            /not (installed|initialized)/i,
            (_, error) => {
-               nodename = nodename || 'localhost';
+               nodename = nodename || Proxmox.NodeName;
                let maskTarget = maskOwnerCt ? view.ownerCt : view;
                rstore.stopUpdate();
                PVE.Utils.showCephInstallOrMask(maskTarget, error.statusText, nodename, win => {
@@ -1822,8 +1882,8 @@ Ext.define('PVE.Utils', {
        return undefined;
     },
 
-    nextFreeMP: function(type, config) {
-       for (let i = 0; i < PVE.Utils.mp_counts[type]; i++) {
+    nextFreeLxcMP: function(type, config) {
+       for (let i = 0; i < PVE.Utils.lxc_mp_counts[type]; i++) {
            let confid = `${type}${i}`;
            if (!Ext.isDefined(config[confid])) {
                return {
@@ -1855,15 +1915,48 @@ Ext.define('PVE.Utils', {
 
     notesTemplateVars: ['cluster', 'guestname', 'node', 'vmid'],
 
-    updateUIOptions: function() {
-       Proxmox.Utils.API2Request({
-           url: '/cluster/options',
-           method: 'GET',
-           success: function(response) {
-               PVE.UIOptions = {};
-               PVE.UIOptions.console = response?.result?.data?.console;
-           },
-       });
+    renderTags: function(tagstext, overrides) {
+       let text = '';
+       if (tagstext) {
+           let tags = (tagstext.split(/[,; ]/) || []).filter(t => !!t);
+           if (PVE.UIOptions.shouldSortTags()) {
+               tags = tags.sort((a, b) => {
+                   let alc = a.toLowerCase();
+                   let blc = b.toLowerCase();
+                   return alc < blc ? -1 : blc < alc ? 1 : a.localeCompare(b);
+               });
+           }
+           text += ' ';
+           tags.forEach((tag) => {
+               text += Proxmox.Utils.getTagElement(tag, overrides);
+           });
+       }
+       return text;
+    },
+
+    tagCharRegex: /^[a-z0-9+_.-]+$/i,
+
+    verificationStateOrder: {
+       'failed': 0,
+       'none': 1,
+       'ok': 2,
+       '__default__': 3,
+    },
+
+    isStandaloneNode: function() {
+       return PVE.data.ResourceStore.getNodes().length < 2;
+    },
+
+    // main use case of this helper is the login window
+    getUiLanguage: function() {
+       let languageCookie = Ext.util.Cookies.get('PVELangCookie');
+       if (languageCookie === 'kr') {
+           // fix-up 'kr' being used for Korean by mistake FIXME: remove with PVE 9
+           let dt = Ext.Date.add(new Date(), Ext.Date.YEAR, 10);
+           languageCookie = 'ko';
+           Ext.util.Cookies.set('PVELangCookie', languageCookie, dt);
+       }
+       return languageCookie || Proxmox.defaultLang || 'en';
     },
 },
 
@@ -1911,7 +2004,7 @@ Ext.define('PVE.Utils', {
            lvmremove: ['Volume Group', gettext('Remove')],
            lvmthincreate: [gettext('LVM-Thin Storage'), gettext('Create')],
            lvmthinremove: ['Thinpool', gettext('Remove')],
-           migrateall: ['', gettext('Migrate all VMs and Containers')],
+           migrateall: ['', gettext('Bulk migrate VMs and Containers')],
            'move_volume': ['CT', gettext('Move Volume')],
            'pbs-download': ['VM/CT', gettext('File Restore Download')],
            pull_file: ['CT', gettext('Pull file')],
@@ -1935,10 +2028,12 @@ Ext.define('PVE.Utils', {
            qmstop: ['VM', gettext('Stop')],
            qmsuspend: ['VM', gettext('Hibernate')],
            qmtemplate: ['VM', gettext('Convert to template')],
+           resize: ['VM/CT', gettext('Resize')],
            spiceproxy: ['VM/CT', gettext('Console') + ' (Spice)'],
            spiceshell: ['', gettext('Shell') + ' (Spice)'],
-           startall: ['', gettext('Start all VMs and Containers')],
-           stopall: ['', gettext('Stop all VMs and Containers')],
+           startall: ['', gettext('Bulk start VMs and Containers')],
+           stopall: ['', gettext('Bulk shutdown VMs and Containers')],
+           suspendall: ['', gettext('Suspend all VMs')],
            unknownimgdel: ['', gettext('Destroy image from unknown guest')],
            wipedisk: ['Device', gettext('Wipe Disk')],
            vncproxy: ['VM/CT', gettext('Console')],