]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
website: update external links to www.proxmox.com
[pve-manager.git] / www / manager6 / Utils.js
index 63c70e61c26d0d9a22df17b61d797ec2a28d5386..6d4842df2578cfe466d38f93a0c53458ede1c8cc 100644 (file)
@@ -34,15 +34,24 @@ 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': [
+           { desc: '11/2022', val: 'win11' },
            { desc: '10/2016/2019', val: 'win10' },
            { desc: '8.x/2012/2012r2', val: 'win8' },
            { desc: '7/2008r2', val: 'win7' },
@@ -392,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) {
@@ -472,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;
            }
@@ -504,13 +517,10 @@ Ext.define('PVE.Utils', {
            return PVE.Parser.printPropertyString(value);
        }
     },
-    render_as_property_string: function(value) {
-       return !value ? Proxmox.Utils.defaultText
-           : PVE.Parser.printPropertyString(value);
-    },
+    render_as_property_string: v => !v ? Proxmox.Utils.defaultText : PVE.Parser.printPropertyString(v),
 
     render_scsihw: function(value) {
-       if (!value) {
+       if (!value || value === '__default__') {
            return Proxmox.Utils.defaultText + ' (LSI 53C895A)';
        } else if (value === 'lsi') {
            return 'LSI 53C895A';
@@ -548,6 +558,7 @@ Ext.define('PVE.Utils', {
     // fixme: auto-generate this
     // for now, please keep in sync with PVE::Tools::kvmkeymaps
     kvm_keymaps: {
+       '__default__': Proxmox.Utils.defaultText,
        //ar: 'Arabic',
        da: 'Danish',
        de: 'German',
@@ -584,6 +595,7 @@ Ext.define('PVE.Utils', {
     },
 
     kvm_vga_drivers: {
+       '__default__': Proxmox.Utils.defaultText,
        std: gettext('Standard VGA'),
        vmware: gettext('VMware compatible'),
        qxl: 'SPICE',
@@ -595,6 +607,7 @@ Ext.define('PVE.Utils', {
        serial2: gettext('Serial terminal') + ' 2',
        serial3: gettext('Serial terminal') + ' 3',
        virtio: 'VirtIO-GPU',
+       'virtio-gl': 'VirGL GPU',
        none: Proxmox.Utils.noneText,
     },
 
@@ -602,20 +615,8 @@ Ext.define('PVE.Utils', {
        if (!value || value === '__default__') {
            return Proxmox.Utils.defaultText;
        }
-       var text = PVE.Utils.kvm_keymaps[value];
-       if (text) {
-           return text + ' (' + value + ')';
-       }
-       return value;
-    },
-
-    kvm_keymap_array: function() {
-       var data = [['__default__', PVE.Utils.render_kvm_language('')]];
-       Ext.Object.each(PVE.Utils.kvm_keymaps, function(key, value) {
-           data.push([key, PVE.Utils.render_kvm_language(value)]);
-       });
-
-       return data;
+       let text = PVE.Utils.kvm_keymaps[value];
+       return text ? `${text} (${value})` : value;
     },
 
     console_map: {
@@ -627,40 +628,19 @@ Ext.define('PVE.Utils', {
 
     render_console_viewer: function(value) {
        value = value || '__default__';
-       if (PVE.Utils.console_map[value]) {
-           return PVE.Utils.console_map[value];
-       }
-       return value;
-    },
-
-    console_viewer_array: function() {
-       return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) {
-           return [v, PVE.Utils.render_console_viewer(v)];
-       });
+       return PVE.Utils.console_map[value] || value;
     },
 
     render_kvm_vga_driver: function(value) {
        if (!value) {
            return Proxmox.Utils.defaultText;
        }
-       var vga = PVE.Parser.parsePropertyString(value, 'type');
-       var text = PVE.Utils.kvm_vga_drivers[vga.type];
+       let vga = PVE.Parser.parsePropertyString(value, 'type');
+       let text = PVE.Utils.kvm_vga_drivers[vga.type];
        if (!vga.type) {
            text = Proxmox.Utils.defaultText;
        }
-       if (text) {
-           return text + ' (' + value + ')';
-       }
-       return value;
-    },
-
-    kvm_vga_driver_array: function() {
-       var data = [['__default__', PVE.Utils.render_kvm_vga_driver('')]];
-       Ext.Object.each(PVE.Utils.kvm_vga_drivers, function(key, value) {
-           data.push([key, PVE.Utils.render_kvm_vga_driver(value)]);
-       });
-
-       return data;
+       return text ? `${text} (${value})` : value;
     },
 
     render_kvm_startup: function(value) {
@@ -793,7 +773,7 @@ Ext.define('PVE.Utils', {
            backups: true,
        },
        cifs: {
-           name: 'CIFS',
+           name: 'SMB/CIFS',
            ipanel: 'CIFSInputPanel',
            faIcon: 'building',
            backups: true,
@@ -999,11 +979,8 @@ Ext.define('PVE.Utils', {
            value = !record || record.get('monhost') ? 'cephfs' : 'pvecephfs';
        }
 
-       var schema = PVE.Utils.storageSchema[value];
-       if (schema) {
-           return schema.name;
-       }
-       return Proxmox.Utils.unknownText;
+       let schema = PVE.Utils.storageSchema[value];
+       return schema?.name ?? value;
     },
 
     format_ha: function(value) {
@@ -1026,15 +1003,18 @@ 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 {
+           result = data.volid.replace(/^.*?:(.*?\/)?/, '');
        }
-       return data.volid.replace(/^.*?:(.*?\/)?/, '');
+       return Ext.String.htmlEncode(result);
     },
 
     render_serverity: function(value) {
@@ -1101,6 +1081,18 @@ Ext.define('PVE.Utils', {
        return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s');
     },
 
+    // render a timestamp or pending
+    render_next_event: function(value) {
+       if (!value) {
+           return '-';
+       }
+       let now = new Date(), next = new Date(value * 1000);
+       if (next < now) {
+           return gettext('pending');
+       }
+       return Proxmox.Utils.render_timestamp(value);
+    },
+
     calculate_mem_usage: function(data) {
        if (!Ext.isNumeric(data.mem) ||
            data.maxmem === 0 ||
@@ -1301,15 +1293,19 @@ Ext.define('PVE.Utils', {
        return Ext.htmlEncode(first + " " + last);
     },
 
-    render_u2f_error: function(error) {
-       var ErrorNames = {
-           '1': gettext('Other Error'),
-           '2': gettext('Bad Request'),
-           '3': gettext('Configuration Unsupported'),
-           '4': gettext('Device Ineligible'),
-           '5': gettext('Timeout'),
-       };
-       return "U2F Error: " + ErrorNames[error] || Proxmox.Utils.unknownText;
+    // 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() {
@@ -1366,7 +1362,7 @@ Ext.define('PVE.Utils', {
            allowSpice = consoles.spice;
            allowXtermjs = !!consoles.xtermjs;
        }
-       let dv = PVE.VersionInfo.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) {
@@ -1547,6 +1543,7 @@ Ext.define('PVE.Utils', {
        sata: 6,
        scsi: 31,
        virtio: 16,
+       unused: 256,
     },
 
     // types is either undefined (all busses), an array of busses, or a single bus
@@ -1578,12 +1575,12 @@ Ext.define('PVE.Utils', {
     },
 
     mp_counts: {
-       mps: 256,
+       mp: 256,
        unused: 256,
     },
 
     forEachMP: function(func, includeUnused) {
-       for (let i = 0; i < PVE.Utils.mp_counts.mps; i++) {
+       for (let i = 0; i < PVE.Utils.mp_counts.mp; i++) {
            let cont = func('mp', i);
            if (!cont && cont !== undefined) {
                return;
@@ -1602,7 +1599,58 @@ Ext.define('PVE.Utils', {
        }
     },
 
-    hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1, tpmstate: 1 },
+    hardware_counts: {
+       net: 32,
+       usb: 14,
+       usb_old: 5,
+       hostpci: 16,
+       audio: 1,
+       efidisk: 1,
+       serial: 4,
+       rng: 1,
+       tpmstate: 1,
+    },
+
+    // we can have usb6 and up only for specific machine/ostypes
+    get_max_usb_count: function(ostype, machine) {
+       if (!ostype) {
+           return PVE.Utils.hardware_counts.usb_old;
+       }
+
+       let match = /-(\d+).(\d+)/.exec(machine ?? '');
+       if (!match || PVE.Utils.qemu_min_version([match[1], match[2]], [7, 1])) {
+           if (ostype === 'l26') {
+               return PVE.Utils.hardware_counts.usb;
+           }
+           let os_match = /^win(\d+)$/.exec(ostype);
+           if (os_match && os_match[1] > 7) {
+               return PVE.Utils.hardware_counts.usb;
+           }
+       }
+
+       return PVE.Utils.hardware_counts.usb_old;
+    },
+
+    // parameters are expected to be arrays, e.g. [7,1], [4,0,1]
+    // returns true if toCheck is equal or greater than minVersion
+    qemu_min_version: function(toCheck, minVersion) {
+       let i;
+       for (i = 0; i < toCheck.length && i < minVersion.length; i++) {
+           if (toCheck[i] < minVersion[i]) {
+               return false;
+           }
+       }
+
+       if (minVersion.length > toCheck.length) {
+           for (; i < minVersion.length; i++) {
+               if (minVersion[i] !== 0) {
+                   return false;
+               }
+           }
+       }
+
+       return true;
+    },
 
     cleanEmptyObjectKeys: function(obj) {
        for (const propName of Object.keys(obj)) {
@@ -1665,6 +1713,9 @@ Ext.define('PVE.Utils', {
                    });
                    win.getViewModel().set('isInstalled', isInstalled);
                    container.add(win);
+                   win.on('close', () => {
+                       container.el.unmask();
+                   });
                    win.show();
                    callback(win);
                }
@@ -1684,7 +1735,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 => {
@@ -1803,6 +1854,67 @@ Ext.define('PVE.Utils', {
 
        return undefined;
     },
+
+    nextFreeMP: function(type, config) {
+       for (let i = 0; i < PVE.Utils.mp_counts[type]; i++) {
+           let confid = `${type}${i}`;
+           if (!Ext.isDefined(config[confid])) {
+               return {
+                   type,
+                   id: i,
+                   confid,
+               };
+           }
+       }
+
+       return undefined;
+    },
+
+    escapeNotesTemplate: function(value) {
+       let replace = {
+           '\\': '\\\\',
+           '\n': '\\n',
+       };
+       return value.replace(/(\\|[\n])/g, match => replace[match]);
+    },
+
+    unEscapeNotesTemplate: function(value) {
+       let replace = {
+           '\\\\': '\\',
+           '\\n': '\n',
+       };
+       return value.replace(/(\\\\|\\n)/g, match => replace[match]);
+    },
+
+    notesTemplateVars: ['cluster', 'guestname', 'node', 'vmid'],
+
+    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,
+    },
 },
 
     singleton: true,
@@ -1830,6 +1942,7 @@ Ext.define('PVE.Utils', {
            cephdestroymon: ['Ceph Monitor', gettext('Destroy')],
            cephdestroyosd: ['Ceph OSD', gettext('Destroy')],
            cephdestroypool: ['Ceph Pool', gettext('Destroy')],
+           cephdestroyfs: ['CephFS', gettext('Destroy')],
            cephfscreate: ['CephFS', gettext('Create')],
            cephsetpool: ['Ceph Pool', gettext('Edit')],
            cephsetflags: ['', gettext('Change global Ceph flags')],
@@ -1845,7 +1958,9 @@ Ext.define('PVE.Utils', {
            imgcopy: ['', gettext('Copy data')],
            imgdel: ['', gettext('Erase data')],
            lvmcreate: [gettext('LVM Storage'), gettext('Create')],
+           lvmremove: ['Volume Group', gettext('Remove')],
            lvmthincreate: [gettext('LVM-Thin Storage'), gettext('Create')],
+           lvmthinremove: ['Thinpool', gettext('Remove')],
            migrateall: ['', gettext('Migrate all VMs and Containers')],
            'move_volume': ['CT', gettext('Move Volume')],
            'pbs-download': ['VM/CT', gettext('File Restore Download')],
@@ -1870,6 +1985,7 @@ 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')],
@@ -1897,6 +2013,7 @@ Ext.define('PVE.Utils', {
            vztemplate: ['CT', gettext('Convert to template')],
            vzumount: ['CT', gettext('Unmount')],
            zfscreate: [gettext('ZFS Storage'), gettext('Create')],
+           zfsremove: ['ZFS Pool', gettext('Remove')],
        });
     },