]>
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 ( PVE
. Parser
. parseBoolean ( value
)) {
280 agentstring
+= Proxmox
. Utils
. enabledText
;
282 agentstring
+= Proxmox
. Utils
. disabledText
;
289 render_qemu_machine : function ( value
) {
290 return value
|| ( Proxmox
. Utils
. defaultText
+ ' (i440fx)' );
293 render_qemu_bios : function ( value
) {
295 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
296 } else if ( value
=== 'seabios' ) {
298 } else if ( value
=== 'ovmf' ) {
299 return "OVMF (UEFI)" ;
305 render_dc_ha_opts : function ( value
) {
307 return Proxmox
. Utils
. defaultText
;
309 return PVE
. Parser
. printPropertyString ( value
);
312 render_as_property_string : function ( value
) {
313 return (! value
) ? Proxmox
. Utils
. defaultText
314 : PVE
. Parser
. printPropertyString ( value
);
317 render_scsihw : function ( value
) {
319 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
320 } else if ( value
=== 'lsi' ) {
321 return 'LSI 53C895A' ;
322 } else if ( value
=== 'lsi53c810' ) {
324 } else if ( value
=== 'megasas' ) {
325 return 'MegaRAID SAS 8708EM2' ;
326 } else if ( value
=== 'virtio-scsi-pci' ) {
327 return 'VirtIO SCSI' ;
328 } else if ( value
=== 'virtio-scsi-single' ) {
329 return 'VirtIO SCSI single' ;
330 } else if ( value
=== 'pvscsi' ) {
331 return 'VMware PVSCSI' ;
337 render_spice_enhancements : function ( values
) {
338 let props
= PVE
. Parser
. parsePropertyString ( values
);
339 if ( Ext
. Object
. isEmpty ( props
)) {
340 return Proxmox
. Utils
. noneText
;
344 if ( PVE
. Parser
. parseBoolean ( props
. foldersharing
)) {
345 output
. push ( 'Folder Sharing: ' + gettext ( 'Enabled' ));
347 if ( props
. videostreaming
=== 'all' || props
. videostreaming
=== 'filter' ) {
348 output
. push ( 'Video Streaming: ' + props
. videostreaming
);
350 return output
. join ( ', ' );
353 // fixme: auto-generate this
354 // for now, please keep in sync with PVE::Tools::kvmkeymaps
359 'de-ch' : 'German (Swiss)' ,
360 'en-gb' : 'English (UK)' ,
361 'en-us' : 'English (USA)' ,
365 //fo: 'Faroe Islands',
367 'fr-be' : 'French (Belgium)' ,
368 'fr-ca' : 'French (Canada)' ,
369 'fr-ch' : 'French (Swiss)' ,
379 //'nl-be': 'Dutch (Belgium)',
383 'pt-br' : 'Portuguese (Brazil)' ,
392 std
: gettext ( 'Standard VGA' ),
393 vmware
: gettext ( 'VMware compatible' ),
395 qxl2
: 'SPICE dual monitor' ,
396 qxl3
: 'SPICE three monitors' ,
397 qxl4
: 'SPICE four monitors' ,
398 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
399 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
400 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
401 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
402 virtio
: 'VirtIO-GPU' ,
403 none
: Proxmox
. Utils
. noneText
406 render_kvm_language : function ( value
) {
407 if (! value
|| value
=== '__default__' ) {
408 return Proxmox
. Utils
. defaultText
;
410 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
412 return text
+ ' (' + value
+ ')' ;
417 kvm_keymap_array : function () {
418 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
419 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
420 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
427 '__default__' : Proxmox
. Utils
. defaultText
+ ' (xterm.js)' ,
428 'vv' : 'SPICE (remote-viewer)' ,
429 'html5' : 'HTML5 (noVNC)' ,
430 'xtermjs' : 'xterm.js'
433 render_console_viewer : function ( value
) {
434 value
= value
|| '__default__' ;
435 if ( PVE
. Utils
. console_map
[ value
]) {
436 return PVE
. Utils
. console_map
[ value
];
441 console_viewer_array : function () {
442 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
443 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
447 render_kvm_vga_driver : function ( value
) {
449 return Proxmox
. Utils
. defaultText
;
451 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
452 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
454 text
= Proxmox
. Utils
. defaultText
;
457 return text
+ ' (' + value
+ ')' ;
462 kvm_vga_driver_array : function () {
463 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
464 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
465 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
471 render_kvm_startup : function ( value
) {
472 var startup
= PVE
. Parser
. parseStartup ( value
);
475 if ( startup
. order
=== undefined ) {
478 res
+= startup
. order
;
480 if ( startup
. up
!== undefined ) {
481 res
+= ',up=' + startup
. up
;
483 if ( startup
. down
!== undefined ) {
484 res
+= ',down=' + startup
. down
;
490 extractFormActionError : function ( action
) {
492 switch ( action
. failureType
) {
493 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
494 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
496 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
497 msg
= gettext ( 'Connection error' );
498 var resp
= action
. response
;
499 if ( resp
. status
&& resp
. statusText
) {
500 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
503 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
504 case Ext
. form
. action
. Action
. SERVER_INVALID
:
505 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
511 format_duration_short : function ( ut
) {
514 return ut
. toFixed ( 1 ) + 's' ;
519 return mins
. toFixed ( 1 ) + 'm' ;
523 var hours
= ut
/ 3600 ;
524 return hours
. toFixed ( 1 ) + 'h' ;
527 var days
= ut
/ 86400 ;
528 return days
. toFixed ( 1 ) + 'd' ;
532 'images' : gettext ( 'Disk image' ),
533 'backup' : gettext ( 'VZDump backup file' ),
534 'vztmpl' : gettext ( 'Container template' ),
535 'iso' : gettext ( 'ISO image' ),
536 'rootdir' : gettext ( 'Container' ),
537 'snippets' : gettext ( 'Snippets' )
542 name
: Proxmox
. Utils
. directoryText
,
543 ipanel
: 'DirInputPanel' ,
548 ipanel
: 'LVMInputPanel' ,
553 ipanel
: 'LvmThinInputPanel' ,
558 ipanel
: 'NFSInputPanel' ,
563 ipanel
: 'CIFSInputPanel' ,
568 ipanel
: 'GlusterFsInputPanel' ,
573 ipanel
: 'IScsiInputPanel' ,
578 ipanel
: 'CephFSInputPanel' ,
582 name
: 'CephFS (PVE)' ,
583 ipanel
: 'CephFSInputPanel' ,
589 ipanel
: 'RBDInputPanel' ,
594 ipanel
: 'RBDInputPanel' ,
599 name
: 'ZFS over iSCSI' ,
600 ipanel
: 'ZFSInputPanel' ,
605 ipanel
: 'ZFSPoolInputPanel' ,
614 format_storage_type : function ( value
, md
, record
) {
615 if ( value
=== 'rbd' ) {
616 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
617 } else if ( value
=== 'cephfs' ) {
618 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
621 var schema
= PVE
. Utils
. storageSchema
[ value
];
625 return Proxmox
. Utils
. unknownText
;
628 format_ha : function ( value
) {
629 var text
= Proxmox
. Utils
. noneText
;
632 text
= value
. state
|| Proxmox
. Utils
. noneText
;
634 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
635 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
641 format_content_types : function ( value
) {
642 return value
. split ( ',' ). sort (). map ( function ( ct
) {
643 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
647 render_storage_content : function ( value
, metaData
, record
) {
648 var data
= record
. data
;
649 if ( Ext
. isNumber ( data
. channel
) &&
650 Ext
. isNumber ( data
. id
) &&
651 Ext
. isNumber ( data
. lun
)) {
653 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
654 " ID " + data
. id
+ " LUN " + data
. lun
;
656 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
659 render_serverity : function ( value
) {
660 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
663 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
665 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
669 var maxcpu
= record
. data
. maxcpu
|| 1 ;
671 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
675 var per
= value
* 100 ;
677 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
680 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
681 /*jslint confusion: true */
683 if (! Ext
. isNumeric ( value
)) {
687 return Proxmox
. Utils
. format_size ( value
);
690 render_bandwidth : function ( value
) {
691 if (! Ext
. isNumeric ( value
)) {
695 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
698 render_timestamp_human_readable : function ( value
) {
699 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
702 render_duration : function ( value
) {
703 if ( value
=== undefined ) {
706 return PVE
. Utils
. format_duration_short ( value
);
709 calculate_mem_usage : function ( data
) {
710 if (! Ext
. isNumeric ( data
. mem
) ||
716 return ( data
. mem
/ data
. maxmem
);
719 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
720 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
724 // we got no percentage but bytes
726 var maxmem
= record
. data
. maxmem
;
727 if (! record
. data
. uptime
||
729 ! Ext
. isNumeric ( mem
)) {
733 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
735 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
738 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
741 var maxmem
= record
. data
. maxmem
;
743 if (! record
. data
. uptime
) {
747 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
751 return PVE
. Utils
. render_size ( value
);
754 calculate_disk_usage : function ( data
) {
756 if (! Ext
. isNumeric ( data
. disk
) ||
757 data
. type
=== 'qemu' ||
758 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
759 data
. maxdisk
=== 0 ) {
763 return ( data
. disk
/ data
. maxdisk
);
766 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
767 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
771 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
774 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
777 var maxdisk
= record
. data
. maxdisk
;
778 var type
= record
. data
. type
;
780 if (! Ext
. isNumeric ( disk
) ||
783 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
787 return PVE
. Utils
. render_size ( value
);
790 get_object_icon_class : function ( type
, record
) {
794 if ( type
=== 'type' ) {
796 objType
= record
. groupbyid
;
797 } else if ( record
. template
) {
799 objType
= 'template' ;
803 status
= record
. status
+ ' ha-' + record
. hastate
;
807 status
+= ' locked lock-' + record
. lock
;
810 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
811 if ( defaults
&& defaults
. iconCls
) {
812 var retVal
= defaults
. iconCls
+ ' ' + status
;
819 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
821 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
823 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
827 render_support_level : function ( value
, metaData
, record
) {
828 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
831 render_upid : function ( value
, metaData
, record
) {
832 var type
= record
. data
. type
;
833 var id
= record
. data
. id
;
835 return Proxmox
. Utils
. format_task_description ( type
, id
);
838 /* render functions for new status panel */
840 render_usage : function ( val
) {
841 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
844 render_cpu_usage : function ( val
, max
) {
845 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
846 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
849 render_size_usage : function ( val
, max
) {
851 return gettext ( 'N/A' );
853 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
854 Ext
. String
. format ( gettext ( '{0} of {1}' ),
855 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
858 /* this is different for nodes */
859 render_node_cpu_usage : function ( value
, record
) {
860 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
863 /* this is different for nodes */
864 render_node_size_usage : function ( record
) {
865 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
868 render_optional_url : function ( value
) {
870 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
871 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
876 render_san : function ( value
) {
878 if ( Ext
. isArray ( value
)) {
879 value
. forEach ( function ( val
) {
880 if (! Ext
. isNumber ( val
)) {
884 return names
. join ( '<br>' );
889 render_full_name : function ( firstname
, metaData
, record
) {
890 var first
= firstname
|| '' ;
891 var last
= record
. data
. lastname
|| '' ;
892 return Ext
. htmlEncode ( first
+ " " + last
);
895 render_u2f_error : function ( error
) {
897 '1' : gettext ( 'Other Error' ),
898 '2' : gettext ( 'Bad Request' ),
899 '3' : gettext ( 'Configuration Unsupported' ),
900 '4' : gettext ( 'Device Ineligible' ),
901 '5' : gettext ( 'Timeout' )
903 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
906 windowHostname : function () {
907 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
908 function ( m
, addr
, offset
, original
) { return addr
; });
911 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
912 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
913 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
, cmd
);
916 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
917 // kvm, lxc, shell, upgrade
919 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
920 throw "missing vmid" ;
924 throw "no nodename specified" ;
927 if ( viewer
=== 'html5' ) {
928 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
929 } else if ( viewer
=== 'xtermjs' ) {
930 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
931 } else if ( viewer
=== 'vv' ) {
933 var params
= { proxy
: PVE
. Utils
. windowHostname () };
934 if ( vmtype
=== 'kvm' ) {
935 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
936 PVE
. Utils
. openSpiceViewer ( url
, params
);
937 } else if ( vmtype
=== 'lxc' ) {
938 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
939 PVE
. Utils
. openSpiceViewer ( url
, params
);
940 } else if ( vmtype
=== 'shell' ) {
941 url
= '/nodes/' + nodename
+ '/spiceshell' ;
942 PVE
. Utils
. openSpiceViewer ( url
, params
);
943 } else if ( vmtype
=== 'upgrade' ) {
944 url
= '/nodes/' + nodename
+ '/spiceshell' ;
946 PVE
. Utils
. openSpiceViewer ( url
, params
);
947 } else if ( vmtype
=== 'cmd' ) {
948 url
= '/nodes/' + nodename
+ '/spiceshell' ;
950 PVE
. Utils
. openSpiceViewer ( url
, params
);
953 throw "unknown viewer type" ;
957 defaultViewer : function ( consoles
) {
959 var allowSpice
, allowXtermjs
;
961 if ( consoles
=== true ) {
964 } else if ( typeof consoles
=== 'object' ) {
965 allowSpice
= consoles
. spice
;
966 allowXtermjs
= !! consoles
. xtermjs
;
968 var dv
= PVE
. VersionInfo
. console
|| 'xtermjs' ;
969 if ( dv
=== 'vv' && ! allowSpice
) {
970 dv
= ( allowXtermjs
) ? 'xtermjs' : 'html5' ;
971 } else if ( dv
=== 'xtermjs' && ! allowXtermjs
) {
972 dv
= ( allowSpice
) ? 'vv' : 'html5' ;
978 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
980 if ( Proxmox
. Utils
. toolkit
!== 'touch' ) {
981 var sp
= Ext
. state
. Manager
. getProvider ();
982 scaling
= sp
. get ( 'novnc-scaling' , 'off' );
984 var url
= Ext
. Object
. toQueryString ({
985 console
: vmtype
, // kvm, lxc, upgrade or shell
993 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
999 openSpiceViewer : function ( url
, params
){
1001 var downloadWithName = function ( uri
, name
) {
1002 var link
= Ext
. DomHelper
. append ( document
. body
, {
1005 css
: 'display:none;visibility:hidden;height:0px;'
1008 // Note: we need to tell android the correct file name extension
1009 // but we do not set 'download' tag for other environments, because
1010 // It can have strange side effects (additional user prompt on firefox)
1011 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1013 link
. download
= name
;
1016 if ( link
. fireEvent
) {
1017 link
. fireEvent ( 'onclick' );
1019 var evt
= document
. createEvent ( "MouseEvents" );
1020 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1021 link
. dispatchEvent ( evt
);
1025 Proxmox
. Utils
. API2Request ({
1029 failure : function ( response
, opts
){
1030 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1032 success : function ( response
, opts
){
1033 var raw
= "[virt-viewer] \n " ;
1034 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1035 raw
+= k
+ "=" + v
+ " \n " ;
1037 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1038 encodeURIComponent ( raw
);
1040 downloadWithName ( url
, "pve-spice.vv" );
1045 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1047 var nodename
= record
. data
. node
;
1048 var vmid
= record
. data
. vmid
;
1049 var vmname
= record
. data
. name
;
1050 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1051 Proxmox
. Utils
. API2Request ({
1052 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1053 failure : function ( response
, opts
) {
1054 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1056 success : function ( response
, opts
) {
1057 let conf
= response
. result
. data
;
1059 spice
: !! conf
. spice
,
1060 xtermjs
: !! conf
. serial
,
1062 PVE
. Utils
. openDefaultConsoleWindow ( consoles
, 'kvm' , vmid
, nodename
, vmname
);
1065 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1066 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1070 // test automation helper
1071 call_menu_handler : function ( menu
, text
) {
1073 var list
= menu
. query ( 'menuitem' );
1075 Ext
. Array
. each ( list
, function ( item
) {
1076 if ( item
. text
=== text
) {
1087 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1089 if (!( v
instanceof Ext
. tree
. View
)) {
1093 var template
= !! record
. data
. template
;
1094 var type
= record
. data
. type
;
1097 if ( type
=== 'qemu' || type
== 'lxc' ) {
1098 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1102 } else if ( type
=== 'qemu' ||
1105 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1107 nodename
: record
. data
. node
1113 menu
. showAt ( event
. getXY ());
1117 // helper for deleting field which are set to there default values
1118 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1119 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1121 if ( values
[ 'delete' ]) {
1122 values
[ 'delete' ] += ',' + fieldname
;
1124 values
[ 'delete' ] = fieldname
;
1128 delete values
[ fieldname
];
1132 loadSSHKeyFromFile : function ( file
, callback
) {
1133 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1134 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1135 // assume: 740*8 for max. 32kbit (5920 byte file)
1136 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1137 if ( file
. size
> 8192 ) {
1138 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1144 var reader
= new FileReader ();
1145 reader
. onload = function ( evt
) {
1146 callback ( evt
. target
. result
);
1148 reader
. readAsText ( file
);
1151 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
1153 // types is either undefined (all busses), an array of busses, or a single bus
1154 forEachBus : function ( types
, func
) {
1155 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
1156 var i
, j
, count
, cont
;
1158 if ( Ext
. isArray ( types
)) {
1160 } else if ( Ext
. isDefined ( types
)) {
1164 // check if we only have valid busses
1165 for ( i
= 0 ; i
< busses
. length
; i
++) {
1166 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
1167 throw "invalid bus: '" + busses
[ i
] + "'" ;
1171 for ( i
= 0 ; i
< busses
. length
; i
++) {
1172 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
1173 for ( j
= 0 ; j
< count
; j
++) {
1174 cont
= func ( busses
[ i
], j
);
1175 if (! cont
&& cont
!== undefined ) {
1182 mp_counts
: { mps
: 256 , unused
: 256 },
1184 forEachMP : function ( func
, includeUnused
) {
1186 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1187 cont
= func ( 'mp' , i
);
1188 if (! cont
&& cont
!== undefined ) {
1193 if (! includeUnused
) {
1197 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1198 cont
= func ( 'unused' , i
);
1199 if (! cont
&& cont
!== undefined ) {
1205 cleanEmptyObjectKeys : function ( obj
) {
1207 for ( propName
in obj
) {
1208 if ( obj
. hasOwnProperty ( propName
)) {
1209 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1210 delete obj
[ propName
];
1216 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1218 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1221 Proxmox
. Utils
. setErrorMask ( me
, false );
1226 if ( operation
. error
. statusText
) {
1227 if ( operation
. error
. statusText
. match ( regex
)) {
1228 callback ( me
, operation
. error
);
1231 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1234 msg
= gettext ( 'Connection error' );
1236 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1240 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1241 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1242 if ( msg
. match ( regex
)) {
1243 if ( Proxmox
. UserName
=== 'root@pam' ) {
1244 container
. el
. mask ();
1245 if (! container
. down ( 'pveCephInstallWindow' )){
1246 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1247 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1250 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1256 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1257 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1265 propertyStringSet : function ( target
, source
, name
, value
) {
1267 if ( value
=== undefined ) {
1268 target
[ name
] = source
;
1270 target
[ name
] = value
;
1273 delete target
[ name
];
1279 constructor : function () {
1281 Ext
. apply ( me
, me
. utilities
);