]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Utils.js
b2066fca2576b313f13cad043a40f7bb5f7a250b
3 // avoid errors related to Accessible Rich Internet Applications
4 // (access for people with disabilities)
5 // TODO reenable after all components are upgraded
6 Ext
.enableAria
= false;
7 Ext
.enableAriaButtons
= false;
8 Ext
.enableAriaPanels
= false;
10 // avoid errors when running without development tools
11 if (!Ext
.isDefined(Ext
.global
.console
)) {
16 console
.log("Starting PVE Manager");
18 Ext
.Ajax
.defaultHeaders
= {
19 'Accept': 'application/json',
22 Ext
.define('PVE.Utils', {
25 // this singleton contains miscellaneous utilities
27 toolkit
: undefined, // (extjs|touch), set inside Toolkit.js
29 bus_match
: /^(ide|sata|virtio|scsi)\d+$/,
43 'c': gettext('Community'),
44 'b': gettext('Basic'),
45 's': gettext('Standard'),
46 'p': gettext('Premium'),
49 noSubKeyHtml
: 'You do not have a valid subscription for this server. Please visit '
50 +'<a target="_blank" href="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">'
51 +'www.proxmox.com</a> to get a list of available options.',
55 { desc
: '5.x - 2.6 Kernel', val
: 'l26' },
56 { desc
: '2.4 Kernel', val
: 'l24' },
58 'Microsoft Windows': [
59 { desc
: '10/2016/2019', val
: 'win10' },
60 { desc
: '8.x/2012/2012r2', val
: 'win8' },
61 { desc
: '7/2008r2', val
: 'win7' },
62 { desc
: 'Vista/2008', val
: 'w2k8' },
63 { desc
: 'XP/2003', val
: 'wxp' },
64 { desc
: '2000', val
: 'w2k' },
67 { desc
: '-', val
: 'solaris' },
70 { desc
: '-', val
: 'other' },
74 is_windows: function(ostype
) {
75 for (let entry
of PVE
.Utils
.kvm_ostypes
['Microsoft Windows']) {
76 if (entry
.val
=== ostype
) {
83 get_health_icon: function(state
, circle
) {
84 if (circle
=== undefined) {
88 if (state
=== undefined) {
92 var icon
= 'faded fa-question';
95 icon
= 'good fa-check';
98 icon
= 'warning fa-upload';
101 icon
= 'warning fa-refresh';
104 icon
= 'warning fa-exclamation';
107 icon
= 'critical fa-times';
119 parse_ceph_version: function(service
) {
120 if (service
.ceph_version_short
) {
121 return service
.ceph_version_short
;
124 if (service
.ceph_version
) {
125 var match
= service
.ceph_version
.match(/version (\d+(\.\d+)*)/);
134 compare_ceph_versions: function(a
, b
) {
142 if (Ext
.isArray(a
)) {
143 avers
= a
.slice(); // copy array
145 avers
= a
.toString().split('.');
148 if (Ext
.isArray(b
)) {
149 bvers
= b
.slice(); // copy array
151 bvers
= b
.toString().split('.');
155 let av
= avers
.shift();
156 let bv
= bvers
.shift();
158 if (av
=== undefined && bv
=== undefined) {
160 } else if (av
=== undefined) {
162 } else if (bv
=== undefined) {
165 let diff
= parseInt(av
, 10) - parseInt(bv
, 10);
166 if (diff
!= 0) return diff
;
167 // else we need to look at the next parts
172 get_ceph_icon_html: function(health
, fw
) {
173 var state
= PVE
.Utils
.map_ceph_health
[health
];
174 var cls
= PVE
.Utils
.get_health_icon(state
);
178 return "<i class='fa " + cls
+ "'></i> ";
183 'HEALTH_UPGRADE': 'upgrade',
185 'HEALTH_WARN': 'warning',
186 'HEALTH_ERR': 'critical',
189 render_ceph_health: function(healthObj
) {
191 iconCls
: PVE
.Utils
.get_health_icon(),
195 if (!healthObj
|| !healthObj
.status
) {
199 var health
= PVE
.Utils
.map_ceph_health
[healthObj
.status
];
201 state
.iconCls
= PVE
.Utils
.get_health_icon(health
, true);
202 state
.text
= healthObj
.status
;
207 render_zfs_health: function(value
) {
208 if (typeof value
== 'undefined') {
211 var iconCls
= 'question-circle';
215 iconCls
= 'check-circle good';
219 iconCls
= 'exclamation-circle warning';
224 iconCls
= 'times-circle critical';
229 return '<i class="fa fa-' + iconCls
+ '"></i> ' + value
;
232 render_pbs_fingerprint
: fp
=> fp
.substring(0, 23),
234 render_backup_encryption: function(v
, meta
, record
) {
236 return gettext('No');
240 if (v
.match(/^[a-fA-F0-9]{2}:/)) { // fingerprint
241 tip
= `Key fingerprint ${PVE.Utils.render_pbs_fingerprint(v)}`;
243 let icon
= `<i class="fa fa-fw fa-lock good"></i>`;
244 return `<span data-qtip="${tip}">${icon} ${gettext('Encrypted')}</span>`;
247 render_backup_verification: function(v
, meta
, record
) {
248 let i
= (cls
, txt
) => `<i class="fa fa-fw fa-${cls}"></i> ${txt}`;
249 if (v
=== undefined || v
=== null) {
250 return i('question-circle-o warning', gettext('None'));
253 let txt
= gettext('Failed');
254 let iconCls
= 'times critical';
255 if (v
.state
=== 'ok') {
257 iconCls
= 'check good';
258 let now
= Date
.now() / 1000;
259 let task
= Proxmox
.Utils
.parse_task_upid(v
.upid
);
260 let verify_time
= Proxmox
.Utils
.render_timestamp(task
.starttime
);
261 tip
= `Last verify task started on ${verify_time}`;
262 if (now
- v
.starttime
> 30 * 24 * 60 * 60) {
263 tip
= `Last verify task over 30 days ago: ${verify_time}`;
264 iconCls
= 'check warning';
267 return `<span data-qtip="${tip}"> ${i(iconCls, txt)} </span>`;
270 render_backup_status: function(value
, meta
, record
) {
271 if (typeof value
== 'undefined') {
275 let iconCls
= 'check-circle good';
276 let text
= gettext('Yes');
278 if (!PVE
.Parser
.parseBoolean(value
.toString())) {
279 iconCls
= 'times-circle critical';
281 text
= gettext('No');
283 let reason
= record
.get('reason');
284 if (typeof reason
!== 'undefined') {
285 if (reason
in PVE
.Utils
.backup_reasons_table
) {
286 reason
= PVE
.Utils
.backup_reasons_table
[record
.get('reason')];
288 text
= `${text} - ${reason}`;
292 return `<i class="fa fa-${iconCls}"></i> ${text}`;
295 render_backup_days_of_week: function(val
) {
296 var dows
= ['sun', 'mon', 'tue', 'wed', 'thu', 'fri', 'sat'];
299 val
.split(',').forEach(function(day
) {
301 var dow
= (dows
.indexOf(day
)+6)%7;
303 if (selected
.length
=== 0 || selected
[selected
.length
-1] === 0) {
306 selected
[selected
.length
-1]++;
319 selected
.forEach(function(item
) {
322 days
.push(Ext
.Date
.dayNames
[cur
+1] + '-' + Ext
.Date
.dayNames
[(cur
+item
)%7]);
324 } else if (item
== 2) {
325 days
.push(Ext
.Date
.dayNames
[cur
+1]);
326 days
.push(Ext
.Date
.dayNames
[(cur
+2)%7]);
328 } else if (item
== 1) {
329 days
.push(Ext
.Date
.dayNames
[(cur
+1)%7]);
332 return days
.join(', ');
335 render_backup_selection: function(value
, metaData
, record
) {
336 let allExceptText
= gettext('All except {0}');
337 let allText
= '-- ' + gettext('All') + ' --';
338 if (record
.data
.all
) {
339 if (record
.data
.exclude
) {
340 return Ext
.String
.format(allExceptText
, record
.data
.exclude
);
344 if (record
.data
.vmid
) {
345 return record
.data
.vmid
;
348 if (record
.data
.pool
) {
349 return "Pool '"+ record
.data
.pool
+ "'";
355 backup_reasons_table
: {
356 'backup=yes': gettext('Enabled'),
357 'backup=no': gettext('Disabled'),
358 'enabled': gettext('Enabled'),
359 'disabled': gettext('Disabled'),
360 'not a volume': gettext('Not a volume'),
361 'efidisk but no OMVF BIOS': gettext('EFI Disk without OMVF BIOS'),
364 get_kvm_osinfo: function(value
) {
365 var info
= { base
: 'Other' }; // default
367 Ext
.each(Object
.keys(PVE
.Utils
.kvm_ostypes
), function(k
) {
368 Ext
.each(PVE
.Utils
.kvm_ostypes
[k
], function(e
) {
369 if (e
.val
=== value
) {
370 info
= { desc
: e
.desc
, base
: k
};
378 render_kvm_ostype: function(value
) {
379 var osinfo
= PVE
.Utils
.get_kvm_osinfo(value
);
380 if (osinfo
.desc
&& osinfo
.desc
!== '-') {
381 return osinfo
.base
+ ' ' + osinfo
.desc
;
387 render_hotplug_features: function(value
) {
390 if (!value
|| value
=== '0') {
391 return gettext('Disabled');
395 value
= 'disk,network,usb';
398 Ext
.each(value
.split(','), function(el
) {
400 fa
.push(gettext('Disk'));
401 } else if (el
=== 'network') {
402 fa
.push(gettext('Network'));
403 } else if (el
=== 'usb') {
405 } else if (el
=== 'memory') {
406 fa
.push(gettext('Memory'));
407 } else if (el
=== 'cpu') {
408 fa
.push(gettext('CPU'));
414 return fa
.join(', ');
417 render_localtime: function(value
) {
418 if (value
=== '__default__') {
419 return Proxmox
.Utils
.defaultText
+ ' (' + gettext('Enabled for Windows') + ')';
421 return Proxmox
.Utils
.format_boolean(value
);
424 render_qga_features: function(value
) {
426 return Proxmox
.Utils
.defaultText
+ ' (' + Proxmox
.Utils
.disabledText
+ ')';
428 var props
= PVE
.Parser
.parsePropertyString(value
, 'enabled');
429 if (!PVE
.Parser
.parseBoolean(props
.enabled
)) {
430 return Proxmox
.Utils
.disabledText
;
433 delete props
.enabled
;
434 var agentstring
= Proxmox
.Utils
.enabledText
;
436 Ext
.Object
.each(props
, function(key
, value
) {
438 agentstring
+= ', ' + key
+ ': ';
440 if (key
=== 'type') {
445 agentstring
+= map
[value
] || Proxmox
.Utils
.unknownText
;
447 if (PVE
.Parser
.parseBoolean(value
)) {
448 agentstring
+= Proxmox
.Utils
.enabledText
;
450 agentstring
+= Proxmox
.Utils
.disabledText
;
458 render_qemu_machine: function(value
) {
459 return value
|| Proxmox
.Utils
.defaultText
+ ' (i440fx)';
462 render_qemu_bios: function(value
) {
464 return Proxmox
.Utils
.defaultText
+ ' (SeaBIOS)';
465 } else if (value
=== 'seabios') {
467 } else if (value
=== 'ovmf') {
468 return "OVMF (UEFI)";
474 render_dc_ha_opts: function(value
) {
476 return Proxmox
.Utils
.defaultText
;
478 return PVE
.Parser
.printPropertyString(value
);
481 render_as_property_string: function(value
) {
482 return !value
? Proxmox
.Utils
.defaultText
483 : PVE
.Parser
.printPropertyString(value
);
486 render_scsihw: function(value
) {
488 return Proxmox
.Utils
.defaultText
+ ' (LSI 53C895A)';
489 } else if (value
=== 'lsi') {
490 return 'LSI 53C895A';
491 } else if (value
=== 'lsi53c810') {
493 } else if (value
=== 'megasas') {
494 return 'MegaRAID SAS 8708EM2';
495 } else if (value
=== 'virtio-scsi-pci') {
496 return 'VirtIO SCSI';
497 } else if (value
=== 'virtio-scsi-single') {
498 return 'VirtIO SCSI single';
499 } else if (value
=== 'pvscsi') {
500 return 'VMware PVSCSI';
506 render_spice_enhancements: function(values
) {
507 let props
= PVE
.Parser
.parsePropertyString(values
);
508 if (Ext
.Object
.isEmpty(props
)) {
509 return Proxmox
.Utils
.noneText
;
513 if (PVE
.Parser
.parseBoolean(props
.foldersharing
)) {
514 output
.push('Folder Sharing: ' + gettext('Enabled'));
516 if (props
.videostreaming
=== 'all' || props
.videostreaming
=== 'filter') {
517 output
.push('Video Streaming: ' + props
.videostreaming
);
519 return output
.join(', ');
522 // fixme: auto-generate this
523 // for now, please keep in sync with PVE::Tools::kvmkeymaps
528 'de-ch': 'German (Swiss)',
529 'en-gb': 'English (UK)',
530 'en-us': 'English (USA)',
534 //fo: 'Faroe Islands',
536 'fr-be': 'French (Belgium)',
537 'fr-ca': 'French (Canada)',
538 'fr-ch': 'French (Swiss)',
548 //'nl-be': 'Dutch (Belgium)',
552 'pt-br': 'Portuguese (Brazil)',
561 std
: gettext('Standard VGA'),
562 vmware
: gettext('VMware compatible'),
564 qxl2
: 'SPICE dual monitor',
565 qxl3
: 'SPICE three monitors',
566 qxl4
: 'SPICE four monitors',
567 serial0
: gettext('Serial terminal') + ' 0',
568 serial1
: gettext('Serial terminal') + ' 1',
569 serial2
: gettext('Serial terminal') + ' 2',
570 serial3
: gettext('Serial terminal') + ' 3',
571 virtio
: 'VirtIO-GPU',
572 none
: Proxmox
.Utils
.noneText
,
575 render_kvm_language: function(value
) {
576 if (!value
|| value
=== '__default__') {
577 return Proxmox
.Utils
.defaultText
;
579 var text
= PVE
.Utils
.kvm_keymaps
[value
];
581 return text
+ ' (' + value
+ ')';
586 kvm_keymap_array: function() {
587 var data
= [['__default__', PVE
.Utils
.render_kvm_language('')]];
588 Ext
.Object
.each(PVE
.Utils
.kvm_keymaps
, function(key
, value
) {
589 data
.push([key
, PVE
.Utils
.render_kvm_language(value
)]);
596 '__default__': Proxmox
.Utils
.defaultText
+ ' (xterm.js)',
597 'vv': 'SPICE (remote-viewer)',
598 'html5': 'HTML5 (noVNC)',
599 'xtermjs': 'xterm.js',
602 render_console_viewer: function(value
) {
603 value
= value
|| '__default__';
604 if (PVE
.Utils
.console_map
[value
]) {
605 return PVE
.Utils
.console_map
[value
];
610 console_viewer_array: function() {
611 return Ext
.Array
.map(Object
.keys(PVE
.Utils
.console_map
), function(v
) {
612 return [v
, PVE
.Utils
.render_console_viewer(v
)];
616 render_kvm_vga_driver: function(value
) {
618 return Proxmox
.Utils
.defaultText
;
620 var vga
= PVE
.Parser
.parsePropertyString(value
, 'type');
621 var text
= PVE
.Utils
.kvm_vga_drivers
[vga
.type
];
623 text
= Proxmox
.Utils
.defaultText
;
626 return text
+ ' (' + value
+ ')';
631 kvm_vga_driver_array: function() {
632 var data
= [['__default__', PVE
.Utils
.render_kvm_vga_driver('')]];
633 Ext
.Object
.each(PVE
.Utils
.kvm_vga_drivers
, function(key
, value
) {
634 data
.push([key
, PVE
.Utils
.render_kvm_vga_driver(value
)]);
640 render_kvm_startup: function(value
) {
641 var startup
= PVE
.Parser
.parseStartup(value
);
644 if (startup
.order
=== undefined) {
647 res
+= startup
.order
;
649 if (startup
.up
!== undefined) {
650 res
+= ',up=' + startup
.up
;
652 if (startup
.down
!== undefined) {
653 res
+= ',down=' + startup
.down
;
659 extractFormActionError: function(action
) {
661 switch (action
.failureType
) {
662 case Ext
.form
.action
.Action
.CLIENT_INVALID
:
663 msg
= gettext('Form fields may not be submitted with invalid values');
665 case Ext
.form
.action
.Action
.CONNECT_FAILURE
:
666 msg
= gettext('Connection error');
667 var resp
= action
.response
;
668 if (resp
.status
&& resp
.statusText
) {
669 msg
+= " " + resp
.status
+ ": " + resp
.statusText
;
672 case Ext
.form
.action
.Action
.LOAD_FAILURE
:
673 case Ext
.form
.action
.Action
.SERVER_INVALID
:
674 msg
= Proxmox
.Utils
.extractRequestError(action
.result
, true);
681 'images': gettext('Disk image'),
682 'backup': gettext('VZDump backup file'),
683 'vztmpl': gettext('Container template'),
684 'iso': gettext('ISO image'),
685 'rootdir': gettext('Container'),
686 'snippets': gettext('Snippets'),
689 volume_is_qemu_backup: function(volid
, format
) {
690 return format
=== 'pbs-vm' || volid
.match(':backup/vzdump-qemu-');
693 volume_is_lxc_backup: function(volid
, format
) {
694 return format
=== 'pbs-ct' || volid
.match(':backup/vzdump-(lxc|openvz)-');
699 name
: gettext('Active Directory Server'),
700 ipanel
: 'pveAuthADPanel',
701 syncipanel
: 'pveAuthLDAPSyncPanel',
705 name
: gettext('LDAP Server'),
706 ipanel
: 'pveAuthLDAPPanel',
707 syncipanel
: 'pveAuthLDAPSyncPanel',
712 ipanel
: 'pveAuthBasePanel',
716 name
: 'Proxmox VE authentication server',
717 ipanel
: 'pveAuthBasePanel',
724 name
: Proxmox
.Utils
.directoryText
,
725 ipanel
: 'DirInputPanel',
731 ipanel
: 'LVMInputPanel',
737 ipanel
: 'LvmThinInputPanel',
743 ipanel
: 'NFSInputPanel',
749 ipanel
: 'CIFSInputPanel',
755 ipanel
: 'GlusterFsInputPanel',
761 ipanel
: 'IScsiInputPanel',
767 ipanel
: 'CephFSInputPanel',
772 name
: 'CephFS (PVE)',
773 ipanel
: 'CephFSInputPanel',
780 ipanel
: 'RBDInputPanel',
786 ipanel
: 'RBDInputPanel',
792 name
: 'ZFS over iSCSI',
793 ipanel
: 'ZFSInputPanel',
799 ipanel
: 'ZFSPoolInputPanel',
804 name
: 'Proxmox Backup Server',
805 ipanel
: 'PBSInputPanel',
830 ipanel
: 'SimpleInputPanel',
835 ipanel
: 'VlanInputPanel',
840 ipanel
: 'QinQInputPanel',
845 ipanel
: 'VxlanInputPanel',
850 ipanel
: 'EvpnInputPanel',
855 sdncontrollerSchema
: {
862 ipanel
: 'EvpnInputPanel',
863 faIcon
: 'crosshairs',
867 format_sdnvnet_type: function(value
, md
, record
) {
868 var schema
= PVE
.Utils
.sdnvnetSchema
[value
];
872 return Proxmox
.Utils
.unknownText
;
875 format_sdnzone_type: function(value
, md
, record
) {
876 var schema
= PVE
.Utils
.sdnzoneSchema
[value
];
880 return Proxmox
.Utils
.unknownText
;
883 format_sdncontroller_type: function(value
, md
, record
) {
884 var schema
= PVE
.Utils
.sdncontrollerSchema
[value
];
888 return Proxmox
.Utils
.unknownText
;
891 format_storage_type: function(value
, md
, record
) {
892 if (value
=== 'rbd') {
893 value
= !record
|| record
.get('monhost') ? 'rbd' : 'pveceph';
894 } else if (value
=== 'cephfs') {
895 value
= !record
|| record
.get('monhost') ? 'cephfs' : 'pvecephfs';
898 var schema
= PVE
.Utils
.storageSchema
[value
];
902 return Proxmox
.Utils
.unknownText
;
905 format_ha: function(value
) {
906 var text
= Proxmox
.Utils
.noneText
;
909 text
= value
.state
|| Proxmox
.Utils
.noneText
;
911 text
+= ', ' + Proxmox
.Utils
.groupText
+ ': ';
912 text
+= value
.group
|| Proxmox
.Utils
.noneText
;
918 format_content_types: function(value
) {
919 return value
.split(',').sort().map(function(ct
) {
920 return PVE
.Utils
.contentTypes
[ct
] || ct
;
924 render_storage_content: function(value
, metaData
, record
) {
925 var data
= record
.data
;
926 if (Ext
.isNumber(data
.channel
) &&
927 Ext
.isNumber(data
.id
) &&
928 Ext
.isNumber(data
.lun
)) {
930 Ext
.String
.leftPad(data
.channel
, 2, '0') +
931 " ID " + data
.id
+ " LUN " + data
.lun
;
933 return data
.volid
.replace(/^.*?:(.*?\/)?/, '');
936 render_serverity: function(value
) {
937 return PVE
.Utils
.log_severity_hash
[value
] || value
;
940 calculate_hostcpu: function(data
) {
942 if (!(data
.uptime
&& Ext
.isNumeric(data
.cpu
))) {
946 if (data
.type
!== 'qemu' && data
.type
!== 'lxc') {
950 var index
= PVE
.data
.ResourceStore
.findExact('id', 'node/' + data
.node
);
951 var node
= PVE
.data
.ResourceStore
.getAt(index
);
952 if (!Ext
.isDefined(node
) || node
=== null) {
955 var maxcpu
= node
.data
.maxcpu
|| 1;
957 if (!Ext
.isNumeric(maxcpu
) && (maxcpu
>= 1)) {
961 return ((data
.cpu
/maxcpu
) * data
.maxcpu
);
964 render_hostcpu: function(value
, metaData
, record
, rowIndex
, colIndex
, store
) {
966 if (!(record
.data
.uptime
&& Ext
.isNumeric(record
.data
.cpu
))) {
970 if (record
.data
.type
!== 'qemu' && record
.data
.type
!== 'lxc') {
974 var index
= PVE
.data
.ResourceStore
.findExact('id', 'node/' + record
.data
.node
);
975 var node
= PVE
.data
.ResourceStore
.getAt(index
);
976 if (!Ext
.isDefined(node
) || node
=== null) {
979 var maxcpu
= node
.data
.maxcpu
|| 1;
981 if (!Ext
.isNumeric(maxcpu
) && (maxcpu
>= 1)) {
985 var per
= (record
.data
.cpu
/maxcpu
) * record
.data
.maxcpu
* 100;
987 return per
.toFixed(1) + '% of ' + maxcpu
.toString() + (maxcpu
> 1 ? 'CPUs' : 'CPU');
990 render_bandwidth: function(value
) {
991 if (!Ext
.isNumeric(value
)) {
995 return Proxmox
.Utils
.format_size(value
) + '/s';
998 render_timestamp_human_readable: function(value
) {
999 return Ext
.Date
.format(new Date(value
* 1000), 'l d F Y H:i:s');
1002 calculate_mem_usage: function(data
) {
1003 if (!Ext
.isNumeric(data
.mem
) ||
1004 data
.maxmem
=== 0 ||
1009 return data
.mem
/ data
.maxmem
;
1012 calculate_hostmem_usage: function(data
) {
1014 if (data
.type
!== 'qemu' && data
.type
!== 'lxc') {
1018 var index
= PVE
.data
.ResourceStore
.findExact('id', 'node/' + data
.node
);
1019 var node
= PVE
.data
.ResourceStore
.getAt(index
);
1021 if (!Ext
.isDefined(node
) || node
=== null) {
1024 var maxmem
= node
.data
.maxmem
|| 0;
1026 if (!Ext
.isNumeric(data
.mem
) ||
1032 return (data
.mem
/ maxmem
);
1035 render_mem_usage_percent: function(value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1036 if (!Ext
.isNumeric(value
) || value
=== -1) {
1040 // we got no percentage but bytes
1042 var maxmem
= record
.data
.maxmem
;
1043 if (!record
.data
.uptime
||
1045 !Ext
.isNumeric(mem
)) {
1049 return (mem
*100/maxmem
).toFixed(1) + " %";
1051 return (value
*100).toFixed(1) + " %";
1054 render_hostmem_usage_percent: function(value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1056 if (!Ext
.isNumeric(record
.data
.mem
) || value
=== -1) {
1060 if (record
.data
.type
!== 'qemu' && record
.data
.type
!== 'lxc') {
1064 var index
= PVE
.data
.ResourceStore
.findExact('id', 'node/' + record
.data
.node
);
1065 var node
= PVE
.data
.ResourceStore
.getAt(index
);
1066 var maxmem
= node
.data
.maxmem
|| 0;
1068 if (record
.data
.mem
> 1 ) {
1069 // we got no percentage but bytes
1070 var mem
= record
.data
.mem
;
1071 if (!record
.data
.uptime
||
1073 !Ext
.isNumeric(mem
)) {
1077 return ((mem
*100)/maxmem
).toFixed(1) + " %";
1079 return (value
*100).toFixed(1) + " %";
1082 render_mem_usage: function(value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1084 var maxmem
= record
.data
.maxmem
;
1086 if (!record
.data
.uptime
) {
1090 if (!(Ext
.isNumeric(mem
) && maxmem
)) {
1094 return Proxmox
.Utils
.render_size(value
);
1097 calculate_disk_usage: function(data
) {
1098 if (!Ext
.isNumeric(data
.disk
) ||
1099 data
.type
=== 'qemu' ||
1100 data
.type
=== 'lxc' && data
.uptime
=== 0 ||
1101 data
.maxdisk
=== 0) {
1105 return data
.disk
/ data
.maxdisk
;
1108 render_disk_usage_percent: function(value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1109 if (!Ext
.isNumeric(value
) || value
=== -1) {
1113 return (value
* 100).toFixed(1) + " %";
1116 render_disk_usage: function(value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1118 var maxdisk
= record
.data
.maxdisk
;
1119 var type
= record
.data
.type
;
1121 if (!Ext
.isNumeric(disk
) ||
1124 type
=== 'lxc' && record
.data
.uptime
=== 0) {
1128 return Proxmox
.Utils
.render_size(value
);
1131 get_object_icon_class: function(type
, record
) {
1135 if (type
=== 'type') {
1137 objType
= record
.groupbyid
;
1138 } else if (record
.template
) {
1140 objType
= 'template';
1144 status
= record
.status
+ ' ha-' + record
.hastate
;
1148 status
+= ' locked lock-' + record
.lock
;
1151 var defaults
= PVE
.tree
.ResourceTree
.typeDefaults
[objType
];
1152 if (defaults
&& defaults
.iconCls
) {
1153 var retVal
= defaults
.iconCls
+ ' ' + status
;
1160 render_resource_type: function(value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1161 var cls
= PVE
.Utils
.get_object_icon_class(value
, record
.data
);
1163 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ';
1167 render_support_level: function(value
, metaData
, record
) {
1168 return PVE
.Utils
.support_level_hash
[value
] || '-';
1171 render_upid: function(value
, metaData
, record
) {
1172 var type
= record
.data
.type
;
1173 var id
= record
.data
.id
;
1175 return Proxmox
.Utils
.format_task_description(type
, id
);
1178 render_optional_url: function(value
) {
1180 if (value
&& (match
= value
.match(/^https?:\/\//)) !== null) {
1181 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>';
1186 render_san: function(value
) {
1188 if (Ext
.isArray(value
)) {
1189 value
.forEach(function(val
) {
1190 if (!Ext
.isNumber(val
)) {
1194 return names
.join('<br>');
1199 render_full_name: function(firstname
, metaData
, record
) {
1200 var first
= firstname
|| '';
1201 var last
= record
.data
.lastname
|| '';
1202 return Ext
.htmlEncode(first
+ " " + last
);
1205 render_u2f_error: function(error
) {
1207 '1': gettext('Other Error'),
1208 '2': gettext('Bad Request'),
1209 '3': gettext('Configuration Unsupported'),
1210 '4': gettext('Device Ineligible'),
1211 '5': gettext('Timeout'),
1213 return "U2F Error: " + ErrorNames
[error
] || Proxmox
.Utils
.unknownText
;
1216 windowHostname: function() {
1217 return window
.location
.hostname
.replace(Proxmox
.Utils
.IP6_bracket_match
,
1218 function(m
, addr
, offset
, original
) { return addr
; });
1221 openDefaultConsoleWindow: function(consoles
, consoleType
, vmid
, nodename
, vmname
, cmd
) {
1222 var dv
= PVE
.Utils
.defaultViewer(consoles
, consoleType
);
1223 PVE
.Utils
.openConsoleWindow(dv
, consoleType
, vmid
, nodename
, vmname
, cmd
);
1226 openConsoleWindow: function(viewer
, consoleType
, vmid
, nodename
, vmname
, cmd
) {
1227 if (vmid
== undefined && (consoleType
=== 'kvm' || consoleType
=== 'lxc')) {
1228 throw "missing vmid";
1231 throw "no nodename specified";
1234 if (viewer
=== 'html5') {
1235 PVE
.Utils
.openVNCViewer(consoleType
, vmid
, nodename
, vmname
, cmd
);
1236 } else if (viewer
=== 'xtermjs') {
1237 Proxmox
.Utils
.openXtermJsViewer(consoleType
, vmid
, nodename
, vmname
, cmd
);
1238 } else if (viewer
=== 'vv') {
1239 let url
= '/nodes/' + nodename
+ '/spiceshell';
1241 proxy
: PVE
.Utils
.windowHostname(),
1243 if (consoleType
=== 'kvm') {
1244 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
.toString() + '/spiceproxy';
1245 } else if (consoleType
=== 'lxc') {
1246 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
.toString() + '/spiceproxy';
1247 } else if (consoleType
=== 'upgrade') {
1248 params
.cmd
= 'upgrade';
1249 } else if (consoleType
=== 'cmd') {
1251 } else if (consoleType
!== 'shell') {
1252 throw `unknown spice viewer type '${consoleType}'`;
1254 PVE
.Utils
.openSpiceViewer(url
, params
);
1256 throw `unknown viewer type '${viewer}'`;
1260 defaultViewer: function(consoles
, type
) {
1261 var allowSpice
, allowXtermjs
;
1263 if (consoles
=== true) {
1265 allowXtermjs
= true;
1266 } else if (typeof consoles
=== 'object') {
1267 allowSpice
= consoles
.spice
;
1268 allowXtermjs
= !!consoles
.xtermjs
;
1270 let dv
= PVE
.VersionInfo
.console
|| (type
=== 'kvm' ? 'vv' : 'xtermjs');
1271 if (dv
=== 'vv' && !allowSpice
) {
1272 dv
= allowXtermjs
? 'xtermjs' : 'html5';
1273 } else if (dv
=== 'xtermjs' && !allowXtermjs
) {
1274 dv
= allowSpice
? 'vv' : 'html5';
1280 openVNCViewer: function(vmtype
, vmid
, nodename
, vmname
, cmd
) {
1281 let scaling
= 'off';
1282 if (Proxmox
.Utils
.toolkit
!== 'touch') {
1283 var sp
= Ext
.state
.Manager
.getProvider();
1284 scaling
= sp
.get('novnc-scaling', 'off');
1286 var url
= Ext
.Object
.toQueryString({
1287 console
: vmtype
, // kvm, lxc, upgrade or shell
1295 var nw
= window
.open("?" + url
, '_blank', "innerWidth=745,innerheight=427");
1301 openSpiceViewer: function(url
, params
) {
1302 var downloadWithName = function(uri
, name
) {
1303 var link
= Ext
.DomHelper
.append(document
.body
, {
1306 css
: 'display:none;visibility:hidden;height:0px;',
1309 // Note: we need to tell Android and Chrome the correct file name extension
1310 // but we do not set 'download' tag for other environments, because
1311 // It can have strange side effects (additional user prompt on firefox)
1312 if (navigator
.userAgent
.match(/Android|Chrome/i)) {
1313 link
.download
= name
;
1316 if (link
.fireEvent
) {
1317 link
.fireEvent('onclick');
1319 let evt
= document
.createEvent("MouseEvents");
1320 evt
.initMouseEvent('click', true, true, window
, 1, 0, 0, 0, 0, false, false, false, false, 0, null);
1321 link
.dispatchEvent(evt
);
1325 Proxmox
.Utils
.API2Request({
1329 failure: function(response
, opts
) {
1330 Ext
.Msg
.alert('Error', response
.htmlStatus
);
1332 success: function(response
, opts
) {
1333 var raw
= "[virt-viewer]\n";
1334 Ext
.Object
.each(response
.result
.data
, function(k
, v
) {
1335 raw
+= k
+ "=" + v
+ "\n";
1337 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1338 encodeURIComponent(raw
);
1340 downloadWithName(url
, "pve-spice.vv");
1345 openTreeConsole: function(tree
, record
, item
, index
, e
) {
1347 var nodename
= record
.data
.node
;
1348 var vmid
= record
.data
.vmid
;
1349 var vmname
= record
.data
.name
;
1350 if (record
.data
.type
=== 'qemu' && !record
.data
.template
) {
1351 Proxmox
.Utils
.API2Request({
1352 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current',
1353 failure: function(response
, opts
) {
1354 Ext
.Msg
.alert('Error', response
.htmlStatus
);
1356 success: function(response
, opts
) {
1357 let conf
= response
.result
.data
;
1359 spice
: !!conf
.spice
,
1360 xtermjs
: !!conf
.serial
,
1362 PVE
.Utils
.openDefaultConsoleWindow(consoles
, 'kvm', vmid
, nodename
, vmname
);
1365 } else if (record
.data
.type
=== 'lxc' && !record
.data
.template
) {
1366 PVE
.Utils
.openDefaultConsoleWindow(true, 'lxc', vmid
, nodename
, vmname
);
1370 // test automation helper
1371 call_menu_handler: function(menu
, text
) {
1372 var list
= menu
.query('menuitem');
1374 Ext
.Array
.each(list
, function(item
) {
1375 if (item
.text
=== text
) {
1386 createCmdMenu: function(v
, record
, item
, index
, event
) {
1388 if (!(v
instanceof Ext
.tree
.View
)) {
1392 var template
= !!record
.data
.template
;
1393 var type
= record
.data
.type
;
1396 if (type
=== 'qemu' || type
== 'lxc') {
1397 menu
= Ext
.create('PVE.menu.TemplateMenu', {
1401 } else if (type
=== 'qemu' ||
1404 menu
= Ext
.create('PVE.' + type
+ '.CmdMenu', {
1406 nodename
: record
.data
.node
,
1412 menu
.showAt(event
.getXY());
1416 // helper for deleting field which are set to there default values
1417 delete_if_default: function(values
, fieldname
, default_val
, create
) {
1418 if (values
[fieldname
] === '' || values
[fieldname
] === default_val
) {
1420 if (values
.delete) {
1421 if (Ext
.isArray(values
.delete)) {
1422 values
.delete.push(fieldname
);
1424 values
.delete += ',' + fieldname
;
1427 values
.delete = fieldname
;
1431 delete values
[fieldname
];
1435 loadSSHKeyFromFile: function(file
, callback
) {
1436 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1437 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1438 // assume: 740*8 for max. 32kbit (5920 byte file)
1439 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1440 if (file
.size
> 8192) {
1441 Ext
.Msg
.alert(gettext('Error'), gettext("Invalid file size: ") + file
.size
);
1447 var reader
= new FileReader();
1448 reader
.onload = function(evt
) {
1449 callback(evt
.target
.result
);
1451 reader
.readAsText(file
);
1454 loadTextFromFile: function(file
, callback
, maxBytes
) {
1455 let maxSize
= maxBytes
|| 8192;
1456 if (file
.size
> maxSize
) {
1457 Ext
.Msg
.alert(gettext('Error'), gettext("Invalid file size: ") + file
.size
);
1463 let reader
= new FileReader();
1464 reader
.onload
= evt
=> callback(evt
.target
.result
);
1465 reader
.readAsText(file
);
1468 diskControllerMaxIDs
: {
1475 // types is either undefined (all busses), an array of busses, or a single bus
1476 forEachBus: function(types
, func
) {
1477 var busses
= Object
.keys(PVE
.Utils
.diskControllerMaxIDs
);
1478 var i
, j
, count
, cont
;
1480 if (Ext
.isArray(types
)) {
1482 } else if (Ext
.isDefined(types
)) {
1486 // check if we only have valid busses
1487 for (i
= 0; i
< busses
.length
; i
++) {
1488 if (!PVE
.Utils
.diskControllerMaxIDs
[busses
[i
]]) {
1489 throw "invalid bus: '" + busses
[i
] + "'";
1493 for (i
= 0; i
< busses
.length
; i
++) {
1494 count
= PVE
.Utils
.diskControllerMaxIDs
[busses
[i
]];
1495 for (j
= 0; j
< count
; j
++) {
1496 cont
= func(busses
[i
], j
);
1497 if (!cont
&& cont
!== undefined) {
1504 mp_counts
: { mps
: 256, unused
: 256 },
1506 forEachMP: function(func
, includeUnused
) {
1508 for (i
= 0; i
< PVE
.Utils
.mp_counts
.mps
; i
++) {
1509 cont
= func('mp', i
);
1510 if (!cont
&& cont
!== undefined) {
1515 if (!includeUnused
) {
1519 for (i
= 0; i
< PVE
.Utils
.mp_counts
.unused
; i
++) {
1520 cont
= func('unused', i
);
1521 if (!cont
&& cont
!== undefined) {
1527 hardware_counts
: { net
: 32, usb
: 5, hostpci
: 16, audio
: 1, efidisk
: 1, serial
: 4, rng
: 1 },
1529 cleanEmptyObjectKeys: function(obj
) {
1531 for (propName
in obj
) {
1532 if (obj
.hasOwnProperty(propName
)) {
1533 if (obj
[propName
] === null || obj
[propName
] === undefined) {
1534 delete obj
[propName
];
1540 acmedomain_count
: 5,
1542 add_domain_to_acme: function(acme
, domain
) {
1543 if (acme
.domains
=== undefined) {
1544 acme
.domains
= [domain
];
1546 acme
.domains
.push(domain
);
1547 acme
.domains
= acme
.domains
.filter((value
, index
, self
) => self
.indexOf(value
) === index
);
1552 remove_domain_from_acme: function(acme
, domain
) {
1553 if (acme
.domains
!== undefined) {
1554 acme
.domains
= acme
.domains
.filter((value
, index
, self
) => self
.indexOf(value
) === index
&& value
!== domain
);
1559 handleStoreErrorOrMask: function(me
, store
, regex
, callback
) {
1560 me
.mon(store
, 'load', function(proxy
, response
, success
, operation
) {
1562 Proxmox
.Utils
.setErrorMask(me
, false);
1567 if (operation
.error
.statusText
) {
1568 if (operation
.error
.statusText
.match(regex
)) {
1569 callback(me
, operation
.error
);
1572 msg
= operation
.error
.statusText
+ ' (' + operation
.error
.status
+ ')';
1575 msg
= gettext('Connection error');
1577 Proxmox
.Utils
.setErrorMask(me
, msg
);
1581 showCephInstallOrMask: function(container
, msg
, nodename
, callback
) {
1582 if (msg
.match(/not (installed|initialized)/i)) {
1583 if (Proxmox
.UserName
=== 'root@pam') {
1584 container
.el
.mask();
1585 if (!container
.down('pveCephInstallWindow')) {
1586 var isInstalled
= !!msg
.match(/not initialized/i);
1587 var win
= Ext
.create('PVE.ceph.Install', {
1590 win
.getViewModel().set('isInstalled', isInstalled
);
1596 container
.mask(Ext
.String
.format(gettext('{0} not installed.') +
1597 ' ' + gettext('Log in as root to install.'), 'Ceph'), ['pve-static-mask']);
1605 monitor_ceph_installed: function(view
, rstore
, nodename
, maskOwnerCt
) {
1606 PVE
.Utils
.handleStoreErrorOrMask(
1609 /not (installed|initialized)/i,
1611 nodename
= nodename
|| 'localhost';
1612 let maskTarget
= maskOwnerCt
? view
.ownerCt
: view
;
1613 rstore
.stopUpdate();
1614 PVE
.Utils
.showCephInstallOrMask(maskTarget
, error
.statusText
, nodename
, win
=> {
1615 view
.mon(win
, 'cephInstallWindowClosed', () => rstore
.startUpdate());
1622 propertyStringSet: function(target
, source
, name
, value
) {
1624 if (value
=== undefined) {
1625 target
[name
] = source
;
1627 target
[name
] = value
;
1630 delete target
[name
];
1634 forEachCorosyncLink: function(nodeinfo
, cb
) {
1635 let re
= /(?:ring|link)(\d+)_addr/;
1636 Ext
.iterate(nodeinfo
, (prop
, val
) => {
1637 let match
= re
.exec(prop
);
1639 cb(Number(match
[1]), val
);
1646 'AuthenticAMD': 'AMD',
1647 'GenuineIntel': 'Intel',
1655 "_default_": 5, // includes custom models
1658 verify_ip64_address_list: function(value
, with_suffix
) {
1659 for (let addr
of value
.split(/[ ,;]+/)) {
1665 let parts
= addr
.split('%');
1668 if (parts
.length
> 2) {
1672 if (parts
.length
> 1 && !addr
.startsWith('fe80:')) {
1677 if (!Proxmox
.Utils
.IP64_match
.test(addr
)) {
1687 constructor: function() {
1689 Ext
.apply(me
, me
.utilities
);
1691 Proxmox
.Utils
.override_task_descriptions({
1692 acmedeactivate
: ['ACME Account', gettext('Deactivate')],
1693 acmenewcert
: ['SRV', gettext('Order Certificate')],
1694 acmerefresh
: ['ACME Account', gettext('Refresh')],
1695 acmeregister
: ['ACME Account', gettext('Register')],
1696 acmerenew
: ['SRV', gettext('Renew Certificate')],
1697 acmerevoke
: ['SRV', gettext('Revoke Certificate')],
1698 acmeupdate
: ['ACME Account', gettext('Update')],
1699 'auth-realm-sync': [gettext('Realm'), gettext('Sync')],
1700 'auth-realm-sync-test': [gettext('Realm'), gettext('Sync Preview')],
1701 cephcreatemds
: ['Ceph Metadata Server', gettext('Create')],
1702 cephcreatemgr
: ['Ceph Manager', gettext('Create')],
1703 cephcreatemon
: ['Ceph Monitor', gettext('Create')],
1704 cephcreateosd
: ['Ceph OSD', gettext('Create')],
1705 cephcreatepool
: ['Ceph Pool', gettext('Create')],
1706 cephdestroymds
: ['Ceph Metadata Server', gettext('Destroy')],
1707 cephdestroymgr
: ['Ceph Manager', gettext('Destroy')],
1708 cephdestroymon
: ['Ceph Monitor', gettext('Destroy')],
1709 cephdestroyosd
: ['Ceph OSD', gettext('Destroy')],
1710 cephdestroypool
: ['Ceph Pool', gettext('Destroy')],
1711 cephfscreate
: ['CephFS', gettext('Create')],
1712 cephsetpool
: ['Ceph Pool', gettext('Edit')],
1713 cephsetflags
: ['', gettext('Change global Ceph flags')],
1714 clustercreate
: ['', gettext('Create Cluster')],
1715 clusterjoin
: ['', gettext('Join Cluster')],
1716 dircreate
: [gettext('Directory Storage'), gettext('Create')],
1717 dirremove
: [gettext('Directory'), gettext('Remove')],
1718 download
: ['', gettext('Download')],
1719 hamigrate
: ['HA', gettext('Migrate')],
1720 hashutdown
: ['HA', gettext('Shutdown')],
1721 hastart
: ['HA', gettext('Start')],
1722 hastop
: ['HA', gettext('Stop')],
1723 imgcopy
: ['', gettext('Copy data')],
1724 imgdel
: ['', gettext('Erase data')],
1725 lvmcreate
: [gettext('LVM Storage'), gettext('Create')],
1726 lvmthincreate
: [gettext('LVM-Thin Storage'), gettext('Create')],
1727 migrateall
: ['', gettext('Migrate all VMs and Containers')],
1728 'move_volume': ['CT', gettext('Move Volume')],
1729 'pbs-download': ['VM/CT', gettext('File Restore Download')],
1730 pull_file
: ['CT', gettext('Pull file')],
1731 push_file
: ['CT', gettext('Push file')],
1732 qmclone
: ['VM', gettext('Clone')],
1733 qmconfig
: ['VM', gettext('Configure')],
1734 qmcreate
: ['VM', gettext('Create')],
1735 qmdelsnapshot
: ['VM', gettext('Delete Snapshot')],
1736 qmdestroy
: ['VM', gettext('Destroy')],
1737 qmigrate
: ['VM', gettext('Migrate')],
1738 qmmove
: ['VM', gettext('Move disk')],
1739 qmpause
: ['VM', gettext('Pause')],
1740 qmreboot
: ['VM', gettext('Reboot')],
1741 qmreset
: ['VM', gettext('Reset')],
1742 qmrestore
: ['VM', gettext('Restore')],
1743 qmresume
: ['VM', gettext('Resume')],
1744 qmrollback
: ['VM', gettext('Rollback')],
1745 qmshutdown
: ['VM', gettext('Shutdown')],
1746 qmsnapshot
: ['VM', gettext('Snapshot')],
1747 qmstart
: ['VM', gettext('Start')],
1748 qmstop
: ['VM', gettext('Stop')],
1749 qmsuspend
: ['VM', gettext('Hibernate')],
1750 qmtemplate
: ['VM', gettext('Convert to template')],
1751 spiceproxy
: ['VM/CT', gettext('Console') + ' (Spice)'],
1752 spiceshell
: ['', gettext('Shell') + ' (Spice)'],
1753 startall
: ['', gettext('Start all VMs and Containers')],
1754 stopall
: ['', gettext('Stop all VMs and Containers')],
1755 unknownimgdel
: ['', gettext('Destroy image from unknown guest')],
1756 vncproxy
: ['VM/CT', gettext('Console')],
1757 vncshell
: ['', gettext('Shell')],
1758 vzclone
: ['CT', gettext('Clone')],
1759 vzcreate
: ['CT', gettext('Create')],
1760 vzdelsnapshot
: ['CT', gettext('Delete Snapshot')],
1761 vzdestroy
: ['CT', gettext('Destroy')],
1762 vzdump
: (type
, id
) => id
? `VM/CT ${id} - ${gettext('Backup')}` : gettext('Backup Job'),
1763 vzmigrate
: ['CT', gettext('Migrate')],
1764 vzmount
: ['CT', gettext('Mount')],
1765 vzreboot
: ['CT', gettext('Reboot')],
1766 vzrestore
: ['CT', gettext('Restore')],
1767 vzresume
: ['CT', gettext('Resume')],
1768 vzrollback
: ['CT', gettext('Rollback')],
1769 vzshutdown
: ['CT', gettext('Shutdown')],
1770 vzsnapshot
: ['CT', gettext('Snapshot')],
1771 vzstart
: ['CT', gettext('Start')],
1772 vzstop
: ['CT', gettext('Stop')],
1773 vzsuspend
: ['CT', gettext('Suspend')],
1774 vztemplate
: ['CT', gettext('Convert to template')],
1775 vzumount
: ['CT', gettext('Unmount')],
1776 zfscreate
: [gettext('ZFS Storage'), gettext('Create')],