]>
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 ipanel
: 'RBDInputPanel' ,
442 name
: 'ZFS over iSCSI' ,
443 ipanel
: 'ZFSInputPanel' ,
448 ipanel
: 'ZFSPoolInputPanel' ,
457 format_storage_type : function ( value
, md
, record
) {
458 if ( value
=== 'rbd' && record
) {
459 value
= ( record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
462 var schema
= PVE
. Utils
. storageSchema
[ value
];
466 return Proxmox
. Utils
. unknownText
;
469 format_ha : function ( value
) {
470 var text
= Proxmox
. Utils
. noneText
;
473 text
= value
. state
|| Proxmox
. Utils
. noneText
;
475 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
476 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
482 format_content_types : function ( value
) {
485 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
486 if ( ct
=== 'images' ) {
487 cta
. push ( PVE
. Utils
. imagesText
);
488 } else if ( ct
=== 'backup' ) {
489 cta
. push ( PVE
. Utils
. backupFileText
);
490 } else if ( ct
=== 'vztmpl' ) {
491 cta
. push ( PVE
. Utils
. vztmplText
);
492 } else if ( ct
=== 'iso' ) {
493 cta
. push ( PVE
. Utils
. isoImageText
);
494 } else if ( ct
=== 'rootdir' ) {
495 cta
. push ( PVE
. Utils
. containersText
);
499 return cta
. join ( ', ' );
502 render_storage_content : function ( value
, metaData
, record
) {
503 var data
= record
. data
;
504 if ( Ext
. isNumber ( data
. channel
) &&
505 Ext
. isNumber ( data
. id
) &&
506 Ext
. isNumber ( data
. lun
)) {
508 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
509 " ID " + data
. id
+ " LUN " + data
. lun
;
511 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
514 render_serverity : function ( value
) {
515 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
518 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
520 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
524 var maxcpu
= record
. data
. maxcpu
|| 1 ;
526 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
530 var per
= value
* 100 ;
532 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
535 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
536 /*jslint confusion: true */
538 if (! Ext
. isNumeric ( value
)) {
542 return Proxmox
. Utils
. format_size ( value
);
545 render_bandwidth : function ( value
) {
546 if (! Ext
. isNumeric ( value
)) {
550 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
553 render_timestamp_human_readable : function ( value
) {
554 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
557 render_duration : function ( value
) {
558 if ( value
=== undefined ) {
561 return PVE
. Utils
. format_duration_short ( value
);
564 calculate_mem_usage : function ( data
) {
565 if (! Ext
. isNumeric ( data
. mem
) ||
571 return ( data
. mem
/ data
. maxmem
);
574 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
575 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
579 // we got no percentage but bytes
581 var maxmem
= record
. data
. maxmem
;
582 if (! record
. data
. uptime
||
584 ! Ext
. isNumeric ( mem
)) {
588 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
590 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
593 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
596 var maxmem
= record
. data
. maxmem
;
598 if (! record
. data
. uptime
) {
602 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
606 return PVE
. Utils
. render_size ( value
);
609 calculate_disk_usage : function ( data
) {
611 if (! Ext
. isNumeric ( data
. disk
) ||
612 data
. type
=== 'qemu' ||
613 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
614 data
. maxdisk
=== 0 ) {
618 return ( data
. disk
/ data
. maxdisk
);
621 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
622 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
626 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
629 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
632 var maxdisk
= record
. data
. maxdisk
;
633 var type
= record
. data
. type
;
635 if (! Ext
. isNumeric ( disk
) ||
638 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
642 return PVE
. Utils
. render_size ( value
);
645 get_object_icon_class : function ( type
, record
) {
649 if ( type
=== 'type' ) {
651 objType
= record
. groupbyid
;
652 } else if ( record
. template
) {
654 objType
= 'template' ;
658 status
= record
. status
+ ' ha-' + record
. hastate
;
661 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
662 if ( defaults
&& defaults
. iconCls
) {
663 var retVal
= defaults
. iconCls
+ ' ' + status
;
670 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
672 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
674 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
678 render_support_level : function ( value
, metaData
, record
) {
679 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
682 render_upid : function ( value
, metaData
, record
) {
683 var type
= record
. data
. type
;
684 var id
= record
. data
. id
;
686 return Proxmox
. Utils
. format_task_description ( type
, id
);
689 /* render functions for new status panel */
691 render_usage : function ( val
) {
692 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
695 render_cpu_usage : function ( val
, max
) {
696 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
697 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
700 render_size_usage : function ( val
, max
) {
702 return gettext ( 'N/A' );
704 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
705 Ext
. String
. format ( gettext ( '{0} of {1}' ),
706 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
709 /* this is different for nodes */
710 render_node_cpu_usage : function ( value
, record
) {
711 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
714 /* this is different for nodes */
715 render_node_size_usage : function ( record
) {
716 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
719 render_optional_url : function ( value
) {
721 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
722 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
727 render_san : function ( value
) {
729 if ( Ext
. isArray ( value
)) {
730 value
. forEach ( function ( val
) {
731 if (! Ext
. isNumber ( val
)) {
735 return names
. join ( '<br>' );
740 windowHostname : function () {
741 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
742 function ( m
, addr
, offset
, original
) { return addr
; });
745 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
) {
746 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
747 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
750 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
751 // kvm, lxc, shell, upgrade
753 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
754 throw "missing vmid" ;
758 throw "no nodename specified" ;
761 if ( viewer
=== 'html5' ) {
762 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
763 } else if ( viewer
=== 'xtermjs' ) {
764 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
);
765 } else if ( viewer
=== 'vv' ) {
767 var params
= { proxy
: PVE
. Utils
. windowHostname () };
768 if ( vmtype
=== 'kvm' ) {
769 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
770 PVE
. Utils
. openSpiceViewer ( url
, params
);
771 } else if ( vmtype
=== 'lxc' ) {
772 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
773 PVE
. Utils
. openSpiceViewer ( url
, params
);
774 } else if ( vmtype
=== 'shell' ) {
775 url
= '/nodes/' + nodename
+ '/spiceshell' ;
776 PVE
. Utils
. openSpiceViewer ( url
, params
);
777 } else if ( vmtype
=== 'upgrade' ) {
778 url
= '/nodes/' + nodename
+ '/spiceshell' ;
780 PVE
. Utils
. openSpiceViewer ( url
, params
);
783 throw "unknown viewer type" ;
787 defaultViewer : function ( consoles
) {
789 var allowSpice
, allowXtermjs
;
791 if ( consoles
=== true ) {
794 } else if ( typeof consoles
=== 'object' ) {
795 allowSpice
= consoles
. spice
;
796 allowXtermjs
= !! consoles
. xtermjs
;
798 var vncdefault
= 'html5' ;
799 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
800 if (( dv
=== 'vv' && ! allowSpice
) || ( dv
=== 'xtermjs' && ! allowXtermjs
)) {
807 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
808 var url
= Ext
. urlEncode ({
809 console
: vmtype
, // kvm, lxc, upgrade or shell
816 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
820 openSpiceViewer : function ( url
, params
){
822 var downloadWithName = function ( uri
, name
) {
823 var link
= Ext
. DomHelper
. append ( document
. body
, {
826 css
: 'display:none;visibility:hidden;height:0px;'
829 // Note: we need to tell android the correct file name extension
830 // but we do not set 'download' tag for other environments, because
831 // It can have strange side effects (additional user prompt on firefox)
832 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
834 link
. download
= name
;
837 if ( link
. fireEvent
) {
838 link
. fireEvent ( 'onclick' );
840 var evt
= document
. createEvent ( "MouseEvents" );
841 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
842 link
. dispatchEvent ( evt
);
846 Proxmox
. Utils
. API2Request ({
850 failure : function ( response
, opts
){
851 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
853 success : function ( response
, opts
){
854 var raw
= "[virt-viewer] \n " ;
855 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
856 raw
+= k
+ "=" + v
+ " \n " ;
858 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
859 encodeURIComponent ( raw
);
861 downloadWithName ( url
, "pve-spice.vv" );
866 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
868 var nodename
= record
. data
. node
;
869 var vmid
= record
. data
. vmid
;
870 var vmname
= record
. data
. name
;
871 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
872 Proxmox
. Utils
. API2Request ({
873 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
874 failure : function ( response
, opts
) {
875 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
877 success : function ( response
, opts
) {
878 var allowSpice
= !! response
. result
. data
. spice
;
879 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
882 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
883 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
887 // test automation helper
888 call_menu_handler : function ( menu
, text
) {
890 var list
= menu
. query ( 'menuitem' );
892 Ext
. Array
. each ( list
, function ( item
) {
893 if ( item
. text
=== text
) {
904 createCmdMenu : function ( v
, record
, item
, index
, event
) {
906 if (!( v
instanceof Ext
. tree
. View
)) {
910 var template
= !! record
. data
. template
;
911 var type
= record
. data
. type
;
914 if ( type
=== 'qemu' || type
== 'lxc' ) {
915 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
919 } else if ( type
=== 'qemu' ||
922 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
924 nodename
: record
. data
. node
930 menu
. showAt ( event
. getXY ());
933 // helper for deleting field which are set to there default values
934 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
935 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
937 if ( values
[ 'delete' ]) {
938 values
[ 'delete' ] += ',' + fieldname
;
940 values
[ 'delete' ] = fieldname
;
944 delete values
[ fieldname
];
948 loadSSHKeyFromFile : function ( file
, callback
) {
949 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
950 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
951 // assume: 740*8 for max. 32kbit (5920 byte file)
952 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
953 if ( file
. size
> 8192 ) {
954 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
960 var reader
= new FileReader ();
961 reader
. onload = function ( evt
) {
962 callback ( evt
. target
. result
);
964 reader
. readAsText ( file
);
967 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
969 // types is either undefined (all busses), an array of busses, or a single bus
970 forEachBus : function ( types
, func
) {
971 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
972 var i
, j
, count
, cont
;
974 if ( Ext
. isArray ( types
)) {
976 } else if ( Ext
. isDefined ( types
)) {
980 // check if we only have valid busses
981 for ( i
= 0 ; i
< busses
. length
; i
++) {
982 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
983 throw "invalid bus: '" + busses
[ i
] + "'" ;
987 for ( i
= 0 ; i
< busses
. length
; i
++) {
988 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
989 for ( j
= 0 ; j
< count
; j
++) {
990 cont
= func ( busses
[ i
], j
);
991 if (! cont
&& cont
!== undefined ) {
998 mp_counts
: { mps
: 10 , unused
: 10 },
1000 forEachMP : function ( func
, includeUnused
) {
1002 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1003 cont
= func ( 'mp' , i
);
1004 if (! cont
&& cont
!== undefined ) {
1009 if (! includeUnused
) {
1013 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1014 cont
= func ( 'unused' , i
);
1015 if (! cont
&& cont
!== undefined ) {
1023 constructor : function () {
1025 Ext
. apply ( me
, me
. utilities
);