]>
git.proxmox.com Git - pve-manager.git/blob - www/manager6/Utils.js
2782660627c494ef720301c41b0433326818b423
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' )
550 name
: Proxmox
. Utils
. directoryText
,
551 ipanel
: 'DirInputPanel' ,
556 ipanel
: 'LVMInputPanel' ,
561 ipanel
: 'LvmThinInputPanel' ,
566 ipanel
: 'NFSInputPanel' ,
571 ipanel
: 'CIFSInputPanel' ,
576 ipanel
: 'GlusterFsInputPanel' ,
581 ipanel
: 'IScsiInputPanel' ,
586 ipanel
: 'CephFSInputPanel' ,
590 name
: 'CephFS (PVE)' ,
591 ipanel
: 'CephFSInputPanel' ,
597 ipanel
: 'RBDInputPanel' ,
602 ipanel
: 'RBDInputPanel' ,
607 name
: 'ZFS over iSCSI' ,
608 ipanel
: 'ZFSInputPanel' ,
613 ipanel
: 'ZFSPoolInputPanel' ,
622 format_storage_type : function ( value
, md
, record
) {
623 if ( value
=== 'rbd' ) {
624 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
625 } else if ( value
=== 'cephfs' ) {
626 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
629 var schema
= PVE
. Utils
. storageSchema
[ value
];
633 return Proxmox
. Utils
. unknownText
;
636 format_ha : function ( value
) {
637 var text
= Proxmox
. Utils
. noneText
;
640 text
= value
. state
|| Proxmox
. Utils
. noneText
;
642 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
643 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
649 format_content_types : function ( value
) {
650 return value
. split ( ',' ). sort (). map ( function ( ct
) {
651 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
655 render_storage_content : function ( value
, metaData
, record
) {
656 var data
= record
. data
;
657 if ( Ext
. isNumber ( data
. channel
) &&
658 Ext
. isNumber ( data
. id
) &&
659 Ext
. isNumber ( data
. lun
)) {
661 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
662 " ID " + data
. id
+ " LUN " + data
. lun
;
664 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
667 render_serverity : function ( value
) {
668 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
671 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
673 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
677 var maxcpu
= record
. data
. maxcpu
|| 1 ;
679 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
683 var per
= value
* 100 ;
685 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
688 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
689 /*jslint confusion: true */
691 if (! Ext
. isNumeric ( value
)) {
695 return Proxmox
. Utils
. format_size ( value
);
698 render_bandwidth : function ( value
) {
699 if (! Ext
. isNumeric ( value
)) {
703 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
706 render_timestamp_human_readable : function ( value
) {
707 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
710 render_duration : function ( value
) {
711 if ( value
=== undefined ) {
714 return PVE
. Utils
. format_duration_short ( value
);
717 calculate_mem_usage : function ( data
) {
718 if (! Ext
. isNumeric ( data
. mem
) ||
724 return ( data
. mem
/ data
. maxmem
);
727 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
728 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
732 // we got no percentage but bytes
734 var maxmem
= record
. data
. maxmem
;
735 if (! record
. data
. uptime
||
737 ! Ext
. isNumeric ( mem
)) {
741 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
743 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
746 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
749 var maxmem
= record
. data
. maxmem
;
751 if (! record
. data
. uptime
) {
755 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
759 return PVE
. Utils
. render_size ( value
);
762 calculate_disk_usage : function ( data
) {
764 if (! Ext
. isNumeric ( data
. disk
) ||
765 data
. type
=== 'qemu' ||
766 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
767 data
. maxdisk
=== 0 ) {
771 return ( data
. disk
/ data
. maxdisk
);
774 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
775 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
779 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
782 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
785 var maxdisk
= record
. data
. maxdisk
;
786 var type
= record
. data
. type
;
788 if (! Ext
. isNumeric ( disk
) ||
791 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
795 return PVE
. Utils
. render_size ( value
);
798 get_object_icon_class : function ( type
, record
) {
802 if ( type
=== 'type' ) {
804 objType
= record
. groupbyid
;
805 } else if ( record
. template
) {
807 objType
= 'template' ;
811 status
= record
. status
+ ' ha-' + record
. hastate
;
815 status
+= ' locked lock-' + record
. lock
;
818 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
819 if ( defaults
&& defaults
. iconCls
) {
820 var retVal
= defaults
. iconCls
+ ' ' + status
;
827 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
829 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
831 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
835 render_support_level : function ( value
, metaData
, record
) {
836 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
839 render_upid : function ( value
, metaData
, record
) {
840 var type
= record
. data
. type
;
841 var id
= record
. data
. id
;
843 return Proxmox
. Utils
. format_task_description ( type
, id
);
846 /* render functions for new status panel */
848 render_usage : function ( val
) {
849 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
852 render_cpu_usage : function ( val
, max
) {
853 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
854 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
857 render_size_usage : function ( val
, max
) {
859 return gettext ( 'N/A' );
861 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
862 Ext
. String
. format ( gettext ( '{0} of {1}' ),
863 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
866 /* this is different for nodes */
867 render_node_cpu_usage : function ( value
, record
) {
868 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
871 /* this is different for nodes */
872 render_node_size_usage : function ( record
) {
873 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
876 render_optional_url : function ( value
) {
878 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
879 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
884 render_san : function ( value
) {
886 if ( Ext
. isArray ( value
)) {
887 value
. forEach ( function ( val
) {
888 if (! Ext
. isNumber ( val
)) {
892 return names
. join ( '<br>' );
897 render_full_name : function ( firstname
, metaData
, record
) {
898 var first
= firstname
|| '' ;
899 var last
= record
. data
. lastname
|| '' ;
900 return Ext
. htmlEncode ( first
+ " " + last
);
903 render_u2f_error : function ( error
) {
905 '1' : gettext ( 'Other Error' ),
906 '2' : gettext ( 'Bad Request' ),
907 '3' : gettext ( 'Configuration Unsupported' ),
908 '4' : gettext ( 'Device Ineligible' ),
909 '5' : gettext ( 'Timeout' )
911 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
914 windowHostname : function () {
915 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
916 function ( m
, addr
, offset
, original
) { return addr
; });
919 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
920 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
921 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
, cmd
);
924 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
925 // kvm, lxc, shell, upgrade
927 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
928 throw "missing vmid" ;
932 throw "no nodename specified" ;
935 if ( viewer
=== 'html5' ) {
936 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
937 } else if ( viewer
=== 'xtermjs' ) {
938 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
939 } else if ( viewer
=== 'vv' ) {
941 var params
= { proxy
: PVE
. Utils
. windowHostname () };
942 if ( vmtype
=== 'kvm' ) {
943 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
944 PVE
. Utils
. openSpiceViewer ( url
, params
);
945 } else if ( vmtype
=== 'lxc' ) {
946 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
947 PVE
. Utils
. openSpiceViewer ( url
, params
);
948 } else if ( vmtype
=== 'shell' ) {
949 url
= '/nodes/' + nodename
+ '/spiceshell' ;
950 PVE
. Utils
. openSpiceViewer ( url
, params
);
951 } else if ( vmtype
=== 'upgrade' ) {
952 url
= '/nodes/' + nodename
+ '/spiceshell' ;
954 PVE
. Utils
. openSpiceViewer ( url
, params
);
955 } else if ( vmtype
=== 'cmd' ) {
956 url
= '/nodes/' + nodename
+ '/spiceshell' ;
958 PVE
. Utils
. openSpiceViewer ( url
, params
);
961 throw "unknown viewer type" ;
965 defaultViewer : function ( consoles
) {
967 var allowSpice
, allowXtermjs
;
969 if ( consoles
=== true ) {
972 } else if ( typeof consoles
=== 'object' ) {
973 allowSpice
= consoles
. spice
;
974 allowXtermjs
= !! consoles
. xtermjs
;
976 var dv
= PVE
. VersionInfo
. console
|| 'xtermjs' ;
977 if ( dv
=== 'vv' && ! allowSpice
) {
978 dv
= ( allowXtermjs
) ? 'xtermjs' : 'html5' ;
979 } else if ( dv
=== 'xtermjs' && ! allowXtermjs
) {
980 dv
= ( allowSpice
) ? 'vv' : 'html5' ;
986 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
988 if ( Proxmox
. Utils
. toolkit
!== 'touch' ) {
989 var sp
= Ext
. state
. Manager
. getProvider ();
990 scaling
= sp
. get ( 'novnc-scaling' , 'off' );
992 var url
= Ext
. Object
. toQueryString ({
993 console
: vmtype
, // kvm, lxc, upgrade or shell
1001 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1007 openSpiceViewer : function ( url
, params
){
1009 var downloadWithName = function ( uri
, name
) {
1010 var link
= Ext
. DomHelper
. append ( document
. body
, {
1013 css
: 'display:none;visibility:hidden;height:0px;'
1016 // Note: we need to tell android the correct file name extension
1017 // but we do not set 'download' tag for other environments, because
1018 // It can have strange side effects (additional user prompt on firefox)
1019 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1021 link
. download
= name
;
1024 if ( link
. fireEvent
) {
1025 link
. fireEvent ( 'onclick' );
1027 var evt
= document
. createEvent ( "MouseEvents" );
1028 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1029 link
. dispatchEvent ( evt
);
1033 Proxmox
. Utils
. API2Request ({
1037 failure : function ( response
, opts
){
1038 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1040 success : function ( response
, opts
){
1041 var raw
= "[virt-viewer] \n " ;
1042 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1043 raw
+= k
+ "=" + v
+ " \n " ;
1045 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1046 encodeURIComponent ( raw
);
1048 downloadWithName ( url
, "pve-spice.vv" );
1053 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1055 var nodename
= record
. data
. node
;
1056 var vmid
= record
. data
. vmid
;
1057 var vmname
= record
. data
. name
;
1058 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1059 Proxmox
. Utils
. API2Request ({
1060 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1061 failure : function ( response
, opts
) {
1062 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1064 success : function ( response
, opts
) {
1065 let conf
= response
. result
. data
;
1067 spice
: !! conf
. spice
,
1068 xtermjs
: !! conf
. serial
,
1070 PVE
. Utils
. openDefaultConsoleWindow ( consoles
, 'kvm' , vmid
, nodename
, vmname
);
1073 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1074 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1078 // test automation helper
1079 call_menu_handler : function ( menu
, text
) {
1081 var list
= menu
. query ( 'menuitem' );
1083 Ext
. Array
. each ( list
, function ( item
) {
1084 if ( item
. text
=== text
) {
1095 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1097 if (!( v
instanceof Ext
. tree
. View
)) {
1101 var template
= !! record
. data
. template
;
1102 var type
= record
. data
. type
;
1105 if ( type
=== 'qemu' || type
== 'lxc' ) {
1106 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1110 } else if ( type
=== 'qemu' ||
1113 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1115 nodename
: record
. data
. node
1121 menu
. showAt ( event
. getXY ());
1125 // helper for deleting field which are set to there default values
1126 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1127 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1129 if ( values
[ 'delete' ]) {
1130 values
[ 'delete' ] += ',' + fieldname
;
1132 values
[ 'delete' ] = fieldname
;
1136 delete values
[ fieldname
];
1140 loadSSHKeyFromFile : function ( file
, callback
) {
1141 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1142 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1143 // assume: 740*8 for max. 32kbit (5920 byte file)
1144 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1145 if ( file
. size
> 8192 ) {
1146 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1152 var reader
= new FileReader ();
1153 reader
. onload = function ( evt
) {
1154 callback ( evt
. target
. result
);
1156 reader
. readAsText ( file
);
1159 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
1161 // types is either undefined (all busses), an array of busses, or a single bus
1162 forEachBus : function ( types
, func
) {
1163 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
1164 var i
, j
, count
, cont
;
1166 if ( Ext
. isArray ( types
)) {
1168 } else if ( Ext
. isDefined ( types
)) {
1172 // check if we only have valid busses
1173 for ( i
= 0 ; i
< busses
. length
; i
++) {
1174 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
1175 throw "invalid bus: '" + busses
[ i
] + "'" ;
1179 for ( i
= 0 ; i
< busses
. length
; i
++) {
1180 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
1181 for ( j
= 0 ; j
< count
; j
++) {
1182 cont
= func ( busses
[ i
], j
);
1183 if (! cont
&& cont
!== undefined ) {
1190 mp_counts
: { mps
: 256 , unused
: 256 },
1192 forEachMP : function ( func
, includeUnused
) {
1194 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1195 cont
= func ( 'mp' , i
);
1196 if (! cont
&& cont
!== undefined ) {
1201 if (! includeUnused
) {
1205 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1206 cont
= func ( 'unused' , i
);
1207 if (! cont
&& cont
!== undefined ) {
1213 cleanEmptyObjectKeys : function ( obj
) {
1215 for ( propName
in obj
) {
1216 if ( obj
. hasOwnProperty ( propName
)) {
1217 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1218 delete obj
[ propName
];
1224 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1226 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1229 Proxmox
. Utils
. setErrorMask ( me
, false );
1234 if ( operation
. error
. statusText
) {
1235 if ( operation
. error
. statusText
. match ( regex
)) {
1236 callback ( me
, operation
. error
);
1239 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1242 msg
= gettext ( 'Connection error' );
1244 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1248 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1249 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1250 if ( msg
. match ( regex
)) {
1251 if ( Proxmox
. UserName
=== 'root@pam' ) {
1252 container
. el
. mask ();
1253 if (! container
. down ( 'pveCephInstallWindow' )){
1254 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1255 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1258 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1264 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1265 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1273 propertyStringSet : function ( target
, source
, name
, value
) {
1275 if ( value
=== undefined ) {
1276 target
[ name
] = source
;
1278 target
[ name
] = value
;
1281 delete target
[ name
];
1285 updateColumns : function ( container
) {
1286 let factor
= container
. getSize (). width
< 1400 ? 1 : 2 ;
1288 if ( container
. oldFactor
=== factor
) {
1292 let items
= container
. query ( '>' ); // direct childs
1293 factor
= Math
. min ( factor
, items
. length
);
1294 container
. oldFactor
= factor
;
1296 items
. forEach (( item
) => {
1297 item
. columnWidth
= 1 / factor
;
1300 // we have to update the layout twice, since the first layout change
1301 // can trigger the scrollbar which reduces the amount of space left
1302 container
. updateLayout ();
1303 container
. updateLayout ();
1308 constructor : function () {
1310 Ext
. apply ( me
, me
. utilities
);