]>
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' , 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 // fixme: auto-generate this
338 // for now, please keep in sync with PVE::Tools::kvmkeymaps
343 'de-ch' : 'German (Swiss)' ,
344 'en-gb' : 'English (UK)' ,
345 'en-us' : 'English (USA)' ,
349 //fo: 'Faroe Islands',
351 'fr-be' : 'French (Belgium)' ,
352 'fr-ca' : 'French (Canada)' ,
353 'fr-ch' : 'French (Swiss)' ,
363 //'nl-be': 'Dutch (Belgium)',
367 'pt-br' : 'Portuguese (Brazil)' ,
376 std
: gettext ( 'Standard VGA' ),
377 vmware
: gettext ( 'VMware compatible' ),
379 qxl2
: 'SPICE dual monitor' ,
380 qxl3
: 'SPICE three monitors' ,
381 qxl4
: 'SPICE four monitors' ,
382 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
383 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
384 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
385 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
386 virtio
: 'VirtIO-GPU' ,
387 none
: Proxmox
. Utils
. noneText
390 render_kvm_language : function ( value
) {
391 if (! value
|| value
=== '__default__' ) {
392 return Proxmox
. Utils
. defaultText
;
394 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
396 return text
+ ' (' + value
+ ')' ;
401 kvm_keymap_array : function () {
402 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
403 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
404 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
411 '__default__' : Proxmox
. Utils
. defaultText
+ ' (xterm.js)' ,
412 'vv' : 'SPICE (remote-viewer)' ,
413 'html5' : 'HTML5 (noVNC)' ,
414 'xtermjs' : 'xterm.js'
417 render_console_viewer : function ( value
) {
418 value
= value
|| '__default__' ;
419 if ( PVE
. Utils
. console_map
[ value
]) {
420 return PVE
. Utils
. console_map
[ value
];
425 console_viewer_array : function () {
426 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
427 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
431 render_kvm_vga_driver : function ( value
) {
433 return Proxmox
. Utils
. defaultText
;
435 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
436 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
438 text
= Proxmox
. Utils
. defaultText
;
441 return text
+ ' (' + value
+ ')' ;
446 kvm_vga_driver_array : function () {
447 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
448 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
449 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
455 render_kvm_startup : function ( value
) {
456 var startup
= PVE
. Parser
. parseStartup ( value
);
459 if ( startup
. order
=== undefined ) {
462 res
+= startup
. order
;
464 if ( startup
. up
!== undefined ) {
465 res
+= ',up=' + startup
. up
;
467 if ( startup
. down
!== undefined ) {
468 res
+= ',down=' + startup
. down
;
474 extractFormActionError : function ( action
) {
476 switch ( action
. failureType
) {
477 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
478 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
480 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
481 msg
= gettext ( 'Connection error' );
482 var resp
= action
. response
;
483 if ( resp
. status
&& resp
. statusText
) {
484 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
487 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
488 case Ext
. form
. action
. Action
. SERVER_INVALID
:
489 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
495 format_duration_short : function ( ut
) {
498 return ut
. toFixed ( 1 ) + 's' ;
503 return mins
. toFixed ( 1 ) + 'm' ;
507 var hours
= ut
/ 3600 ;
508 return hours
. toFixed ( 1 ) + 'h' ;
511 var days
= ut
/ 86400 ;
512 return days
. toFixed ( 1 ) + 'd' ;
516 'images' : gettext ( 'Disk image' ),
517 'backup' : gettext ( 'VZDump backup file' ),
518 'vztmpl' : gettext ( 'Container template' ),
519 'iso' : gettext ( 'ISO image' ),
520 'rootdir' : gettext ( 'Container' ),
521 'snippets' : gettext ( 'Snippets' )
526 name
: Proxmox
. Utils
. directoryText
,
527 ipanel
: 'DirInputPanel' ,
532 ipanel
: 'LVMInputPanel' ,
537 ipanel
: 'LvmThinInputPanel' ,
542 ipanel
: 'NFSInputPanel' ,
547 ipanel
: 'CIFSInputPanel' ,
552 ipanel
: 'GlusterFsInputPanel' ,
557 ipanel
: 'IScsiInputPanel' ,
562 ipanel
: 'CephFSInputPanel' ,
566 name
: 'CephFS (PVE)' ,
567 ipanel
: 'CephFSInputPanel' ,
573 ipanel
: 'RBDInputPanel' ,
578 ipanel
: 'RBDInputPanel' ,
583 name
: 'ZFS over iSCSI' ,
584 ipanel
: 'ZFSInputPanel' ,
589 ipanel
: 'ZFSPoolInputPanel' ,
598 format_storage_type : function ( value
, md
, record
) {
599 if ( value
=== 'rbd' ) {
600 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
601 } else if ( value
=== 'cephfs' ) {
602 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
605 var schema
= PVE
. Utils
. storageSchema
[ value
];
609 return Proxmox
. Utils
. unknownText
;
612 format_ha : function ( value
) {
613 var text
= Proxmox
. Utils
. noneText
;
616 text
= value
. state
|| Proxmox
. Utils
. noneText
;
618 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
619 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
625 format_content_types : function ( value
) {
626 return value
. split ( ',' ). sort (). map ( function ( ct
) {
627 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
631 render_storage_content : function ( value
, metaData
, record
) {
632 var data
= record
. data
;
633 if ( Ext
. isNumber ( data
. channel
) &&
634 Ext
. isNumber ( data
. id
) &&
635 Ext
. isNumber ( data
. lun
)) {
637 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
638 " ID " + data
. id
+ " LUN " + data
. lun
;
640 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
643 render_serverity : function ( value
) {
644 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
647 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
649 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
653 var maxcpu
= record
. data
. maxcpu
|| 1 ;
655 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
659 var per
= value
* 100 ;
661 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
664 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
665 /*jslint confusion: true */
667 if (! Ext
. isNumeric ( value
)) {
671 return Proxmox
. Utils
. format_size ( value
);
674 render_bandwidth : function ( value
) {
675 if (! Ext
. isNumeric ( value
)) {
679 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
682 render_timestamp_human_readable : function ( value
) {
683 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
686 render_duration : function ( value
) {
687 if ( value
=== undefined ) {
690 return PVE
. Utils
. format_duration_short ( value
);
693 calculate_mem_usage : function ( data
) {
694 if (! Ext
. isNumeric ( data
. mem
) ||
700 return ( data
. mem
/ data
. maxmem
);
703 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
704 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
708 // we got no percentage but bytes
710 var maxmem
= record
. data
. maxmem
;
711 if (! record
. data
. uptime
||
713 ! Ext
. isNumeric ( mem
)) {
717 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
719 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
722 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
725 var maxmem
= record
. data
. maxmem
;
727 if (! record
. data
. uptime
) {
731 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
735 return PVE
. Utils
. render_size ( value
);
738 calculate_disk_usage : function ( data
) {
740 if (! Ext
. isNumeric ( data
. disk
) ||
741 data
. type
=== 'qemu' ||
742 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
743 data
. maxdisk
=== 0 ) {
747 return ( data
. disk
/ data
. maxdisk
);
750 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
751 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
755 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
758 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
761 var maxdisk
= record
. data
. maxdisk
;
762 var type
= record
. data
. type
;
764 if (! Ext
. isNumeric ( disk
) ||
767 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
771 return PVE
. Utils
. render_size ( value
);
774 get_object_icon_class : function ( type
, record
) {
778 if ( type
=== 'type' ) {
780 objType
= record
. groupbyid
;
781 } else if ( record
. template
) {
783 objType
= 'template' ;
787 status
= record
. status
+ ' ha-' + record
. hastate
;
791 status
+= ' locked lock-' + record
. lock
;
794 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
795 if ( defaults
&& defaults
. iconCls
) {
796 var retVal
= defaults
. iconCls
+ ' ' + status
;
803 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
805 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
807 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
811 render_support_level : function ( value
, metaData
, record
) {
812 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
815 render_upid : function ( value
, metaData
, record
) {
816 var type
= record
. data
. type
;
817 var id
= record
. data
. id
;
819 return Proxmox
. Utils
. format_task_description ( type
, id
);
822 /* render functions for new status panel */
824 render_usage : function ( val
) {
825 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
828 render_cpu_usage : function ( val
, max
) {
829 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
830 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
833 render_size_usage : function ( val
, max
) {
835 return gettext ( 'N/A' );
837 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
838 Ext
. String
. format ( gettext ( '{0} of {1}' ),
839 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
842 /* this is different for nodes */
843 render_node_cpu_usage : function ( value
, record
) {
844 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
847 /* this is different for nodes */
848 render_node_size_usage : function ( record
) {
849 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
852 render_optional_url : function ( value
) {
854 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
855 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
860 render_san : function ( value
) {
862 if ( Ext
. isArray ( value
)) {
863 value
. forEach ( function ( val
) {
864 if (! Ext
. isNumber ( val
)) {
868 return names
. join ( '<br>' );
873 render_full_name : function ( firstname
, metaData
, record
) {
874 var first
= firstname
|| '' ;
875 var last
= record
. data
. lastname
|| '' ;
876 return Ext
. htmlEncode ( first
+ " " + last
);
879 render_u2f_error : function ( error
) {
881 '1' : gettext ( 'Other Error' ),
882 '2' : gettext ( 'Bad Request' ),
883 '3' : gettext ( 'Configuration Unsupported' ),
884 '4' : gettext ( 'Device Ineligible' ),
885 '5' : gettext ( 'Timeout' )
887 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
890 windowHostname : function () {
891 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
892 function ( m
, addr
, offset
, original
) { return addr
; });
895 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
896 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
897 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
, cmd
);
900 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
901 // kvm, lxc, shell, upgrade
903 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
904 throw "missing vmid" ;
908 throw "no nodename specified" ;
911 if ( viewer
=== 'html5' ) {
912 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
913 } else if ( viewer
=== 'xtermjs' ) {
914 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
915 } else if ( viewer
=== 'vv' ) {
917 var params
= { proxy
: PVE
. Utils
. windowHostname () };
918 if ( vmtype
=== 'kvm' ) {
919 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
920 PVE
. Utils
. openSpiceViewer ( url
, params
);
921 } else if ( vmtype
=== 'lxc' ) {
922 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
923 PVE
. Utils
. openSpiceViewer ( url
, params
);
924 } else if ( vmtype
=== 'shell' ) {
925 url
= '/nodes/' + nodename
+ '/spiceshell' ;
926 PVE
. Utils
. openSpiceViewer ( url
, params
);
927 } else if ( vmtype
=== 'upgrade' ) {
928 url
= '/nodes/' + nodename
+ '/spiceshell' ;
930 PVE
. Utils
. openSpiceViewer ( url
, params
);
931 } else if ( vmtype
=== 'cmd' ) {
932 url
= '/nodes/' + nodename
+ '/spiceshell' ;
934 PVE
. Utils
. openSpiceViewer ( url
, params
);
937 throw "unknown viewer type" ;
941 defaultViewer : function ( consoles
) {
943 var allowSpice
, allowXtermjs
;
945 if ( consoles
=== true ) {
948 } else if ( typeof consoles
=== 'object' ) {
949 allowSpice
= consoles
. spice
;
950 allowXtermjs
= !! consoles
. xtermjs
;
952 var dv
= PVE
. VersionInfo
. console
|| 'xtermjs' ;
953 if ( dv
=== 'vv' && ! allowSpice
) {
954 dv
= ( allowXtermjs
) ? 'xtermjs' : 'html5' ;
955 } else if ( dv
=== 'xtermjs' && ! allowXtermjs
) {
956 dv
= ( allowSpice
) ? 'vv' : 'html5' ;
962 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
963 var url
= Ext
. Object
. toQueryString ({
964 console
: vmtype
, // kvm, lxc, upgrade or shell
972 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
978 openSpiceViewer : function ( url
, params
){
980 var downloadWithName = function ( uri
, name
) {
981 var link
= Ext
. DomHelper
. append ( document
. body
, {
984 css
: 'display:none;visibility:hidden;height:0px;'
987 // Note: we need to tell android the correct file name extension
988 // but we do not set 'download' tag for other environments, because
989 // It can have strange side effects (additional user prompt on firefox)
990 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
992 link
. download
= name
;
995 if ( link
. fireEvent
) {
996 link
. fireEvent ( 'onclick' );
998 var evt
= document
. createEvent ( "MouseEvents" );
999 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1000 link
. dispatchEvent ( evt
);
1004 Proxmox
. Utils
. API2Request ({
1008 failure : function ( response
, opts
){
1009 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1011 success : function ( response
, opts
){
1012 var raw
= "[virt-viewer] \n " ;
1013 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1014 raw
+= k
+ "=" + v
+ " \n " ;
1016 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1017 encodeURIComponent ( raw
);
1019 downloadWithName ( url
, "pve-spice.vv" );
1024 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1026 var nodename
= record
. data
. node
;
1027 var vmid
= record
. data
. vmid
;
1028 var vmname
= record
. data
. name
;
1029 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1030 Proxmox
. Utils
. API2Request ({
1031 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1032 failure : function ( response
, opts
) {
1033 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1035 success : function ( response
, opts
) {
1036 let conf
= response
. result
. data
;
1038 spice
: !! conf
. spice
,
1039 xtermjs
: !! conf
. serial
,
1041 PVE
. Utils
. openDefaultConsoleWindow ( consoles
, 'kvm' , vmid
, nodename
, vmname
);
1044 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1045 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1049 // test automation helper
1050 call_menu_handler : function ( menu
, text
) {
1052 var list
= menu
. query ( 'menuitem' );
1054 Ext
. Array
. each ( list
, function ( item
) {
1055 if ( item
. text
=== text
) {
1066 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1068 if (!( v
instanceof Ext
. tree
. View
)) {
1072 var template
= !! record
. data
. template
;
1073 var type
= record
. data
. type
;
1076 if ( type
=== 'qemu' || type
== 'lxc' ) {
1077 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1081 } else if ( type
=== 'qemu' ||
1084 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1086 nodename
: record
. data
. node
1092 menu
. showAt ( event
. getXY ());
1096 // helper for deleting field which are set to there default values
1097 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1098 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1100 if ( values
[ 'delete' ]) {
1101 values
[ 'delete' ] += ',' + fieldname
;
1103 values
[ 'delete' ] = fieldname
;
1107 delete values
[ fieldname
];
1111 loadSSHKeyFromFile : function ( file
, callback
) {
1112 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1113 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1114 // assume: 740*8 for max. 32kbit (5920 byte file)
1115 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1116 if ( file
. size
> 8192 ) {
1117 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1123 var reader
= new FileReader ();
1124 reader
. onload = function ( evt
) {
1125 callback ( evt
. target
. result
);
1127 reader
. readAsText ( file
);
1130 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
1132 // types is either undefined (all busses), an array of busses, or a single bus
1133 forEachBus : function ( types
, func
) {
1134 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
1135 var i
, j
, count
, cont
;
1137 if ( Ext
. isArray ( types
)) {
1139 } else if ( Ext
. isDefined ( types
)) {
1143 // check if we only have valid busses
1144 for ( i
= 0 ; i
< busses
. length
; i
++) {
1145 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
1146 throw "invalid bus: '" + busses
[ i
] + "'" ;
1150 for ( i
= 0 ; i
< busses
. length
; i
++) {
1151 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
1152 for ( j
= 0 ; j
< count
; j
++) {
1153 cont
= func ( busses
[ i
], j
);
1154 if (! cont
&& cont
!== undefined ) {
1161 mp_counts
: { mps
: 256 , unused
: 256 },
1163 forEachMP : function ( func
, includeUnused
) {
1165 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1166 cont
= func ( 'mp' , i
);
1167 if (! cont
&& cont
!== undefined ) {
1172 if (! includeUnused
) {
1176 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1177 cont
= func ( 'unused' , i
);
1178 if (! cont
&& cont
!== undefined ) {
1184 cleanEmptyObjectKeys : function ( obj
) {
1186 for ( propName
in obj
) {
1187 if ( obj
. hasOwnProperty ( propName
)) {
1188 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1189 delete obj
[ propName
];
1195 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1197 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1200 Proxmox
. Utils
. setErrorMask ( me
, false );
1205 if ( operation
. error
. statusText
) {
1206 if ( operation
. error
. statusText
. match ( regex
)) {
1207 callback ( me
, operation
. error
);
1210 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1213 msg
= gettext ( 'Connection error' );
1215 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1219 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1220 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1221 if ( msg
. match ( regex
)) {
1222 if ( Proxmox
. UserName
=== 'root@pam' ) {
1223 container
. el
. mask ();
1224 if (! container
. down ( 'pveCephInstallWindow' )){
1225 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1226 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1229 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1235 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1236 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1246 constructor : function () {
1248 Ext
. apply ( me
, me
. utilities
);