]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Utils.js
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' , { utilities
: {
24 // this singleton contains miscellaneous utilities
26 toolkit
: undefined , // (extjs|touch), set inside Toolkit.js
28 bus_match
: /^(ide|sata|virtio|scsi)\d+$/ ,
42 'c' : gettext ( 'Community' ),
43 'b' : gettext ( 'Basic' ),
44 's' : gettext ( 'Standard' ),
45 'p' : gettext ( 'Premium' )
48 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.' ,
52 { desc
: '5.x - 2.6 Kernel' , val
: 'l26' },
53 { desc
: '2.4 Kernel' , val
: 'l24' }
55 'Microsoft Windows' : [
56 { desc
: '10/2016/2019' , val
: 'win10' },
57 { desc
: '8.x/2012/2012r2' , val
: 'win8' },
58 { desc
: '7/2008r2' , val
: 'win7' },
59 { desc
: 'Vista/2008' , val
: 'w2k8' },
60 { desc
: 'XP/2003' , val
: 'wxp' },
61 { desc
: '2000' , val
: 'w2k' }
64 { desc
: '-' , val
: 'solaris' }
67 { desc
: '-' , val
: 'other' }
71 get_health_icon : function ( state
, circle
) {
72 if ( circle
=== undefined ) {
76 if ( state
=== undefined ) {
80 var icon
= 'faded fa-question' ;
83 icon
= 'good fa-check' ;
86 icon
= 'warning fa-upload' ;
89 icon
= 'warning fa-refresh' ;
92 icon
= 'warning fa-exclamation' ;
95 icon
= 'critical fa-times' ;
107 parse_ceph_version : function ( service
) {
108 if ( service
. ceph_version_short
) {
109 return service
. ceph_version_short
;
112 if ( service
. ceph_version
) {
113 var match
= service
. ceph_version
. match ( /version (\d+(\.\d+)*)/ );
122 compare_ceph_versions : function ( a
, b
) {
130 if ( Ext
. isArray ( a
)) {
131 avers
= a
. slice (); // copy array
133 avers
= a
. toString (). split ( '.' );
136 if ( Ext
. isArray ( b
)) {
137 bvers
= b
. slice (); // copy array
139 bvers
= b
. toString (). split ( '.' );
143 let av
= avers
. shift ();
144 let bv
= bvers
. shift ();
146 if ( av
=== undefined && bv
=== undefined ) {
148 } else if ( av
=== undefined ) {
150 } else if ( bv
=== undefined ) {
153 let diff
= parseInt ( av
, 10 ) - parseInt ( bv
, 10 );
154 if ( diff
!= 0 ) return diff
;
155 // else we need to look at the next parts
161 get_ceph_icon_html : function ( health
, fw
) {
162 var state
= PVE
. Utils
. map_ceph_health
[ health
];
163 var cls
= PVE
. Utils
. get_health_icon ( state
);
167 return "<i class='fa " + cls
+ "'></i> " ;
172 'HEALTH_UPGRADE' : 'upgrade' ,
174 'HEALTH_WARN' : 'warning' ,
175 'HEALTH_ERR' : 'critical'
178 render_ceph_health : function ( healthObj
) {
180 iconCls
: PVE
. Utils
. get_health_icon (),
184 if (! healthObj
|| ! healthObj
. status
) {
188 var health
= PVE
. Utils
. map_ceph_health
[ healthObj
. status
];
190 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
191 state
. text
= healthObj
. status
;
196 render_zfs_health : function ( value
) {
197 if ( typeof value
== 'undefined' ){
200 var iconCls
= 'question-circle' ;
204 iconCls
= 'check-circle good' ;
208 iconCls
= 'exclamation-circle warning' ;
213 iconCls
= 'times-circle critical' ;
218 return '<i class="fa fa-' + iconCls
+ '"></i> ' + value
;
222 render_backup_status : function ( value
, meta
, record
) {
223 if ( typeof value
== 'undefined' ) {
227 let iconCls
= 'check-circle good' ;
228 let text
= gettext ( 'Yes' );
230 if (! PVE
. Parser
. parseBoolean ( value
. toString ())) {
231 iconCls
= 'times-circle critical' ;
233 text
= gettext ( 'No' );
235 let reason
= record
. get ( 'reason' );
236 if ( typeof reason
!== 'undefined' ) {
237 if ( reason
in PVE
. Utils
. backup_reasons_table
) {
238 reason
= PVE
. Utils
. backup_reasons_table
[ record
. get ( 'reason' )];
240 text
= ` ${text} - ${reason} ` ;
244 return `<i class="fa fa- ${iconCls} "></i> ${text} ` ;
247 render_backup_days_of_week : function ( val
) {
248 var dows
= [ 'sun' , 'mon' , 'tue' , 'wed' , 'thu' , 'fri' , 'sat' ];
251 val
. split ( ',' ). forEach ( function ( day
){
253 var dow
= ( dows
. indexOf ( day
)+ 6 )% 7 ;
255 if ( selected
. length
=== 0 || selected
[ selected
. length
- 1 ] === 0 ) {
258 selected
[ selected
. length
- 1 ]++;
271 selected
. forEach ( function ( item
) {
274 days
. push ( Ext
. Date
. dayNames
[( cur
+ 1 )] + '-' + Ext
. Date
. dayNames
[( cur
+ item
)% 7 ]);
276 } else if ( item
== 2 ) {
277 days
. push ( Ext
. Date
. dayNames
[ cur
+ 1 ]);
278 days
. push ( Ext
. Date
. dayNames
[( cur
+ 2 )% 7 ]);
280 } else if ( item
== 1 ) {
281 days
. push ( Ext
. Date
. dayNames
[( cur
+ 1 )% 7 ]);
284 return days
. join ( ', ' );
287 render_backup_selection : function ( value
, metaData
, record
) {
288 let allExceptText
= gettext ( 'All except {0}' );
289 let allText
= '-- ' + gettext ( 'All' ) + ' --' ;
290 if ( record
. data
. all
) {
291 if ( record
. data
. exclude
) {
292 return Ext
. String
. format ( allExceptText
, record
. data
. exclude
);
296 if ( record
. data
. vmid
) {
297 return record
. data
. vmid
;
300 if ( record
. data
. pool
) {
301 return "Pool '" + record
. data
. pool
+ "'" ;
307 backup_reasons_table
: {
308 'backup=yes' : gettext ( 'Enabled' ),
309 'backup=no' : gettext ( 'Disabled' ),
310 'enabled' : gettext ( 'Enabled' ),
311 'disabled' : gettext ( 'Disabled' ),
312 'not a volume' : gettext ( 'Not a volume' ),
313 'efidisk but no OMVF BIOS' : gettext ( 'EFI Disk without OMVF BIOS' ),
316 get_kvm_osinfo : function ( value
) {
317 var info
= { base
: 'Other' }; // default
319 Ext
. each ( Object
. keys ( PVE
. Utils
. kvm_ostypes
), function ( k
) {
320 Ext
. each ( PVE
. Utils
. kvm_ostypes
[ k
], function ( e
) {
321 if ( e
. val
=== value
) {
322 info
= { desc
: e
. desc
, base
: k
};
330 render_kvm_ostype : function ( value
) {
331 var osinfo
= PVE
. Utils
. get_kvm_osinfo ( value
);
332 if ( osinfo
. desc
&& osinfo
. desc
!== '-' ) {
333 return osinfo
. base
+ ' ' + osinfo
. desc
;
339 render_hotplug_features : function ( value
) {
342 if (! value
|| ( value
=== '0' )) {
343 return gettext ( 'Disabled' );
347 value
= 'disk,network,usb' ;
350 Ext
. each ( value
. split ( ',' ), function ( el
) {
352 fa
. push ( gettext ( 'Disk' ));
353 } else if ( el
=== 'network' ) {
354 fa
. push ( gettext ( 'Network' ));
355 } else if ( el
=== 'usb' ) {
357 } else if ( el
=== 'memory' ) {
358 fa
. push ( gettext ( 'Memory' ));
359 } else if ( el
=== 'cpu' ) {
360 fa
. push ( gettext ( 'CPU' ));
366 return fa
. join ( ', ' );
369 render_localtime : function ( value
) {
370 if ( value
=== '__default__' ) {
371 return Proxmox
. Utils
. defaultText
+ ' (' + gettext ( 'Enabled for Windows' ) + ')' ;
373 return Proxmox
. Utils
. format_boolean ( value
);
376 render_qga_features : function ( value
) {
378 return Proxmox
. Utils
. defaultText
+ ' (' + Proxmox
. Utils
. disabledText
+ ')' ;
380 var props
= PVE
. Parser
. parsePropertyString ( value
, 'enabled' );
381 if (! PVE
. Parser
. parseBoolean ( props
. enabled
)) {
382 return Proxmox
. Utils
. disabledText
;
385 delete props
. enabled
;
386 var agentstring
= Proxmox
. Utils
. enabledText
;
388 Ext
. Object
. each ( props
, function ( key
, value
) {
390 agentstring
+= ', ' + key
+ ': ' ;
392 if ( key
=== 'type' ) {
397 agentstring
+= map
[ value
] || Proxmox
. Utils
. unknownText
;
399 if ( PVE
. Parser
. parseBoolean ( value
)) {
400 agentstring
+= Proxmox
. Utils
. enabledText
;
402 agentstring
+= Proxmox
. Utils
. disabledText
;
410 render_qemu_machine : function ( value
) {
411 return value
|| ( Proxmox
. Utils
. defaultText
+ ' (i440fx)' );
414 render_qemu_bios : function ( value
) {
416 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
417 } else if ( value
=== 'seabios' ) {
419 } else if ( value
=== 'ovmf' ) {
420 return "OVMF (UEFI)" ;
426 render_dc_ha_opts : function ( value
) {
428 return Proxmox
. Utils
. defaultText
;
430 return PVE
. Parser
. printPropertyString ( value
);
433 render_as_property_string : function ( value
) {
434 return (! value
) ? Proxmox
. Utils
. defaultText
435 : PVE
. Parser
. printPropertyString ( value
);
438 render_scsihw : function ( value
) {
440 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
441 } else if ( value
=== 'lsi' ) {
442 return 'LSI 53C895A' ;
443 } else if ( value
=== 'lsi53c810' ) {
445 } else if ( value
=== 'megasas' ) {
446 return 'MegaRAID SAS 8708EM2' ;
447 } else if ( value
=== 'virtio-scsi-pci' ) {
448 return 'VirtIO SCSI' ;
449 } else if ( value
=== 'virtio-scsi-single' ) {
450 return 'VirtIO SCSI single' ;
451 } else if ( value
=== 'pvscsi' ) {
452 return 'VMware PVSCSI' ;
458 render_spice_enhancements : function ( values
) {
459 let props
= PVE
. Parser
. parsePropertyString ( values
);
460 if ( Ext
. Object
. isEmpty ( props
)) {
461 return Proxmox
. Utils
. noneText
;
465 if ( PVE
. Parser
. parseBoolean ( props
. foldersharing
)) {
466 output
. push ( 'Folder Sharing: ' + gettext ( 'Enabled' ));
468 if ( props
. videostreaming
=== 'all' || props
. videostreaming
=== 'filter' ) {
469 output
. push ( 'Video Streaming: ' + props
. videostreaming
);
471 return output
. join ( ', ' );
474 // fixme: auto-generate this
475 // for now, please keep in sync with PVE::Tools::kvmkeymaps
480 'de-ch' : 'German (Swiss)' ,
481 'en-gb' : 'English (UK)' ,
482 'en-us' : 'English (USA)' ,
486 //fo: 'Faroe Islands',
488 'fr-be' : 'French (Belgium)' ,
489 'fr-ca' : 'French (Canada)' ,
490 'fr-ch' : 'French (Swiss)' ,
500 //'nl-be': 'Dutch (Belgium)',
504 'pt-br' : 'Portuguese (Brazil)' ,
513 std
: gettext ( 'Standard VGA' ),
514 vmware
: gettext ( 'VMware compatible' ),
516 qxl2
: 'SPICE dual monitor' ,
517 qxl3
: 'SPICE three monitors' ,
518 qxl4
: 'SPICE four monitors' ,
519 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
520 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
521 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
522 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
523 virtio
: 'VirtIO-GPU' ,
524 none
: Proxmox
. Utils
. noneText
527 render_kvm_language : function ( value
) {
528 if (! value
|| value
=== '__default__' ) {
529 return Proxmox
. Utils
. defaultText
;
531 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
533 return text
+ ' (' + value
+ ')' ;
538 kvm_keymap_array : function () {
539 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
540 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
541 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
548 '__default__' : Proxmox
. Utils
. defaultText
+ ' (xterm.js)' ,
549 'vv' : 'SPICE (remote-viewer)' ,
550 'html5' : 'HTML5 (noVNC)' ,
551 'xtermjs' : 'xterm.js'
554 render_console_viewer : function ( value
) {
555 value
= value
|| '__default__' ;
556 if ( PVE
. Utils
. console_map
[ value
]) {
557 return PVE
. Utils
. console_map
[ value
];
562 console_viewer_array : function () {
563 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
564 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
568 render_kvm_vga_driver : function ( value
) {
570 return Proxmox
. Utils
. defaultText
;
572 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
573 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
575 text
= Proxmox
. Utils
. defaultText
;
578 return text
+ ' (' + value
+ ')' ;
583 kvm_vga_driver_array : function () {
584 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
585 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
586 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
592 render_kvm_startup : function ( value
) {
593 var startup
= PVE
. Parser
. parseStartup ( value
);
596 if ( startup
. order
=== undefined ) {
599 res
+= startup
. order
;
601 if ( startup
. up
!== undefined ) {
602 res
+= ',up=' + startup
. up
;
604 if ( startup
. down
!== undefined ) {
605 res
+= ',down=' + startup
. down
;
611 extractFormActionError : function ( action
) {
613 switch ( action
. failureType
) {
614 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
615 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
617 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
618 msg
= gettext ( 'Connection error' );
619 var resp
= action
. response
;
620 if ( resp
. status
&& resp
. statusText
) {
621 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
624 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
625 case Ext
. form
. action
. Action
. SERVER_INVALID
:
626 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
633 'images' : gettext ( 'Disk image' ),
634 'backup' : gettext ( 'VZDump backup file' ),
635 'vztmpl' : gettext ( 'Container template' ),
636 'iso' : gettext ( 'ISO image' ),
637 'rootdir' : gettext ( 'Container' ),
638 'snippets' : gettext ( 'Snippets' )
641 volume_is_qemu_backup : function ( volid
, format
) {
642 return format
=== 'pbs-vm' || volid
. match ( ':backup/vzdump-qemu-' );
645 volume_is_lxc_backup : function ( volid
, format
) {
646 return format
=== 'pbs-ct' || volid
. match ( ':backup/vzdump-(lxc|openvz)-' );
651 name
: gettext ( 'Active Directory Server' ),
652 ipanel
: 'pveAuthADPanel' ,
653 syncipanel
: 'pveAuthLDAPSyncPanel' ,
657 name
: gettext ( 'LDAP Server' ),
658 ipanel
: 'pveAuthLDAPPanel' ,
659 syncipanel
: 'pveAuthLDAPSyncPanel' ,
664 ipanel
: 'pveAuthBasePanel' ,
668 name
: 'Proxmox VE authentication server' ,
669 ipanel
: 'pveAuthBasePanel' ,
676 name
: Proxmox
. Utils
. directoryText
,
677 ipanel
: 'DirInputPanel' ,
682 ipanel
: 'LVMInputPanel' ,
687 ipanel
: 'LvmThinInputPanel' ,
692 ipanel
: 'NFSInputPanel' ,
697 ipanel
: 'CIFSInputPanel' ,
702 ipanel
: 'GlusterFsInputPanel' ,
707 ipanel
: 'IScsiInputPanel' ,
712 ipanel
: 'CephFSInputPanel' ,
716 name
: 'CephFS (PVE)' ,
717 ipanel
: 'CephFSInputPanel' ,
723 ipanel
: 'RBDInputPanel' ,
728 ipanel
: 'RBDInputPanel' ,
733 name
: 'ZFS over iSCSI' ,
734 ipanel
: 'ZFSInputPanel' ,
739 ipanel
: 'ZFSPoolInputPanel' ,
743 name
: 'Proxmox Backup Server' ,
744 ipanel
: 'PBSInputPanel' ,
767 ipanel
: 'SimpleInputPanel' ,
772 ipanel
: 'VlanInputPanel' ,
777 ipanel
: 'QinQInputPanel' ,
782 ipanel
: 'VxlanInputPanel' ,
787 ipanel
: 'EvpnInputPanel' ,
792 sdncontrollerSchema
: {
799 ipanel
: 'EvpnInputPanel' ,
804 format_sdnvnet_type : function ( value
, md
, record
) {
805 var schema
= PVE
. Utils
. sdnvnetSchema
[ value
];
809 return Proxmox
. Utils
. unknownText
;
812 format_sdnzone_type : function ( value
, md
, record
) {
813 var schema
= PVE
. Utils
. sdnzoneSchema
[ value
];
817 return Proxmox
. Utils
. unknownText
;
820 format_sdncontroller_type : function ( value
, md
, record
) {
821 var schema
= PVE
. Utils
. sdncontrollerSchema
[ value
];
825 return Proxmox
. Utils
. unknownText
;
828 format_storage_type : function ( value
, md
, record
) {
829 if ( value
=== 'rbd' ) {
830 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
831 } else if ( value
=== 'cephfs' ) {
832 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
835 var schema
= PVE
. Utils
. storageSchema
[ value
];
839 return Proxmox
. Utils
. unknownText
;
842 format_ha : function ( value
) {
843 var text
= Proxmox
. Utils
. noneText
;
846 text
= value
. state
|| Proxmox
. Utils
. noneText
;
848 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
849 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
855 format_content_types : function ( value
) {
856 return value
. split ( ',' ). sort (). map ( function ( ct
) {
857 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
861 render_storage_content : function ( value
, metaData
, record
) {
862 var data
= record
. data
;
863 if ( Ext
. isNumber ( data
. channel
) &&
864 Ext
. isNumber ( data
. id
) &&
865 Ext
. isNumber ( data
. lun
)) {
867 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
868 " ID " + data
. id
+ " LUN " + data
. lun
;
870 return data
. volid
. replace ( /^.*?:(.*?\/)?/ , '' );
873 render_serverity : function ( value
) {
874 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
877 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
879 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
883 var maxcpu
= record
. data
. maxcpu
|| 1 ;
885 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
889 var per
= value
* 100 ;
891 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
894 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
896 if (! Ext
. isNumeric ( value
)) {
900 return Proxmox
. Utils
. format_size ( value
);
903 render_bandwidth : function ( value
) {
904 if (! Ext
. isNumeric ( value
)) {
908 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
911 render_timestamp_human_readable : function ( value
) {
912 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
915 calculate_mem_usage : function ( data
) {
916 if (! Ext
. isNumeric ( data
. mem
) ||
922 return ( data
. mem
/ data
. maxmem
);
925 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
926 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
930 // we got no percentage but bytes
932 var maxmem
= record
. data
. maxmem
;
933 if (! record
. data
. uptime
||
935 ! Ext
. isNumeric ( mem
)) {
939 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
941 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
944 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
947 var maxmem
= record
. data
. maxmem
;
949 if (! record
. data
. uptime
) {
953 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
957 return PVE
. Utils
. render_size ( value
);
960 calculate_disk_usage : function ( data
) {
962 if (! Ext
. isNumeric ( data
. disk
) ||
963 data
. type
=== 'qemu' ||
964 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
965 data
. maxdisk
=== 0 ) {
969 return ( data
. disk
/ data
. maxdisk
);
972 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
973 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
977 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
980 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
983 var maxdisk
= record
. data
. maxdisk
;
984 var type
= record
. data
. type
;
986 if (! Ext
. isNumeric ( disk
) ||
989 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
993 return PVE
. Utils
. render_size ( value
);
996 get_object_icon_class : function ( type
, record
) {
1000 if ( type
=== 'type' ) {
1002 objType
= record
. groupbyid
;
1003 } else if ( record
. template
) {
1005 objType
= 'template' ;
1009 status
= record
. status
+ ' ha-' + record
. hastate
;
1013 status
+= ' locked lock-' + record
. lock
;
1016 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
1017 if ( defaults
&& defaults
. iconCls
) {
1018 var retVal
= defaults
. iconCls
+ ' ' + status
;
1025 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1027 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
1029 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
1033 render_support_level : function ( value
, metaData
, record
) {
1034 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
1037 render_upid : function ( value
, metaData
, record
) {
1038 var type
= record
. data
. type
;
1039 var id
= record
. data
. id
;
1041 return Proxmox
. Utils
. format_task_description ( type
, id
);
1044 /* render functions for new status panel */
1046 render_usage : function ( val
) {
1047 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
1050 render_cpu_usage : function ( val
, max
) {
1051 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
1052 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
1055 render_size_usage : function ( val
, max
) {
1057 return gettext ( 'N/A' );
1059 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
1060 Ext
. String
. format ( gettext ( '{0} of {1}' ),
1061 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
1064 /* this is different for nodes */
1065 render_node_cpu_usage : function ( value
, record
) {
1066 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
1069 /* this is different for nodes */
1070 render_node_size_usage : function ( record
) {
1071 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
1074 render_optional_url : function ( value
) {
1076 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
1077 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
1082 render_san : function ( value
) {
1084 if ( Ext
. isArray ( value
)) {
1085 value
. forEach ( function ( val
) {
1086 if (! Ext
. isNumber ( val
)) {
1090 return names
. join ( '<br>' );
1095 render_full_name : function ( firstname
, metaData
, record
) {
1096 var first
= firstname
|| '' ;
1097 var last
= record
. data
. lastname
|| '' ;
1098 return Ext
. htmlEncode ( first
+ " " + last
);
1101 render_u2f_error : function ( error
) {
1103 '1' : gettext ( 'Other Error' ),
1104 '2' : gettext ( 'Bad Request' ),
1105 '3' : gettext ( 'Configuration Unsupported' ),
1106 '4' : gettext ( 'Device Ineligible' ),
1107 '5' : gettext ( 'Timeout' )
1109 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
1112 windowHostname : function () {
1113 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
1114 function ( m
, addr
, offset
, original
) { return addr
; });
1117 openDefaultConsoleWindow : function ( consoles
, consoleType
, vmid
, nodename
, vmname
, cmd
) {
1118 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
1119 PVE
. Utils
. openConsoleWindow ( dv
, consoleType
, vmid
, nodename
, vmname
, cmd
);
1122 openConsoleWindow : function ( viewer
, consoleType
, vmid
, nodename
, vmname
, cmd
) {
1123 if ( vmid
== undefined && ( consoleType
=== 'kvm' || consoleType
=== 'lxc' )) {
1124 throw "missing vmid" ;
1127 throw "no nodename specified" ;
1130 if ( viewer
=== 'html5' ) {
1131 PVE
. Utils
. openVNCViewer ( consoleType
, vmid
, nodename
, vmname
, cmd
);
1132 } else if ( viewer
=== 'xtermjs' ) {
1133 Proxmox
. Utils
. openXtermJsViewer ( consoleType
, vmid
, nodename
, vmname
, cmd
);
1134 } else if ( viewer
=== 'vv' ) {
1135 let url
= '/nodes/' + nodename
+ '/spiceshell' ;
1137 proxy
: PVE
. Utils
. windowHostname (),
1139 if ( consoleType
=== 'kvm' ) {
1140 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1141 } else if ( consoleType
=== 'lxc' ) {
1142 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1143 } else if ( consoleType
=== 'upgrade' ) {
1144 params
. cmd
= 'upgrade' ;
1145 } else if ( consoleType
=== 'cmd' ) {
1147 } else if ( consoleType
!== 'shell' ) {
1148 throw `unknown spice viewer type ' ${consoleType} '` ;
1150 PVE
. Utils
. openSpiceViewer ( url
, params
);
1152 throw `unknown viewer type ' ${viewer} '` ;
1156 defaultViewer : function ( consoles
) {
1158 var allowSpice
, allowXtermjs
;
1160 if ( consoles
=== true ) {
1162 allowXtermjs
= true ;
1163 } else if ( typeof consoles
=== 'object' ) {
1164 allowSpice
= consoles
. spice
;
1165 allowXtermjs
= !! consoles
. xtermjs
;
1167 var dv
= PVE
. VersionInfo
. console
|| 'xtermjs' ;
1168 if ( dv
=== 'vv' && ! allowSpice
) {
1169 dv
= ( allowXtermjs
) ? 'xtermjs' : 'html5' ;
1170 } else if ( dv
=== 'xtermjs' && ! allowXtermjs
) {
1171 dv
= ( allowSpice
) ? 'vv' : 'html5' ;
1177 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
1178 let scaling
= 'off' ;
1179 if ( Proxmox
. Utils
. toolkit
!== 'touch' ) {
1180 var sp
= Ext
. state
. Manager
. getProvider ();
1181 scaling
= sp
. get ( 'novnc-scaling' , 'off' );
1183 var url
= Ext
. Object
. toQueryString ({
1184 console
: vmtype
, // kvm, lxc, upgrade or shell
1192 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1198 openSpiceViewer : function ( url
, params
){
1200 var downloadWithName = function ( uri
, name
) {
1201 var link
= Ext
. DomHelper
. append ( document
. body
, {
1204 css
: 'display:none;visibility:hidden;height:0px;'
1207 // Note: we need to tell android the correct file name extension
1208 // but we do not set 'download' tag for other environments, because
1209 // It can have strange side effects (additional user prompt on firefox)
1210 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1212 link
. download
= name
;
1215 if ( link
. fireEvent
) {
1216 link
. fireEvent ( 'onclick' );
1218 let evt
= document
. createEvent ( "MouseEvents" );
1219 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1220 link
. dispatchEvent ( evt
);
1224 Proxmox
. Utils
. API2Request ({
1228 failure : function ( response
, opts
){
1229 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1231 success : function ( response
, opts
){
1232 var raw
= "[virt-viewer] \n " ;
1233 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1234 raw
+= k
+ "=" + v
+ " \n " ;
1236 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1237 encodeURIComponent ( raw
);
1239 downloadWithName ( url
, "pve-spice.vv" );
1244 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1246 var nodename
= record
. data
. node
;
1247 var vmid
= record
. data
. vmid
;
1248 var vmname
= record
. data
. name
;
1249 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1250 Proxmox
. Utils
. API2Request ({
1251 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1252 failure : function ( response
, opts
) {
1253 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1255 success : function ( response
, opts
) {
1256 let conf
= response
. result
. data
;
1258 spice
: !! conf
. spice
,
1259 xtermjs
: !! conf
. serial
,
1261 PVE
. Utils
. openDefaultConsoleWindow ( consoles
, 'kvm' , vmid
, nodename
, vmname
);
1264 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1265 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1269 // test automation helper
1270 call_menu_handler : function ( menu
, text
) {
1272 var list
= menu
. query ( 'menuitem' );
1274 Ext
. Array
. each ( list
, function ( item
) {
1275 if ( item
. text
=== text
) {
1286 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1288 if (!( v
instanceof Ext
. tree
. View
)) {
1292 var template
= !! record
. data
. template
;
1293 var type
= record
. data
. type
;
1296 if ( type
=== 'qemu' || type
== 'lxc' ) {
1297 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1301 } else if ( type
=== 'qemu' ||
1304 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1306 nodename
: record
. data
. node
1312 menu
. showAt ( event
. getXY ());
1316 // helper for deleting field which are set to there default values
1317 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1318 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1320 if ( values
[ 'delete' ]) {
1321 if ( Ext
. isArray ( values
[ 'delete' ])) {
1322 values
[ 'delete' ]. push ( fieldname
);
1324 values
[ 'delete' ] += ',' + fieldname
;
1327 values
[ 'delete' ] = fieldname
;
1331 delete values
[ fieldname
];
1335 loadSSHKeyFromFile : function ( file
, callback
) {
1336 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1337 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1338 // assume: 740*8 for max. 32kbit (5920 byte file)
1339 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1340 if ( file
. size
> 8192 ) {
1341 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1347 var reader
= new FileReader ();
1348 reader
. onload = function ( evt
) {
1349 callback ( evt
. target
. result
);
1351 reader
. readAsText ( file
);
1354 diskControllerMaxIDs
: {
1361 // types is either undefined (all busses), an array of busses, or a single bus
1362 forEachBus : function ( types
, func
) {
1363 var busses
= Object
. keys ( PVE
. Utils
. diskControllerMaxIDs
);
1364 var i
, j
, count
, cont
;
1366 if ( Ext
. isArray ( types
)) {
1368 } else if ( Ext
. isDefined ( types
)) {
1372 // check if we only have valid busses
1373 for ( i
= 0 ; i
< busses
. length
; i
++) {
1374 if (! PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]]) {
1375 throw "invalid bus: '" + busses
[ i
] + "'" ;
1379 for ( i
= 0 ; i
< busses
. length
; i
++) {
1380 count
= PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]];
1381 for ( j
= 0 ; j
< count
; j
++) {
1382 cont
= func ( busses
[ i
], j
);
1383 if (! cont
&& cont
!== undefined ) {
1390 mp_counts
: { mps
: 256 , unused
: 256 },
1392 forEachMP : function ( func
, includeUnused
) {
1394 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1395 cont
= func ( 'mp' , i
);
1396 if (! cont
&& cont
!== undefined ) {
1401 if (! includeUnused
) {
1405 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1406 cont
= func ( 'unused' , i
);
1407 if (! cont
&& cont
!== undefined ) {
1413 hardware_counts
: { net
: 32 , usb
: 5 , hostpci
: 16 , audio
: 1 , efidisk
: 1 , serial
: 4 , rng
: 1 },
1415 cleanEmptyObjectKeys : function ( obj
) {
1417 for ( propName
in obj
) {
1418 if ( obj
. hasOwnProperty ( propName
)) {
1419 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1420 delete obj
[ propName
];
1426 acmedomain_count
: 5 ,
1428 add_domain_to_acme : function ( acme
, domain
) {
1429 if ( acme
. domains
=== undefined ) {
1430 acme
. domains
= [ domain
];
1432 acme
. domains
. push ( domain
);
1433 acme
. domains
= acme
. domains
. filter (( value
, index
, self
) => {
1434 return self
. indexOf ( value
) === index
;
1440 remove_domain_from_acme : function ( acme
, domain
) {
1441 if ( acme
. domains
!== undefined ) {
1442 acme
. domains
= acme
. domains
. filter (( value
, index
, self
) => {
1443 return self
. indexOf ( value
) === index
&& value
!== domain
;
1449 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1451 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1454 Proxmox
. Utils
. setErrorMask ( me
, false );
1459 if ( operation
. error
. statusText
) {
1460 if ( operation
. error
. statusText
. match ( regex
)) {
1461 callback ( me
, operation
. error
);
1464 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1467 msg
= gettext ( 'Connection error' );
1469 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1473 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1474 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1475 if ( msg
. match ( regex
)) {
1476 if ( Proxmox
. UserName
=== 'root@pam' ) {
1477 container
. el
. mask ();
1478 if (! container
. down ( 'pveCephInstallWindow' )){
1479 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1480 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1483 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1489 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1490 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1498 propertyStringSet : function ( target
, source
, name
, value
) {
1500 if ( value
=== undefined ) {
1501 target
[ name
] = source
;
1503 target
[ name
] = value
;
1506 delete target
[ name
];
1510 updateColumns : function ( container
) {
1511 let mode
= Ext
. state
. Manager
. get ( 'summarycolumns' ) || 'auto' ;
1513 if ( mode
!== 'auto' ) {
1514 factor
= parseInt ( mode
, 10 );
1515 if ( Number
. isNaN ( factor
)) {
1519 factor
= container
. getSize (). width
< 1400 ? 1 : 2 ;
1522 if ( container
. oldFactor
=== factor
) {
1526 let items
= container
. query ( '>' ); // direct childs
1527 factor
= Math
. min ( factor
, items
. length
);
1528 container
. oldFactor
= factor
;
1530 items
. forEach (( item
) => {
1531 item
. columnWidth
= 1 / factor
;
1534 // we have to update the layout twice, since the first layout change
1535 // can trigger the scrollbar which reduces the amount of space left
1536 container
. updateLayout ();
1537 container
. updateLayout ();
1540 forEachCorosyncLink : function ( nodeinfo
, cb
) {
1541 let re
= /(?:ring|link)(\d+)_addr/ ;
1542 Ext
. iterate ( nodeinfo
, ( prop
, val
) => {
1543 let match
= re
. exec ( prop
);
1545 cb ( Number ( match
[ 1 ]), val
);
1552 'AuthenticAMD' : 'AMD' ,
1553 'GenuineIntel' : 'Intel'
1561 "_default_" : 5 , // includes custom models
1566 constructor : function () {
1568 Ext
. apply ( me
, me
. utilities
);
1570 Proxmox
. Utils
. override_task_descriptions ({
1571 acmedeactivate
: [ 'ACME Account' , gettext ( 'Deactivate' )],
1572 acmenewcert
: [ 'SRV' , gettext ( 'Order Certificate' )],
1573 acmerefresh
: [ 'ACME Account' , gettext ( 'Refresh' )],
1574 acmeregister
: [ 'ACME Account' , gettext ( 'Register' )],
1575 acmerenew
: [ 'SRV' , gettext ( 'Renew Certificate' )],
1576 acmerevoke
: [ 'SRV' , gettext ( 'Revoke Certificate' )],
1577 acmeupdate
: [ 'ACME Account' , gettext ( 'Update' )],
1578 'auth-realm-sync' : [ gettext ( 'Realm' ), gettext ( 'Sync' )],
1579 'auth-realm-sync-test' : [ gettext ( 'Realm' ), gettext ( 'Sync Preview' )],
1580 cephcreatemds
: [ 'Ceph Metadata Server' , gettext ( 'Create' )],
1581 cephcreatemgr
: [ 'Ceph Manager' , gettext ( 'Create' )],
1582 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' )],
1583 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' )],
1584 cephcreatepool
: [ 'Ceph Pool' , gettext ( 'Create' )],
1585 cephdestroymds
: [ 'Ceph Metadata Server' , gettext ( 'Destroy' )],
1586 cephdestroymgr
: [ 'Ceph Manager' , gettext ( 'Destroy' )],
1587 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' )],
1588 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' )],
1589 cephdestroypool
: [ 'Ceph Pool' , gettext ( 'Destroy' )],
1590 cephfscreate
: [ 'CephFS' , gettext ( 'Create' )],
1591 clustercreate
: [ '' , gettext ( 'Create Cluster' )],
1592 clusterjoin
: [ '' , gettext ( 'Join Cluster' )],
1593 dircreate
: [ gettext ( 'Directory Storage' ), gettext ( 'Create' )],
1594 dirremove
: [ gettext ( 'Directory' ), gettext ( 'Remove' )],
1595 download
: [ '' , gettext ( 'Download' )],
1596 hamigrate
: [ 'HA' , gettext ( 'Migrate' )],
1597 hashutdown
: [ 'HA' , gettext ( 'Shutdown' )],
1598 hastart
: [ 'HA' , gettext ( 'Start' )],
1599 hastop
: [ 'HA' , gettext ( 'Stop' )],
1600 imgcopy
: [ '' , gettext ( 'Copy data' )],
1601 imgdel
: [ '' , gettext ( 'Erase data' )],
1602 lvmcreate
: [ gettext ( 'LVM Storage' ), gettext ( 'Create' )],
1603 lvmthincreate
: [ gettext ( 'LVM-Thin Storage' ), gettext ( 'Create' )],
1604 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' )],
1605 'move_volume' : [ 'CT' , gettext ( 'Move Volume' )],
1606 pull_file
: [ 'CT' , gettext ( 'Pull file' )],
1607 push_file
: [ 'CT' , gettext ( 'Push file' )],
1608 qmclone
: [ 'VM' , gettext ( 'Clone' )],
1609 qmconfig
: [ 'VM' , gettext ( 'Configure' )],
1610 qmcreate
: [ 'VM' , gettext ( 'Create' )],
1611 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' )],
1612 qmdestroy
: [ 'VM' , gettext ( 'Destroy' )],
1613 qmigrate
: [ 'VM' , gettext ( 'Migrate' )],
1614 qmmove
: [ 'VM' , gettext ( 'Move disk' )],
1615 qmpause
: [ 'VM' , gettext ( 'Pause' )],
1616 qmreboot
: [ 'VM' , gettext ( 'Reboot' )],
1617 qmreset
: [ 'VM' , gettext ( 'Reset' )],
1618 qmrestore
: [ 'VM' , gettext ( 'Restore' )],
1619 qmresume
: [ 'VM' , gettext ( 'Resume' )],
1620 qmrollback
: [ 'VM' , gettext ( 'Rollback' )],
1621 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' )],
1622 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' )],
1623 qmstart
: [ 'VM' , gettext ( 'Start' )],
1624 qmstop
: [ 'VM' , gettext ( 'Stop' )],
1625 qmsuspend
: [ 'VM' , gettext ( 'Hibernate' )],
1626 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' )],
1627 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
1628 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
1629 startall
: [ '' , gettext ( 'Start all VMs and Containers' )],
1630 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' )],
1631 unknownimgdel
: [ '' , gettext ( 'Destroy image from unknown guest' )],
1632 vncproxy
: [ 'VM/CT' , gettext ( 'Console' )],
1633 vncshell
: [ '' , gettext ( 'Shell' )],
1634 vzclone
: [ 'CT' , gettext ( 'Clone' )],
1635 vzcreate
: [ 'CT' , gettext ( 'Create' )],
1636 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' )],
1637 vzdestroy
: [ 'CT' , gettext ( 'Destroy' )],
1638 vzdump
: ( type
, id
) => id
? `VM/CT ${id} - ${gettext('Backup')} ` : gettext ( 'Backup Job' ),
1639 vzmigrate
: [ 'CT' , gettext ( 'Migrate' )],
1640 vzmount
: [ 'CT' , gettext ( 'Mount' )],
1641 vzreboot
: [ 'CT' , gettext ( 'Reboot' )],
1642 vzrestore
: [ 'CT' , gettext ( 'Restore' )],
1643 vzresume
: [ 'CT' , gettext ( 'Resume' )],
1644 vzrollback
: [ 'CT' , gettext ( 'Rollback' )],
1645 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' )],
1646 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' )],
1647 vzstart
: [ 'CT' , gettext ( 'Start' )],
1648 vzstop
: [ 'CT' , gettext ( 'Stop' )],
1649 vzsuspend
: [ 'CT' , gettext ( 'Suspend' )],
1650 vztemplate
: [ 'CT' , gettext ( 'Convert to template' )],
1651 vzumount
: [ 'CT' , gettext ( 'Unmount' )],
1652 zfscreate
: [ gettext ( 'ZFS Storage' ), gettext ( 'Create' )],