]>
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 Ext
. define ( 'PVE.Utils' , { utilities
: {
24 // this singleton contains miscellaneous utilities
26 toolkit
: undefined , // (extjs|touch), set inside Toolkit.js
28 bus_match
: /^(ide|sata|virtio|scsi)\d+$/ ,
42 'c' : gettext ( 'Community' ),
43 'b' : gettext ( 'Basic' ),
44 's' : gettext ( 'Standard' ),
45 'p' : gettext ( 'Premium' )
48 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.' ,
52 { desc
: '4.X/3.X/2.6 Kernel' , val
: 'l26' },
53 { desc
: '2.4 Kernel' , val
: 'l24' }
55 'Microsoft Windows' : [
56 { desc
: '10/2016' , val
: 'win10' },
57 { desc
: '8.x/2012/2012r2' , val
: 'win8' },
58 { desc
: '7/2008r2' , val
: 'win7' },
59 { desc
: 'Vista/2008' , val
: 'w2k8' },
60 { desc
: 'XP/2003' , val
: 'wxp' },
61 { desc
: '2000' , val
: 'w2k' }
64 { desc
: '-' , val
: 'solaris' }
67 { desc
: '-' , val
: 'other' }
71 get_health_icon : function ( state
, circle
) {
72 if ( circle
=== undefined ) {
76 if ( state
=== undefined ) {
80 var icon
= 'faded fa-question' ;
83 icon
= 'good fa-check' ;
86 icon
= 'warning fa-exclamation' ;
89 icon
= 'critical fa-times' ;
103 'HEALTH_WARN' : 'warning' ,
104 'HEALTH_ERR' : 'critical'
107 render_ceph_health : function ( healthObj
) {
109 iconCls
: PVE
. Utils
. get_health_icon (),
113 if (! healthObj
|| ! healthObj
. status
) {
117 var health
= PVE
. Utils
. map_ceph_health
[ healthObj
. status
];
119 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
120 state
. text
= healthObj
. status
;
125 get_kvm_osinfo : function ( value
) {
126 var info
= { base
: 'Other' }; // default
128 Ext
. each ( Object
. keys ( PVE
. Utils
. kvm_ostypes
), function ( k
) {
129 Ext
. each ( PVE
. Utils
. kvm_ostypes
[ k
], function ( e
) {
130 if ( e
. val
=== value
) {
131 info
= { desc
: e
. desc
, base
: k
};
139 render_kvm_ostype : function ( value
) {
140 var osinfo
= PVE
. Utils
. get_kvm_osinfo ( value
);
141 if ( osinfo
. desc
&& osinfo
. desc
!== '-' ) {
142 return osinfo
. base
+ ' ' + osinfo
. desc
;
148 render_hotplug_features : function ( value
) {
151 if (! value
|| ( value
=== '0' )) {
152 return gettext ( 'Disabled' );
156 value
= 'disk,network,usb' ;
159 Ext
. each ( value
. split ( ',' ), function ( el
) {
161 fa
. push ( gettext ( 'Disk' ));
162 } else if ( el
=== 'network' ) {
163 fa
. push ( gettext ( 'Network' ));
164 } else if ( el
=== 'usb' ) {
166 } else if ( el
=== 'memory' ) {
167 fa
. push ( gettext ( 'Memory' ));
168 } else if ( el
=== 'cpu' ) {
169 fa
. push ( gettext ( 'CPU' ));
175 return fa
. join ( ', ' );
178 render_qga_features : function ( value
) {
180 return Proxmox
. Utils
. defaultText
+ ' (' + Proxmox
. Utils
. disabledText
+ ')' ;
182 var props
= PVE
. Parser
. parsePropertyString ( value
, 'enabled' );
183 if (! PVE
. Parser
. parseBoolean ( props
. enabled
)) {
184 return Proxmox
. Utils
. disabledText
;
187 delete props
. enabled
;
188 var agentstring
= Proxmox
. Utils
. enabledText
;
190 Ext
. Object
. each ( props
, function ( key
, value
) {
192 agentstring
+= ', ' + key
+ ': ' ;
194 if ( PVE
. Parser
. parseBoolean ( value
)) {
195 agentstring
+= Proxmox
. Utils
. enabledText
;
197 agentstring
+= Proxmox
. Utils
. disabledText
;
204 render_qemu_bios : function ( value
) {
206 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
207 } else if ( value
=== 'seabios' ) {
209 } else if ( value
=== 'ovmf' ) {
210 return "OVMF (UEFI)" ;
216 render_scsihw : function ( value
) {
218 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
219 } else if ( value
=== 'lsi' ) {
220 return 'LSI 53C895A' ;
221 } else if ( value
=== 'lsi53c810' ) {
223 } else if ( value
=== 'megasas' ) {
224 return 'MegaRAID SAS 8708EM2' ;
225 } else if ( value
=== 'virtio-scsi-pci' ) {
226 return 'VirtIO SCSI' ;
227 } else if ( value
=== 'virtio-scsi-single' ) {
228 return 'VirtIO SCSI single' ;
229 } else if ( value
=== 'pvscsi' ) {
230 return 'VMware PVSCSI' ;
236 // fixme: auto-generate this
237 // for now, please keep in sync with PVE::Tools::kvmkeymaps
242 'de-ch' : 'German (Swiss)' ,
243 'en-gb' : 'English (UK)' ,
244 'en-us' : 'English (USA)' ,
248 //fo: 'Faroe Islands',
250 'fr-be' : 'French (Belgium)' ,
251 'fr-ca' : 'French (Canada)' ,
252 'fr-ch' : 'French (Swiss)' ,
262 //'nl-be': 'Dutch (Belgium)',
266 'pt-br' : 'Portuguese (Brazil)' ,
275 std
: gettext ( 'Standard VGA' ),
276 vmware
: gettext ( 'VMware compatible' ),
278 qxl2
: 'SPICE dual monitor' ,
279 qxl3
: 'SPICE three monitors' ,
280 qxl4
: 'SPICE four monitors' ,
281 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
282 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
283 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
284 serial3
: gettext ( 'Serial terminal' ) + ' 3'
287 render_kvm_language : function ( value
) {
288 if (! value
|| value
=== '__default__' ) {
289 return Proxmox
. Utils
. defaultText
;
291 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
293 return text
+ ' (' + value
+ ')' ;
298 kvm_keymap_array : function () {
299 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
300 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
301 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
308 '__default__' : Proxmox
. Utils
. defaultText
+ ' (HTML5)' ,
309 'vv' : 'SPICE (remote-viewer)' ,
310 'html5' : 'HTML5 (noVNC)' ,
311 'xtermjs' : 'xterm.js'
314 render_console_viewer : function ( value
) {
315 value
= value
|| '__default__' ;
316 if ( PVE
. Utils
. console_map
[ value
]) {
317 return PVE
. Utils
. console_map
[ value
];
322 console_viewer_array : function () {
323 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
324 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
328 render_kvm_vga_driver : function ( value
) {
330 return Proxmox
. Utils
. defaultText
;
332 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
334 return text
+ ' (' + value
+ ')' ;
339 kvm_vga_driver_array : function () {
340 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
341 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
342 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
348 render_kvm_startup : function ( value
) {
349 var startup
= PVE
. Parser
. parseStartup ( value
);
352 if ( startup
. order
=== undefined ) {
355 res
+= startup
. order
;
357 if ( startup
. up
!== undefined ) {
358 res
+= ',up=' + startup
. up
;
360 if ( startup
. down
!== undefined ) {
361 res
+= ',down=' + startup
. down
;
367 extractFormActionError : function ( action
) {
369 switch ( action
. failureType
) {
370 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
371 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
373 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
374 msg
= gettext ( 'Connection error' );
375 var resp
= action
. response
;
376 if ( resp
. status
&& resp
. statusText
) {
377 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
380 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
381 case Ext
. form
. action
. Action
. SERVER_INVALID
:
382 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
388 format_duration_short : function ( ut
) {
391 return ut
. toFixed ( 1 ) + 's' ;
396 return mins
. toFixed ( 1 ) + 'm' ;
400 var hours
= ut
/ 3600 ;
401 return hours
. toFixed ( 1 ) + 'h' ;
404 var days
= ut
/ 86400 ;
405 return days
. toFixed ( 1 ) + 'd' ;
408 imagesText
: gettext ( 'Disk image' ),
409 backupFileText
: gettext ( 'VZDump backup file' ),
410 vztmplText
: gettext ( 'Container template' ),
411 isoImageText
: gettext ( 'ISO image' ),
412 containersText
: gettext ( 'Container' ),
416 name
: Proxmox
. Utils
. directoryText
,
417 ipanel
: 'DirInputPanel' ,
422 ipanel
: 'LVMInputPanel' ,
427 ipanel
: 'LvmThinInputPanel' ,
432 ipanel
: 'NFSInputPanel' ,
437 ipanel
: 'CIFSInputPanel' ,
442 ipanel
: 'GlusterFsInputPanel' ,
447 ipanel
: 'IScsiInputPanel' ,
452 ipanel
: 'SheepdogInputPanel' ,
458 ipanel
: 'RBDInputPanel' ,
463 ipanel
: 'RBDInputPanel' ,
468 name
: 'ZFS over iSCSI' ,
469 ipanel
: 'ZFSInputPanel' ,
474 ipanel
: 'ZFSPoolInputPanel' ,
483 format_storage_type : function ( value
, md
, record
) {
484 if ( value
=== 'rbd' && record
) {
485 value
= ( record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
488 var schema
= PVE
. Utils
. storageSchema
[ value
];
492 return Proxmox
. Utils
. unknownText
;
495 format_ha : function ( value
) {
496 var text
= Proxmox
. Utils
. noneText
;
499 text
= value
. state
|| Proxmox
. Utils
. noneText
;
501 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
502 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
508 format_content_types : function ( value
) {
511 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
512 if ( ct
=== 'images' ) {
513 cta
. push ( PVE
. Utils
. imagesText
);
514 } else if ( ct
=== 'backup' ) {
515 cta
. push ( PVE
. Utils
. backupFileText
);
516 } else if ( ct
=== 'vztmpl' ) {
517 cta
. push ( PVE
. Utils
. vztmplText
);
518 } else if ( ct
=== 'iso' ) {
519 cta
. push ( PVE
. Utils
. isoImageText
);
520 } else if ( ct
=== 'rootdir' ) {
521 cta
. push ( PVE
. Utils
. containersText
);
525 return cta
. join ( ', ' );
528 render_storage_content : function ( value
, metaData
, record
) {
529 var data
= record
. data
;
530 if ( Ext
. isNumber ( data
. channel
) &&
531 Ext
. isNumber ( data
. id
) &&
532 Ext
. isNumber ( data
. lun
)) {
534 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
535 " ID " + data
. id
+ " LUN " + data
. lun
;
537 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
540 render_serverity : function ( value
) {
541 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
544 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
546 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
550 var maxcpu
= record
. data
. maxcpu
|| 1 ;
552 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
556 var per
= value
* 100 ;
558 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
561 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
562 /*jslint confusion: true */
564 if (! Ext
. isNumeric ( value
)) {
568 return Proxmox
. Utils
. format_size ( value
);
571 render_bandwidth : function ( value
) {
572 if (! Ext
. isNumeric ( value
)) {
576 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
579 render_timestamp_human_readable : function ( value
) {
580 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
583 render_duration : function ( value
) {
584 if ( value
=== undefined ) {
587 return PVE
. Utils
. format_duration_short ( value
);
590 calculate_mem_usage : function ( data
) {
591 if (! Ext
. isNumeric ( data
. mem
) ||
597 return ( data
. mem
/ data
. maxmem
);
600 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
601 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
605 // we got no percentage but bytes
607 var maxmem
= record
. data
. maxmem
;
608 if (! record
. data
. uptime
||
610 ! Ext
. isNumeric ( mem
)) {
614 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
616 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
619 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
622 var maxmem
= record
. data
. maxmem
;
624 if (! record
. data
. uptime
) {
628 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
632 return PVE
. Utils
. render_size ( value
);
635 calculate_disk_usage : function ( data
) {
637 if (! Ext
. isNumeric ( data
. disk
) ||
638 data
. type
=== 'qemu' ||
639 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
640 data
. maxdisk
=== 0 ) {
644 return ( data
. disk
/ data
. maxdisk
);
647 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
648 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
652 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
655 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
658 var maxdisk
= record
. data
. maxdisk
;
659 var type
= record
. data
. type
;
661 if (! Ext
. isNumeric ( disk
) ||
664 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
668 return PVE
. Utils
. render_size ( value
);
671 get_object_icon_class : function ( type
, record
) {
675 if ( type
=== 'type' ) {
677 objType
= record
. groupbyid
;
678 } else if ( record
. template
) {
680 objType
= 'template' ;
684 status
= record
. status
+ ' ha-' + record
. hastate
;
687 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
688 if ( defaults
&& defaults
. iconCls
) {
689 var retVal
= defaults
. iconCls
+ ' ' + status
;
696 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
698 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
700 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
704 render_support_level : function ( value
, metaData
, record
) {
705 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
708 render_upid : function ( value
, metaData
, record
) {
709 var type
= record
. data
. type
;
710 var id
= record
. data
. id
;
712 return Proxmox
. Utils
. format_task_description ( type
, id
);
715 /* render functions for new status panel */
717 render_usage : function ( val
) {
718 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
721 render_cpu_usage : function ( val
, max
) {
722 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
723 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
726 render_size_usage : function ( val
, max
) {
728 return gettext ( 'N/A' );
730 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
731 Ext
. String
. format ( gettext ( '{0} of {1}' ),
732 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
735 /* this is different for nodes */
736 render_node_cpu_usage : function ( value
, record
) {
737 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
740 /* this is different for nodes */
741 render_node_size_usage : function ( record
) {
742 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
745 render_optional_url : function ( value
) {
747 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
748 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
753 render_san : function ( value
) {
755 if ( Ext
. isArray ( value
)) {
756 value
. forEach ( function ( val
) {
757 if (! Ext
. isNumber ( val
)) {
761 return names
. join ( '<br>' );
766 windowHostname : function () {
767 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
768 function ( m
, addr
, offset
, original
) { return addr
; });
771 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
) {
772 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
773 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
776 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
777 // kvm, lxc, shell, upgrade
779 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
780 throw "missing vmid" ;
784 throw "no nodename specified" ;
787 if ( viewer
=== 'html5' ) {
788 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
789 } else if ( viewer
=== 'xtermjs' ) {
790 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
);
791 } else if ( viewer
=== 'vv' ) {
793 var params
= { proxy
: PVE
. Utils
. windowHostname () };
794 if ( vmtype
=== 'kvm' ) {
795 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
796 PVE
. Utils
. openSpiceViewer ( url
, params
);
797 } else if ( vmtype
=== 'lxc' ) {
798 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
799 PVE
. Utils
. openSpiceViewer ( url
, params
);
800 } else if ( vmtype
=== 'shell' ) {
801 url
= '/nodes/' + nodename
+ '/spiceshell' ;
802 PVE
. Utils
. openSpiceViewer ( url
, params
);
803 } else if ( vmtype
=== 'upgrade' ) {
804 url
= '/nodes/' + nodename
+ '/spiceshell' ;
806 PVE
. Utils
. openSpiceViewer ( url
, params
);
809 throw "unknown viewer type" ;
813 defaultViewer : function ( consoles
) {
815 var allowSpice
, allowXtermjs
;
817 if ( consoles
=== true ) {
820 } else if ( typeof consoles
=== 'object' ) {
821 allowSpice
= consoles
. spice
;
822 allowXtermjs
= !! consoles
. xtermjs
;
824 var vncdefault
= 'html5' ;
825 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
826 if (( dv
=== 'vv' && ! allowSpice
) || ( dv
=== 'xtermjs' && ! allowXtermjs
)) {
833 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
834 var url
= Ext
. urlEncode ({
835 console
: vmtype
, // kvm, lxc, upgrade or shell
842 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
846 openSpiceViewer : function ( url
, params
){
848 var downloadWithName = function ( uri
, name
) {
849 var link
= Ext
. DomHelper
. append ( document
. body
, {
852 css
: 'display:none;visibility:hidden;height:0px;'
855 // Note: we need to tell android the correct file name extension
856 // but we do not set 'download' tag for other environments, because
857 // It can have strange side effects (additional user prompt on firefox)
858 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
860 link
. download
= name
;
863 if ( link
. fireEvent
) {
864 link
. fireEvent ( 'onclick' );
866 var evt
= document
. createEvent ( "MouseEvents" );
867 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
868 link
. dispatchEvent ( evt
);
872 Proxmox
. Utils
. API2Request ({
876 failure : function ( response
, opts
){
877 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
879 success : function ( response
, opts
){
880 var raw
= "[virt-viewer] \n " ;
881 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
882 raw
+= k
+ "=" + v
+ " \n " ;
884 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
885 encodeURIComponent ( raw
);
887 downloadWithName ( url
, "pve-spice.vv" );
892 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
894 var nodename
= record
. data
. node
;
895 var vmid
= record
. data
. vmid
;
896 var vmname
= record
. data
. name
;
897 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
898 Proxmox
. Utils
. API2Request ({
899 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
900 failure : function ( response
, opts
) {
901 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
903 success : function ( response
, opts
) {
904 var allowSpice
= !! response
. result
. data
. spice
;
905 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
908 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
909 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
913 // test automation helper
914 call_menu_handler : function ( menu
, text
) {
916 var list
= menu
. query ( 'menuitem' );
918 Ext
. Array
. each ( list
, function ( item
) {
919 if ( item
. text
=== text
) {
930 createCmdMenu : function ( v
, record
, item
, index
, event
) {
932 if (!( v
instanceof Ext
. tree
. View
)) {
936 var template
= !! record
. data
. template
;
937 var type
= record
. data
. type
;
940 if ( type
=== 'qemu' || type
== 'lxc' ) {
941 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
945 } else if ( type
=== 'qemu' ||
948 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
950 nodename
: record
. data
. node
956 menu
. showAt ( event
. getXY ());
959 // helper for deleting field which are set to there default values
960 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
961 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
963 if ( values
[ 'delete' ]) {
964 values
[ 'delete' ] += ',' + fieldname
;
966 values
[ 'delete' ] = fieldname
;
970 delete values
[ fieldname
];
974 loadSSHKeyFromFile : function ( file
, callback
) {
975 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
976 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
977 // assume: 740*8 for max. 32kbit (5920 byte file)
978 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
979 if ( file
. size
> 8192 ) {
980 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
986 var reader
= new FileReader ();
987 reader
. onload = function ( evt
) {
988 callback ( evt
. target
. result
);
990 reader
. readAsText ( file
);
993 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
995 // types is either undefined (all busses), an array of busses, or a single bus
996 forEachBus : function ( types
, func
) {
997 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
998 var i
, j
, count
, cont
;
1000 if ( Ext
. isArray ( types
)) {
1002 } else if ( Ext
. isDefined ( types
)) {
1006 // check if we only have valid busses
1007 for ( i
= 0 ; i
< busses
. length
; i
++) {
1008 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
1009 throw "invalid bus: '" + busses
[ i
] + "'" ;
1013 for ( i
= 0 ; i
< busses
. length
; i
++) {
1014 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
1015 for ( j
= 0 ; j
< count
; j
++) {
1016 cont
= func ( busses
[ i
], j
);
1017 if (! cont
&& cont
!== undefined ) {
1024 mp_counts
: { mps
: 10 , unused
: 10 },
1026 forEachMP : function ( func
, includeUnused
) {
1028 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1029 cont
= func ( 'mp' , i
);
1030 if (! cont
&& cont
!== undefined ) {
1035 if (! includeUnused
) {
1039 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1040 cont
= func ( 'unused' , i
);
1041 if (! cont
&& cont
!== undefined ) {
1049 constructor : function () {
1051 Ext
. apply ( me
, me
. utilities
);