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 = {
- dir: function() {},
- log: function() {}
+if (!Ext.isDefined(Ext.global.console)) {
+ var console = {
+ dir: function() {},
+ log: function() {}
};
}
-console.log("Starting PVE Manager");
+console.log("Starting PVE Manager");
Ext.Ajax.defaultHeaders = {
'Accept': 'application/json'
Ext.Ajax.on('beforerequest', function(conn, options) {
if (PVE.CSRFPreventionToken) {
- if (!options.headers) {
+ if (!options.headers) {
options.headers = {};
}
options.headers.CSRFPreventionToken = PVE.CSRFPreventionToken;
var IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
-var IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/[1-3][0-9]?$");
+var IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
var IPV6_REGEXP = "(?:" +
"(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
")";
var IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
-var IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/[0-9]{1,3}?$");
+var IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
var IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
var IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
// this class only contains static functions
- toolkit: undefined, // (extjs|touch), set inside Toolkit.js
+ toolkit: undefined, // (extjs|touch), set inside Toolkit.js
log_severity_hash: {
0: "panic",
w2k: 'Microsoft Windows 2000',
w2k8: 'Microsoft Windows Vista/2008',
win7: 'Microsoft Windows 7/2008r2',
- win8: 'Microsoft Windows 8/2012',
+ win8: 'Microsoft Windows 8.x/10/2012/r2',
l24: 'Linux 2.4 Kernel',
- l26: 'Linux 3.X/2.6 Kernel',
+ l26: 'Linux 4.X/3.X/2.6 Kernel',
solaris: 'Solaris Kernel'
},
}
var text = PVE.Utils.kvm_ostypes[value];
if (text) {
- return text + ' (' + value + ')';
+ return text;
}
return value;
},
render_hotplug_features: function (value) {
- var fa = [];
+ var fa = [];
if (!value || (value === '0')) {
return gettext('disabled');
}
+ if (value === '1') {
+ value = 'disk,network,usb';
+ }
+
Ext.each(value.split(','), function(el) {
if (el === 'disk') {
fa.push(gettext('Disk'));
},
render_network_iface_type: function(value) {
- return PVE.Utils.network_iface_types[value] ||
+ return PVE.Utils.network_iface_types[value] ||
PVE.Utils.unknownText;
},
+ render_qemu_bios: function(value) {
+ if (!value) {
+ return PVE.Utils.defaultText + ' (SeaBIOS)';
+ } else if (value === 'seabios') {
+ return "SeaBIOS";
+ } else if (value === 'ovmf') {
+ return "OVMF (UEFI)";
+ } else {
+ return value;
+ }
+ },
+
render_scsihw: function(value) {
if (!value) {
return PVE.Utils.defaultText + ' (LSI 53C895A)';
kvm_keymaps: {
//ar: 'Arabic',
da: 'Danish',
- de: 'German',
- 'de-ch': 'German (Swiss)',
- 'en-gb': 'English (UK)',
+ de: 'German',
+ 'de-ch': 'German (Swiss)',
+ 'en-gb': 'English (UK)',
'en-us': 'English (USA)',
es: 'Spanish',
//et: 'Estonia',
fi: 'Finnish',
- //fo: 'Faroe Islands',
- fr: 'French',
- 'fr-be': 'French (Belgium)',
+ //fo: 'Faroe Islands',
+ fr: 'French',
+ 'fr-be': 'French (Belgium)',
'fr-ca': 'French (Canada)',
'fr-ch': 'French (Swiss)',
//hr: 'Croatia',
hu: 'Hungarian',
is: 'Icelandic',
- it: 'Italian',
+ it: 'Italian',
ja: 'Japanese',
lt: 'Lithuanian',
//lv: 'Latvian',
- mk: 'Macedonian',
+ mk: 'Macedonian',
nl: 'Dutch',
//'nl-be': 'Dutch (Belgium)',
- no: 'Norwegian',
+ no: 'Norwegian',
pl: 'Polish',
pt: 'Portuguese',
'pt-br': 'Portuguese (Brazil)',
},
kvm_keymap_array: function() {
- var data = [['', PVE.Utils.render_kvm_language('')]];
+ 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)]);
});
},
render_console_viewer: function(value) {
- if (!value) {
+ if (!value || value === '__default__') {
return PVE.Utils.defaultText + ' (HTML5)';
- } else if (value === 'applet') {
- return 'Java VNC Applet';
} else if (value === 'vv') {
return 'SPICE (remote-viewer)';
} else if (value === 'html5') {
},
language_array: function() {
- var data = [['', PVE.Utils.render_language('')]];
+ var data = [['__default__', PVE.Utils.render_language('')]];
Ext.Object.each(PVE.Utils.language_map, function(key, value) {
data.push([key, PVE.Utils.render_language(value)]);
});
return PVE.Utils.defaultText;
}
var text = PVE.Utils.kvm_vga_drivers[value];
- if (text) {
+ if (text) {
return text + ' (' + value + ')';
}
return value;
},
kvm_vga_driver_array: function() {
- var data = [['', PVE.Utils.render_kvm_vga_driver('')]];
+ 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)]);
});
// fixme: remove - not needed?
gridLineHeigh: function() {
return 21;
-
+
//if (Ext.isGecko)
//return 23;
//return 21;
if (verbose && Ext.isObject(result.errors)) {
msg += "<br>";
Ext.Object.each(result.errors, function(prop, desc) {
- msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " +
+ msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " +
Ext.htmlEncode(desc);
});
- }
+ }
}
return msg;
qmsuspend: [ 'VM', gettext('Suspend') ],
qmresume: [ 'VM', gettext('Resume') ],
qmconfig: [ 'VM', gettext('Configure') ],
+ vzsnapshot: [ 'CT', gettext('Snapshot') ],
+ vzrollback: [ 'CT', gettext('Rollback') ],
+ vzdelsnapshot: [ 'CT', gettext('Delete Snapshot') ],
vzcreate: ['CT', gettext('Create') ],
vzrestore: ['CT', gettext('Restore') ],
vzdestroy: ['CT', gettext('Destroy') ],
vzmigrate: [ 'CT', gettext('Migrate') ],
+ vzclone: [ 'CT', gettext('Clone') ],
+ vztemplate: [ 'CT', gettext('Convert to template') ],
vzstart: ['CT', gettext('Start') ],
vzstop: ['CT', gettext('Stop') ],
vzmount: ['CT', gettext('Mount') ],
migrateall: [ '', gettext('Migrate all VMs and Containers') ]
},
- format_task_description: function(type, id) {
+ format_task_description: function(type, id) {
var farray = PVE.Utils.task_desc_table[type];
if (!farray) {
return type;
var prefix = farray[0];
var text = farray[1];
if (prefix) {
- return prefix + ' ' + id + ' - ' + text;
+ return prefix + ' ' + id + ' - ' + text;
}
return text;
},
format_size: function(size) {
/*jslint confusion: true */
- if (size < 1024) {
- return size;
- }
-
- var kb = size / 1024;
+ var units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'];
+ var num = 0;
- if (kb < 1024) {
- return kb.toFixed(0) + "KB";
+ while (size >= 1024 && ((num++)+1) < units.length) {
+ size = size / 1024;
}
- var mb = size / (1024*1024);
-
- if (mb < 1024) {
- return mb.toFixed(0) + "MB";
- }
-
- var gb = mb / 1024;
-
- if (gb < 1024) {
- return gb.toFixed(2) + "GB";
- }
-
- var tb = gb / 1024;
-
- return tb.toFixed(2) + "TB";
-
+ return size.toFixed((num > 0)?2:0) + " " + units[num] + "B";
},
format_html_bar: function(per, text) {
return "<div class='pve-bar-wrap'>" + text + "<div class='pve-bar-border'>" +
"<div class='pve-bar-inner' style='width:" + per + "%;'></div>" +
"</div></div>";
-
+
},
format_cpu_bar: function(per1, per2, text) {
return "<div class='pve-bar-border'>" +
"<div class='pve-bar-inner' style='width:" + per1 + "%;'></div>" +
"<div class='pve-bar-inner2' style='width:" + per2 + "%;'></div>" +
- "<div class='pve-bar-text'>" + text + "</div>" +
+ "<div class='pve-bar-text'>" + text + "</div>" +
"</div>";
},
return "<div class='pve-largebar-border'>" +
"<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" +
- "<div class='pve-largebar-text'>" + text + "</div>" +
+ "<div class='pve-largebar-text'>" + text + "</div>" +
"</div>";
},
if (days) {
var ds = days > 1 ? PVE.Utils.daysText : PVE.Utils.dayText;
- return days.toString() + ' ' + ds + ' ' +
+ return days.toString() + ' ' + ds + ' ' +
hours_str + ':' + mins_str + ':' + ut_str;
} else {
return hours_str + ':' + mins_str + ':' + ut_str;
},
format_duration_short: function(ut) {
-
+
if (ut < 60) {
return ut.toString() + 's';
}
}
var days = ut / 86400;
- return days.toFixed(0) + 'd';
+ return days.toFixed(0) + 'd';
},
yesText: gettext('Yes'),
vztmplText: gettext('Container template'),
isoImageText: gettext('ISO image'),
containersText: gettext('Container'),
+ stateText: gettext('State'),
+ groupText: gettext('Group'),
format_expire: function(date) {
if (!date) {
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 'ZFS';
} else if (value === 'iscsidirect') {
return 'iSCSIDirect';
+ } else if (value === 'drbd') {
+ return 'DRBD';
} else {
return PVE.Utils.unknownText;
}
},
format_boolean_with_default: function(value) {
- if (Ext.isDefined(value) && value !== '') {
+ if (Ext.isDefined(value) && value !== '__default__') {
return value ? PVE.Utils.yesText : PVE.Utils.noText;
}
return PVE.Utils.defaultText;
return !value ? PVE.Utils.yesText : PVE.Utils.noText;
},
+ format_ha: function(value) {
+ var text = PVE.Utils.format_boolean(value.managed);
+
+ if (value.managed) {
+ text += ', ' + PVE.Utils.stateText + ': ';
+ text += value.state || PVE.Utils.noneText;
+
+ text += ', ' + PVE.Utils.groupText + ': ';
+ text += value.group || PVE.Utils.noneText;
+ }
+
+ return text;
+ },
+
format_content_types: function(value) {
var cta = [];
if (Ext.isNumber(data.channel) &&
Ext.isNumber(data.id) &&
Ext.isNumber(data.lun)) {
- return "CH " +
- Ext.String.leftPad(data.channel,2, '0') +
+ return "CH " +
+ Ext.String.leftPad(data.channel,2, '0') +
" ID " + data.id + " LUN " + data.lun;
}
return data.volid.replace(/^.*:(.*\/)?/,'');
if (!Ext.isNumeric(maxcpu) && (maxcpu >= 1)) {
return '';
}
-
+
var per = value * 100;
return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
return Ext.Date.format(servertime, 'Y-m-d H:i:s');
},
+ calculate_mem_usage: function(data) {
+ if (!Ext.isNumeric(data.mem) ||
+ data.maxmem === 0 ||
+ data.uptime < 1) {
+ return -1;
+ }
+
+ return (data.mem / data.maxmem);
+ },
+
+ render_mem_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
+ if (!Ext.isNumeric(value) || value === -1) {
+ return '';
+ }
+ if (value > 1 ) {
+ // we got no percentage but bytes
+ var mem = value;
+ var maxmem = record.data.maxmem;
+ if (!record.data.uptime ||
+ maxmem === 0 ||
+ !Ext.isNumeric(mem)) {
+ return '';
+ }
+
+ return ((mem*100)/maxmem).toFixed(1) + " %";
+ }
+ return (value*100).toFixed(1) + " %";
+ },
+
render_mem_usage: function(value, metaData, record, rowIndex, colIndex, store) {
var mem = value;
var maxmem = record.data.maxmem;
-
+
if (!record.data.uptime) {
return '';
}
return '';
}
- var per = (mem * 100) / maxmem;
+ return PVE.Utils.render_size(value);
+ },
- return per.toFixed(1) + '%';
+ calculate_disk_usage: function(data) {
+
+ if (!Ext.isNumeric(data.disk) ||
+ data.type === 'qemu' ||
+ (data.type === 'lxc' && data.uptime === 0) ||
+ data.maxdisk === 0) {
+ return -1;
+ }
+
+ return (data.disk / data.maxdisk);
+ },
+
+ render_disk_usage_percent: function(value, metaData, record, rowIndex, colIndex, store) {
+ if (!Ext.isNumeric(value) || value === -1) {
+ return '';
+ }
+
+ return (value * 100).toFixed(1) + " %";
},
render_disk_usage: function(value, metaData, record, rowIndex, colIndex, store) {
var disk = value;
var maxdisk = record.data.maxdisk;
+ var type = record.data.type;
- if (!(Ext.isNumeric(disk) && maxdisk)) {
+ if (!Ext.isNumeric(disk) ||
+ type === 'qemu' ||
+ maxdisk === 0 ||
+ (type === 'lxc' && record.data.uptime === 0)) {
return '';
}
- var per = (disk * 100) / maxdisk;
-
- return per.toFixed(1) + '%';
+ return PVE.Utils.render_size(value);
},
render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
- var cls = 'pve-itype-icon-' + value;
+ var icon = '';
+ var gridcls = '';
+
+ switch (value) {
+ case 'lxc': icon = 'cube';
+ gridcls = '-stopped';
+ break;
+ case 'qemu': icon = 'desktop';
+ gridcls = '-stopped';
+ break;
+ case 'node': icon = 'building';
+ gridcls = '-offline';
+ break;
+ case 'storage': icon = 'database'; break;
+ case 'pool': icon = 'tags'; break;
+ default: icon = 'file';
+ }
- if (record.data.running) {
- metaData.tdCls = cls + "-running";
- } else if (record.data.template) {
- metaData.tdCls = cls + "-template";
- } else {
- metaData.tdCls = cls;
+ if (value === 'lxc' || value === 'qemu') {
+ if (record.data.running && record.data.status !== 'paused') {
+ gridcls = '-running';
+ } else if (record.data.running) {
+ gridcls = '-paused';
+ }
+ if (record.data.template) {
+ icon = 'file-o';
+ gridcls = '-template-' + value;
+ }
+ } else if (value === 'node') {
+ if (record.data.running) {
+ gridcls = '-online';
+ }
}
- return value;
+ var fa = '<i class="fa fa-fw x-fa-grid' + gridcls + ' fa-' + icon + '"></i> ';
+ return fa + value;
},
render_uptime: function(value, metaData, record, rowIndex, colIndex, store) {
if (uptime === undefined) {
return '';
}
-
+
if (uptime <= 0) {
return '-';
}
return PVE.Utils.support_level_hash[value] || '-';
},
- render_upid: function(value, metaData, record) {
+ render_upid: function(value, metaData, record) {
var type = record.data.type;
var id = record.data.id;
return window.location.hostname.replace(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);
throw "no nodename specified";
}
- if (viewer === 'applet' || viewer === 'html5') {
- PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname, viewer === 'html5');
+ if (viewer === 'html5') {
+ PVE.Utils.openVNCViewer(vmtype, vmid, nodename, vmname);
} else if (viewer === 'vv') {
var url;
var params = { proxy: PVE.Utils.windowHostname() };
return dv;
},
- openVNCViewer: function(vmtype, vmid, nodename, vmname, novnc) {
+ openVNCViewer: function(vmtype, vmid, nodename, vmname) {
var url = Ext.urlEncode({
console: vmtype, // kvm, lxc, upgrade or shell
- novnc: novnc ? 1 : 0,
+ novnc: 1,
vmid: vmid,
vmname: vmname,
node: nodename
});
var url = 'data:application/x-virt-viewer;charset=UTF-8,' +
encodeURIComponent(raw);
-
+
downloadWithName(url, "pve-spice.vv");
}
});
},
- // comp.setLoading() is buggy in ExtJS 4.0.7, so we
+ // comp.setLoading() is buggy in ExtJS 4.0.7, so we
// use el.mask() instead
setErrorMask: function(comp, msg) {
var el = comp.el;
}
var msg;
- var operation = request.operation;
+ /*jslint nomen: true */
+ var operation = request._operation;
var error = operation.getError();
if (error.statusText) {
msg = error.statusText + ' (' + error.status + ')';
}
PVE.Utils.setErrorMask(me, msg);
});
- }
+ },
+
+ createCmdMenu: function(v, record, item, index, event) {
+ event.stopEvent();
+ v.select(record);
+ var menu;
+ 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 {
+ return;
+ }
+
+ menu.showAt(event.getXY());
+ }
}});