]>
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_machine : function ( value
) {
232 return value
|| ( Proxmox
. Utils
. defaultText
+ ' (i440fx)' );
235 render_qemu_bios : function ( value
) {
237 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
238 } else if ( value
=== 'seabios' ) {
240 } else if ( value
=== 'ovmf' ) {
241 return "OVMF (UEFI)" ;
247 render_scsihw : function ( value
) {
249 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
250 } else if ( value
=== 'lsi' ) {
251 return 'LSI 53C895A' ;
252 } else if ( value
=== 'lsi53c810' ) {
254 } else if ( value
=== 'megasas' ) {
255 return 'MegaRAID SAS 8708EM2' ;
256 } else if ( value
=== 'virtio-scsi-pci' ) {
257 return 'VirtIO SCSI' ;
258 } else if ( value
=== 'virtio-scsi-single' ) {
259 return 'VirtIO SCSI single' ;
260 } else if ( value
=== 'pvscsi' ) {
261 return 'VMware PVSCSI' ;
267 // fixme: auto-generate this
268 // for now, please keep in sync with PVE::Tools::kvmkeymaps
273 'de-ch' : 'German (Swiss)' ,
274 'en-gb' : 'English (UK)' ,
275 'en-us' : 'English (USA)' ,
279 //fo: 'Faroe Islands',
281 'fr-be' : 'French (Belgium)' ,
282 'fr-ca' : 'French (Canada)' ,
283 'fr-ch' : 'French (Swiss)' ,
293 //'nl-be': 'Dutch (Belgium)',
297 'pt-br' : 'Portuguese (Brazil)' ,
306 std
: gettext ( 'Standard VGA' ),
307 vmware
: gettext ( 'VMware compatible' ),
309 qxl2
: 'SPICE dual monitor' ,
310 qxl3
: 'SPICE three monitors' ,
311 qxl4
: 'SPICE four monitors' ,
312 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
313 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
314 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
315 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
316 virtio
: 'VirtIO-GPU' ,
317 none
: Proxmox
. Utils
. noneText
320 render_kvm_language : function ( value
) {
321 if (! value
|| value
=== '__default__' ) {
322 return Proxmox
. Utils
. defaultText
;
324 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
326 return text
+ ' (' + value
+ ')' ;
331 kvm_keymap_array : function () {
332 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
333 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
334 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
341 '__default__' : Proxmox
. Utils
. defaultText
+ ' (HTML5)' ,
342 'vv' : 'SPICE (remote-viewer)' ,
343 'html5' : 'HTML5 (noVNC)' ,
344 'xtermjs' : 'xterm.js'
347 render_console_viewer : function ( value
) {
348 value
= value
|| '__default__' ;
349 if ( PVE
. Utils
. console_map
[ value
]) {
350 return PVE
. Utils
. console_map
[ value
];
355 console_viewer_array : function () {
356 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
357 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
361 render_kvm_vga_driver : function ( value
) {
363 return Proxmox
. Utils
. defaultText
;
365 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
366 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
368 text
= Proxmox
. Utils
. defaultText
;
371 return text
+ ' (' + value
+ ')' ;
376 kvm_vga_driver_array : function () {
377 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
378 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
379 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
385 render_kvm_startup : function ( value
) {
386 var startup
= PVE
. Parser
. parseStartup ( value
);
389 if ( startup
. order
=== undefined ) {
392 res
+= startup
. order
;
394 if ( startup
. up
!== undefined ) {
395 res
+= ',up=' + startup
. up
;
397 if ( startup
. down
!== undefined ) {
398 res
+= ',down=' + startup
. down
;
404 extractFormActionError : function ( action
) {
406 switch ( action
. failureType
) {
407 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
408 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
410 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
411 msg
= gettext ( 'Connection error' );
412 var resp
= action
. response
;
413 if ( resp
. status
&& resp
. statusText
) {
414 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
417 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
418 case Ext
. form
. action
. Action
. SERVER_INVALID
:
419 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
425 format_duration_short : function ( ut
) {
428 return ut
. toFixed ( 1 ) + 's' ;
433 return mins
. toFixed ( 1 ) + 'm' ;
437 var hours
= ut
/ 3600 ;
438 return hours
. toFixed ( 1 ) + 'h' ;
441 var days
= ut
/ 86400 ;
442 return days
. toFixed ( 1 ) + 'd' ;
446 'images' : gettext ( 'Disk image' ),
447 'backup' : gettext ( 'VZDump backup file' ),
448 'vztmpl' : gettext ( 'Container template' ),
449 'iso' : gettext ( 'ISO image' ),
450 'rootdir' : gettext ( 'Container' ),
451 'snippets' : gettext ( 'Snippets' )
456 name
: Proxmox
. Utils
. directoryText
,
457 ipanel
: 'DirInputPanel' ,
462 ipanel
: 'LVMInputPanel' ,
467 ipanel
: 'LvmThinInputPanel' ,
472 ipanel
: 'NFSInputPanel' ,
477 ipanel
: 'CIFSInputPanel' ,
482 ipanel
: 'GlusterFsInputPanel' ,
487 ipanel
: 'IScsiInputPanel' ,
492 ipanel
: 'SheepdogInputPanel' ,
498 ipanel
: 'CephFSInputPanel' ,
502 name
: 'CephFS (PVE)' ,
503 ipanel
: 'CephFSInputPanel' ,
509 ipanel
: 'RBDInputPanel' ,
514 ipanel
: 'RBDInputPanel' ,
519 name
: 'ZFS over iSCSI' ,
520 ipanel
: 'ZFSInputPanel' ,
525 ipanel
: 'ZFSPoolInputPanel' ,
534 format_storage_type : function ( value
, md
, record
) {
535 if ( value
=== 'rbd' ) {
536 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
537 } else if ( value
=== 'cephfs' ) {
538 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
541 var schema
= PVE
. Utils
. storageSchema
[ value
];
545 return Proxmox
. Utils
. unknownText
;
548 format_ha : function ( value
) {
549 var text
= Proxmox
. Utils
. noneText
;
552 text
= value
. state
|| Proxmox
. Utils
. noneText
;
554 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
555 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
561 format_content_types : function ( value
) {
562 return value
. split ( ',' ). sort (). map ( function ( ct
) {
563 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
567 render_storage_content : function ( value
, metaData
, record
) {
568 var data
= record
. data
;
569 if ( Ext
. isNumber ( data
. channel
) &&
570 Ext
. isNumber ( data
. id
) &&
571 Ext
. isNumber ( data
. lun
)) {
573 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
574 " ID " + data
. id
+ " LUN " + data
. lun
;
576 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
579 render_serverity : function ( value
) {
580 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
583 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
585 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
589 var maxcpu
= record
. data
. maxcpu
|| 1 ;
591 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
595 var per
= value
* 100 ;
597 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
600 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
601 /*jslint confusion: true */
603 if (! Ext
. isNumeric ( value
)) {
607 return Proxmox
. Utils
. format_size ( value
);
610 render_bandwidth : function ( value
) {
611 if (! Ext
. isNumeric ( value
)) {
615 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
618 render_timestamp_human_readable : function ( value
) {
619 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
622 render_duration : function ( value
) {
623 if ( value
=== undefined ) {
626 return PVE
. Utils
. format_duration_short ( value
);
629 calculate_mem_usage : function ( data
) {
630 if (! Ext
. isNumeric ( data
. mem
) ||
636 return ( data
. mem
/ data
. maxmem
);
639 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
640 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
644 // we got no percentage but bytes
646 var maxmem
= record
. data
. maxmem
;
647 if (! record
. data
. uptime
||
649 ! Ext
. isNumeric ( mem
)) {
653 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
655 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
658 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
661 var maxmem
= record
. data
. maxmem
;
663 if (! record
. data
. uptime
) {
667 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
671 return PVE
. Utils
. render_size ( value
);
674 calculate_disk_usage : function ( data
) {
676 if (! Ext
. isNumeric ( data
. disk
) ||
677 data
. type
=== 'qemu' ||
678 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
679 data
. maxdisk
=== 0 ) {
683 return ( data
. disk
/ data
. maxdisk
);
686 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
687 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
691 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
694 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
697 var maxdisk
= record
. data
. maxdisk
;
698 var type
= record
. data
. type
;
700 if (! Ext
. isNumeric ( disk
) ||
703 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
707 return PVE
. Utils
. render_size ( value
);
710 get_object_icon_class : function ( type
, record
) {
714 if ( type
=== 'type' ) {
716 objType
= record
. groupbyid
;
717 } else if ( record
. template
) {
719 objType
= 'template' ;
723 status
= record
. status
+ ' ha-' + record
. hastate
;
726 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
727 if ( defaults
&& defaults
. iconCls
) {
728 var retVal
= defaults
. iconCls
+ ' ' + status
;
735 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
737 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
739 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
743 render_support_level : function ( value
, metaData
, record
) {
744 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
747 render_upid : function ( value
, metaData
, record
) {
748 var type
= record
. data
. type
;
749 var id
= record
. data
. id
;
751 return Proxmox
. Utils
. format_task_description ( type
, id
);
754 /* render functions for new status panel */
756 render_usage : function ( val
) {
757 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
760 render_cpu_usage : function ( val
, max
) {
761 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
762 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
765 render_size_usage : function ( val
, max
) {
767 return gettext ( 'N/A' );
769 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
770 Ext
. String
. format ( gettext ( '{0} of {1}' ),
771 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
774 /* this is different for nodes */
775 render_node_cpu_usage : function ( value
, record
) {
776 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
779 /* this is different for nodes */
780 render_node_size_usage : function ( record
) {
781 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
784 render_optional_url : function ( value
) {
786 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
787 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
792 render_san : function ( value
) {
794 if ( Ext
. isArray ( value
)) {
795 value
. forEach ( function ( val
) {
796 if (! Ext
. isNumber ( val
)) {
800 return names
. join ( '<br>' );
805 render_full_name : function ( firstname
, metaData
, record
) {
806 var first
= firstname
|| '' ;
807 var last
= record
. data
. lastname
|| '' ;
808 return Ext
. htmlEncode ( first
+ " " + last
);
811 windowHostname : function () {
812 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
813 function ( m
, addr
, offset
, original
) { return addr
; });
816 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
817 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
818 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
, cmd
);
821 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
822 // kvm, lxc, shell, upgrade
824 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
825 throw "missing vmid" ;
829 throw "no nodename specified" ;
832 if ( viewer
=== 'html5' ) {
833 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
834 } else if ( viewer
=== 'xtermjs' ) {
835 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
836 } else if ( viewer
=== 'vv' ) {
838 var params
= { proxy
: PVE
. Utils
. windowHostname () };
839 if ( vmtype
=== 'kvm' ) {
840 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
841 PVE
. Utils
. openSpiceViewer ( url
, params
);
842 } else if ( vmtype
=== 'lxc' ) {
843 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
844 PVE
. Utils
. openSpiceViewer ( url
, params
);
845 } else if ( vmtype
=== 'shell' ) {
846 url
= '/nodes/' + nodename
+ '/spiceshell' ;
847 PVE
. Utils
. openSpiceViewer ( url
, params
);
848 } else if ( vmtype
=== 'upgrade' ) {
849 url
= '/nodes/' + nodename
+ '/spiceshell' ;
851 PVE
. Utils
. openSpiceViewer ( url
, params
);
852 } else if ( vmtype
=== 'cmd' ) {
853 url
= '/nodes/' + nodename
+ '/spiceshell' ;
855 PVE
. Utils
. openSpiceViewer ( url
, params
);
858 throw "unknown viewer type" ;
862 defaultViewer : function ( consoles
) {
864 var allowSpice
, allowXtermjs
;
866 if ( consoles
=== true ) {
869 } else if ( typeof consoles
=== 'object' ) {
870 allowSpice
= consoles
. spice
;
871 allowXtermjs
= !! consoles
. xtermjs
;
873 var vncdefault
= 'html5' ;
874 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
875 if (( dv
=== 'vv' && ! allowSpice
) || ( dv
=== 'xtermjs' && ! allowXtermjs
)) {
882 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
883 var url
= Ext
. Object
. toQueryString ({
884 console
: vmtype
, // kvm, lxc, upgrade or shell
892 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
898 openSpiceViewer : function ( url
, params
){
900 var downloadWithName = function ( uri
, name
) {
901 var link
= Ext
. DomHelper
. append ( document
. body
, {
904 css
: 'display:none;visibility:hidden;height:0px;'
907 // Note: we need to tell android the correct file name extension
908 // but we do not set 'download' tag for other environments, because
909 // It can have strange side effects (additional user prompt on firefox)
910 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
912 link
. download
= name
;
915 if ( link
. fireEvent
) {
916 link
. fireEvent ( 'onclick' );
918 var evt
= document
. createEvent ( "MouseEvents" );
919 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
920 link
. dispatchEvent ( evt
);
924 Proxmox
. Utils
. API2Request ({
928 failure : function ( response
, opts
){
929 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
931 success : function ( response
, opts
){
932 var raw
= "[virt-viewer] \n " ;
933 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
934 raw
+= k
+ "=" + v
+ " \n " ;
936 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
937 encodeURIComponent ( raw
);
939 downloadWithName ( url
, "pve-spice.vv" );
944 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
946 var nodename
= record
. data
. node
;
947 var vmid
= record
. data
. vmid
;
948 var vmname
= record
. data
. name
;
949 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
950 Proxmox
. Utils
. API2Request ({
951 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
952 failure : function ( response
, opts
) {
953 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
955 success : function ( response
, opts
) {
956 var allowSpice
= !! response
. result
. data
. spice
;
957 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
960 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
961 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
965 // test automation helper
966 call_menu_handler : function ( menu
, text
) {
968 var list
= menu
. query ( 'menuitem' );
970 Ext
. Array
. each ( list
, function ( item
) {
971 if ( item
. text
=== text
) {
982 createCmdMenu : function ( v
, record
, item
, index
, event
) {
984 if (!( v
instanceof Ext
. tree
. View
)) {
988 var template
= !! record
. data
. template
;
989 var type
= record
. data
. type
;
992 if ( type
=== 'qemu' || type
== 'lxc' ) {
993 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
997 } else if ( type
=== 'qemu' ||
1000 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1002 nodename
: record
. data
. node
1008 menu
. showAt ( event
. getXY ());
1012 // helper for deleting field which are set to there default values
1013 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1014 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1016 if ( values
[ 'delete' ]) {
1017 values
[ 'delete' ] += ',' + fieldname
;
1019 values
[ 'delete' ] = fieldname
;
1023 delete values
[ fieldname
];
1027 loadSSHKeyFromFile : function ( file
, callback
) {
1028 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1029 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1030 // assume: 740*8 for max. 32kbit (5920 byte file)
1031 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1032 if ( file
. size
> 8192 ) {
1033 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1039 var reader
= new FileReader ();
1040 reader
. onload = function ( evt
) {
1041 callback ( evt
. target
. result
);
1043 reader
. readAsText ( file
);
1046 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
1048 // types is either undefined (all busses), an array of busses, or a single bus
1049 forEachBus : function ( types
, func
) {
1050 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
1051 var i
, j
, count
, cont
;
1053 if ( Ext
. isArray ( types
)) {
1055 } else if ( Ext
. isDefined ( types
)) {
1059 // check if we only have valid busses
1060 for ( i
= 0 ; i
< busses
. length
; i
++) {
1061 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
1062 throw "invalid bus: '" + busses
[ i
] + "'" ;
1066 for ( i
= 0 ; i
< busses
. length
; i
++) {
1067 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
1068 for ( j
= 0 ; j
< count
; j
++) {
1069 cont
= func ( busses
[ i
], j
);
1070 if (! cont
&& cont
!== undefined ) {
1077 mp_counts
: { mps
: 256 , unused
: 256 },
1079 forEachMP : function ( func
, includeUnused
) {
1081 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1082 cont
= func ( 'mp' , i
);
1083 if (! cont
&& cont
!== undefined ) {
1088 if (! includeUnused
) {
1092 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1093 cont
= func ( 'unused' , i
);
1094 if (! cont
&& cont
!== undefined ) {
1100 cleanEmptyObjectKeys : function ( obj
) {
1102 for ( propName
in obj
) {
1103 if ( obj
. hasOwnProperty ( propName
)) {
1104 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1105 delete obj
[ propName
];
1111 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1113 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1116 Proxmox
. Utils
. setErrorMask ( me
, false );
1121 if ( operation
. error
. statusText
) {
1122 if ( operation
. error
. statusText
. match ( regex
)) {
1123 callback ( me
, operation
. error
);
1126 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1129 msg
= gettext ( 'Connection error' );
1131 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1135 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1136 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1137 if ( msg
. match ( regex
)) {
1138 if ( Proxmox
. UserName
=== 'root@pam' ) {
1139 container
. el
. mask ();
1140 if (! container
. down ( 'pveCephInstallWindow' )){
1141 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1149 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1150 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1160 constructor : function () {
1162 Ext
. apply ( me
, me
. utilities
);