]>
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
)]);
281 render_console_viewer : function ( value
) {
282 if (! value
|| value
=== '__default__' ) {
283 return Proxmox
. Utils
. defaultText
+ ' (HTML5)' ;
284 } else if ( value
=== 'vv' ) {
285 return 'SPICE (remote-viewer)' ;
286 } else if ( value
=== 'html5' ) {
287 return 'HTML5 (noVNC)' ;
293 console_viewer_array : function () {
294 return Ext
. Array
. map ([ '__default__' , 'vv' , 'html5' ], function ( v
) {
295 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
299 render_kvm_vga_driver : function ( value
) {
301 return Proxmox
. Utils
. defaultText
;
303 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
305 return text
+ ' (' + value
+ ')' ;
310 kvm_vga_driver_array : function () {
311 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
312 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
313 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
319 render_kvm_startup : function ( value
) {
320 var startup
= PVE
. Parser
. parseStartup ( value
);
323 if ( startup
. order
=== undefined ) {
326 res
+= startup
. order
;
328 if ( startup
. up
!== undefined ) {
329 res
+= ',up=' + startup
. up
;
331 if ( startup
. down
!== undefined ) {
332 res
+= ',down=' + startup
. down
;
338 extractFormActionError : function ( action
) {
340 switch ( action
. failureType
) {
341 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
342 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
344 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
345 msg
= gettext ( 'Connection error' );
346 var resp
= action
. response
;
347 if ( resp
. status
&& resp
. statusText
) {
348 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
351 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
352 case Ext
. form
. action
. Action
. SERVER_INVALID
:
353 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
359 format_duration_short : function ( ut
) {
362 return ut
. toFixed ( 1 ) + 's' ;
367 return mins
. toFixed ( 1 ) + 'm' ;
371 var hours
= ut
/ 3600 ;
372 return hours
. toFixed ( 1 ) + 'h' ;
375 var days
= ut
/ 86400 ;
376 return days
. toFixed ( 1 ) + 'd' ;
379 imagesText
: gettext ( 'Disk image' ),
380 backupFileText
: gettext ( 'VZDump backup file' ),
381 vztmplText
: gettext ( 'Container template' ),
382 isoImageText
: gettext ( 'ISO image' ),
383 containersText
: gettext ( 'Container' ),
387 name
: Proxmox
. Utils
. directoryText
,
388 ipanel
: 'DirInputPanel' ,
393 ipanel
: 'LVMInputPanel' ,
398 ipanel
: 'LvmThinInputPanel' ,
403 ipanel
: 'NFSInputPanel' ,
408 ipanel
: 'CIFSInputPanel' ,
413 ipanel
: 'GlusterFsInputPanel' ,
418 ipanel
: 'IScsiInputPanel' ,
423 ipanel
: 'SheepdogInputPanel' ,
429 ipanel
: 'RBDInputPanel' ,
434 name
: 'RBD (external)' ,
435 ipanel
: 'RBDInputPanel' ,
440 ipanel
: 'PVERBDInputPanel' ,
444 name
: 'ZFS over iSCSI' ,
445 ipanel
: 'ZFSInputPanel' ,
450 ipanel
: 'ZFSPoolInputPanel' ,
459 format_storage_type : function ( value
, md
, record
) {
460 if ( value
=== 'rbd' && record
) {
461 value
= ( record
. get ( 'monhost' )? 'rbd_ext' : 'pveceph' );
464 var schema
= PVE
. Utils
. storageSchema
[ value
];
468 return Proxmox
. Utils
. unknownText
;
471 format_ha : function ( value
) {
472 var text
= Proxmox
. Utils
. noneText
;
475 text
= value
. state
|| Proxmox
. Utils
. noneText
;
477 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
478 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
484 format_content_types : function ( value
) {
487 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
488 if ( ct
=== 'images' ) {
489 cta
. push ( PVE
. Utils
. imagesText
);
490 } else if ( ct
=== 'backup' ) {
491 cta
. push ( PVE
. Utils
. backupFileText
);
492 } else if ( ct
=== 'vztmpl' ) {
493 cta
. push ( PVE
. Utils
. vztmplText
);
494 } else if ( ct
=== 'iso' ) {
495 cta
. push ( PVE
. Utils
. isoImageText
);
496 } else if ( ct
=== 'rootdir' ) {
497 cta
. push ( PVE
. Utils
. containersText
);
501 return cta
. join ( ', ' );
504 render_storage_content : function ( value
, metaData
, record
) {
505 var data
= record
. data
;
506 if ( Ext
. isNumber ( data
. channel
) &&
507 Ext
. isNumber ( data
. id
) &&
508 Ext
. isNumber ( data
. lun
)) {
510 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
511 " ID " + data
. id
+ " LUN " + data
. lun
;
513 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
516 render_serverity : function ( value
) {
517 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
520 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
522 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
526 var maxcpu
= record
. data
. maxcpu
|| 1 ;
528 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
532 var per
= value
* 100 ;
534 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
537 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
538 /*jslint confusion: true */
540 if (! Ext
. isNumeric ( value
)) {
544 return Proxmox
. Utils
. format_size ( value
);
547 render_bandwidth : function ( value
) {
548 if (! Ext
. isNumeric ( value
)) {
552 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
555 render_timestamp_human_readable : function ( value
) {
556 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
559 render_duration : function ( value
) {
560 if ( value
=== undefined ) {
563 return PVE
. Utils
. format_duration_short ( value
);
566 calculate_mem_usage : function ( data
) {
567 if (! Ext
. isNumeric ( data
. mem
) ||
573 return ( data
. mem
/ data
. maxmem
);
576 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
577 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
581 // we got no percentage but bytes
583 var maxmem
= record
. data
. maxmem
;
584 if (! record
. data
. uptime
||
586 ! Ext
. isNumeric ( mem
)) {
590 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
592 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
595 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
598 var maxmem
= record
. data
. maxmem
;
600 if (! record
. data
. uptime
) {
604 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
608 return PVE
. Utils
. render_size ( value
);
611 calculate_disk_usage : function ( data
) {
613 if (! Ext
. isNumeric ( data
. disk
) ||
614 data
. type
=== 'qemu' ||
615 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
616 data
. maxdisk
=== 0 ) {
620 return ( data
. disk
/ data
. maxdisk
);
623 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
624 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
628 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
631 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
634 var maxdisk
= record
. data
. maxdisk
;
635 var type
= record
. data
. type
;
637 if (! Ext
. isNumeric ( disk
) ||
640 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
644 return PVE
. Utils
. render_size ( value
);
647 get_object_icon_class : function ( type
, record
) {
651 if ( type
=== 'type' ) {
653 objType
= record
. groupbyid
;
654 } else if ( record
. template
) {
656 objType
= 'template' ;
660 status
= record
. status
+ ' ha-' + record
. hastate
;
663 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
664 if ( defaults
&& defaults
. iconCls
) {
665 var retVal
= defaults
. iconCls
+ ' ' + status
;
672 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
674 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
676 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
680 render_support_level : function ( value
, metaData
, record
) {
681 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
684 render_upid : function ( value
, metaData
, record
) {
685 var type
= record
. data
. type
;
686 var id
= record
. data
. id
;
688 return Proxmox
. Utils
. format_task_description ( type
, id
);
691 /* render functions for new status panel */
693 render_usage : function ( val
) {
694 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
697 render_cpu_usage : function ( val
, max
) {
698 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
699 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
702 render_size_usage : function ( val
, max
) {
704 return gettext ( 'N/A' );
706 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
707 Ext
. String
. format ( gettext ( '{0} of {1}' ),
708 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
711 /* this is different for nodes */
712 render_node_cpu_usage : function ( value
, record
) {
713 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
716 /* this is different for nodes */
717 render_node_size_usage : function ( record
) {
718 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
721 windowHostname : function () {
722 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
723 function ( m
, addr
, offset
, original
) { return addr
; });
726 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
727 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
728 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
731 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
732 // kvm, lxc, shell, upgrade
734 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
735 throw "missing vmid" ;
739 throw "no nodename specified" ;
742 if ( viewer
=== 'html5' ) {
743 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
744 } else if ( viewer
=== 'xtermjs' ) {
745 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
);
746 } else if ( viewer
=== 'vv' ) {
748 var params
= { proxy
: PVE
. Utils
. windowHostname () };
749 if ( vmtype
=== 'kvm' ) {
750 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
751 PVE
. Utils
. openSpiceViewer ( url
, params
);
752 } else if ( vmtype
=== 'lxc' ) {
753 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
754 PVE
. Utils
. openSpiceViewer ( url
, params
);
755 } else if ( vmtype
=== 'shell' ) {
756 url
= '/nodes/' + nodename
+ '/spiceshell' ;
757 PVE
. Utils
. openSpiceViewer ( url
, params
);
758 } else if ( vmtype
=== 'upgrade' ) {
759 url
= '/nodes/' + nodename
+ '/spiceshell' ;
761 PVE
. Utils
. openSpiceViewer ( url
, params
);
764 throw "unknown viewer type" ;
768 defaultViewer : function ( allowSpice
) {
769 var vncdefault
= 'html5' ;
770 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
771 if ( dv
=== 'vv' && ! allowSpice
) {
778 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
779 var url
= Ext
. urlEncode ({
780 console
: vmtype
, // kvm, lxc, upgrade or shell
786 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
790 openSpiceViewer : function ( url
, params
){
792 var downloadWithName = function ( uri
, name
) {
793 var link
= Ext
. DomHelper
. append ( document
. body
, {
796 css
: 'display:none;visibility:hidden;height:0px;'
799 // Note: we need to tell android the correct file name extension
800 // but we do not set 'download' tag for other environments, because
801 // It can have strange side effects (additional user prompt on firefox)
802 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
804 link
. download
= name
;
807 if ( link
. fireEvent
) {
808 link
. fireEvent ( 'onclick' );
810 var evt
= document
. createEvent ( "MouseEvents" );
811 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
812 link
. dispatchEvent ( evt
);
816 Proxmox
. Utils
. API2Request ({
820 failure : function ( response
, opts
){
821 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
823 success : function ( response
, opts
){
824 var raw
= "[virt-viewer] \n " ;
825 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
826 raw
+= k
+ "=" + v
+ " \n " ;
828 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
829 encodeURIComponent ( raw
);
831 downloadWithName ( url
, "pve-spice.vv" );
836 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
838 var nodename
= record
. data
. node
;
839 var vmid
= record
. data
. vmid
;
840 var vmname
= record
. data
. name
;
841 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
842 Proxmox
. Utils
. API2Request ({
843 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
844 failure : function ( response
, opts
) {
845 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
847 success : function ( response
, opts
) {
848 var allowSpice
= response
. result
. data
. spice
;
849 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
852 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
853 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
857 // test automation helper
858 call_menu_handler : function ( menu
, text
) {
860 var list
= menu
. query ( 'menuitem' );
862 Ext
. Array
. each ( list
, function ( item
) {
863 if ( item
. text
=== text
) {
874 createCmdMenu : function ( v
, record
, item
, index
, event
) {
876 if (!( v
instanceof Ext
. tree
. View
)) {
880 var template
= !! record
. data
. template
;
881 var type
= record
. data
. type
;
884 if ( type
=== 'qemu' || type
== 'lxc' ) {
885 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
889 } else if ( type
=== 'qemu' ||
892 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
894 nodename
: record
. data
. node
900 menu
. showAt ( event
. getXY ());
903 // helper for deleting field which are set to there default values
904 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
905 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
907 if ( values
[ 'delete' ]) {
908 values
[ 'delete' ] += ',' + fieldname
;
910 values
[ 'delete' ] = fieldname
;
914 delete values
[ fieldname
];
918 loadSSHKeyFromFile : function ( file
, callback
) {
919 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
920 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
921 // assume: 740*8 for max. 32kbit (5920 byte file)
922 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
923 if ( file
. size
> 8192 ) {
924 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
930 var reader
= new FileReader ();
931 reader
. onload = function ( evt
) {
932 callback ( evt
. target
. result
);
934 reader
. readAsText ( file
);
937 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
939 // types is either undefined (all busses), an array of busses, or a single bus
940 forEachBus : function ( types
, func
) {
941 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
942 var i
, j
, count
, cont
;
944 if ( Ext
. isArray ( types
)) {
946 } else if ( Ext
. isDefined ( types
)) {
950 // check if we only have valid busses
951 for ( i
= 0 ; i
< busses
. length
; i
++) {
952 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
953 throw "invalid bus: '" + busses
[ i
] + "'" ;
957 for ( i
= 0 ; i
< busses
. length
; i
++) {
958 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
959 for ( j
= 0 ; j
< count
; j
++) {
960 cont
= func ( busses
[ i
], j
);
961 if (! cont
&& cont
!== undefined ) {
968 mp_counts
: { mps
: 10 , unused
: 10 },
970 forEachMP : function ( func
, includeUnused
) {
972 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
973 cont
= func ( 'mp' , i
);
974 if (! cont
&& cont
!== undefined ) {
979 if (! includeUnused
) {
983 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
984 cont
= func ( 'unused' , i
);
985 if (! cont
&& cont
!== undefined ) {
993 constructor : function () {
995 Ext
. apply ( me
, me
. utilities
);