]>
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 /*jslint confusion: true */
23 Ext
. define ( 'PVE.Utils' , { utilities
: {
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 <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.' ,
53 { desc
: '5.x - 2.6 Kernel' , val
: 'l26' },
54 { desc
: '2.4 Kernel' , val
: 'l24' }
56 'Microsoft Windows' : [
57 { desc
: '10/2016/2019' , val
: 'win10' },
58 { desc
: '8.x/2012/2012r2' , val
: 'win8' },
59 { desc
: '7/2008r2' , val
: 'win7' },
60 { desc
: 'Vista/2008' , val
: 'w2k8' },
61 { desc
: 'XP/2003' , val
: 'wxp' },
62 { desc
: '2000' , val
: 'w2k' }
65 { desc
: '-' , val
: 'solaris' }
68 { desc
: '-' , val
: 'other' }
72 get_health_icon : function ( state
, circle
) {
73 if ( circle
=== undefined ) {
77 if ( state
=== undefined ) {
81 var icon
= 'faded fa-question' ;
84 icon
= 'good fa-check' ;
87 icon
= 'warning fa-upload' ;
90 icon
= 'warning fa-refresh' ;
93 icon
= 'warning fa-exclamation' ;
96 icon
= 'critical fa-times' ;
108 parse_ceph_version : function ( service
) {
109 if ( service
. ceph_version_short
) {
110 return service
. ceph_version_short
;
113 if ( service
. ceph_version
) {
114 var match
= service
. ceph_version
. match ( /version (\d+(\.\d+)*)/ );
123 compare_ceph_versions : function ( a
, b
) {
127 let avers
= a
. toString (). split ( '.' );
128 let bvers
= b
. toString (). split ( '.' );
131 let av
= avers
. shift ();
132 let bv
= bvers
. shift ();
134 if ( av
=== undefined && bv
=== undefined ) {
136 } else if ( av
=== undefined ) {
138 } else if ( bv
=== undefined ) {
141 let diff
= parseInt ( av
, 10 ) - parseInt ( bv
, 10 );
142 if ( diff
!= 0 ) return diff
;
143 // else we need to look at the next parts
149 get_ceph_icon_html : function ( health
, fw
) {
150 var state
= PVE
. Utils
. map_ceph_health
[ health
];
151 var cls
= PVE
. Utils
. get_health_icon ( state
);
155 return "<i class='fa " + cls
+ "'></i> " ;
160 'HEALTH_UPGRADE' : 'upgrade' ,
162 'HEALTH_WARN' : 'warning' ,
163 'HEALTH_ERR' : 'critical'
166 render_ceph_health : function ( healthObj
) {
168 iconCls
: PVE
. Utils
. get_health_icon (),
172 if (! healthObj
|| ! healthObj
. status
) {
176 var health
= PVE
. Utils
. map_ceph_health
[ healthObj
. status
];
178 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
179 state
. text
= healthObj
. status
;
184 render_zfs_health : function ( value
) {
185 if ( typeof value
== 'undefined' ){
188 var iconCls
= 'question-circle' ;
192 iconCls
= 'check-circle good' ;
196 iconCls
= 'exclamation-circle warning' ;
201 iconCls
= 'times-circle critical' ;
206 return '<i class="fa fa-' + iconCls
+ '"></i> ' + value
;
210 get_kvm_osinfo : function ( value
) {
211 var info
= { base
: 'Other' }; // default
213 Ext
. each ( Object
. keys ( PVE
. Utils
. kvm_ostypes
), function ( k
) {
214 Ext
. each ( PVE
. Utils
. kvm_ostypes
[ k
], function ( e
) {
215 if ( e
. val
=== value
) {
216 info
= { desc
: e
. desc
, base
: k
};
224 render_kvm_ostype : function ( value
) {
225 var osinfo
= PVE
. Utils
. get_kvm_osinfo ( value
);
226 if ( osinfo
. desc
&& osinfo
. desc
!== '-' ) {
227 return osinfo
. base
+ ' ' + osinfo
. desc
;
233 render_hotplug_features : function ( value
) {
236 if (! value
|| ( value
=== '0' )) {
237 return gettext ( 'Disabled' );
241 value
= 'disk,network,usb' ;
244 Ext
. each ( value
. split ( ',' ), function ( el
) {
246 fa
. push ( gettext ( 'Disk' ));
247 } else if ( el
=== 'network' ) {
248 fa
. push ( gettext ( 'Network' ));
249 } else if ( el
=== 'usb' ) {
251 } else if ( el
=== 'memory' ) {
252 fa
. push ( gettext ( 'Memory' ));
253 } else if ( el
=== 'cpu' ) {
254 fa
. push ( gettext ( 'CPU' ));
260 return fa
. join ( ', ' );
263 render_qga_features : function ( value
) {
265 return Proxmox
. Utils
. defaultText
+ ' (' + Proxmox
. Utils
. disabledText
+ ')' ;
267 var props
= PVE
. Parser
. parsePropertyString ( value
, 'enabled' );
268 if (! PVE
. Parser
. parseBoolean ( props
. enabled
)) {
269 return Proxmox
. Utils
. disabledText
;
272 delete props
. enabled
;
273 var agentstring
= Proxmox
. Utils
. enabledText
;
275 Ext
. Object
. each ( props
, function ( key
, value
) {
277 agentstring
+= ', ' + key
+ ': ' ;
279 if ( key
=== 'type' ) {
284 agentstring
+= map
[ value
] || Proxmox
. Utils
. unknownText
;
286 if ( PVE
. Parser
. parseBoolean ( value
)) {
287 agentstring
+= Proxmox
. Utils
. enabledText
;
289 agentstring
+= Proxmox
. Utils
. disabledText
;
297 render_qemu_machine : function ( value
) {
298 return value
|| ( Proxmox
. Utils
. defaultText
+ ' (i440fx)' );
301 render_qemu_bios : function ( value
) {
303 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
304 } else if ( value
=== 'seabios' ) {
306 } else if ( value
=== 'ovmf' ) {
307 return "OVMF (UEFI)" ;
313 render_dc_ha_opts : function ( value
) {
315 return Proxmox
. Utils
. defaultText
;
317 return PVE
. Parser
. printPropertyString ( value
);
320 render_as_property_string : function ( value
) {
321 return (! value
) ? Proxmox
. Utils
. defaultText
322 : PVE
. Parser
. printPropertyString ( value
);
325 render_scsihw : function ( value
) {
327 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
328 } else if ( value
=== 'lsi' ) {
329 return 'LSI 53C895A' ;
330 } else if ( value
=== 'lsi53c810' ) {
332 } else if ( value
=== 'megasas' ) {
333 return 'MegaRAID SAS 8708EM2' ;
334 } else if ( value
=== 'virtio-scsi-pci' ) {
335 return 'VirtIO SCSI' ;
336 } else if ( value
=== 'virtio-scsi-single' ) {
337 return 'VirtIO SCSI single' ;
338 } else if ( value
=== 'pvscsi' ) {
339 return 'VMware PVSCSI' ;
345 render_spice_enhancements : function ( values
) {
346 let props
= PVE
. Parser
. parsePropertyString ( values
);
347 if ( Ext
. Object
. isEmpty ( props
)) {
348 return Proxmox
. Utils
. noneText
;
352 if ( PVE
. Parser
. parseBoolean ( props
. foldersharing
)) {
353 output
. push ( 'Folder Sharing: ' + gettext ( 'Enabled' ));
355 if ( props
. videostreaming
=== 'all' || props
. videostreaming
=== 'filter' ) {
356 output
. push ( 'Video Streaming: ' + props
. videostreaming
);
358 return output
. join ( ', ' );
361 // fixme: auto-generate this
362 // for now, please keep in sync with PVE::Tools::kvmkeymaps
367 'de-ch' : 'German (Swiss)' ,
368 'en-gb' : 'English (UK)' ,
369 'en-us' : 'English (USA)' ,
373 //fo: 'Faroe Islands',
375 'fr-be' : 'French (Belgium)' ,
376 'fr-ca' : 'French (Canada)' ,
377 'fr-ch' : 'French (Swiss)' ,
387 //'nl-be': 'Dutch (Belgium)',
391 'pt-br' : 'Portuguese (Brazil)' ,
400 std
: gettext ( 'Standard VGA' ),
401 vmware
: gettext ( 'VMware compatible' ),
403 qxl2
: 'SPICE dual monitor' ,
404 qxl3
: 'SPICE three monitors' ,
405 qxl4
: 'SPICE four monitors' ,
406 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
407 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
408 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
409 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
410 virtio
: 'VirtIO-GPU' ,
411 none
: Proxmox
. Utils
. noneText
414 render_kvm_language : function ( value
) {
415 if (! value
|| value
=== '__default__' ) {
416 return Proxmox
. Utils
. defaultText
;
418 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
420 return text
+ ' (' + value
+ ')' ;
425 kvm_keymap_array : function () {
426 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
427 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
428 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
435 '__default__' : Proxmox
. Utils
. defaultText
+ ' (xterm.js)' ,
436 'vv' : 'SPICE (remote-viewer)' ,
437 'html5' : 'HTML5 (noVNC)' ,
438 'xtermjs' : 'xterm.js'
441 render_console_viewer : function ( value
) {
442 value
= value
|| '__default__' ;
443 if ( PVE
. Utils
. console_map
[ value
]) {
444 return PVE
. Utils
. console_map
[ value
];
449 console_viewer_array : function () {
450 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
451 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
455 render_kvm_vga_driver : function ( value
) {
457 return Proxmox
. Utils
. defaultText
;
459 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
460 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
462 text
= Proxmox
. Utils
. defaultText
;
465 return text
+ ' (' + value
+ ')' ;
470 kvm_vga_driver_array : function () {
471 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
472 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
473 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
479 render_kvm_startup : function ( value
) {
480 var startup
= PVE
. Parser
. parseStartup ( value
);
483 if ( startup
. order
=== undefined ) {
486 res
+= startup
. order
;
488 if ( startup
. up
!== undefined ) {
489 res
+= ',up=' + startup
. up
;
491 if ( startup
. down
!== undefined ) {
492 res
+= ',down=' + startup
. down
;
498 extractFormActionError : function ( action
) {
500 switch ( action
. failureType
) {
501 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
502 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
504 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
505 msg
= gettext ( 'Connection error' );
506 var resp
= action
. response
;
507 if ( resp
. status
&& resp
. statusText
) {
508 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
511 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
512 case Ext
. form
. action
. Action
. SERVER_INVALID
:
513 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
519 format_duration_short : function ( ut
) {
522 return ut
. toFixed ( 1 ) + 's' ;
527 return mins
. toFixed ( 1 ) + 'm' ;
531 var hours
= ut
/ 3600 ;
532 return hours
. toFixed ( 1 ) + 'h' ;
535 var days
= ut
/ 86400 ;
536 return days
. toFixed ( 1 ) + 'd' ;
540 'images' : gettext ( 'Disk image' ),
541 'backup' : gettext ( 'VZDump backup file' ),
542 'vztmpl' : gettext ( 'Container template' ),
543 'iso' : gettext ( 'ISO image' ),
544 'rootdir' : gettext ( 'Container' ),
545 'snippets' : gettext ( 'Snippets' )
548 volume_is_qemu_backup : function ( volid
, format
) {
549 return format
=== 'pbs-vm' || volid
. match ( ':backup/vzdump-qemu-' );
552 volume_is_lxc_backup : function ( volid
, format
) {
553 return format
=== 'pbs-ct' || volid
. match ( ':backup/vzdump-(lxc|openvz)-' );
558 name
: Proxmox
. Utils
. directoryText
,
559 ipanel
: 'DirInputPanel' ,
564 ipanel
: 'LVMInputPanel' ,
569 ipanel
: 'LvmThinInputPanel' ,
574 ipanel
: 'NFSInputPanel' ,
579 ipanel
: 'CIFSInputPanel' ,
584 ipanel
: 'GlusterFsInputPanel' ,
589 ipanel
: 'IScsiInputPanel' ,
594 ipanel
: 'CephFSInputPanel' ,
598 name
: 'CephFS (PVE)' ,
599 ipanel
: 'CephFSInputPanel' ,
605 ipanel
: 'RBDInputPanel' ,
610 ipanel
: 'RBDInputPanel' ,
615 name
: 'ZFS over iSCSI' ,
616 ipanel
: 'ZFSInputPanel' ,
621 ipanel
: 'ZFSPoolInputPanel' ,
630 format_storage_type : function ( value
, md
, record
) {
631 if ( value
=== 'rbd' ) {
632 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
633 } else if ( value
=== 'cephfs' ) {
634 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
637 var schema
= PVE
. Utils
. storageSchema
[ value
];
641 return Proxmox
. Utils
. unknownText
;
644 format_ha : function ( value
) {
645 var text
= Proxmox
. Utils
. noneText
;
648 text
= value
. state
|| Proxmox
. Utils
. noneText
;
650 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
651 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
657 format_content_types : function ( value
) {
658 return value
. split ( ',' ). sort (). map ( function ( ct
) {
659 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
663 render_storage_content : function ( value
, metaData
, record
) {
664 var data
= record
. data
;
665 if ( Ext
. isNumber ( data
. channel
) &&
666 Ext
. isNumber ( data
. id
) &&
667 Ext
. isNumber ( data
. lun
)) {
669 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
670 " ID " + data
. id
+ " LUN " + data
. lun
;
672 return data
. volid
. replace ( /^.*?:(.*?\/)?/ , '' );
675 render_serverity : function ( value
) {
676 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
679 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
681 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
685 var maxcpu
= record
. data
. maxcpu
|| 1 ;
687 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
691 var per
= value
* 100 ;
693 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
696 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
697 /*jslint confusion: true */
699 if (! Ext
. isNumeric ( value
)) {
703 return Proxmox
. Utils
. format_size ( value
);
706 render_bandwidth : function ( value
) {
707 if (! Ext
. isNumeric ( value
)) {
711 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
714 render_timestamp_human_readable : function ( value
) {
715 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
718 render_duration : function ( value
) {
719 if ( value
=== undefined ) {
722 return PVE
. Utils
. format_duration_short ( value
);
725 calculate_mem_usage : function ( data
) {
726 if (! Ext
. isNumeric ( data
. mem
) ||
732 return ( data
. mem
/ data
. maxmem
);
735 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
736 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
740 // we got no percentage but bytes
742 var maxmem
= record
. data
. maxmem
;
743 if (! record
. data
. uptime
||
745 ! Ext
. isNumeric ( mem
)) {
749 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
751 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
754 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
757 var maxmem
= record
. data
. maxmem
;
759 if (! record
. data
. uptime
) {
763 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
767 return PVE
. Utils
. render_size ( value
);
770 calculate_disk_usage : function ( data
) {
772 if (! Ext
. isNumeric ( data
. disk
) ||
773 data
. type
=== 'qemu' ||
774 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
775 data
. maxdisk
=== 0 ) {
779 return ( data
. disk
/ data
. maxdisk
);
782 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
783 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
787 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
790 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
793 var maxdisk
= record
. data
. maxdisk
;
794 var type
= record
. data
. type
;
796 if (! Ext
. isNumeric ( disk
) ||
799 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
803 return PVE
. Utils
. render_size ( value
);
806 get_object_icon_class : function ( type
, record
) {
810 if ( type
=== 'type' ) {
812 objType
= record
. groupbyid
;
813 } else if ( record
. template
) {
815 objType
= 'template' ;
819 status
= record
. status
+ ' ha-' + record
. hastate
;
823 status
+= ' locked lock-' + record
. lock
;
826 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
827 if ( defaults
&& defaults
. iconCls
) {
828 var retVal
= defaults
. iconCls
+ ' ' + status
;
835 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
837 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
839 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
843 render_support_level : function ( value
, metaData
, record
) {
844 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
847 render_upid : function ( value
, metaData
, record
) {
848 var type
= record
. data
. type
;
849 var id
= record
. data
. id
;
851 return Proxmox
. Utils
. format_task_description ( type
, id
);
854 /* render functions for new status panel */
856 render_usage : function ( val
) {
857 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
860 render_cpu_usage : function ( val
, max
) {
861 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
862 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
865 render_size_usage : function ( val
, max
) {
867 return gettext ( 'N/A' );
869 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
870 Ext
. String
. format ( gettext ( '{0} of {1}' ),
871 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
874 /* this is different for nodes */
875 render_node_cpu_usage : function ( value
, record
) {
876 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
879 /* this is different for nodes */
880 render_node_size_usage : function ( record
) {
881 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
884 render_optional_url : function ( value
) {
886 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
887 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
892 render_san : function ( value
) {
894 if ( Ext
. isArray ( value
)) {
895 value
. forEach ( function ( val
) {
896 if (! Ext
. isNumber ( val
)) {
900 return names
. join ( '<br>' );
905 render_full_name : function ( firstname
, metaData
, record
) {
906 var first
= firstname
|| '' ;
907 var last
= record
. data
. lastname
|| '' ;
908 return Ext
. htmlEncode ( first
+ " " + last
);
911 render_u2f_error : function ( error
) {
913 '1' : gettext ( 'Other Error' ),
914 '2' : gettext ( 'Bad Request' ),
915 '3' : gettext ( 'Configuration Unsupported' ),
916 '4' : gettext ( 'Device Ineligible' ),
917 '5' : gettext ( 'Timeout' )
919 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
922 windowHostname : function () {
923 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
924 function ( m
, addr
, offset
, original
) { return addr
; });
927 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
928 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
929 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
, cmd
);
932 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
933 // kvm, lxc, shell, upgrade
935 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
936 throw "missing vmid" ;
940 throw "no nodename specified" ;
943 if ( viewer
=== 'html5' ) {
944 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
945 } else if ( viewer
=== 'xtermjs' ) {
946 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
947 } else if ( viewer
=== 'vv' ) {
949 var params
= { proxy
: PVE
. Utils
. windowHostname () };
950 if ( vmtype
=== 'kvm' ) {
951 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
952 PVE
. Utils
. openSpiceViewer ( url
, params
);
953 } else if ( vmtype
=== 'lxc' ) {
954 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
955 PVE
. Utils
. openSpiceViewer ( url
, params
);
956 } else if ( vmtype
=== 'shell' ) {
957 url
= '/nodes/' + nodename
+ '/spiceshell' ;
958 PVE
. Utils
. openSpiceViewer ( url
, params
);
959 } else if ( vmtype
=== 'upgrade' ) {
960 url
= '/nodes/' + nodename
+ '/spiceshell' ;
962 PVE
. Utils
. openSpiceViewer ( url
, params
);
963 } else if ( vmtype
=== 'cmd' ) {
964 url
= '/nodes/' + nodename
+ '/spiceshell' ;
966 PVE
. Utils
. openSpiceViewer ( url
, params
);
969 throw "unknown viewer type" ;
973 defaultViewer : function ( consoles
) {
975 var allowSpice
, allowXtermjs
;
977 if ( consoles
=== true ) {
980 } else if ( typeof consoles
=== 'object' ) {
981 allowSpice
= consoles
. spice
;
982 allowXtermjs
= !! consoles
. xtermjs
;
984 var dv
= PVE
. VersionInfo
. console
|| 'xtermjs' ;
985 if ( dv
=== 'vv' && ! allowSpice
) {
986 dv
= ( allowXtermjs
) ? 'xtermjs' : 'html5' ;
987 } else if ( dv
=== 'xtermjs' && ! allowXtermjs
) {
988 dv
= ( allowSpice
) ? 'vv' : 'html5' ;
994 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
996 if ( Proxmox
. Utils
. toolkit
!== 'touch' ) {
997 var sp
= Ext
. state
. Manager
. getProvider ();
998 scaling
= sp
. get ( 'novnc-scaling' , 'off' );
1000 var url
= Ext
. Object
. toQueryString ({
1001 console
: vmtype
, // kvm, lxc, upgrade or shell
1009 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1015 openSpiceViewer : function ( url
, params
){
1017 var downloadWithName = function ( uri
, name
) {
1018 var link
= Ext
. DomHelper
. append ( document
. body
, {
1021 css
: 'display:none;visibility:hidden;height:0px;'
1024 // Note: we need to tell android the correct file name extension
1025 // but we do not set 'download' tag for other environments, because
1026 // It can have strange side effects (additional user prompt on firefox)
1027 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1029 link
. download
= name
;
1032 if ( link
. fireEvent
) {
1033 link
. fireEvent ( 'onclick' );
1035 var evt
= document
. createEvent ( "MouseEvents" );
1036 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1037 link
. dispatchEvent ( evt
);
1041 Proxmox
. Utils
. API2Request ({
1045 failure : function ( response
, opts
){
1046 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1048 success : function ( response
, opts
){
1049 var raw
= "[virt-viewer] \n " ;
1050 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1051 raw
+= k
+ "=" + v
+ " \n " ;
1053 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1054 encodeURIComponent ( raw
);
1056 downloadWithName ( url
, "pve-spice.vv" );
1061 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1063 var nodename
= record
. data
. node
;
1064 var vmid
= record
. data
. vmid
;
1065 var vmname
= record
. data
. name
;
1066 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1067 Proxmox
. Utils
. API2Request ({
1068 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1069 failure : function ( response
, opts
) {
1070 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1072 success : function ( response
, opts
) {
1073 let conf
= response
. result
. data
;
1075 spice
: !! conf
. spice
,
1076 xtermjs
: !! conf
. serial
,
1078 PVE
. Utils
. openDefaultConsoleWindow ( consoles
, 'kvm' , vmid
, nodename
, vmname
);
1081 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1082 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1086 // test automation helper
1087 call_menu_handler : function ( menu
, text
) {
1089 var list
= menu
. query ( 'menuitem' );
1091 Ext
. Array
. each ( list
, function ( item
) {
1092 if ( item
. text
=== text
) {
1103 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1105 if (!( v
instanceof Ext
. tree
. View
)) {
1109 var template
= !! record
. data
. template
;
1110 var type
= record
. data
. type
;
1113 if ( type
=== 'qemu' || type
== 'lxc' ) {
1114 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1118 } else if ( type
=== 'qemu' ||
1121 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1123 nodename
: record
. data
. node
1129 menu
. showAt ( event
. getXY ());
1133 // helper for deleting field which are set to there default values
1134 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1135 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1137 if ( values
[ 'delete' ]) {
1138 values
[ 'delete' ] += ',' + fieldname
;
1140 values
[ 'delete' ] = fieldname
;
1144 delete values
[ fieldname
];
1148 loadSSHKeyFromFile : function ( file
, callback
) {
1149 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1150 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1151 // assume: 740*8 for max. 32kbit (5920 byte file)
1152 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1153 if ( file
. size
> 8192 ) {
1154 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1160 var reader
= new FileReader ();
1161 reader
. onload = function ( evt
) {
1162 callback ( evt
. target
. result
);
1164 reader
. readAsText ( file
);
1167 diskControllerMaxIDs
: {
1174 // types is either undefined (all busses), an array of busses, or a single bus
1175 forEachBus : function ( types
, func
) {
1176 var busses
= Object
. keys ( PVE
. Utils
. diskControllerMaxIDs
);
1177 var i
, j
, count
, cont
;
1179 if ( Ext
. isArray ( types
)) {
1181 } else if ( Ext
. isDefined ( types
)) {
1185 // check if we only have valid busses
1186 for ( i
= 0 ; i
< busses
. length
; i
++) {
1187 if (! PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]]) {
1188 throw "invalid bus: '" + busses
[ i
] + "'" ;
1192 for ( i
= 0 ; i
< busses
. length
; i
++) {
1193 count
= PVE
. Utils
. diskControllerMaxIDs
[ busses
[ i
]];
1194 for ( j
= 0 ; j
< count
; j
++) {
1195 cont
= func ( busses
[ i
], j
);
1196 if (! cont
&& cont
!== undefined ) {
1203 mp_counts
: { mps
: 256 , unused
: 256 },
1205 forEachMP : function ( func
, includeUnused
) {
1207 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1208 cont
= func ( 'mp' , i
);
1209 if (! cont
&& cont
!== undefined ) {
1214 if (! includeUnused
) {
1218 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1219 cont
= func ( 'unused' , i
);
1220 if (! cont
&& cont
!== undefined ) {
1226 hardware_counts
: { net
: 32 , usb
: 5 , hostpci
: 16 , audio
: 1 , efidisk
: 1 , serial
: 4 , rng
: 1 },
1228 cleanEmptyObjectKeys : function ( obj
) {
1230 for ( propName
in obj
) {
1231 if ( obj
. hasOwnProperty ( propName
)) {
1232 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1233 delete obj
[ propName
];
1239 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1241 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1244 Proxmox
. Utils
. setErrorMask ( me
, false );
1249 if ( operation
. error
. statusText
) {
1250 if ( operation
. error
. statusText
. match ( regex
)) {
1251 callback ( me
, operation
. error
);
1254 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1257 msg
= gettext ( 'Connection error' );
1259 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1263 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1264 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1265 if ( msg
. match ( regex
)) {
1266 if ( Proxmox
. UserName
=== 'root@pam' ) {
1267 container
. el
. mask ();
1268 if (! container
. down ( 'pveCephInstallWindow' )){
1269 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1270 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1273 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1279 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1280 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1288 propertyStringSet : function ( target
, source
, name
, value
) {
1290 if ( value
=== undefined ) {
1291 target
[ name
] = source
;
1293 target
[ name
] = value
;
1296 delete target
[ name
];
1300 updateColumns : function ( container
) {
1301 let mode
= Ext
. state
. Manager
. get ( 'summarycolumns' ) || 'auto' ;
1303 if ( mode
!== 'auto' ) {
1304 factor
= parseInt ( mode
, 10 );
1305 if ( Number
. isNaN ( factor
)) {
1309 factor
= container
. getSize (). width
< 1400 ? 1 : 2 ;
1312 if ( container
. oldFactor
=== factor
) {
1316 let items
= container
. query ( '>' ); // direct childs
1317 factor
= Math
. min ( factor
, items
. length
);
1318 container
. oldFactor
= factor
;
1320 items
. forEach (( item
) => {
1321 item
. columnWidth
= 1 / factor
;
1324 // we have to update the layout twice, since the first layout change
1325 // can trigger the scrollbar which reduces the amount of space left
1326 container
. updateLayout ();
1327 container
. updateLayout ();
1330 forEachCorosyncLink : function ( nodeinfo
, cb
) {
1331 let re
= /(?:ring|link)(\d+)_addr/ ;
1332 Ext
. iterate ( nodeinfo
, ( prop
, val
) => {
1333 let match
= re
. exec ( prop
);
1335 cb ( Number ( match
[ 1 ]), val
);
1342 constructor : function () {
1344 Ext
. apply ( me
, me
. utilities
);