]>
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="http://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.' ,
53 { desc
: '4.X/3.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-refresh' ;
90 icon
= 'warning fa-exclamation' ;
93 icon
= 'critical fa-times' ;
105 parse_ceph_version : function ( service
) {
106 if ( service
. ceph_version_short
) {
107 return service
. ceph_version_short
;
110 if ( service
. ceph_version
) {
111 var match
= service
. ceph_version
. match ( /version (\d+\.\d+\.\d+)/ );
120 get_ceph_icon_html : function ( health
, fw
) {
121 var state
= PVE
. Utils
. map_ceph_health
[ health
];
122 var cls
= PVE
. Utils
. get_health_icon ( state
);
126 return "<i class='fa " + cls
+ "'></i> " ;
132 'HEALTH_WARN' : 'warning' ,
133 'HEALTH_ERR' : 'critical'
136 render_ceph_health : function ( healthObj
) {
138 iconCls
: PVE
. Utils
. get_health_icon (),
142 if (! healthObj
|| ! healthObj
. status
) {
146 var health
= PVE
. Utils
. map_ceph_health
[ healthObj
. status
];
148 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
149 state
. text
= healthObj
. status
;
154 render_zfs_health : function ( value
) {
155 if ( typeof value
== 'undefined' ){
158 var iconCls
= 'question-circle' ;
162 iconCls
= 'check-circle good' ;
166 iconCls
= 'exclamation-circle warning' ;
171 iconCls
= 'times-circle critical' ;
176 return '<i class="fa fa-' + iconCls
+ '"></i> ' + value
;
180 get_kvm_osinfo : function ( value
) {
181 var info
= { base
: 'Other' }; // default
183 Ext
. each ( Object
. keys ( PVE
. Utils
. kvm_ostypes
), function ( k
) {
184 Ext
. each ( PVE
. Utils
. kvm_ostypes
[ k
], function ( e
) {
185 if ( e
. val
=== value
) {
186 info
= { desc
: e
. desc
, base
: k
};
194 render_kvm_ostype : function ( value
) {
195 var osinfo
= PVE
. Utils
. get_kvm_osinfo ( value
);
196 if ( osinfo
. desc
&& osinfo
. desc
!== '-' ) {
197 return osinfo
. base
+ ' ' + osinfo
. desc
;
203 render_hotplug_features : function ( value
) {
206 if (! value
|| ( value
=== '0' )) {
207 return gettext ( 'Disabled' );
211 value
= 'disk,network,usb' ;
214 Ext
. each ( value
. split ( ',' ), function ( el
) {
216 fa
. push ( gettext ( 'Disk' ));
217 } else if ( el
=== 'network' ) {
218 fa
. push ( gettext ( 'Network' ));
219 } else if ( el
=== 'usb' ) {
221 } else if ( el
=== 'memory' ) {
222 fa
. push ( gettext ( 'Memory' ));
223 } else if ( el
=== 'cpu' ) {
224 fa
. push ( gettext ( 'CPU' ));
230 return fa
. join ( ', ' );
233 render_qga_features : function ( value
) {
235 return Proxmox
. Utils
. defaultText
+ ' (' + Proxmox
. Utils
. disabledText
+ ')' ;
237 var props
= PVE
. Parser
. parsePropertyString ( value
, 'enabled' );
238 if (! PVE
. Parser
. parseBoolean ( props
. enabled
)) {
239 return Proxmox
. Utils
. disabledText
;
242 delete props
. enabled
;
243 var agentstring
= Proxmox
. Utils
. enabledText
;
245 Ext
. Object
. each ( props
, function ( key
, value
) {
247 agentstring
+= ', ' + key
+ ': ' ;
249 if ( PVE
. Parser
. parseBoolean ( value
)) {
250 agentstring
+= Proxmox
. Utils
. enabledText
;
252 agentstring
+= Proxmox
. Utils
. disabledText
;
259 render_qemu_machine : function ( value
) {
260 return value
|| ( Proxmox
. Utils
. defaultText
+ ' (i440fx)' );
263 render_qemu_bios : function ( value
) {
265 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
266 } else if ( value
=== 'seabios' ) {
268 } else if ( value
=== 'ovmf' ) {
269 return "OVMF (UEFI)" ;
275 render_dc_ha_opts : function ( value
) {
277 return Proxmox
. Utils
. defaultText
;
279 return PVE
. Parser
. printPropertyString ( value
);
282 render_as_property_string : function ( value
) {
283 return (! value
) ? Proxmox
. Utils
. defaultText
284 : PVE
. Parser
. printPropertyString ( value
);
287 render_scsihw : function ( value
) {
289 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
290 } else if ( value
=== 'lsi' ) {
291 return 'LSI 53C895A' ;
292 } else if ( value
=== 'lsi53c810' ) {
294 } else if ( value
=== 'megasas' ) {
295 return 'MegaRAID SAS 8708EM2' ;
296 } else if ( value
=== 'virtio-scsi-pci' ) {
297 return 'VirtIO SCSI' ;
298 } else if ( value
=== 'virtio-scsi-single' ) {
299 return 'VirtIO SCSI single' ;
300 } else if ( value
=== 'pvscsi' ) {
301 return 'VMware PVSCSI' ;
307 // fixme: auto-generate this
308 // for now, please keep in sync with PVE::Tools::kvmkeymaps
313 'de-ch' : 'German (Swiss)' ,
314 'en-gb' : 'English (UK)' ,
315 'en-us' : 'English (USA)' ,
319 //fo: 'Faroe Islands',
321 'fr-be' : 'French (Belgium)' ,
322 'fr-ca' : 'French (Canada)' ,
323 'fr-ch' : 'French (Swiss)' ,
333 //'nl-be': 'Dutch (Belgium)',
337 'pt-br' : 'Portuguese (Brazil)' ,
346 std
: gettext ( 'Standard VGA' ),
347 vmware
: gettext ( 'VMware compatible' ),
349 qxl2
: 'SPICE dual monitor' ,
350 qxl3
: 'SPICE three monitors' ,
351 qxl4
: 'SPICE four monitors' ,
352 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
353 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
354 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
355 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
356 virtio
: 'VirtIO-GPU' ,
357 none
: Proxmox
. Utils
. noneText
360 render_kvm_language : function ( value
) {
361 if (! value
|| value
=== '__default__' ) {
362 return Proxmox
. Utils
. defaultText
;
364 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
366 return text
+ ' (' + value
+ ')' ;
371 kvm_keymap_array : function () {
372 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
373 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
374 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
381 '__default__' : Proxmox
. Utils
. defaultText
+ ' (HTML5)' ,
382 'vv' : 'SPICE (remote-viewer)' ,
383 'html5' : 'HTML5 (noVNC)' ,
384 'xtermjs' : 'xterm.js'
387 render_console_viewer : function ( value
) {
388 value
= value
|| '__default__' ;
389 if ( PVE
. Utils
. console_map
[ value
]) {
390 return PVE
. Utils
. console_map
[ value
];
395 console_viewer_array : function () {
396 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
397 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
401 render_kvm_vga_driver : function ( value
) {
403 return Proxmox
. Utils
. defaultText
;
405 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
406 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
408 text
= Proxmox
. Utils
. defaultText
;
411 return text
+ ' (' + value
+ ')' ;
416 kvm_vga_driver_array : function () {
417 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
418 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
419 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
425 render_kvm_startup : function ( value
) {
426 var startup
= PVE
. Parser
. parseStartup ( value
);
429 if ( startup
. order
=== undefined ) {
432 res
+= startup
. order
;
434 if ( startup
. up
!== undefined ) {
435 res
+= ',up=' + startup
. up
;
437 if ( startup
. down
!== undefined ) {
438 res
+= ',down=' + startup
. down
;
444 extractFormActionError : function ( action
) {
446 switch ( action
. failureType
) {
447 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
448 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
450 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
451 msg
= gettext ( 'Connection error' );
452 var resp
= action
. response
;
453 if ( resp
. status
&& resp
. statusText
) {
454 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
457 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
458 case Ext
. form
. action
. Action
. SERVER_INVALID
:
459 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
465 format_duration_short : function ( ut
) {
468 return ut
. toFixed ( 1 ) + 's' ;
473 return mins
. toFixed ( 1 ) + 'm' ;
477 var hours
= ut
/ 3600 ;
478 return hours
. toFixed ( 1 ) + 'h' ;
481 var days
= ut
/ 86400 ;
482 return days
. toFixed ( 1 ) + 'd' ;
486 'images' : gettext ( 'Disk image' ),
487 'backup' : gettext ( 'VZDump backup file' ),
488 'vztmpl' : gettext ( 'Container template' ),
489 'iso' : gettext ( 'ISO image' ),
490 'rootdir' : gettext ( 'Container' ),
491 'snippets' : gettext ( 'Snippets' )
496 name
: Proxmox
. Utils
. directoryText
,
497 ipanel
: 'DirInputPanel' ,
502 ipanel
: 'LVMInputPanel' ,
507 ipanel
: 'LvmThinInputPanel' ,
512 ipanel
: 'NFSInputPanel' ,
517 ipanel
: 'CIFSInputPanel' ,
522 ipanel
: 'GlusterFsInputPanel' ,
527 ipanel
: 'IScsiInputPanel' ,
532 ipanel
: 'SheepdogInputPanel' ,
538 ipanel
: 'CephFSInputPanel' ,
542 name
: 'CephFS (PVE)' ,
543 ipanel
: 'CephFSInputPanel' ,
549 ipanel
: 'RBDInputPanel' ,
554 ipanel
: 'RBDInputPanel' ,
559 name
: 'ZFS over iSCSI' ,
560 ipanel
: 'ZFSInputPanel' ,
565 ipanel
: 'ZFSPoolInputPanel' ,
574 format_storage_type : function ( value
, md
, record
) {
575 if ( value
=== 'rbd' ) {
576 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
577 } else if ( value
=== 'cephfs' ) {
578 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
581 var schema
= PVE
. Utils
. storageSchema
[ value
];
585 return Proxmox
. Utils
. unknownText
;
588 format_ha : function ( value
) {
589 var text
= Proxmox
. Utils
. noneText
;
592 text
= value
. state
|| Proxmox
. Utils
. noneText
;
594 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
595 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
601 format_content_types : function ( value
) {
602 return value
. split ( ',' ). sort (). map ( function ( ct
) {
603 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
607 render_storage_content : function ( value
, metaData
, record
) {
608 var data
= record
. data
;
609 if ( Ext
. isNumber ( data
. channel
) &&
610 Ext
. isNumber ( data
. id
) &&
611 Ext
. isNumber ( data
. lun
)) {
613 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
614 " ID " + data
. id
+ " LUN " + data
. lun
;
616 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
619 render_serverity : function ( value
) {
620 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
623 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
625 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
629 var maxcpu
= record
. data
. maxcpu
|| 1 ;
631 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
635 var per
= value
* 100 ;
637 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
640 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
641 /*jslint confusion: true */
643 if (! Ext
. isNumeric ( value
)) {
647 return Proxmox
. Utils
. format_size ( value
);
650 render_bandwidth : function ( value
) {
651 if (! Ext
. isNumeric ( value
)) {
655 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
658 render_timestamp_human_readable : function ( value
) {
659 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
662 render_duration : function ( value
) {
663 if ( value
=== undefined ) {
666 return PVE
. Utils
. format_duration_short ( value
);
669 calculate_mem_usage : function ( data
) {
670 if (! Ext
. isNumeric ( data
. mem
) ||
676 return ( data
. mem
/ data
. maxmem
);
679 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
680 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
684 // we got no percentage but bytes
686 var maxmem
= record
. data
. maxmem
;
687 if (! record
. data
. uptime
||
689 ! Ext
. isNumeric ( mem
)) {
693 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
695 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
698 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
701 var maxmem
= record
. data
. maxmem
;
703 if (! record
. data
. uptime
) {
707 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
711 return PVE
. Utils
. render_size ( value
);
714 calculate_disk_usage : function ( data
) {
716 if (! Ext
. isNumeric ( data
. disk
) ||
717 data
. type
=== 'qemu' ||
718 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
719 data
. maxdisk
=== 0 ) {
723 return ( data
. disk
/ data
. maxdisk
);
726 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
727 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
731 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
734 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
737 var maxdisk
= record
. data
. maxdisk
;
738 var type
= record
. data
. type
;
740 if (! Ext
. isNumeric ( disk
) ||
743 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
747 return PVE
. Utils
. render_size ( value
);
750 get_object_icon_class : function ( type
, record
) {
754 if ( type
=== 'type' ) {
756 objType
= record
. groupbyid
;
757 } else if ( record
. template
) {
759 objType
= 'template' ;
763 status
= record
. status
+ ' ha-' + record
. hastate
;
766 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
767 if ( defaults
&& defaults
. iconCls
) {
768 var retVal
= defaults
. iconCls
+ ' ' + status
;
775 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
777 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
779 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
783 render_support_level : function ( value
, metaData
, record
) {
784 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
787 render_upid : function ( value
, metaData
, record
) {
788 var type
= record
. data
. type
;
789 var id
= record
. data
. id
;
791 return Proxmox
. Utils
. format_task_description ( type
, id
);
794 /* render functions for new status panel */
796 render_usage : function ( val
) {
797 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
800 render_cpu_usage : function ( val
, max
) {
801 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
802 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
805 render_size_usage : function ( val
, max
) {
807 return gettext ( 'N/A' );
809 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
810 Ext
. String
. format ( gettext ( '{0} of {1}' ),
811 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
814 /* this is different for nodes */
815 render_node_cpu_usage : function ( value
, record
) {
816 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
819 /* this is different for nodes */
820 render_node_size_usage : function ( record
) {
821 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
824 render_optional_url : function ( value
) {
826 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
827 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
832 render_san : function ( value
) {
834 if ( Ext
. isArray ( value
)) {
835 value
. forEach ( function ( val
) {
836 if (! Ext
. isNumber ( val
)) {
840 return names
. join ( '<br>' );
845 render_full_name : function ( firstname
, metaData
, record
) {
846 var first
= firstname
|| '' ;
847 var last
= record
. data
. lastname
|| '' ;
848 return Ext
. htmlEncode ( first
+ " " + last
);
851 render_u2f_error : function ( error
) {
853 '1' : gettext ( 'Other Error' ),
854 '2' : gettext ( 'Bad Request' ),
855 '3' : gettext ( 'Configuration Unsupported' ),
856 '4' : gettext ( 'Device Ineligible' ),
857 '5' : gettext ( 'Timeout' )
859 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
862 windowHostname : function () {
863 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
864 function ( m
, addr
, offset
, original
) { return addr
; });
867 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
868 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
869 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
, cmd
);
872 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
873 // kvm, lxc, shell, upgrade
875 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
876 throw "missing vmid" ;
880 throw "no nodename specified" ;
883 if ( viewer
=== 'html5' ) {
884 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
885 } else if ( viewer
=== 'xtermjs' ) {
886 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
887 } else if ( viewer
=== 'vv' ) {
889 var params
= { proxy
: PVE
. Utils
. windowHostname () };
890 if ( vmtype
=== 'kvm' ) {
891 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
892 PVE
. Utils
. openSpiceViewer ( url
, params
);
893 } else if ( vmtype
=== 'lxc' ) {
894 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
895 PVE
. Utils
. openSpiceViewer ( url
, params
);
896 } else if ( vmtype
=== 'shell' ) {
897 url
= '/nodes/' + nodename
+ '/spiceshell' ;
898 PVE
. Utils
. openSpiceViewer ( url
, params
);
899 } else if ( vmtype
=== 'upgrade' ) {
900 url
= '/nodes/' + nodename
+ '/spiceshell' ;
902 PVE
. Utils
. openSpiceViewer ( url
, params
);
903 } else if ( vmtype
=== 'cmd' ) {
904 url
= '/nodes/' + nodename
+ '/spiceshell' ;
906 PVE
. Utils
. openSpiceViewer ( url
, params
);
909 throw "unknown viewer type" ;
913 defaultViewer : function ( consoles
) {
915 var allowSpice
, allowXtermjs
;
917 if ( consoles
=== true ) {
920 } else if ( typeof consoles
=== 'object' ) {
921 allowSpice
= consoles
. spice
;
922 allowXtermjs
= !! consoles
. xtermjs
;
924 var vncdefault
= 'html5' ;
925 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
926 if (( dv
=== 'vv' && ! allowSpice
) || ( dv
=== 'xtermjs' && ! allowXtermjs
)) {
933 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
934 var url
= Ext
. Object
. toQueryString ({
935 console
: vmtype
, // kvm, lxc, upgrade or shell
943 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
949 openSpiceViewer : function ( url
, params
){
951 var downloadWithName = function ( uri
, name
) {
952 var link
= Ext
. DomHelper
. append ( document
. body
, {
955 css
: 'display:none;visibility:hidden;height:0px;'
958 // Note: we need to tell android the correct file name extension
959 // but we do not set 'download' tag for other environments, because
960 // It can have strange side effects (additional user prompt on firefox)
961 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
963 link
. download
= name
;
966 if ( link
. fireEvent
) {
967 link
. fireEvent ( 'onclick' );
969 var evt
= document
. createEvent ( "MouseEvents" );
970 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
971 link
. dispatchEvent ( evt
);
975 Proxmox
. Utils
. API2Request ({
979 failure : function ( response
, opts
){
980 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
982 success : function ( response
, opts
){
983 var raw
= "[virt-viewer] \n " ;
984 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
985 raw
+= k
+ "=" + v
+ " \n " ;
987 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
988 encodeURIComponent ( raw
);
990 downloadWithName ( url
, "pve-spice.vv" );
995 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
997 var nodename
= record
. data
. node
;
998 var vmid
= record
. data
. vmid
;
999 var vmname
= record
. data
. name
;
1000 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1001 Proxmox
. Utils
. API2Request ({
1002 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1003 failure : function ( response
, opts
) {
1004 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1006 success : function ( response
, opts
) {
1007 var allowSpice
= !! response
. result
. data
. spice
;
1008 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
1011 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1012 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1016 // test automation helper
1017 call_menu_handler : function ( menu
, text
) {
1019 var list
= menu
. query ( 'menuitem' );
1021 Ext
. Array
. each ( list
, function ( item
) {
1022 if ( item
. text
=== text
) {
1033 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1035 if (!( v
instanceof Ext
. tree
. View
)) {
1039 var template
= !! record
. data
. template
;
1040 var type
= record
. data
. type
;
1043 if ( type
=== 'qemu' || type
== 'lxc' ) {
1044 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1048 } else if ( type
=== 'qemu' ||
1051 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1053 nodename
: record
. data
. node
1059 menu
. showAt ( event
. getXY ());
1063 // helper for deleting field which are set to there default values
1064 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1065 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1067 if ( values
[ 'delete' ]) {
1068 values
[ 'delete' ] += ',' + fieldname
;
1070 values
[ 'delete' ] = fieldname
;
1074 delete values
[ fieldname
];
1078 loadSSHKeyFromFile : function ( file
, callback
) {
1079 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1080 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1081 // assume: 740*8 for max. 32kbit (5920 byte file)
1082 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1083 if ( file
. size
> 8192 ) {
1084 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1090 var reader
= new FileReader ();
1091 reader
. onload = function ( evt
) {
1092 callback ( evt
. target
. result
);
1094 reader
. readAsText ( file
);
1097 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
1099 // types is either undefined (all busses), an array of busses, or a single bus
1100 forEachBus : function ( types
, func
) {
1101 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
1102 var i
, j
, count
, cont
;
1104 if ( Ext
. isArray ( types
)) {
1106 } else if ( Ext
. isDefined ( types
)) {
1110 // check if we only have valid busses
1111 for ( i
= 0 ; i
< busses
. length
; i
++) {
1112 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
1113 throw "invalid bus: '" + busses
[ i
] + "'" ;
1117 for ( i
= 0 ; i
< busses
. length
; i
++) {
1118 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
1119 for ( j
= 0 ; j
< count
; j
++) {
1120 cont
= func ( busses
[ i
], j
);
1121 if (! cont
&& cont
!== undefined ) {
1128 mp_counts
: { mps
: 256 , unused
: 256 },
1130 forEachMP : function ( func
, includeUnused
) {
1132 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1133 cont
= func ( 'mp' , i
);
1134 if (! cont
&& cont
!== undefined ) {
1139 if (! includeUnused
) {
1143 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1144 cont
= func ( 'unused' , i
);
1145 if (! cont
&& cont
!== undefined ) {
1151 cleanEmptyObjectKeys : function ( obj
) {
1153 for ( propName
in obj
) {
1154 if ( obj
. hasOwnProperty ( propName
)) {
1155 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1156 delete obj
[ propName
];
1162 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1164 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1167 Proxmox
. Utils
. setErrorMask ( me
, false );
1172 if ( operation
. error
. statusText
) {
1173 if ( operation
. error
. statusText
. match ( regex
)) {
1174 callback ( me
, operation
. error
);
1177 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1180 msg
= gettext ( 'Connection error' );
1182 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1186 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1187 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1188 if ( msg
. match ( regex
)) {
1189 if ( Proxmox
. UserName
=== 'root@pam' ) {
1190 container
. el
. mask ();
1191 if (! container
. down ( 'pveCephInstallWindow' )){
1192 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1193 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1196 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1202 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1203 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1213 constructor : function () {
1215 Ext
. apply ( me
, me
. utilities
);