// avoid errors when running without development tools
if (!Ext.isDefined(Ext.global.console)) {
var console = {
- dir: function() {},
log: function() {}
};
}
'Accept': 'application/json'
};
+/*jslint confusion: true */
Ext.define('PVE.Utils', { utilities: {
// this singleton contains miscellaneous utilities
return state;
},
+ render_zfs_health: function(value) {
+ if (typeof value == 'undefined'){
+ return "";
+ }
+ var iconCls = 'question-circle';
+ switch (value) {
+ case 'AVAIL':
+ case 'ONLINE':
+ iconCls = 'check-circle good';
+ break;
+ case 'REMOVED':
+ case 'DEGRADED':
+ iconCls = 'exclamation-circle warning';
+ break;
+ case 'UNAVAIL':
+ case 'FAULTED':
+ case 'OFFLINE':
+ iconCls = 'times-circle critical';
+ break;
+ default: //unknown
+ }
+
+ return '<i class="fa fa-' + iconCls + '"></i> ' + value;
+
+ },
+
get_kvm_osinfo: function(value) {
var info = { base: 'Other' }; // default
if (value) {
return fa.join(', ');
},
+ render_qga_features: function(value) {
+ if (!value) {
+ return Proxmox.Utils.defaultText + ' (' + Proxmox.Utils.disabledText + ')';
+ }
+ var props = PVE.Parser.parsePropertyString(value, 'enabled');
+ if (!PVE.Parser.parseBoolean(props.enabled)) {
+ return Proxmox.Utils.disabledText;
+ }
+
+ delete props.enabled;
+ var agentstring = Proxmox.Utils.enabledText;
+
+ Ext.Object.each(props, function(key, value) {
+ var keystring = '' ;
+ agentstring += ', ' + key + ': ';
+
+ if (PVE.Parser.parseBoolean(value)) {
+ agentstring += Proxmox.Utils.enabledText;
+ } else {
+ agentstring += Proxmox.Utils.disabledText;
+ }
+ });
+
+ return agentstring;
+ },
+
render_qemu_bios: function(value) {
if (!value) {
return Proxmox.Utils.defaultText + ' (SeaBIOS)';
serial0: gettext('Serial terminal') + ' 0',
serial1: gettext('Serial terminal') + ' 1',
serial2: gettext('Serial terminal') + ' 2',
- serial3: gettext('Serial terminal') + ' 3'
+ serial3: gettext('Serial terminal') + ' 3',
+ virtio: 'VirtIO-GPU',
+ none: Proxmox.Utils.noneText
},
render_kvm_language: function (value) {
return data;
},
+ console_map: {
+ '__default__': Proxmox.Utils.defaultText + ' (HTML5)',
+ 'vv': 'SPICE (remote-viewer)',
+ 'html5': 'HTML5 (noVNC)',
+ 'xtermjs': 'xterm.js'
+ },
+
render_console_viewer: function(value) {
- if (!value || value === '__default__') {
- return Proxmox.Utils.defaultText + ' (HTML5)';
- } else if (value === 'vv') {
- return 'SPICE (remote-viewer)';
- } else if (value === 'html5') {
- return 'HTML5 (noVNC)';
- } else {
- return 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(['__default__','vv', 'html5'], function(v) {
+ return Ext.Array.map(Object.keys(PVE.Utils.console_map), function(v) {
return [v, PVE.Utils.render_console_viewer(v)];
});
},
if (!value) {
return Proxmox.Utils.defaultText;
}
- var text = PVE.Utils.kvm_vga_drivers[value];
+ var vga = PVE.Parser.parsePropertyString(value, 'type');
+ var text = PVE.Utils.kvm_vga_drivers[vga.type];
+ if (!vga.type) {
+ text = Proxmox.Utils.defaultText;
+ }
if (text) {
return text + ' (' + value + ')';
}
return days.toFixed(1) + 'd';
},
- imagesText: gettext('Disk image'),
- backupFileText: gettext('VZDump backup file'),
- vztmplText: gettext('Container template'),
- isoImageText: gettext('ISO image'),
- containersText: gettext('Container'),
+ contentTypes: {
+ 'images': gettext('Disk image'),
+ 'backup': gettext('VZDump backup file'),
+ 'vztmpl': gettext('Container template'),
+ 'iso': gettext('ISO image'),
+ 'rootdir': gettext('Container'),
+ 'snippets': gettext('Snippets')
+ },
+
+ storageSchema: {
+ dir: {
+ name: Proxmox.Utils.directoryText,
+ ipanel: 'DirInputPanel',
+ faIcon: 'folder'
+ },
+ lvm: {
+ name: 'LVM',
+ ipanel: 'LVMInputPanel',
+ faIcon: 'folder'
+ },
+ lvmthin: {
+ name: 'LVM-Thin',
+ ipanel: 'LvmThinInputPanel',
+ faIcon: 'folder'
+ },
+ nfs: {
+ name: 'NFS',
+ ipanel: 'NFSInputPanel',
+ faIcon: 'building'
+ },
+ cifs: {
+ name: 'CIFS',
+ ipanel: 'CIFSInputPanel',
+ faIcon: 'building'
+ },
+ glusterfs: {
+ name: 'GlusterFS',
+ ipanel: 'GlusterFsInputPanel',
+ faIcon: 'building'
+ },
+ iscsi: {
+ name: 'iSCSI',
+ ipanel: 'IScsiInputPanel',
+ faIcon: 'building'
+ },
+ sheepdog: {
+ name: 'Sheepdog',
+ ipanel: 'SheepdogInputPanel',
+ hideAdd: true,
+ faIcon: 'building'
+ },
+ cephfs: {
+ name: 'CephFS',
+ ipanel: 'CephFSInputPanel',
+ faIcon: 'building'
+ },
+ pvecephfs: {
+ name: 'CephFS (PVE)',
+ ipanel: 'CephFSInputPanel',
+ hideAdd: true,
+ faIcon: 'building'
+ },
+ rbd: {
+ name: 'RBD',
+ ipanel: 'RBDInputPanel',
+ faIcon: 'building'
+ },
+ pveceph: {
+ name: 'RBD (PVE)',
+ ipanel: 'RBDInputPanel',
+ hideAdd: true,
+ faIcon: 'building'
+ },
+ zfs: {
+ name: 'ZFS over iSCSI',
+ ipanel: 'ZFSInputPanel',
+ faIcon: 'building'
+ },
+ zfspool: {
+ name: 'ZFS',
+ ipanel: 'ZFSPoolInputPanel',
+ faIcon: 'folder'
+ },
+ drbd: {
+ name: 'DRBD',
+ hideAdd: true
+ }
+ },
format_storage_type: function(value, md, record) {
- if (value === 'rbd' && record) {
- value = (record.get('monhost')?'rbd_ext':'pveceph');
- }
- if (value === 'dir') {
- return Proxmox.Utils.directoryText;
- } else if (value === 'nfs') {
- return 'NFS';
- } else if (value === 'glusterfs') {
- return 'GlusterFS';
- } else if (value === 'lvm') {
- return 'LVM';
- } else if (value === 'lvmthin') {
- return 'LVM-Thin';
- } else if (value === 'iscsi') {
- return 'iSCSI';
- } else if (value === 'rbd') {
- return 'RBD';
- } else if (value === 'rbd_ext') {
- return 'RBD (external)';
- } else if (value === 'pveceph') {
- return 'RBD (PVE)';
- } else if (value === 'sheepdog') {
- return 'Sheepdog';
- } else if (value === 'zfs') {
- return 'ZFS over iSCSI';
- } else if (value === 'zfspool') {
- return 'ZFS';
- } else if (value === 'iscsidirect') {
- return 'iSCSIDirect';
- } else if (value === 'drbd') {
- return 'DRBD';
- } else {
- return Proxmox.Utils.unknownText;
+ if (value === 'rbd') {
+ value = (!record || record.get('monhost') ? 'rbd' : 'pveceph');
+ } else if (value === 'cephfs') {
+ value = (!record || record.get('monhost') ? 'cephfs' : 'pvecephfs');
}
+
+ var schema = PVE.Utils.storageSchema[value];
+ if (schema) {
+ return schema.name;
+ }
+ return Proxmox.Utils.unknownText;
},
format_ha: function(value) {
},
format_content_types: function(value) {
- var cta = [];
-
- Ext.each(value.split(',').sort(), function(ct) {
- if (ct === 'images') {
- cta.push(PVE.Utils.imagesText);
- } else if (ct === 'backup') {
- cta.push(PVE.Utils.backupFileText);
- } else if (ct === 'vztmpl') {
- cta.push(PVE.Utils.vztmplText);
- } else if (ct === 'iso') {
- cta.push(PVE.Utils.isoImageText);
- } else if (ct === 'rootdir') {
- cta.push(PVE.Utils.containersText);
- }
- });
-
- return cta.join(', ');
+ return value.split(',').sort().map(function(ct) {
+ return PVE.Utils.contentTypes[ct] || ct;
+ }).join(', ');
},
render_storage_content: function(value, metaData, record) {
return PVE.Utils.render_size_usage(record.used, record.total);
},
+ render_optional_url: function(value) {
+ var match;
+ if (value && (match = value.match(/^https?:\/\//)) !== null) {
+ return '<a target="_blank" href="' + value + '">' + value + '</a>';
+ }
+ return value;
+ },
+
+ render_san: function(value) {
+ var names = [];
+ if (Ext.isArray(value)) {
+ value.forEach(function(val) {
+ if (!Ext.isNumber(val)) {
+ names.push(val);
+ }
+ });
+ return names.join('<br>');
+ }
+ return value;
+ },
+
+ render_full_name: function(firstname, metaData, record) {
+ var first = firstname || '';
+ var last = record.data.lastname || '';
+ return Ext.htmlEncode(first + " " + last);
+ },
+
windowHostname: function() {
return window.location.hostname.replace(Proxmox.Utils.IP6_bracket_match,
function(m, addr, offset, original) { return addr; });
},
- openDefaultConsoleWindow: function(allowSpice, vmtype, vmid, nodename, vmname) {
- var dv = PVE.Utils.defaultViewer(allowSpice);
- PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname);
+ openDefaultConsoleWindow: function(consoles, vmtype, vmid, nodename, vmname, cmd) {
+ var dv = PVE.Utils.defaultViewer(consoles);
+ PVE.Utils.openConsoleWindow(dv, vmtype, vmid, nodename, vmname, cmd);
},
- openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname) {
+ openConsoleWindow: function(viewer, vmtype, vmid, nodename, vmname, cmd) {
// kvm, lxc, shell, upgrade
if (vmid == undefined && (vmtype === 'kvm' || vmtype === 'lxc')) {
}
if (viewer === 'html5') {
- PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname);
+ PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname, cmd);
} else if (viewer === 'xtermjs') {
- Proxmox.Utils.openXtermJsViewer(vmtype, vmid, nodename, vmname);
+ Proxmox.Utils.openXtermJsViewer(vmtype, vmid, nodename, vmname, cmd);
} else if (viewer === 'vv') {
var url;
var params = { proxy: PVE.Utils.windowHostname() };
url = '/nodes/' + nodename + '/spiceshell';
params.upgrade = 1;
PVE.Utils.openSpiceViewer(url, params);
+ } else if (vmtype === 'cmd') {
+ url = '/nodes/' + nodename + '/spiceshell';
+ params.cmd = cmd;
+ PVE.Utils.openSpiceViewer(url, params);
}
} else {
throw "unknown viewer type";
}
},
- defaultViewer: function(allowSpice) {
+ defaultViewer: function(consoles) {
+
+ var allowSpice, allowXtermjs;
+
+ if (consoles === true) {
+ allowSpice = true;
+ allowXtermjs = true;
+ } else if (typeof consoles === 'object') {
+ allowSpice = consoles.spice;
+ allowXtermjs = !!consoles.xtermjs;
+ }
var vncdefault = 'html5';
var dv = PVE.VersionInfo.console || vncdefault;
- if (dv === 'vv' && !allowSpice) {
+ if ((dv === 'vv' && !allowSpice) || (dv === 'xtermjs' && !allowXtermjs)) {
dv = vncdefault;
}
return dv;
},
- openVNCViewer: function(vmtype, vmid, nodename, vmname) {
- var url = Ext.urlEncode({
+ openVNCViewer: function(vmtype, vmid, nodename, vmname, cmd) {
+ var url = Ext.Object.toQueryString({
console: vmtype, // kvm, lxc, upgrade or shell
novnc: 1,
vmid: vmid,
vmname: vmname,
- node: nodename
+ node: nodename,
+ resize: 'off',
+ cmd: cmd
});
var nw = window.open("?" + url, '_blank', "innerWidth=745,innerheight=427");
- nw.focus();
+ if (nw) {
+ nw.focus();
+ }
},
openSpiceViewer: function(url, params){
Ext.Msg.alert('Error', response.htmlStatus);
},
success: function(response, opts) {
- var allowSpice = response.result.data.spice;
+ var allowSpice = !!response.result.data.spice;
PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname);
}
});
v.select(record);
}
var menu;
+ var template = !!record.data.template;
+ var type = record.data.type;
- if (record.data.type === 'qemu' && !record.data.template) {
- menu = Ext.create('PVE.qemu.CmdMenu', {
- pveSelNode: record
- });
- } else if (record.data.type === 'qemu' && record.data.template) {
- menu = Ext.create('PVE.qemu.TemplateMenu', {
- pveSelNode: record
- });
- } else if (record.data.type === 'lxc' && !record.data.template) {
- menu = Ext.create('PVE.lxc.CmdMenu', {
- pveSelNode: record
- });
- } else if (record.data.type === 'lxc' && record.data.template) {
- /* since clone does not work reliably, disable for now
- menu = Ext.create('PVE.lxc.TemplateMenu', {
- pveSelNode: record
- });
- */
- return;
-
- } else if (record.data.type === 'node' ){
- menu = Ext.create('PVE.node.CmdMenu', {
+ if (template) {
+ if (type === 'qemu' || type == 'lxc') {
+ menu = Ext.create('PVE.menu.TemplateMenu', {
+ pveSelNode: record
+ });
+ }
+ } else if (type === 'qemu' ||
+ type === 'lxc' ||
+ type === 'node') {
+ menu = Ext.create('PVE.' + type + '.CmdMenu', {
+ pveSelNode: record,
nodename: record.data.node
});
-
} else {
return;
}
menu.showAt(event.getXY());
+ return menu;
},
// helper for deleting field which are set to there default values
delete values[fieldname];
}
+ },
+
+ 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);
+ return;
+ }
+ /*global
+ FileReader
+ */
+ var reader = new FileReader();
+ reader.onload = function(evt) {
+ callback(evt.target.result);
+ };
+ reader.readAsText(file);
+ },
+
+ bus_counts: { ide: 4, sata: 6, scsi: 16, virtio: 16 },
+
+ // types is either undefined (all busses), an array of busses, or a single bus
+ forEachBus: function(types, func) {
+ var busses = Object.keys(PVE.Utils.bus_counts);
+ var i, j, count, cont;
+
+ if (Ext.isArray(types)) {
+ busses = types;
+ } else if (Ext.isDefined(types)) {
+ busses = [ types ];
+ }
+
+ // check if we only have valid busses
+ for (i = 0; i < busses.length; i++) {
+ if (!PVE.Utils.bus_counts[busses[i]]) {
+ throw "invalid bus: '" + busses[i] + "'";
+ }
+ }
+
+ for (i = 0; i < busses.length; i++) {
+ count = PVE.Utils.bus_counts[busses[i]];
+ for (j = 0; j < count; j++) {
+ cont = func(busses[i], j);
+ if (!cont && cont !== undefined) {
+ return;
+ }
+ }
+ }
+ },
+
+ mp_counts: { mps: 256, unused: 256 },
+
+ forEachMP: function(func, includeUnused) {
+ var i, cont;
+ for (i = 0; i < PVE.Utils.mp_counts.mps; i++) {
+ cont = func('mp', i);
+ if (!cont && cont !== undefined) {
+ return;
+ }
+ }
+
+ if (!includeUnused) {
+ return;
+ }
+
+ for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
+ cont = func('unused', i);
+ if (!cont && cont !== undefined) {
+ return;
+ }
+ }
}
},