]>
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-exclamation' ;
90 icon
= 'critical fa-times' ;
104 'HEALTH_WARN' : 'warning' ,
105 'HEALTH_ERR' : 'critical'
108 render_ceph_health : function ( healthObj
) {
110 iconCls
: PVE
. Utils
. get_health_icon (),
114 if (! healthObj
|| ! healthObj
. status
) {
118 var health
= PVE
. Utils
. map_ceph_health
[ healthObj
. status
];
120 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
121 state
. text
= healthObj
. status
;
126 render_zfs_health : function ( value
) {
127 if ( typeof value
== 'undefined' ){
130 var iconCls
= 'question-circle' ;
134 iconCls
= 'check-circle good' ;
138 iconCls
= 'exclamation-circle warning' ;
143 iconCls
= 'times-circle critical' ;
148 return '<i class="fa fa-' + iconCls
+ '"></i> ' + value
;
152 get_kvm_osinfo : function ( value
) {
153 var info
= { base
: 'Other' }; // default
155 Ext
. each ( Object
. keys ( PVE
. Utils
. kvm_ostypes
), function ( k
) {
156 Ext
. each ( PVE
. Utils
. kvm_ostypes
[ k
], function ( e
) {
157 if ( e
. val
=== value
) {
158 info
= { desc
: e
. desc
, base
: k
};
166 render_kvm_ostype : function ( value
) {
167 var osinfo
= PVE
. Utils
. get_kvm_osinfo ( value
);
168 if ( osinfo
. desc
&& osinfo
. desc
!== '-' ) {
169 return osinfo
. base
+ ' ' + osinfo
. desc
;
175 render_hotplug_features : function ( value
) {
178 if (! value
|| ( value
=== '0' )) {
179 return gettext ( 'Disabled' );
183 value
= 'disk,network,usb' ;
186 Ext
. each ( value
. split ( ',' ), function ( el
) {
188 fa
. push ( gettext ( 'Disk' ));
189 } else if ( el
=== 'network' ) {
190 fa
. push ( gettext ( 'Network' ));
191 } else if ( el
=== 'usb' ) {
193 } else if ( el
=== 'memory' ) {
194 fa
. push ( gettext ( 'Memory' ));
195 } else if ( el
=== 'cpu' ) {
196 fa
. push ( gettext ( 'CPU' ));
202 return fa
. join ( ', ' );
205 render_qga_features : function ( value
) {
207 return Proxmox
. Utils
. defaultText
+ ' (' + Proxmox
. Utils
. disabledText
+ ')' ;
209 var props
= PVE
. Parser
. parsePropertyString ( value
, 'enabled' );
210 if (! PVE
. Parser
. parseBoolean ( props
. enabled
)) {
211 return Proxmox
. Utils
. disabledText
;
214 delete props
. enabled
;
215 var agentstring
= Proxmox
. Utils
. enabledText
;
217 Ext
. Object
. each ( props
, function ( key
, value
) {
219 agentstring
+= ', ' + key
+ ': ' ;
221 if ( PVE
. Parser
. parseBoolean ( value
)) {
222 agentstring
+= Proxmox
. Utils
. enabledText
;
224 agentstring
+= Proxmox
. Utils
. disabledText
;
231 render_qemu_bios : function ( value
) {
233 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
234 } else if ( value
=== 'seabios' ) {
236 } else if ( value
=== 'ovmf' ) {
237 return "OVMF (UEFI)" ;
243 render_scsihw : function ( value
) {
245 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
246 } else if ( value
=== 'lsi' ) {
247 return 'LSI 53C895A' ;
248 } else if ( value
=== 'lsi53c810' ) {
250 } else if ( value
=== 'megasas' ) {
251 return 'MegaRAID SAS 8708EM2' ;
252 } else if ( value
=== 'virtio-scsi-pci' ) {
253 return 'VirtIO SCSI' ;
254 } else if ( value
=== 'virtio-scsi-single' ) {
255 return 'VirtIO SCSI single' ;
256 } else if ( value
=== 'pvscsi' ) {
257 return 'VMware PVSCSI' ;
263 // fixme: auto-generate this
264 // for now, please keep in sync with PVE::Tools::kvmkeymaps
269 'de-ch' : 'German (Swiss)' ,
270 'en-gb' : 'English (UK)' ,
271 'en-us' : 'English (USA)' ,
275 //fo: 'Faroe Islands',
277 'fr-be' : 'French (Belgium)' ,
278 'fr-ca' : 'French (Canada)' ,
279 'fr-ch' : 'French (Swiss)' ,
289 //'nl-be': 'Dutch (Belgium)',
293 'pt-br' : 'Portuguese (Brazil)' ,
302 std
: gettext ( 'Standard VGA' ),
303 vmware
: gettext ( 'VMware compatible' ),
305 qxl2
: 'SPICE dual monitor' ,
306 qxl3
: 'SPICE three monitors' ,
307 qxl4
: 'SPICE four monitors' ,
308 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
309 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
310 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
311 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
312 virtio
: 'VirtIO-GPU' ,
313 none
: Proxmox
. Utils
. noneText
316 render_kvm_language : function ( value
) {
317 if (! value
|| value
=== '__default__' ) {
318 return Proxmox
. Utils
. defaultText
;
320 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
322 return text
+ ' (' + value
+ ')' ;
327 kvm_keymap_array : function () {
328 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
329 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
330 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
337 '__default__' : Proxmox
. Utils
. defaultText
+ ' (HTML5)' ,
338 'vv' : 'SPICE (remote-viewer)' ,
339 'html5' : 'HTML5 (noVNC)' ,
340 'xtermjs' : 'xterm.js'
343 render_console_viewer : function ( value
) {
344 value
= value
|| '__default__' ;
345 if ( PVE
. Utils
. console_map
[ value
]) {
346 return PVE
. Utils
. console_map
[ value
];
351 console_viewer_array : function () {
352 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
353 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
357 render_kvm_vga_driver : function ( value
) {
359 return Proxmox
. Utils
. defaultText
;
361 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
362 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
364 text
= Proxmox
. Utils
. defaultText
;
367 return text
+ ' (' + value
+ ')' ;
372 kvm_vga_driver_array : function () {
373 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
374 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
375 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
381 render_kvm_startup : function ( value
) {
382 var startup
= PVE
. Parser
. parseStartup ( value
);
385 if ( startup
. order
=== undefined ) {
388 res
+= startup
. order
;
390 if ( startup
. up
!== undefined ) {
391 res
+= ',up=' + startup
. up
;
393 if ( startup
. down
!== undefined ) {
394 res
+= ',down=' + startup
. down
;
400 extractFormActionError : function ( action
) {
402 switch ( action
. failureType
) {
403 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
404 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
406 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
407 msg
= gettext ( 'Connection error' );
408 var resp
= action
. response
;
409 if ( resp
. status
&& resp
. statusText
) {
410 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
413 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
414 case Ext
. form
. action
. Action
. SERVER_INVALID
:
415 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
421 format_duration_short : function ( ut
) {
424 return ut
. toFixed ( 1 ) + 's' ;
429 return mins
. toFixed ( 1 ) + 'm' ;
433 var hours
= ut
/ 3600 ;
434 return hours
. toFixed ( 1 ) + 'h' ;
437 var days
= ut
/ 86400 ;
438 return days
. toFixed ( 1 ) + 'd' ;
442 'images' : gettext ( 'Disk image' ),
443 'backup' : gettext ( 'VZDump backup file' ),
444 'vztmpl' : gettext ( 'Container template' ),
445 'iso' : gettext ( 'ISO image' ),
446 'rootdir' : gettext ( 'Container' )
451 name
: Proxmox
. Utils
. directoryText
,
452 ipanel
: 'DirInputPanel' ,
457 ipanel
: 'LVMInputPanel' ,
462 ipanel
: 'LvmThinInputPanel' ,
467 ipanel
: 'NFSInputPanel' ,
472 ipanel
: 'CIFSInputPanel' ,
477 ipanel
: 'GlusterFsInputPanel' ,
482 ipanel
: 'IScsiInputPanel' ,
487 ipanel
: 'SheepdogInputPanel' ,
493 ipanel
: 'CephFSInputPanel' ,
497 name
: 'CephFS (PVE)' ,
498 ipanel
: 'CephFSInputPanel' ,
504 ipanel
: 'RBDInputPanel' ,
509 ipanel
: 'RBDInputPanel' ,
514 name
: 'ZFS over iSCSI' ,
515 ipanel
: 'ZFSInputPanel' ,
520 ipanel
: 'ZFSPoolInputPanel' ,
529 format_storage_type : function ( value
, md
, record
) {
530 if ( value
=== 'rbd' ) {
531 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
532 } else if ( value
=== 'cephfs' ) {
533 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
536 var schema
= PVE
. Utils
. storageSchema
[ value
];
540 return Proxmox
. Utils
. unknownText
;
543 format_ha : function ( value
) {
544 var text
= Proxmox
. Utils
. noneText
;
547 text
= value
. state
|| Proxmox
. Utils
. noneText
;
549 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
550 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
556 format_content_types : function ( value
) {
557 return value
. split ( ',' ). sort (). map ( function ( ct
) {
558 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
562 render_storage_content : function ( value
, metaData
, record
) {
563 var data
= record
. data
;
564 if ( Ext
. isNumber ( data
. channel
) &&
565 Ext
. isNumber ( data
. id
) &&
566 Ext
. isNumber ( data
. lun
)) {
568 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
569 " ID " + data
. id
+ " LUN " + data
. lun
;
571 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
574 render_serverity : function ( value
) {
575 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
578 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
580 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
584 var maxcpu
= record
. data
. maxcpu
|| 1 ;
586 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
590 var per
= value
* 100 ;
592 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
595 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
596 /*jslint confusion: true */
598 if (! Ext
. isNumeric ( value
)) {
602 return Proxmox
. Utils
. format_size ( value
);
605 render_bandwidth : function ( value
) {
606 if (! Ext
. isNumeric ( value
)) {
610 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
613 render_timestamp_human_readable : function ( value
) {
614 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
617 render_duration : function ( value
) {
618 if ( value
=== undefined ) {
621 return PVE
. Utils
. format_duration_short ( value
);
624 calculate_mem_usage : function ( data
) {
625 if (! Ext
. isNumeric ( data
. mem
) ||
631 return ( data
. mem
/ data
. maxmem
);
634 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
635 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
639 // we got no percentage but bytes
641 var maxmem
= record
. data
. maxmem
;
642 if (! record
. data
. uptime
||
644 ! Ext
. isNumeric ( mem
)) {
648 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
650 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
653 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
656 var maxmem
= record
. data
. maxmem
;
658 if (! record
. data
. uptime
) {
662 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
666 return PVE
. Utils
. render_size ( value
);
669 calculate_disk_usage : function ( data
) {
671 if (! Ext
. isNumeric ( data
. disk
) ||
672 data
. type
=== 'qemu' ||
673 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
674 data
. maxdisk
=== 0 ) {
678 return ( data
. disk
/ data
. maxdisk
);
681 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
682 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
686 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
689 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
692 var maxdisk
= record
. data
. maxdisk
;
693 var type
= record
. data
. type
;
695 if (! Ext
. isNumeric ( disk
) ||
698 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
702 return PVE
. Utils
. render_size ( value
);
705 get_object_icon_class : function ( type
, record
) {
709 if ( type
=== 'type' ) {
711 objType
= record
. groupbyid
;
712 } else if ( record
. template
) {
714 objType
= 'template' ;
718 status
= record
. status
+ ' ha-' + record
. hastate
;
721 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
722 if ( defaults
&& defaults
. iconCls
) {
723 var retVal
= defaults
. iconCls
+ ' ' + status
;
730 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
732 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
734 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
738 render_support_level : function ( value
, metaData
, record
) {
739 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
742 render_upid : function ( value
, metaData
, record
) {
743 var type
= record
. data
. type
;
744 var id
= record
. data
. id
;
746 return Proxmox
. Utils
. format_task_description ( type
, id
);
749 /* render functions for new status panel */
751 render_usage : function ( val
) {
752 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
755 render_cpu_usage : function ( val
, max
) {
756 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
757 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
760 render_size_usage : function ( val
, max
) {
762 return gettext ( 'N/A' );
764 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
765 Ext
. String
. format ( gettext ( '{0} of {1}' ),
766 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
769 /* this is different for nodes */
770 render_node_cpu_usage : function ( value
, record
) {
771 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
774 /* this is different for nodes */
775 render_node_size_usage : function ( record
) {
776 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
779 render_optional_url : function ( value
) {
781 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
782 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
787 render_san : function ( value
) {
789 if ( Ext
. isArray ( value
)) {
790 value
. forEach ( function ( val
) {
791 if (! Ext
. isNumber ( val
)) {
795 return names
. join ( '<br>' );
800 render_full_name : function ( firstname
, metaData
, record
) {
801 var first
= firstname
|| '' ;
802 var last
= record
. data
. lastname
|| '' ;
803 return Ext
. htmlEncode ( first
+ " " + last
);
806 windowHostname : function () {
807 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
808 function ( m
, addr
, offset
, original
) { return addr
; });
811 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
) {
812 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
813 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
816 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
817 // kvm, lxc, shell, upgrade
819 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
820 throw "missing vmid" ;
824 throw "no nodename specified" ;
827 if ( viewer
=== 'html5' ) {
828 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
829 } else if ( viewer
=== 'xtermjs' ) {
830 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
);
831 } else if ( viewer
=== 'vv' ) {
833 var params
= { proxy
: PVE
. Utils
. windowHostname () };
834 if ( vmtype
=== 'kvm' ) {
835 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
836 PVE
. Utils
. openSpiceViewer ( url
, params
);
837 } else if ( vmtype
=== 'lxc' ) {
838 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
839 PVE
. Utils
. openSpiceViewer ( url
, params
);
840 } else if ( vmtype
=== 'shell' ) {
841 url
= '/nodes/' + nodename
+ '/spiceshell' ;
842 PVE
. Utils
. openSpiceViewer ( url
, params
);
843 } else if ( vmtype
=== 'upgrade' ) {
844 url
= '/nodes/' + nodename
+ '/spiceshell' ;
846 PVE
. Utils
. openSpiceViewer ( url
, params
);
849 throw "unknown viewer type" ;
853 defaultViewer : function ( consoles
) {
855 var allowSpice
, allowXtermjs
;
857 if ( consoles
=== true ) {
860 } else if ( typeof consoles
=== 'object' ) {
861 allowSpice
= consoles
. spice
;
862 allowXtermjs
= !! consoles
. xtermjs
;
864 var vncdefault
= 'html5' ;
865 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
866 if (( dv
=== 'vv' && ! allowSpice
) || ( dv
=== 'xtermjs' && ! allowXtermjs
)) {
873 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
874 var url
= Ext
. urlEncode ({
875 console
: vmtype
, // kvm, lxc, upgrade or shell
882 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
886 openSpiceViewer : function ( url
, params
){
888 var downloadWithName = function ( uri
, name
) {
889 var link
= Ext
. DomHelper
. append ( document
. body
, {
892 css
: 'display:none;visibility:hidden;height:0px;'
895 // Note: we need to tell android the correct file name extension
896 // but we do not set 'download' tag for other environments, because
897 // It can have strange side effects (additional user prompt on firefox)
898 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
900 link
. download
= name
;
903 if ( link
. fireEvent
) {
904 link
. fireEvent ( 'onclick' );
906 var evt
= document
. createEvent ( "MouseEvents" );
907 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
908 link
. dispatchEvent ( evt
);
912 Proxmox
. Utils
. API2Request ({
916 failure : function ( response
, opts
){
917 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
919 success : function ( response
, opts
){
920 var raw
= "[virt-viewer] \n " ;
921 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
922 raw
+= k
+ "=" + v
+ " \n " ;
924 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
925 encodeURIComponent ( raw
);
927 downloadWithName ( url
, "pve-spice.vv" );
932 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
934 var nodename
= record
. data
. node
;
935 var vmid
= record
. data
. vmid
;
936 var vmname
= record
. data
. name
;
937 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
938 Proxmox
. Utils
. API2Request ({
939 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
940 failure : function ( response
, opts
) {
941 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
943 success : function ( response
, opts
) {
944 var allowSpice
= !! response
. result
. data
. spice
;
945 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
948 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
949 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
953 // test automation helper
954 call_menu_handler : function ( menu
, text
) {
956 var list
= menu
. query ( 'menuitem' );
958 Ext
. Array
. each ( list
, function ( item
) {
959 if ( item
. text
=== text
) {
970 createCmdMenu : function ( v
, record
, item
, index
, event
) {
972 if (!( v
instanceof Ext
. tree
. View
)) {
976 var template
= !! record
. data
. template
;
977 var type
= record
. data
. type
;
980 if ( type
=== 'qemu' || type
== 'lxc' ) {
981 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
985 } else if ( type
=== 'qemu' ||
988 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
990 nodename
: record
. data
. node
996 menu
. showAt ( event
. getXY ());
999 // helper for deleting field which are set to there default values
1000 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1001 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1003 if ( values
[ 'delete' ]) {
1004 values
[ 'delete' ] += ',' + fieldname
;
1006 values
[ 'delete' ] = fieldname
;
1010 delete values
[ fieldname
];
1014 loadSSHKeyFromFile : function ( file
, callback
) {
1015 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1016 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1017 // assume: 740*8 for max. 32kbit (5920 byte file)
1018 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1019 if ( file
. size
> 8192 ) {
1020 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1026 var reader
= new FileReader ();
1027 reader
. onload = function ( evt
) {
1028 callback ( evt
. target
. result
);
1030 reader
. readAsText ( file
);
1033 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
1035 // types is either undefined (all busses), an array of busses, or a single bus
1036 forEachBus : function ( types
, func
) {
1037 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
1038 var i
, j
, count
, cont
;
1040 if ( Ext
. isArray ( types
)) {
1042 } else if ( Ext
. isDefined ( types
)) {
1046 // check if we only have valid busses
1047 for ( i
= 0 ; i
< busses
. length
; i
++) {
1048 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
1049 throw "invalid bus: '" + busses
[ i
] + "'" ;
1053 for ( i
= 0 ; i
< busses
. length
; i
++) {
1054 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
1055 for ( j
= 0 ; j
< count
; j
++) {
1056 cont
= func ( busses
[ i
], j
);
1057 if (! cont
&& cont
!== undefined ) {
1064 mp_counts
: { mps
: 256 , unused
: 256 },
1066 forEachMP : function ( func
, includeUnused
) {
1068 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1069 cont
= func ( 'mp' , i
);
1070 if (! cont
&& cont
!== undefined ) {
1075 if (! includeUnused
) {
1079 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1080 cont
= func ( 'unused' , i
);
1081 if (! cont
&& cont
!== undefined ) {
1089 constructor : function () {
1091 Ext
. apply ( me
, me
. utilities
);