]> git.proxmox.com Git - pve-manager.git/blobdiff - www/manager6/Utils.js
ui: utils: rework kvm-vga/keymaps and console-viewer schema handling
[pve-manager.git] / www / manager6 / Utils.js
index b2066fca2576b313f13cad043a40f7bb5f7a250b..3e39ea6cf18a29d2aee39d79781363b804b2e886 100644 (file)
@@ -1,19 +1,6 @@
 Ext.ns('PVE');
 
-// avoid errors related to Accessible Rich Internet Applications
-// (access for people with disabilities)
-// TODO reenable after all components are upgraded
-Ext.enableAria = false;
-Ext.enableAriaButtons = false;
-Ext.enableAriaPanels = false;
-
-// avoid errors when running without development tools
-if (!Ext.isDefined(Ext.global.console)) {
-    var console = {
-       log: function() {},
-    };
-}
-console.log("Starting PVE Manager");
+console.log("Starting Proxmox VE Manager");
 
 Ext.Ajax.defaultHeaders = {
     'Accept': 'application/json',
@@ -26,7 +13,7 @@ Ext.define('PVE.Utils', {
 
     toolkit: undefined, // (extjs|touch), set inside Toolkit.js
 
-    bus_match: /^(ide|sata|virtio|scsi)\d+$/,
+    bus_match: /^(ide|sata|virtio|scsi)(\d+)$/,
 
     log_severity_hash: {
        0: "panic",
@@ -56,6 +43,7 @@ Ext.define('PVE.Utils', {
            { 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' },
@@ -151,7 +139,7 @@ Ext.define('PVE.Utils', {
            bvers = b.toString().split('.');
        }
 
-       while (true) {
+       for (;;) {
            let av = avers.shift();
            let bv = bvers.shift();
 
@@ -163,7 +151,7 @@ Ext.define('PVE.Utils', {
                return 1;
            } else {
                let diff = parseInt(av, 10) - parseInt(bv, 10);
-               if (diff != 0) return diff;
+               if (diff !== 0) return diff;
                // else we need to look at the next parts
            }
        }
@@ -186,6 +174,50 @@ Ext.define('PVE.Utils', {
        'HEALTH_ERR': 'critical',
     },
 
+    render_sdn_pending: function(rec, value, key, index) {
+       if (rec.data.state === undefined || rec.data.state === null) {
+           return value;
+       }
+
+       if (rec.data.state === 'deleted') {
+           if (value === undefined) {
+               return ' ';
+           } else {
+               return '<div style="text-decoration: line-through;">'+ value +'</div>';
+           }
+       } else if (rec.data.pending[key] !== undefined && rec.data.pending[key] !== null) {
+           if (rec.data.pending[key] === 'deleted') {
+               return ' ';
+           } else {
+               return rec.data.pending[key];
+           }
+       }
+       return value;
+    },
+
+    render_sdn_pending_state: function(rec, value) {
+       if (value === undefined || value === null) {
+           return ' ';
+       }
+
+       let icon = `<i class="fa fa-fw fa-refresh warning"></i>`;
+
+       if (value === 'deleted') {
+           return '<span>' + icon + value + '</span>';
+       }
+
+       let tip = gettext('Pending Changes') + ': <br>';
+
+       for (const [key, keyvalue] of Object.entries(rec.data.pending)) {
+           if ((rec.data[key] !== undefined && rec.data.pending[key] !== rec.data[key]) ||
+               rec.data[key] === undefined
+           ) {
+               tip += `${key}: ${keyvalue} <br>`;
+           }
+       }
+       return '<span data-qtip="' + tip + '">'+ icon + value + '</span>';
+    },
+
     render_ceph_health: function(healthObj) {
        var state = {
            iconCls: PVE.Utils.get_health_icon(),
@@ -205,7 +237,7 @@ Ext.define('PVE.Utils', {
     },
 
     render_zfs_health: function(value) {
-       if (typeof value == 'undefined') {
+       if (typeof value === 'undefined') {
            return "";
        }
        var iconCls = 'question-circle';
@@ -268,7 +300,7 @@ Ext.define('PVE.Utils', {
     },
 
     render_backup_status: function(value, meta, record) {
-       if (typeof value == 'undefined') {
+       if (typeof value === 'undefined') {
            return "";
        }
 
@@ -321,11 +353,11 @@ Ext.define('PVE.Utils', {
            if (item > 2) {
                days.push(Ext.Date.dayNames[cur+1] + '-' + Ext.Date.dayNames[(cur+item)%7]);
                cur += item-1;
-           } else if (item == 2) {
+           } else if (item === 2) {
                days.push(Ext.Date.dayNames[cur+1]);
                days.push(Ext.Date.dayNames[(cur+2)%7]);
                cur++;
-           } else if (item == 1) {
+           } else if (item === 1) {
                days.push(Ext.Date.dayNames[(cur+1)%7]);
            }
        });
@@ -421,36 +453,31 @@ Ext.define('PVE.Utils', {
        return Proxmox.Utils.format_boolean(value);
     },
 
-    render_qga_features: function(value) {
-       if (!value) {
+    render_qga_features: function(config) {
+       if (!config) {
            return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')';
        }
-       var props = PVE.Parser.parsePropertyString(value, 'enabled');
-       if (!PVE.Parser.parseBoolean(props.enabled)) {
+       let qga = PVE.Parser.parsePropertyString(config, 'enabled');
+       if (!PVE.Parser.parseBoolean(qga.enabled)) {
            return Proxmox.Utils.disabledText;
        }
+       delete qga.enabled;
 
-       delete props.enabled;
-       var agentstring = Proxmox.Utils.enabledText;
-
-       Ext.Object.each(props, function(key, value) {
-           var keystring = '';
-           agentstring += ', ' + key + ': ';
+       let agentstring = Proxmox.Utils.enabledText;
 
+       for (const [key, value] of Object.entries(qga)) {
+           let displayText = Proxmox.Utils.disabledText;
            if (key === 'type') {
                let map = {
                    isa: "ISA",
                    virtio: "VirtIO",
                };
-               agentstring += map[value] || Proxmox.Utils.unknownText;
-           } else {
-               if (PVE.Parser.parseBoolean(value)) {
-                   agentstring += Proxmox.Utils.enabledText;
-               } else {
-                   agentstring += Proxmox.Utils.disabledText;
-               }
+               displayText = map[value] || Proxmox.Utils.unknownText;
+           } else if (PVE.Parser.parseBoolean(value)) {
+               displayText = Proxmox.Utils.enabledText;
            }
-       });
+           agentstring += `, ${key}: ${displayText}`;
+       }
 
        return agentstring;
     },
@@ -478,10 +505,7 @@ 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) {
@@ -522,6 +546,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',
@@ -556,8 +581,10 @@ Ext.define('PVE.Utils', {
        //th: 'Thai',
        tr: 'Turkish',
     },
+    kvm_keymap_array: () => Object.entries(PVE.Utils.kvm_keymaps),
 
     kvm_vga_drivers: {
+       '__default__': Proxmox.Utils.defaultText,
        std: gettext('Standard VGA'),
        vmware: gettext('VMware compatible'),
        qxl: 'SPICE',
@@ -571,25 +598,14 @@ Ext.define('PVE.Utils', {
        virtio: 'VirtIO-GPU',
        none: Proxmox.Utils.noneText,
     },
+    kvm_vga_driver_array: () => Object.entries(PVE.Utils.kvm_vga_drivers),
 
     render_kvm_language: function(value) {
-       if (!value || value === '__default__') {
+       if (!value) {
            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: {
@@ -598,43 +614,23 @@ Ext.define('PVE.Utils', {
        'html5': 'HTML5 (noVNC)',
        'xtermjs': 'xterm.js',
     },
+    console_viewer_array: () => Object.entries(PVE.Utils.console_map),
 
     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) {
@@ -700,22 +696,38 @@ Ext.define('PVE.Utils', {
            ipanel: 'pveAuthADPanel',
            syncipanel: 'pveAuthLDAPSyncPanel',
            add: true,
+           tfa: true,
+           pwchange: true,
        },
        ldap: {
            name: gettext('LDAP Server'),
            ipanel: 'pveAuthLDAPPanel',
            syncipanel: 'pveAuthLDAPSyncPanel',
            add: true,
+           tfa: true,
+           pwchange: true,
+       },
+       openid: {
+           name: gettext('OpenID Connect Server'),
+           ipanel: 'pveAuthOpenIDPanel',
+           add: true,
+           tfa: false,
+           pwchange: false,
+           iconCls: 'pmx-itype-icon-openid-logo',
        },
        pam: {
            name: 'Linux PAM',
            ipanel: 'pveAuthBasePanel',
            add: false,
+           tfa: true,
+           pwchange: true,
        },
        pve: {
            name: 'Proxmox VE authentication server',
            ipanel: 'pveAuthBasePanel',
            add: false,
+           tfa: true,
+           pwchange: true,
        },
     },
 
@@ -738,6 +750,12 @@ Ext.define('PVE.Utils', {
            faIcon: 'folder',
            backups: false,
        },
+       btrfs: {
+           name: 'BTRFS',
+           ipanel: 'BTRFSInputPanel',
+           faIcon: 'folder',
+           backups: true,
+       },
        nfs: {
            name: 'NFS',
            ipanel: 'NFSInputPanel',
@@ -745,7 +763,7 @@ Ext.define('PVE.Utils', {
            backups: true,
        },
        cifs: {
-           name: 'CIFS',
+           name: 'SMB/CIFS',
            ipanel: 'CIFSInputPanel',
            faIcon: 'building',
            backups: true,
@@ -862,6 +880,46 @@ Ext.define('PVE.Utils', {
            ipanel: 'EvpnInputPanel',
            faIcon: 'crosshairs',
        },
+       bgp: {
+           name: 'bgp',
+           ipanel: 'BgpInputPanel',
+           faIcon: 'crosshairs',
+       },
+    },
+
+    sdnipamSchema: {
+       ipam: {
+            name: 'ipam',
+            hideAdd: true,
+       },
+       pve: {
+           name: 'PVE',
+           ipanel: 'PVEIpamInputPanel',
+           faIcon: 'th',
+           hideAdd: true,
+       },
+       netbox: {
+           name: 'Netbox',
+           ipanel: 'NetboxInputPanel',
+           faIcon: 'th',
+       },
+       phpipam: {
+           name: 'PhpIpam',
+           ipanel: 'PhpIpamInputPanel',
+           faIcon: 'th',
+       },
+    },
+
+    sdndnsSchema: {
+       dns: {
+            name: 'dns',
+            hideAdd: true,
+       },
+       powerdns: {
+           name: 'powerdns',
+           ipanel: 'PowerdnsInputPanel',
+           faIcon: 'th',
+       },
     },
 
     format_sdnvnet_type: function(value, md, record) {
@@ -888,6 +946,22 @@ Ext.define('PVE.Utils', {
        return Proxmox.Utils.unknownText;
     },
 
+    format_sdnipam_type: function(value, md, record) {
+       var schema = PVE.Utils.sdnipamSchema[value];
+       if (schema) {
+           return schema.name;
+       }
+       return Proxmox.Utils.unknownText;
+    },
+
+    format_sdndns_type: function(value, md, record) {
+       var schema = PVE.Utils.sdndnsSchema[value];
+       if (schema) {
+           return schema.name;
+       }
+       return Proxmox.Utils.unknownText;
+    },
+
     format_storage_type: function(value, md, record) {
        if (value === 'rbd') {
            value = !record || record.get('monhost') ? 'rbd' : 'pveceph';
@@ -895,11 +969,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) {
@@ -938,7 +1009,6 @@ Ext.define('PVE.Utils', {
     },
 
     calculate_hostcpu: function(data) {
-
        if (!(data.uptime && Ext.isNumeric(data.cpu))) {
            return -1;
        }
@@ -958,11 +1028,10 @@ Ext.define('PVE.Utils', {
            return -1;
        }
 
-       return ((data.cpu/maxcpu) * data.maxcpu);
+       return (data.cpu/maxcpu) * data.maxcpu;
     },
 
     render_hostcpu: function(value, metaData, record, rowIndex, colIndex, store) {
-
        if (!(record.data.uptime && Ext.isNumeric(record.data.cpu))) {
            return '';
        }
@@ -999,6 +1068,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 ||
@@ -1010,7 +1091,6 @@ Ext.define('PVE.Utils', {
     },
 
     calculate_hostmem_usage: function(data) {
-
        if (data.type !== 'qemu' && data.type !== 'lxc') {
            return -1;
        }
@@ -1029,7 +1109,7 @@ Ext.define('PVE.Utils', {
            return -1;
        }
 
-       return (data.mem / maxmem);
+       return data.mem / maxmem;
     },
 
     render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
@@ -1052,7 +1132,6 @@ Ext.define('PVE.Utils', {
     },
 
     render_hostmem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
-
        if (!Ext.isNumeric(record.data.mem) || value === -1) {
            return '';
        }
@@ -1065,7 +1144,7 @@ Ext.define('PVE.Utils', {
        var node = PVE.data.ResourceStore.getAt(index);
        var maxmem = node.data.maxmem || 0;
 
-       if (record.data.mem > 1 ) {
+       if (record.data.mem > 1) {
            // we got no percentage but bytes
            var mem = record.data.mem;
            if (!record.data.uptime ||
@@ -1096,9 +1175,9 @@ Ext.define('PVE.Utils', {
 
     calculate_disk_usage: function(data) {
        if (!Ext.isNumeric(data.disk) ||
-           data.type === 'qemu' ||
-           data.type === 'lxc' && data.uptime === 0 ||
-           data.maxdisk === 0) {
+           ((data.type === 'qemu' || data.type === 'lxc') && data.uptime === 0) ||
+           data.maxdisk === 0
+       ) {
            return -1;
        }
 
@@ -1119,9 +1198,9 @@ Ext.define('PVE.Utils', {
        var type = record.data.type;
 
        if (!Ext.isNumeric(disk) ||
-           type === 'qemu' ||
            maxdisk === 0 ||
-           type === 'lxc' && record.data.uptime === 0) {
+           ((type === 'qemu' || type === 'lxc') && record.data.uptime === 0)
+       ) {
            return '';
        }
 
@@ -1176,8 +1255,7 @@ Ext.define('PVE.Utils', {
     },
 
     render_optional_url: function(value) {
-       var match;
-       if (value && (match = value.match(/^https?:\/\//)) !== null) {
+       if (value && value.match(/^https?:\/\//)) {
            return '<a target="_blank" href="' + value + '">' + value + '</a>';
        }
        return value;
@@ -1202,17 +1280,6 @@ 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;
-    },
-
     windowHostname: function() {
        return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
             function(m, addr, offset, original) { return addr; });
@@ -1224,7 +1291,7 @@ Ext.define('PVE.Utils', {
     },
 
     openConsoleWindow: function(viewer, consoleType, vmid, nodename, vmname, cmd) {
-       if (vmid == undefined && (consoleType === 'kvm' || consoleType === 'lxc')) {
+       if (vmid === undefined && (consoleType === 'kvm' || consoleType === 'lxc')) {
            throw "missing vmid";
        }
        if (!nodename) {
@@ -1330,32 +1397,26 @@ Ext.define('PVE.Utils', {
                Ext.Msg.alert('Error', response.htmlStatus);
            },
            success: function(response, opts) {
-               var raw = "[virt-viewer]\n";
-               Ext.Object.each(response.result.data, function(k, v) {
-                   raw += k + "=" + v + "\n";
-               });
-               var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
-                   encodeURIComponent(raw);
-
-               downloadWithName(url, "pve-spice.vv");
+               let cfg = response.result.data;
+               let raw = Object.entries(cfg).reduce((acc, [k, v]) => acc + `${k}=${v}\n`, "[virt-viewer]\n");
+               let spiceDownload = 'data:application/x-virt-viewer;charset=UTF-8,' + encodeURIComponent(raw);
+               downloadWithName(spiceDownload, "pve-spice.vv");
            },
        });
     },
 
     openTreeConsole: function(tree, record, item, index, e) {
        e.stopEvent();
-       var nodename = record.data.node;
-       var vmid = record.data.vmid;
-       var vmname = record.data.name;
+       let nodename = record.data.node;
+       let vmid = record.data.vmid;
+       let vmname = record.data.name;
        if (record.data.type === 'qemu' && !record.data.template) {
            Proxmox.Utils.API2Request({
-               url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
-               failure: function(response, opts) {
-                   Ext.Msg.alert('Error', response.htmlStatus);
-               },
+               url: `/nodes/${nodename}/qemu/${vmid}/status/current`,
+               failure: response => Ext.Msg.alert('Error', response.htmlStatus),
                success: function(response, opts) {
                    let conf = response.result.data;
-                   var consoles = {
+                   let consoles = {
                        spice: !!conf.spice,
                        xtermjs: !!conf.serial,
                    };
@@ -1369,18 +1430,10 @@ Ext.define('PVE.Utils', {
 
     // test automation helper
     call_menu_handler: function(menu, text) {
-       var list = menu.query('menuitem');
-
-       Ext.Array.each(list, function(item) {
-           if (item.text === text) {
-               if (item.handler) {
-                   item.handler();
-                   return 1;
-               } else {
-                   return undefined;
-               }
-           }
-       });
+       let item = menu.query('menuitem').find(el => el.text === text);
+       if (item && item.handler) {
+           item.handler();
+       }
     },
 
     createCmdMenu: function(v, record, item, index, event) {
@@ -1388,25 +1441,22 @@ Ext.define('PVE.Utils', {
        if (!(v instanceof Ext.tree.View)) {
            v.select(record);
        }
-       var menu;
-       var template = !!record.data.template;
-       var type = record.data.type;
+       let menu;
+       let type = record.data.type;
 
-       if (template) {
-           if (type === 'qemu' || type == 'lxc') {
+       if (record.data.template) {
+           if (type === 'qemu' || type === 'lxc') {
                menu = Ext.create('PVE.menu.TemplateMenu', {
                    pveSelNode: record,
                });
            }
-       } else if (type === 'qemu' ||
-                  type === 'lxc' ||
-                  type === 'node') {
+       } else if (type === 'qemu' || type === 'lxc' || type === 'node') {
            menu = Ext.create('PVE.' + type + '.CmdMenu', {
                pveSelNode: record,
                nodename: record.data.node,
            });
        } else {
-           return;
+           return undefined;
        }
 
        menu.showAt(event.getXY());
@@ -1433,21 +1483,19 @@ Ext.define('PVE.Utils', {
     },
 
     loadSSHKeyFromFile: function(file, callback) {
-       // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
-       // a user@host comment, 1420 for 8192 bits; current max is 16kbit
-       // assume: 740*8 for max. 32kbit (5920 byte file)
-       // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
-       if (file.size > 8192) {
-           Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
+       // ssh-keygen produces ~ 740 bytes for a 4096 bit RSA key,  current max is 16 kbit, so assume:
+       // 740 * 8 for max. 32kbit (5920 bytes), round upwards to 8192 bytes, leaves lots of comment space
+       PVE.Utils.loadFile(file, callback, 8192);
+    },
+
+    loadFile: function(file, callback, maxSize) {
+       maxSize = maxSize || 32 * 1024;
+       if (file.size > maxSize) {
+           Ext.Msg.alert(gettext('Error'), `${gettext("Invalid file size")}: ${file.size} > ${maxSize}`);
            return;
        }
-       /*global
-         FileReader
-       */
-       var reader = new FileReader();
-       reader.onload = function(evt) {
-           callback(evt.target.result);
-       };
+       let reader = new FileReader();
+       reader.onload = evt => callback(evt.target.result);
        reader.readAsText(file);
     },
 
@@ -1457,9 +1505,6 @@ Ext.define('PVE.Utils', {
            Ext.Msg.alert(gettext('Error'), gettext("Invalid file size: ") + file.size);
            return;
        }
-       /*global
-         FileReader
-       */
        let reader = new FileReader();
        reader.onload = evt => callback(evt.target.result);
        reader.readAsText(file);
@@ -1470,12 +1515,12 @@ 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
     forEachBus: function(types, func) {
-       var busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
-       var i, j, count, cont;
+       let busses = Object.keys(PVE.Utils.diskControllerMaxIDs);
 
        if (Ext.isArray(types)) {
            busses = types;
@@ -1484,16 +1529,16 @@ Ext.define('PVE.Utils', {
        }
 
        // check if we only have valid busses
-       for (i = 0; i < busses.length; i++) {
+       for (let i = 0; i < busses.length; i++) {
            if (!PVE.Utils.diskControllerMaxIDs[busses[i]]) {
                throw "invalid bus: '" + busses[i] + "'";
            }
        }
 
-       for (i = 0; i < busses.length; i++) {
-           count = PVE.Utils.diskControllerMaxIDs[busses[i]];
-           for (j = 0; j < count; j++) {
-               cont = func(busses[i], j);
+       for (let i = 0; i < busses.length; i++) {
+           let count = PVE.Utils.diskControllerMaxIDs[busses[i]];
+           for (let j = 0; j < count; j++) {
+               let cont = func(busses[i], j);
                if (!cont && cont !== undefined) {
                    return;
                }
@@ -1501,12 +1546,14 @@ Ext.define('PVE.Utils', {
        }
     },
 
-    mp_counts: { mps: 256, unused: 256 },
+    mp_counts: {
+       mp: 256,
+       unused: 256,
+    },
 
     forEachMP: function(func, includeUnused) {
-       var i, cont;
-       for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
-           cont = func('mp', i);
+       for (let i = 0; i < PVE.Utils.mp_counts.mp; i++) {
+           let cont = func('mp', i);
            if (!cont && cont !== undefined) {
                return;
            }
@@ -1516,23 +1563,20 @@ Ext.define('PVE.Utils', {
            return;
        }
 
-       for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
-           cont = func('unused', i);
+       for (let i = 0; i < PVE.Utils.mp_counts.unused; i++) {
+           let cont = func('unused', i);
            if (!cont && cont !== undefined) {
                return;
            }
        }
     },
 
-    hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1 },
+    hardware_counts: { net: 32, usb: 5, hostpci: 16, audio: 1, efidisk: 1, serial: 4, rng: 1, tpmstate: 1 },
 
     cleanEmptyObjectKeys: function(obj) {
-       var propName;
-       for (propName in obj) {
-           if (obj.hasOwnProperty(propName)) {
-               if (obj[propName] === null || obj[propName] === undefined) {
-                   delete obj[propName];
-               }
+       for (const propName of Object.keys(obj)) {
+           if (obj[propName] === null || obj[propName] === undefined) {
+               delete obj[propName];
            }
        }
     },
@@ -1551,22 +1595,23 @@ Ext.define('PVE.Utils', {
 
     remove_domain_from_acme: function(acme, domain) {
        if (acme.domains !== undefined) {
-           acme.domains = acme.domains.filter((value, index, self) => self.indexOf(value) === index && value !== domain);
+           acme.domains = acme
+               .domains
+               .filter((value, index, self) => self.indexOf(value) === index && value !== domain);
        }
        return acme;
     },
 
-    handleStoreErrorOrMask: function(me, store, regex, callback) {
-       me.mon(store, 'load', function(proxy, response, success, operation) {
+    handleStoreErrorOrMask: function(view, store, regex, callback) {
+       view.mon(store, 'load', function(proxy, response, success, operation) {
            if (success) {
-               Proxmox.Utils.setErrorMask(me, false);
+               Proxmox.Utils.setErrorMask(view, false);
                return;
            }
-           var msg;
-
+           let msg;
            if (operation.error.statusText) {
                if (operation.error.statusText.match(regex)) {
-                   callback(me, operation.error);
+                   callback(view, operation.error);
                    return;
                } else {
                    msg = operation.error.statusText + ' (' + operation.error.status + ')';
@@ -1574,7 +1619,7 @@ Ext.define('PVE.Utils', {
            } else {
                msg = gettext('Connection error');
            }
-           Proxmox.Utils.setErrorMask(me, msg);
+           Proxmox.Utils.setErrorMask(view, msg);
        });
     },
 
@@ -1681,6 +1726,67 @@ Ext.define('PVE.Utils', {
 
        return true;
     },
+
+    sortByPreviousUsage: function(vmconfig, controllerList) {
+       if (!controllerList) {
+           controllerList = ['ide', 'virtio', 'scsi', 'sata'];
+       }
+       let usedControllers = {};
+       for (const type of Object.keys(PVE.Utils.diskControllerMaxIDs)) {
+           usedControllers[type] = 0;
+       }
+
+       for (const property of Object.keys(vmconfig)) {
+           if (property.match(PVE.Utils.bus_match) && !vmconfig[property].match(/media=cdrom/)) {
+               const foundController = property.match(PVE.Utils.bus_match)[1];
+               usedControllers[foundController]++;
+           }
+       }
+
+       let sortPriority = PVE.qemu.OSDefaults.getDefaults(vmconfig.ostype).busPriority;
+
+       let sortedList = Ext.clone(controllerList);
+       sortedList.sort(function(a, b) {
+           if (usedControllers[b] === usedControllers[a]) {
+               return sortPriority[b] - sortPriority[a];
+           }
+           return usedControllers[b] - usedControllers[a];
+       });
+
+       return sortedList;
+    },
+
+    nextFreeDisk: function(controllers, config) {
+       for (const controller of controllers) {
+           for (let i = 0; i < PVE.Utils.diskControllerMaxIDs[controller]; i++) {
+               let confid = controller + i.toString();
+               if (!Ext.isDefined(config[confid])) {
+                   return {
+                       controller,
+                       id: i,
+                       confid,
+                   };
+               }
+           }
+       }
+
+       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;
+    },
 },
 
     singleton: true,
@@ -1708,6 +1814,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')],
@@ -1715,7 +1822,7 @@ Ext.define('PVE.Utils', {
            clusterjoin: ['', gettext('Join Cluster')],
            dircreate: [gettext('Directory Storage'), gettext('Create')],
            dirremove: [gettext('Directory'), gettext('Remove')],
-           download: ['', gettext('Download')],
+           download: [gettext('File'), gettext('Download')],
            hamigrate: ['HA', gettext('Migrate')],
            hashutdown: ['HA', gettext('Shutdown')],
            hastart: ['HA', gettext('Start')],
@@ -1723,7 +1830,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')],
@@ -1753,6 +1862,7 @@ Ext.define('PVE.Utils', {
            startall: ['', gettext('Start all VMs and Containers')],
            stopall: ['', gettext('Stop all VMs and Containers')],
            unknownimgdel: ['', gettext('Destroy image from unknown guest')],
+           wipedisk: ['Device', gettext('Wipe Disk')],
            vncproxy: ['VM/CT', gettext('Console')],
            vncshell: ['', gettext('Shell')],
            vzclone: ['CT', gettext('Clone')],
@@ -1774,6 +1884,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')],
        });
     },