]>
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_qemu_bios : function ( value
) {
180 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
181 } else if ( value
=== 'seabios' ) {
183 } else if ( value
=== 'ovmf' ) {
184 return "OVMF (UEFI)" ;
190 render_scsihw : function ( value
) {
192 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
193 } else if ( value
=== 'lsi' ) {
194 return 'LSI 53C895A' ;
195 } else if ( value
=== 'lsi53c810' ) {
197 } else if ( value
=== 'megasas' ) {
198 return 'MegaRAID SAS 8708EM2' ;
199 } else if ( value
=== 'virtio-scsi-pci' ) {
200 return 'VirtIO SCSI' ;
201 } else if ( value
=== 'virtio-scsi-single' ) {
202 return 'VirtIO SCSI single' ;
203 } else if ( value
=== 'pvscsi' ) {
204 return 'VMware PVSCSI' ;
210 // fixme: auto-generate this
211 // for now, please keep in sync with PVE::Tools::kvmkeymaps
216 'de-ch' : 'German (Swiss)' ,
217 'en-gb' : 'English (UK)' ,
218 'en-us' : 'English (USA)' ,
222 //fo: 'Faroe Islands',
224 'fr-be' : 'French (Belgium)' ,
225 'fr-ca' : 'French (Canada)' ,
226 'fr-ch' : 'French (Swiss)' ,
236 //'nl-be': 'Dutch (Belgium)',
240 'pt-br' : 'Portuguese (Brazil)' ,
249 std
: gettext ( 'Standard VGA' ),
250 vmware
: gettext ( 'VMware compatible' ),
252 qxl2
: 'SPICE dual monitor' ,
253 qxl3
: 'SPICE three monitors' ,
254 qxl4
: 'SPICE four monitors' ,
255 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
256 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
257 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
258 serial3
: gettext ( 'Serial terminal' ) + ' 3'
261 render_kvm_language : function ( value
) {
262 if (! value
|| value
=== '__default__' ) {
263 return Proxmox
. Utils
. defaultText
;
265 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
267 return text
+ ' (' + value
+ ')' ;
272 kvm_keymap_array : function () {
273 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
274 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
275 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
282 '__default__' : Proxmox
. Utils
. defaultText
+ ' (HTML5)' ,
283 'vv' : 'SPICE (remote-viewer)' ,
284 'html5' : 'HTML5 (noVNC)' ,
285 'xtermjs' : 'xterm.js'
288 render_console_viewer : function ( value
) {
289 value
= value
|| '__default__' ;
290 if ( PVE
. Utils
. console_map
[ value
]) {
291 return PVE
. Utils
. console_map
[ value
];
296 console_viewer_array : function () {
297 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
298 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
302 render_kvm_vga_driver : function ( value
) {
304 return Proxmox
. Utils
. defaultText
;
306 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
308 return text
+ ' (' + value
+ ')' ;
313 kvm_vga_driver_array : function () {
314 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
315 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
316 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
322 render_kvm_startup : function ( value
) {
323 var startup
= PVE
. Parser
. parseStartup ( value
);
326 if ( startup
. order
=== undefined ) {
329 res
+= startup
. order
;
331 if ( startup
. up
!== undefined ) {
332 res
+= ',up=' + startup
. up
;
334 if ( startup
. down
!== undefined ) {
335 res
+= ',down=' + startup
. down
;
341 extractFormActionError : function ( action
) {
343 switch ( action
. failureType
) {
344 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
345 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
347 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
348 msg
= gettext ( 'Connection error' );
349 var resp
= action
. response
;
350 if ( resp
. status
&& resp
. statusText
) {
351 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
354 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
355 case Ext
. form
. action
. Action
. SERVER_INVALID
:
356 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
362 format_duration_short : function ( ut
) {
365 return ut
. toFixed ( 1 ) + 's' ;
370 return mins
. toFixed ( 1 ) + 'm' ;
374 var hours
= ut
/ 3600 ;
375 return hours
. toFixed ( 1 ) + 'h' ;
378 var days
= ut
/ 86400 ;
379 return days
. toFixed ( 1 ) + 'd' ;
382 imagesText
: gettext ( 'Disk image' ),
383 backupFileText
: gettext ( 'VZDump backup file' ),
384 vztmplText
: gettext ( 'Container template' ),
385 isoImageText
: gettext ( 'ISO image' ),
386 containersText
: gettext ( 'Container' ),
390 name
: Proxmox
. Utils
. directoryText
,
391 ipanel
: 'DirInputPanel' ,
396 ipanel
: 'LVMInputPanel' ,
401 ipanel
: 'LvmThinInputPanel' ,
406 ipanel
: 'NFSInputPanel' ,
411 ipanel
: 'CIFSInputPanel' ,
416 ipanel
: 'GlusterFsInputPanel' ,
421 ipanel
: 'IScsiInputPanel' ,
426 ipanel
: 'SheepdogInputPanel' ,
432 ipanel
: 'RBDInputPanel' ,
437 name
: 'RBD (external)' ,
438 ipanel
: 'RBDInputPanel' ,
443 ipanel
: 'PVERBDInputPanel' ,
447 name
: 'ZFS over iSCSI' ,
448 ipanel
: 'ZFSInputPanel' ,
453 ipanel
: 'ZFSPoolInputPanel' ,
462 format_storage_type : function ( value
, md
, record
) {
463 if ( value
=== 'rbd' && record
) {
464 value
= ( record
. get ( 'monhost' )? 'rbd_ext' : 'pveceph' );
467 var schema
= PVE
. Utils
. storageSchema
[ value
];
471 return Proxmox
. Utils
. unknownText
;
474 format_ha : function ( value
) {
475 var text
= Proxmox
. Utils
. noneText
;
478 text
= value
. state
|| Proxmox
. Utils
. noneText
;
480 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
481 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
487 format_content_types : function ( value
) {
490 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
491 if ( ct
=== 'images' ) {
492 cta
. push ( PVE
. Utils
. imagesText
);
493 } else if ( ct
=== 'backup' ) {
494 cta
. push ( PVE
. Utils
. backupFileText
);
495 } else if ( ct
=== 'vztmpl' ) {
496 cta
. push ( PVE
. Utils
. vztmplText
);
497 } else if ( ct
=== 'iso' ) {
498 cta
. push ( PVE
. Utils
. isoImageText
);
499 } else if ( ct
=== 'rootdir' ) {
500 cta
. push ( PVE
. Utils
. containersText
);
504 return cta
. join ( ', ' );
507 render_storage_content : function ( value
, metaData
, record
) {
508 var data
= record
. data
;
509 if ( Ext
. isNumber ( data
. channel
) &&
510 Ext
. isNumber ( data
. id
) &&
511 Ext
. isNumber ( data
. lun
)) {
513 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
514 " ID " + data
. id
+ " LUN " + data
. lun
;
516 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
519 render_serverity : function ( value
) {
520 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
523 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
525 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
529 var maxcpu
= record
. data
. maxcpu
|| 1 ;
531 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
535 var per
= value
* 100 ;
537 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
540 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
541 /*jslint confusion: true */
543 if (! Ext
. isNumeric ( value
)) {
547 return Proxmox
. Utils
. format_size ( value
);
550 render_bandwidth : function ( value
) {
551 if (! Ext
. isNumeric ( value
)) {
555 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
558 render_timestamp_human_readable : function ( value
) {
559 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
562 render_duration : function ( value
) {
563 if ( value
=== undefined ) {
566 return PVE
. Utils
. format_duration_short ( value
);
569 calculate_mem_usage : function ( data
) {
570 if (! Ext
. isNumeric ( data
. mem
) ||
576 return ( data
. mem
/ data
. maxmem
);
579 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
580 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
584 // we got no percentage but bytes
586 var maxmem
= record
. data
. maxmem
;
587 if (! record
. data
. uptime
||
589 ! Ext
. isNumeric ( mem
)) {
593 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
595 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
598 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
601 var maxmem
= record
. data
. maxmem
;
603 if (! record
. data
. uptime
) {
607 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
611 return PVE
. Utils
. render_size ( value
);
614 calculate_disk_usage : function ( data
) {
616 if (! Ext
. isNumeric ( data
. disk
) ||
617 data
. type
=== 'qemu' ||
618 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
619 data
. maxdisk
=== 0 ) {
623 return ( data
. disk
/ data
. maxdisk
);
626 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
627 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
631 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
634 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
637 var maxdisk
= record
. data
. maxdisk
;
638 var type
= record
. data
. type
;
640 if (! Ext
. isNumeric ( disk
) ||
643 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
647 return PVE
. Utils
. render_size ( value
);
650 get_object_icon_class : function ( type
, record
) {
654 if ( type
=== 'type' ) {
656 objType
= record
. groupbyid
;
657 } else if ( record
. template
) {
659 objType
= 'template' ;
663 status
= record
. status
+ ' ha-' + record
. hastate
;
666 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
667 if ( defaults
&& defaults
. iconCls
) {
668 var retVal
= defaults
. iconCls
+ ' ' + status
;
675 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
677 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
679 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
683 render_support_level : function ( value
, metaData
, record
) {
684 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
687 render_upid : function ( value
, metaData
, record
) {
688 var type
= record
. data
. type
;
689 var id
= record
. data
. id
;
691 return Proxmox
. Utils
. format_task_description ( type
, id
);
694 /* render functions for new status panel */
696 render_usage : function ( val
) {
697 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
700 render_cpu_usage : function ( val
, max
) {
701 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
702 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
705 render_size_usage : function ( val
, max
) {
707 return gettext ( 'N/A' );
709 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
710 Ext
. String
. format ( gettext ( '{0} of {1}' ),
711 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
714 /* this is different for nodes */
715 render_node_cpu_usage : function ( value
, record
) {
716 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
719 /* this is different for nodes */
720 render_node_size_usage : function ( record
) {
721 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
724 render_optional_url : function ( value
) {
726 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
727 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
732 render_san : function ( value
) {
734 if ( Ext
. isArray ( value
)) {
735 value
. forEach ( function ( val
) {
736 if (! Ext
. isNumber ( val
)) {
740 return names
. join ( '<br>' );
745 windowHostname : function () {
746 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
747 function ( m
, addr
, offset
, original
) { return addr
; });
750 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
) {
751 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
752 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
755 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
756 // kvm, lxc, shell, upgrade
758 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
759 throw "missing vmid" ;
763 throw "no nodename specified" ;
766 if ( viewer
=== 'html5' ) {
767 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
768 } else if ( viewer
=== 'xtermjs' ) {
769 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
);
770 } else if ( viewer
=== 'vv' ) {
772 var params
= { proxy
: PVE
. Utils
. windowHostname () };
773 if ( vmtype
=== 'kvm' ) {
774 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
775 PVE
. Utils
. openSpiceViewer ( url
, params
);
776 } else if ( vmtype
=== 'lxc' ) {
777 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
778 PVE
. Utils
. openSpiceViewer ( url
, params
);
779 } else if ( vmtype
=== 'shell' ) {
780 url
= '/nodes/' + nodename
+ '/spiceshell' ;
781 PVE
. Utils
. openSpiceViewer ( url
, params
);
782 } else if ( vmtype
=== 'upgrade' ) {
783 url
= '/nodes/' + nodename
+ '/spiceshell' ;
785 PVE
. Utils
. openSpiceViewer ( url
, params
);
788 throw "unknown viewer type" ;
792 defaultViewer : function ( consoles
) {
794 var allowSpice
, allowXtermjs
;
796 if ( consoles
=== true ) {
799 } else if ( typeof consoles
=== 'object' ) {
800 allowSpice
= consoles
. spice
;
801 allowXtermjs
= !! consoles
. xtermjs
;
803 var vncdefault
= 'html5' ;
804 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
805 if (( dv
=== 'vv' && ! allowSpice
) || ( dv
=== 'xtermjs' && ! allowXtermjs
)) {
812 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
813 var url
= Ext
. urlEncode ({
814 console
: vmtype
, // kvm, lxc, upgrade or shell
820 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
824 openSpiceViewer : function ( url
, params
){
826 var downloadWithName = function ( uri
, name
) {
827 var link
= Ext
. DomHelper
. append ( document
. body
, {
830 css
: 'display:none;visibility:hidden;height:0px;'
833 // Note: we need to tell android the correct file name extension
834 // but we do not set 'download' tag for other environments, because
835 // It can have strange side effects (additional user prompt on firefox)
836 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
838 link
. download
= name
;
841 if ( link
. fireEvent
) {
842 link
. fireEvent ( 'onclick' );
844 var evt
= document
. createEvent ( "MouseEvents" );
845 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
846 link
. dispatchEvent ( evt
);
850 Proxmox
. Utils
. API2Request ({
854 failure : function ( response
, opts
){
855 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
857 success : function ( response
, opts
){
858 var raw
= "[virt-viewer] \n " ;
859 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
860 raw
+= k
+ "=" + v
+ " \n " ;
862 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
863 encodeURIComponent ( raw
);
865 downloadWithName ( url
, "pve-spice.vv" );
870 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
872 var nodename
= record
. data
. node
;
873 var vmid
= record
. data
. vmid
;
874 var vmname
= record
. data
. name
;
875 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
876 Proxmox
. Utils
. API2Request ({
877 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
878 failure : function ( response
, opts
) {
879 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
881 success : function ( response
, opts
) {
882 var allowSpice
= response
. result
. data
. spice
;
883 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
886 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
887 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
891 // test automation helper
892 call_menu_handler : function ( menu
, text
) {
894 var list
= menu
. query ( 'menuitem' );
896 Ext
. Array
. each ( list
, function ( item
) {
897 if ( item
. text
=== text
) {
908 createCmdMenu : function ( v
, record
, item
, index
, event
) {
910 if (!( v
instanceof Ext
. tree
. View
)) {
914 var template
= !! record
. data
. template
;
915 var type
= record
. data
. type
;
918 if ( type
=== 'qemu' || type
== 'lxc' ) {
919 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
923 } else if ( type
=== 'qemu' ||
926 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
928 nodename
: record
. data
. node
934 menu
. showAt ( event
. getXY ());
937 // helper for deleting field which are set to there default values
938 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
939 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
941 if ( values
[ 'delete' ]) {
942 values
[ 'delete' ] += ',' + fieldname
;
944 values
[ 'delete' ] = fieldname
;
948 delete values
[ fieldname
];
952 loadSSHKeyFromFile : function ( file
, callback
) {
953 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
954 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
955 // assume: 740*8 for max. 32kbit (5920 byte file)
956 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
957 if ( file
. size
> 8192 ) {
958 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
964 var reader
= new FileReader ();
965 reader
. onload = function ( evt
) {
966 callback ( evt
. target
. result
);
968 reader
. readAsText ( file
);
971 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
973 // types is either undefined (all busses), an array of busses, or a single bus
974 forEachBus : function ( types
, func
) {
975 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
976 var i
, j
, count
, cont
;
978 if ( Ext
. isArray ( types
)) {
980 } else if ( Ext
. isDefined ( types
)) {
984 // check if we only have valid busses
985 for ( i
= 0 ; i
< busses
. length
; i
++) {
986 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
987 throw "invalid bus: '" + busses
[ i
] + "'" ;
991 for ( i
= 0 ; i
< busses
. length
; i
++) {
992 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
993 for ( j
= 0 ; j
< count
; j
++) {
994 cont
= func ( busses
[ i
], j
);
995 if (! cont
&& cont
!== undefined ) {
1002 mp_counts
: { mps
: 10 , unused
: 10 },
1004 forEachMP : function ( func
, includeUnused
) {
1006 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1007 cont
= func ( 'mp' , i
);
1008 if (! cont
&& cont
!== undefined ) {
1013 if (! includeUnused
) {
1017 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1018 cont
= func ( 'unused' , i
);
1019 if (! cont
&& cont
!== undefined ) {
1027 constructor : function () {
1029 Ext
. apply ( me
, me
. utilities
);