// avoid errors when running without development tools
if (!Ext.isDefined(Ext.global.console)) {
var console = {
- dir: function() {},
log: function() {}
};
}
'Accept': 'application/json'
};
-Ext.Ajax.on('beforerequest', function(conn, options) {
- if (PVE.CSRFPreventionToken) {
- if (!options.headers) {
- options.headers = {};
- }
- options.headers.CSRFPreventionToken = PVE.CSRFPreventionToken;
- }
-});
-
+/*jslint confusion: true */
Ext.define('PVE.Utils', { utilities: {
// this singleton contains miscellaneous utilities
'p': gettext('Premium')
},
- noSubKeyHtml: 'You do not have a valid subscription for this server. Please visit <a target="_blank" href="http://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.',
+ 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">www.proxmox.com</a> to get a list of available options.',
kvm_ostypes: {
- other: gettext('Other OS types'),
- wxp: 'Microsoft Windows XP/2003',
- w2k: 'Microsoft Windows 2000',
- w2k8: 'Microsoft Windows Vista/2008',
- win7: 'Microsoft Windows 7/2008r2',
- win8: 'Microsoft Windows 8.x/2012/2012r2',
- win10: 'Microsoft Windows 10/2016',
- l24: 'Linux 2.4 Kernel',
- l26: 'Linux 4.X/3.X/2.6 Kernel',
- solaris: 'Solaris Kernel'
+ 'Linux': [
+ { desc: '5.x - 2.6 Kernel', val: 'l26' },
+ { desc: '2.4 Kernel', val: 'l24' }
+ ],
+ 'Microsoft Windows': [
+ { desc: '10/2016', val: 'win10' },
+ { desc: '8.x/2012/2012r2', val: 'win8' },
+ { desc: '7/2008r2', val: 'win7' },
+ { desc: 'Vista/2008', val: 'w2k8' },
+ { desc: 'XP/2003', val: 'wxp' },
+ { desc: '2000', val: 'w2k' }
+ ],
+ 'Solaris Kernel': [
+ { desc: '-', val: 'solaris'}
+ ],
+ 'Other': [
+ { desc: '-', val: 'other'}
+ ]
},
get_health_icon: function(state, circle) {
case 'good':
icon = 'good fa-check';
break;
+ case 'old':
+ icon = 'warning fa-refresh';
+ break;
case 'warning':
icon = 'warning fa-exclamation';
break;
return icon;
},
+ parse_ceph_version: function(service) {
+ if (service.ceph_version_short) {
+ return service.ceph_version_short;
+ }
+
+ if (service.ceph_version) {
+ var match = service.ceph_version.match(/version (\d+(\.\d+)*)/);
+ if (match) {
+ return match[1];
+ }
+ }
+
+ return undefined;
+ },
+
+ compare_ceph_versions: function(a, b) {
+ if (a === b) {
+ return 0;
+ }
+ let avers = a.toString().split('.');
+ let bvers = b.toString().split('.');
+
+ while (true) {
+ let av = avers.shift();
+ let bv = bvers.shift();
+
+ if (av === undefined && bv === undefined) {
+ return 0;
+ } else if (av === undefined) {
+ return -1;
+ } else if (bv === undefined) {
+ return 1;
+ } else {
+ let diff = parseInt(av, 10) - parseInt(bv, 10);
+ if (diff != 0) return diff;
+ // else we need to look at the next parts
+ }
+ }
+
+ },
+
+ get_ceph_icon_html: function(health, fw) {
+ var state = PVE.Utils.map_ceph_health[health];
+ var cls = PVE.Utils.get_health_icon(state);
+ if (fw) {
+ cls += ' fa-fw';
+ }
+ return "<i class='fa " + cls + "'></i> ";
+ },
+
map_ceph_health: {
'HEALTH_OK':'good',
+ 'HEALTH_OLD':'old',
'HEALTH_WARN':'warning',
'HEALTH_ERR':'critical'
},
- render_ceph_health: function(record) {
+ render_ceph_health: function(healthObj) {
var state = {
iconCls: PVE.Utils.get_health_icon(),
text: ''
};
- if (!record || !record.data) {
+ if (!healthObj || !healthObj.status) {
return state;
}
- var health = PVE.Utils.map_ceph_health[record.data.health.overall_status];
+ var health = PVE.Utils.map_ceph_health[healthObj.status];
state.iconCls = PVE.Utils.get_health_icon(health, true);
- state.text = record.data.health.overall_status;
+ state.text = healthObj.status;
return state;
},
- render_kvm_ostype: function (value) {
- if (!value) {
- return gettext('Other OS types');
+ render_zfs_health: function(value) {
+ if (typeof value == 'undefined'){
+ return "";
}
- var text = PVE.Utils.kvm_ostypes[value];
- if (text) {
- return text;
+ 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) {
+ Ext.each(Object.keys(PVE.Utils.kvm_ostypes), function(k) {
+ Ext.each(PVE.Utils.kvm_ostypes[k], function(e) {
+ if (e.val === value) {
+ info = { desc: e.desc, base: k };
+ }
+ });
+ });
+ }
+ return info;
+ },
+
+ render_kvm_ostype: function (value) {
+ var osinfo = PVE.Utils.get_kvm_osinfo(value);
+ if (osinfo.desc && osinfo.desc !== '-') {
+ return osinfo.base + ' ' + osinfo.desc;
+ } else {
+ return osinfo.base;
}
- return value;
},
render_hotplug_features: function (value) {
return fa.join(', ');
},
- network_iface_types: {
- eth: gettext("Network Device"),
- bridge: 'Linux Bridge',
- bond: 'Linux Bond',
- OVSBridge: 'OVS Bridge',
- OVSBond: 'OVS Bond',
- OVSPort: 'OVS Port',
- OVSIntPort: 'OVS IntPort'
+ 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_network_iface_type: function(value) {
- return PVE.Utils.network_iface_types[value] ||
- PVE.Utils.unknownText;
+ render_qemu_machine: function(value) {
+ return value || (Proxmox.Utils.defaultText + ' (i440fx)');
},
render_qemu_bios: function(value) {
if (!value) {
- return PVE.Utils.defaultText + ' (SeaBIOS)';
+ return Proxmox.Utils.defaultText + ' (SeaBIOS)';
} else if (value === 'seabios') {
return "SeaBIOS";
} else if (value === 'ovmf') {
}
},
+ render_dc_ha_opts: function(value) {
+ if (!value) {
+ return Proxmox.Utils.defaultText;
+ } else {
+ return PVE.Parser.printPropertyString(value);
+ }
+ },
+ render_as_property_string: function(value) {
+ return (!value) ? Proxmox.Utils.defaultText
+ : PVE.Parser.printPropertyString(value);
+ },
+
render_scsihw: function(value) {
if (!value) {
- return PVE.Utils.defaultText + ' (LSI 53C895A)';
+ return Proxmox.Utils.defaultText + ' (LSI 53C895A)';
} else if (value === 'lsi') {
return 'LSI 53C895A';
} else if (value === 'lsi53c810') {
kvm_vga_drivers: {
std: gettext('Standard VGA'),
vmware: gettext('VMware compatible'),
- cirrus: 'Cirrus Logic GD5446',
qxl: 'SPICE',
qxl2: 'SPICE dual monitor',
qxl3: 'SPICE three monitors',
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) {
- if (!value) {
- return PVE.Utils.defaultText;
+ if (!value || value === '__default__') {
+ return Proxmox.Utils.defaultText;
}
var text = PVE.Utils.kvm_keymaps[value];
if (text) {
return data;
},
- render_console_viewer: function(value) {
- if (!value || value === '__default__') {
- return PVE.Utils.defaultText + ' (HTML5)';
- } else if (value === 'vv') {
- return 'SPICE (remote-viewer)';
- } else if (value === 'html5') {
- return 'HTML5 (noVNC)';
- } else {
- return value;
- }
- },
-
- language_map: {
- zh_CN: 'Chinese',
- ca: 'Catalan',
- da: 'Danish',
- en: 'English',
- eu: 'Euskera (Basque)',
- fr: 'French',
- de: 'German',
- it: 'Italian',
- ja: 'Japanese',
- nb: 'Norwegian (Bokmal)',
- nn: 'Norwegian (Nynorsk)',
- fa: 'Persian (Farsi)',
- pl: 'Polish',
- pt_BR: 'Portuguese (Brazil)',
- ru: 'Russian',
- sl: 'Slovenian',
- es: 'Spanish',
- sv: 'Swedish',
- tr: 'Turkish'
+ console_map: {
+ '__default__': Proxmox.Utils.defaultText + ' (xterm.js)',
+ 'vv': 'SPICE (remote-viewer)',
+ 'html5': 'HTML5 (noVNC)',
+ 'xtermjs': 'xterm.js'
},
- render_language: function (value) {
- if (!value) {
- return PVE.Utils.defaultText + ' (English)';
- }
- var text = PVE.Utils.language_map[value];
- if (text) {
- return text + ' (' + value + ')';
+ render_console_viewer: function(value) {
+ value = value || '__default__';
+ if (PVE.Utils.console_map[value]) {
+ return PVE.Utils.console_map[value];
}
return value;
},
- language_array: function() {
- 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)]);
+ 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 data;
},
render_kvm_vga_driver: function (value) {
if (!value) {
- return PVE.Utils.defaultText;
+ return Proxmox.Utils.defaultText;
+ }
+ var vga = PVE.Parser.parsePropertyString(value, 'type');
+ var text = PVE.Utils.kvm_vga_drivers[vga.type];
+ if (!vga.type) {
+ text = Proxmox.Utils.defaultText;
}
- var text = PVE.Utils.kvm_vga_drivers[value];
if (text) {
return text + ' (' + value + ')';
}
return res;
},
- authOK: function() {
- return Ext.util.Cookies.get('PVEAuthCookie');
- },
-
- authClear: function() {
- Ext.util.Cookies.clear("PVEAuthCookie");
- },
-
- // fixme: remove - not needed?
- gridLineHeigh: function() {
- return 21;
-
- //if (Ext.isGecko)
- //return 23;
- //return 21;
- },
-
- extractRequestError: function(result, verbose) {
- var msg = gettext('Successful');
-
- if (!result.success) {
- msg = gettext("Unknown error");
- if (result.message) {
- msg = result.message;
- if (result.status) {
- msg += ' (' + result.status + ')';
- }
- }
- if (verbose && Ext.isObject(result.errors)) {
- msg += "<br>";
- Ext.Object.each(result.errors, function(prop, desc) {
- msg += "<br><b>" + Ext.htmlEncode(prop) + "</b>: " +
- Ext.htmlEncode(desc);
- });
- }
- }
-
- return msg;
- },
-
extractFormActionError: function(action) {
var msg;
switch (action.failureType) {
break;
case Ext.form.action.Action.LOAD_FAILURE:
case Ext.form.action.Action.SERVER_INVALID:
- msg = PVE.Utils.extractRequestError(action.result, true);
+ msg = Proxmox.Utils.extractRequestError(action.result, true);
break;
}
return msg;
},
- // Ext.Ajax.request
- API2Request: function(reqOpts) {
-
- var newopts = Ext.apply({
- waitMsg: gettext('Please wait...')
- }, reqOpts);
-
- if (!newopts.url.match(/^\/api2/)) {
- newopts.url = '/api2/extjs' + newopts.url;
- }
- delete newopts.callback;
-
- var createWrapper = function(successFn, callbackFn, failureFn) {
- Ext.apply(newopts, {
- success: function(response, options) {
- if (options.waitMsgTarget) {
- if (PVE.Utils.toolkit === 'touch') {
- options.waitMsgTarget.setMasked(false);
- } else {
- options.waitMsgTarget.setLoading(false);
- }
- }
- var result = Ext.decode(response.responseText);
- response.result = result;
- if (!result.success) {
- response.htmlStatus = PVE.Utils.extractRequestError(result, true);
- Ext.callback(callbackFn, options.scope, [options, false, response]);
- Ext.callback(failureFn, options.scope, [response, options]);
- return;
- }
- Ext.callback(callbackFn, options.scope, [options, true, response]);
- Ext.callback(successFn, options.scope, [response, options]);
- },
- failure: function(response, options) {
- if (options.waitMsgTarget) {
- if (PVE.Utils.toolkit === 'touch') {
- options.waitMsgTarget.setMasked(false);
- } else {
- options.waitMsgTarget.setLoading(false);
- }
- }
- response.result = {};
- try {
- response.result = Ext.decode(response.responseText);
- } catch(e) {}
- var msg = gettext('Connection error') + ' - server offline?';
- if (response.aborted) {
- msg = gettext('Connection error') + ' - aborted.';
- } else if (response.timedout) {
- msg = gettext('Connection error') + ' - Timeout.';
- } else if (response.status && response.statusText) {
- msg = gettext('Connection error') + ' ' + response.status + ': ' + response.statusText;
- }
- response.htmlStatus = msg;
- Ext.callback(callbackFn, options.scope, [options, false, response]);
- Ext.callback(failureFn, options.scope, [response, options]);
- }
- });
- };
-
- createWrapper(reqOpts.success, reqOpts.callback, reqOpts.failure);
-
- var target = newopts.waitMsgTarget;
- if (target) {
- if (PVE.Utils.toolkit === 'touch') {
- target.setMasked({ xtype: 'loadmask', message: newopts.waitMsg} );
- } else {
- // Note: ExtJS bug - this does not work when component is not rendered
- target.setLoading(newopts.waitMsg);
- }
- }
- Ext.Ajax.request(newopts);
- },
-
- assemble_field_data: function(values, data) {
- if (Ext.isObject(data)) {
- Ext.Object.each(data, function(name, val) {
- if (values.hasOwnProperty(name)) {
- var bucket = values[name];
- if (!Ext.isArray(bucket)) {
- bucket = values[name] = [bucket];
- }
- if (Ext.isArray(val)) {
- values[name] = bucket.concat(val);
- } else {
- bucket.push(val);
- }
- } else {
- values[name] = val;
- }
- });
- }
- },
-
- checked_command: function(orig_cmd) {
- PVE.Utils.API2Request({
- url: '/nodes/localhost/subscription',
- method: 'GET',
- //waitMsgTarget: me,
- failure: function(response, opts) {
- Ext.Msg.alert(gettext('Error'), response.htmlStatus);
- },
- success: function(response, opts) {
- var data = response.result.data;
-
- if (data.status !== 'Active') {
- Ext.Msg.show({
- title: gettext('No valid subscription'),
- icon: Ext.Msg.WARNING,
- msg: PVE.Utils.noSubKeyHtml,
- buttons: Ext.Msg.OK,
- callback: function(btn) {
- if (btn !== 'ok') {
- return;
- }
- orig_cmd();
- }
- });
- } else {
- orig_cmd();
- }
- }
- });
- },
-
- task_desc_table: {
- diskinit: [ 'Disk', gettext('Initialize Disk with GPT') ],
- vncproxy: [ 'VM/CT', gettext('Console') ],
- spiceproxy: [ 'VM/CT', gettext('Console') + ' (Spice)' ],
- vncshell: [ '', gettext('Shell') ],
- spiceshell: [ '', gettext('Shell') + ' (Spice)' ],
- qmsnapshot: [ 'VM', gettext('Snapshot') ],
- qmrollback: [ 'VM', gettext('Rollback') ],
- qmdelsnapshot: [ 'VM', gettext('Delete Snapshot') ],
- qmcreate: [ 'VM', gettext('Create') ],
- qmrestore: [ 'VM', gettext('Restore') ],
- qmdestroy: [ 'VM', gettext('Destroy') ],
- qmigrate: [ 'VM', gettext('Migrate') ],
- qmclone: [ 'VM', gettext('Clone') ],
- qmmove: [ 'VM', gettext('Move disk') ],
- qmtemplate: [ 'VM', gettext('Convert to template') ],
- qmstart: [ 'VM', gettext('Start') ],
- qmstop: [ 'VM', gettext('Stop') ],
- qmreset: [ 'VM', gettext('Reset') ],
- qmshutdown: [ 'VM', gettext('Shutdown') ],
- 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') ],
- vzumount: ['CT', gettext('Unmount') ],
- vzshutdown: ['CT', gettext('Shutdown') ],
- vzsuspend: [ 'CT', gettext('Suspend') ],
- vzresume: [ 'CT', gettext('Resume') ],
- hamigrate: [ 'HA', gettext('Migrate') ],
- hastart: [ 'HA', gettext('Start') ],
- hastop: [ 'HA', gettext('Stop') ],
- srvstart: ['SRV', gettext('Start') ],
- srvstop: ['SRV', gettext('Stop') ],
- srvrestart: ['SRV', gettext('Restart') ],
- srvreload: ['SRV', gettext('Reload') ],
- cephcreatemon: ['Ceph Monitor', gettext('Create') ],
- cephdestroymon: ['Ceph Monitor', gettext('Destroy') ],
- cephcreateosd: ['Ceph OSD', gettext('Create') ],
- cephdestroyosd: ['Ceph OSD', gettext('Destroy') ],
- imgcopy: ['', gettext('Copy data') ],
- imgdel: ['', gettext('Erase data') ],
- download: ['', gettext('Download') ],
- vzdump: ['', gettext('Backup') ],
- aptupdate: ['', gettext('Update package database') ],
- startall: [ '', gettext('Start all VMs and Containers') ],
- stopall: [ '', gettext('Stop all VMs and Containers') ],
- migrateall: [ '', gettext('Migrate all VMs and Containers') ]
- },
-
- 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 text;
- },
-
- parse_task_upid: function(upid) {
- var task = {};
-
- var res = upid.match(/^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/);
- if (!res) {
- throw "unable to parse upid '" + upid + "'";
- }
- task.node = res[1];
- task.pid = parseInt(res[2], 16);
- task.pstart = parseInt(res[3], 16);
- task.starttime = parseInt(res[4], 16);
- task.type = res[5];
- task.id = res[6];
- task.user = res[7];
-
- task.desc = PVE.Utils.format_task_description(task.type, task.id);
-
- return task;
- },
-
- format_size: function(size) {
- /*jslint confusion: true */
-
- var units = ['', 'Ki', 'Mi', 'Gi', 'Ti', 'Pi', 'Ei', 'Zi', 'Yi'];
- var num = 0;
-
- while (size >= 1024 && ((num++)+1) < units.length) {
- size = size / 1024;
- }
-
- 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>";
- },
-
- format_large_bar: function(per, text) {
-
- if (!text) {
- text = per.toFixed(1) + "%";
- }
-
- return "<div class='pve-largebar-border'>" +
- "<div class='pve-largebar-inner' style='width:" + per + "%;'></div>" +
- "<div class='pve-largebar-text'>" + text + "</div>" +
- "</div>";
- },
-
- format_duration_long: function(ut) {
-
- var days = Math.floor(ut / 86400);
- ut -= days*86400;
- var hours = Math.floor(ut / 3600);
- ut -= hours*3600;
- var mins = Math.floor(ut / 60);
- ut -= mins*60;
-
- var hours_str = '00' + hours.toString();
- hours_str = hours_str.substr(hours_str.length - 2);
- var mins_str = "00" + mins.toString();
- mins_str = mins_str.substr(mins_str.length - 2);
- var ut_str = "00" + ut.toString();
- ut_str = ut_str.substr(ut_str.length - 2);
-
- if (days) {
- var ds = days > 1 ? PVE.Utils.daysText : PVE.Utils.dayText;
- 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';
+ return ut.toFixed(1) + 's';
}
if (ut < 3600) {
var mins = ut / 60;
- return mins.toFixed(0) + 'm';
+ return mins.toFixed(1) + 'm';
}
if (ut < 86400) {
var hours = ut / 3600;
- return hours.toFixed(0) + 'h';
+ return hours.toFixed(1) + 'h';
}
var days = ut / 86400;
- return days.toFixed(0) + 'd';
- },
-
- yesText: gettext('Yes'),
- noText: gettext('No'),
- enabledText: gettext('Enabled'),
- disabledText: gettext('Disabled'),
- noneText: gettext('none'),
- errorText: gettext('Error'),
- unknownText: gettext('Unknown'),
- defaultText: gettext('Default'),
- daysText: gettext('days'),
- dayText: gettext('day'),
- runningText: gettext('running'),
- stoppedText: gettext('stopped'),
- neverText: gettext('never'),
- totalText: gettext('Total'),
- usedText: gettext('Used'),
- directoryText: gettext('Directory'),
- imagesText: gettext('Disk image'),
- backupFileText: gettext('VZDump backup file'),
- vztmplText: gettext('Container template'),
- isoImageText: gettext('ISO image'),
- containersText: gettext('Container'),
- stateText: gettext('State'),
- groupText: gettext('Group'),
-
- format_expire: function(date) {
- if (!date) {
- return PVE.Utils.neverText;
- }
- return Ext.Date.format(date, "Y-m-d");
- },
-
- format_storage_type: function(value) {
- if (value === 'dir') {
- return PVE.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 === '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 PVE.Utils.unknownText;
- }
- },
-
- format_boolean_with_default: function(value) {
- if (Ext.isDefined(value) && value !== '__default__') {
- return value ? PVE.Utils.yesText : PVE.Utils.noText;
- }
- return PVE.Utils.defaultText;
- },
-
- format_boolean: function(value) {
- return value ? PVE.Utils.yesText : PVE.Utils.noText;
- },
-
- format_neg_boolean: function(value) {
- return !value ? PVE.Utils.yesText : PVE.Utils.noText;
- },
-
- format_enabled_toggle: function(value) {
- return value ? PVE.Utils.enabledText :PVE.Utils.disabledText;
+ return days.toFixed(1) + 'd';
+ },
+
+ 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'
+ },
+ 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') {
+ 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) {
- var text = PVE.Utils.format_boolean(value.managed);
+ var text = Proxmox.Utils.noneText;
if (value.managed) {
- text += ', ' + PVE.Utils.stateText + ': ';
- text += value.state || PVE.Utils.noneText;
+ text = value.state || Proxmox.Utils.noneText;
- text += ', ' + PVE.Utils.groupText + ': ';
- text += value.group || PVE.Utils.noneText;
+ text += ', ' + Proxmox.Utils.groupText + ': ';
+ text += value.group || Proxmox.Utils.noneText;
}
return text;
},
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 '';
}
- return PVE.Utils.format_size(value);
+ return Proxmox.Utils.format_size(value);
},
render_bandwidth: function(value) {
return '';
}
- return PVE.Utils.format_size(value) + '/s';
- },
-
- render_timestamp: function(value, metaData, record, rowIndex, colIndex, store) {
- var servertime = new Date(value * 1000);
- return Ext.Date.format(servertime, 'Y-m-d H:i:s');
+ return Proxmox.Utils.format_size(value) + '/s';
},
render_timestamp_human_readable: function(value) {
return Ext.Date.format(new Date(value * 1000), 'l d F Y H:i:s');
},
+ render_duration: function(value) {
+ if (value === undefined) {
+ return '-';
+ }
+ return PVE.Utils.format_duration_short(value);
+ },
+
calculate_mem_usage: function(data) {
if (!Ext.isNumeric(data.mem) ||
data.maxmem === 0 ||
return PVE.Utils.render_size(value);
},
- render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
+ get_object_icon_class: function(type, record) {
+ var status = '';
+ var objType = type;
- var icon = '';
- var gridcls = '';
+ if (type === 'type') {
+ // for folder view
+ objType = record.groupbyid;
+ } else if (record.template) {
+ // templates
+ objType = 'template';
+ status = type;
+ } else {
+ // everything else
+ status = record.status + ' ha-' + record.hastate;
+ }
- 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 (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';
- }
+ if (record.lock) {
+ status += ' locked lock-' + record.lock;
}
- // overwrite anything else
- if (record.data.hastate === 'error') {
- gridcls = '-offline';
+ var defaults = PVE.tree.ResourceTree.typeDefaults[objType];
+ if (defaults && defaults.iconCls) {
+ var retVal = defaults.iconCls + ' ' + status;
+ return retVal;
}
- var fa = '<i class="fa fa-fw x-fa-grid' + gridcls + ' fa-' + icon + '"></i> ';
- return fa + value;
+ return '';
},
- render_uptime: function(value, metaData, record, rowIndex, colIndex, store) {
-
- var uptime = value;
-
- if (uptime === undefined) {
- return '';
- }
+ render_resource_type: function(value, metaData, record, rowIndex, colIndex, store) {
- if (uptime <= 0) {
- return '-';
- }
+ var cls = PVE.Utils.get_object_icon_class(value,record.data);
- return PVE.Utils.format_duration_long(uptime);
+ var fa = '<i class="fa-fw x-grid-icon-custom ' + cls + '"></i> ';
+ return fa + value;
},
render_support_level: function(value, metaData, record) {
var type = record.data.type;
var id = record.data.id;
- return PVE.Utils.format_task_description(type, id);
+ return Proxmox.Utils.format_task_description(type, id);
},
/* render functions for new status panel */
return PVE.Utils.render_size_usage(record.used, record.total);
},
- dialog_title: function(subject, create, isAdd) {
- if (create) {
- if (isAdd) {
- return gettext('Add') + ': ' + subject;
- } else {
- return gettext('Create') + ': ' + subject;
- }
- } else {
- return gettext('Edit') + ': ' + subject;
+ 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);
+ },
+
+ 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(PVE.Utils.IP6_bracket_match,
+ 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, 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) {
- var vncdefault = 'html5';
- var dv = PVE.VersionInfo.console || vncdefault;
- if (dv === 'vv' && !allowSpice) {
- dv = vncdefault;
+ 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 dv = PVE.VersionInfo.console || 'xtermjs';
+ if ((dv === 'vv' && !allowSpice) || (dv === 'xtermjs' && !allowXtermjs)) {
+ dv = 'html5';
}
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){
}
};
- PVE.Utils.API2Request({
+ Proxmox.Utils.API2Request({
url: url,
params: params,
method: 'POST',
});
},
- // comp.setLoading() is buggy in ExtJS 4.0.7, so we
- // use el.mask() instead
- setErrorMask: function(comp, msg) {
- var el = comp.el;
- if (!el) {
- return;
- }
- if (!msg) {
- el.unmask();
- } else {
- if (msg === true) {
- el.mask(gettext("Loading..."));
- } else {
- el.mask(msg);
- }
- }
- },
-
- monStoreErrors: function(me, store) {
- me.mon(store, 'beforeload', function(s, operation, eOpts) {
- if (!me.loadCount) {
- me.loadCount = 0; // make sure it is numeric
- PVE.Utils.setErrorMask(me, true);
- }
- });
-
- // only works with 'pve' proxy
- me.mon(store.proxy, 'afterload', function(proxy, request, success) {
- me.loadCount++;
-
- if (success) {
- PVE.Utils.setErrorMask(me, false);
- return;
- }
-
- var msg;
- /*jslint nomen: true */
- var operation = request._operation;
- var error = operation.getError();
- if (error.statusText) {
- msg = error.statusText + ' (' + error.status + ')';
- } else {
- msg = gettext('Connection error');
- }
- PVE.Utils.setErrorMask(me, msg);
- });
- },
-
openTreeConsole: function(tree, record, item, index, e) {
e.stopEvent();
var nodename = record.data.node;
var vmid = record.data.vmid;
var vmname = record.data.name;
if (record.data.type === 'qemu' && !record.data.template) {
- PVE.Utils.API2Request({
+ Proxmox.Utils.API2Request({
url: '/nodes/' + nodename + '/qemu/' + vmid + '/status/current',
failure: function(response, opts) {
Ext.Msg.alert('Error', response.htmlStatus);
},
success: function(response, opts) {
- var allowSpice = response.result.data.spice;
- PVE.Utils.openDefaultConsoleWindow(allowSpice, 'kvm', vmid, nodename, vmname);
+ var consoles = {
+ spice: !!response.result.data.spice,
+ xtermjs: !!response.result.data.serial,
+ };
+ PVE.Utils.openDefaultConsoleWindow(consoles, 'kvm', vmid, nodename, vmname);
}
});
} else if (record.data.type === 'lxc' && !record.data.template) {
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_if_default: function(values, fieldname, default_val, create) {
}
},
- singleton: true,
- constructor: function() {
- var me = this;
- Ext.apply(me, me.utilities);
+ 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);
+ },
- var IPV4_OCTET = "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])";
- var IPV4_REGEXP = "(?:(?:" + IPV4_OCTET + "\\.){3}" + IPV4_OCTET + ")";
- var IPV6_H16 = "(?:[0-9a-fA-F]{1,4})";
- var IPV6_LS32 = "(?:(?:" + IPV6_H16 + ":" + IPV6_H16 + ")|" + IPV4_REGEXP + ")";
+ 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;
- me.IP4_match = new RegExp("^(?:" + IPV4_REGEXP + ")$");
- me.IP4_cidr_match = new RegExp("^(?:" + IPV4_REGEXP + ")\/([0-9]{1,2})$");
+ if (Ext.isArray(types)) {
+ busses = types;
+ } else if (Ext.isDefined(types)) {
+ busses = [ types ];
+ }
- var IPV6_REGEXP = "(?:" +
- "(?:(?:" + "(?:" + IPV6_H16 + ":){6})" + IPV6_LS32 + ")|" +
- "(?:(?:" + "::" + "(?:" + IPV6_H16 + ":){5})" + IPV6_LS32 + ")|" +
- "(?:(?:(?:" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){4})" + IPV6_LS32 + ")|" +
- "(?:(?:(?:(?:" + IPV6_H16 + ":){0,1}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){3})" + IPV6_LS32 + ")|" +
- "(?:(?:(?:(?:" + IPV6_H16 + ":){0,2}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){2})" + IPV6_LS32 + ")|" +
- "(?:(?:(?:(?:" + IPV6_H16 + ":){0,3}" + IPV6_H16 + ")?::" + "(?:" + IPV6_H16 + ":){1})" + IPV6_LS32 + ")|" +
- "(?:(?:(?:(?:" + IPV6_H16 + ":){0,4}" + IPV6_H16 + ")?::" + ")" + IPV6_LS32 + ")|" +
- "(?:(?:(?:(?:" + IPV6_H16 + ":){0,5}" + IPV6_H16 + ")?::" + ")" + IPV6_H16 + ")|" +
- "(?:(?:(?:(?:" + IPV6_H16 + ":){0,7}" + IPV6_H16 + ")?::" + ")" + ")" +
- ")";
+ // 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] + "'";
+ }
+ }
- me.IP6_match = new RegExp("^(?:" + IPV6_REGEXP + ")$");
- me.IP6_cidr_match = new RegExp("^(?:" + IPV6_REGEXP + ")\/([0-9]{1,3})$");
- me.IP6_bracket_match = new RegExp("^\\[(" + IPV6_REGEXP + ")\\]");
+ 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;
+ }
+ }
+ }
+ },
- me.IP64_match = new RegExp("^(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + ")$");
+ mp_counts: { mps: 256, unused: 256 },
- var DnsName_REGEXP = "(?:(([a-zA-Z0-9]([a-zA-Z0-9\\-]*[a-zA-Z0-9])?)\\.)*([A-Za-z0-9]([A-Za-z0-9\\-]*[A-Za-z0-9])?))";
- me.DnsName_match = new RegExp("^" + DnsName_REGEXP + "$");
+ 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;
+ }
+ }
- me.HostPort_match = new RegExp("^(" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")(:\\d+)?$");
- me.HostPortBrackets_match = new RegExp("^\\[(?:" + IPV6_REGEXP + "|" + IPV4_REGEXP + "|" + DnsName_REGEXP + ")\\](:\\d+)?$");
- me.IP6_dotnotation_match = new RegExp("^" + IPV6_REGEXP + "(\\.\\d+)?$");
+ if (!includeUnused) {
+ return;
+ }
+
+ for (i = 0; i < PVE.Utils.mp_counts.unused; i++) {
+ cont = func('unused', i);
+ if (!cont && cont !== undefined) {
+ return;
+ }
+ }
+ },
+
+ cleanEmptyObjectKeys: function (obj) {
+ var propName;
+ for (propName in obj) {
+ if (obj.hasOwnProperty(propName)) {
+ if (obj[propName] === null || obj[propName] === undefined) {
+ delete obj[propName];
+ }
+ }
+ }
+ },
+
+ handleStoreErrorOrMask: function(me, store, regex, callback) {
+
+ me.mon(store, 'load', function (proxy, response, success, operation) {
+
+ if (success) {
+ Proxmox.Utils.setErrorMask(me, false);
+ return;
+ }
+ var msg;
+
+ if (operation.error.statusText) {
+ if (operation.error.statusText.match(regex)) {
+ callback(me, operation.error);
+ return;
+ } else {
+ msg = operation.error.statusText + ' (' + operation.error.status + ')';
+ }
+ } else {
+ msg = gettext('Connection error');
+ }
+ Proxmox.Utils.setErrorMask(me, msg);
+ });
+ },
+
+ showCephInstallOrMask: function(container, msg, nodename, callback){
+ var regex = new RegExp("not (installed|initialized)", "i");
+ if (msg.match(regex)) {
+ if (Proxmox.UserName === 'root@pam') {
+ container.el.mask();
+ if (!container.down('pveCephInstallWindow')){
+ var isInstalled = msg.match(/not initialized/i) ? true : false;
+ var win = Ext.create('PVE.ceph.Install', {
+ nodename: nodename
+ });
+ win.getViewModel().set('isInstalled', isInstalled);
+ container.add(win);
+ win.show();
+ callback(win);
+ }
+ } else {
+ container.mask(Ext.String.format(gettext('{0} not installed.') +
+ ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
+ }
+ return true;
+ } else {
+ return false;
+ }
}
+},
+
+ singleton: true,
+ constructor: function() {
+ var me = this;
+ Ext.apply(me, me.utilities);
+ }
+
});