]>
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_bios : function ( value
) {
233 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
234 } else if ( value
=== 'seabios' ) {
236 } else if ( value
=== 'ovmf' ) {
237 return "OVMF (UEFI)" ;
243 render_scsihw : function ( value
) {
245 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
246 } else if ( value
=== 'lsi' ) {
247 return 'LSI 53C895A' ;
248 } else if ( value
=== 'lsi53c810' ) {
250 } else if ( value
=== 'megasas' ) {
251 return 'MegaRAID SAS 8708EM2' ;
252 } else if ( value
=== 'virtio-scsi-pci' ) {
253 return 'VirtIO SCSI' ;
254 } else if ( value
=== 'virtio-scsi-single' ) {
255 return 'VirtIO SCSI single' ;
256 } else if ( value
=== 'pvscsi' ) {
257 return 'VMware PVSCSI' ;
263 // fixme: auto-generate this
264 // for now, please keep in sync with PVE::Tools::kvmkeymaps
269 'de-ch' : 'German (Swiss)' ,
270 'en-gb' : 'English (UK)' ,
271 'en-us' : 'English (USA)' ,
275 //fo: 'Faroe Islands',
277 'fr-be' : 'French (Belgium)' ,
278 'fr-ca' : 'French (Canada)' ,
279 'fr-ch' : 'French (Swiss)' ,
289 //'nl-be': 'Dutch (Belgium)',
293 'pt-br' : 'Portuguese (Brazil)' ,
302 std
: gettext ( 'Standard VGA' ),
303 vmware
: gettext ( 'VMware compatible' ),
305 qxl2
: 'SPICE dual monitor' ,
306 qxl3
: 'SPICE three monitors' ,
307 qxl4
: 'SPICE four monitors' ,
308 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
309 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
310 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
311 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
312 virtio
: 'VirtIO-GPU' ,
313 none
: Proxmox
. Utils
. noneText
316 render_kvm_language : function ( value
) {
317 if (! value
|| value
=== '__default__' ) {
318 return Proxmox
. Utils
. defaultText
;
320 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
322 return text
+ ' (' + value
+ ')' ;
327 kvm_keymap_array : function () {
328 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
329 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
330 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
337 '__default__' : Proxmox
. Utils
. defaultText
+ ' (HTML5)' ,
338 'vv' : 'SPICE (remote-viewer)' ,
339 'html5' : 'HTML5 (noVNC)' ,
340 'xtermjs' : 'xterm.js'
343 render_console_viewer : function ( value
) {
344 value
= value
|| '__default__' ;
345 if ( PVE
. Utils
. console_map
[ value
]) {
346 return PVE
. Utils
. console_map
[ value
];
351 console_viewer_array : function () {
352 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
353 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
357 render_kvm_vga_driver : function ( value
) {
359 return Proxmox
. Utils
. defaultText
;
361 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
362 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
364 text
= Proxmox
. Utils
. defaultText
;
367 return text
+ ' (' + value
+ ')' ;
372 kvm_vga_driver_array : function () {
373 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
374 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
375 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
381 render_kvm_startup : function ( value
) {
382 var startup
= PVE
. Parser
. parseStartup ( value
);
385 if ( startup
. order
=== undefined ) {
388 res
+= startup
. order
;
390 if ( startup
. up
!== undefined ) {
391 res
+= ',up=' + startup
. up
;
393 if ( startup
. down
!== undefined ) {
394 res
+= ',down=' + startup
. down
;
400 extractFormActionError : function ( action
) {
402 switch ( action
. failureType
) {
403 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
404 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
406 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
407 msg
= gettext ( 'Connection error' );
408 var resp
= action
. response
;
409 if ( resp
. status
&& resp
. statusText
) {
410 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
413 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
414 case Ext
. form
. action
. Action
. SERVER_INVALID
:
415 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
421 format_duration_short : function ( ut
) {
424 return ut
. toFixed ( 1 ) + 's' ;
429 return mins
. toFixed ( 1 ) + 'm' ;
433 var hours
= ut
/ 3600 ;
434 return hours
. toFixed ( 1 ) + 'h' ;
437 var days
= ut
/ 86400 ;
438 return days
. toFixed ( 1 ) + 'd' ;
442 'images' : gettext ( 'Disk image' ),
443 'backup' : gettext ( 'VZDump backup file' ),
444 'vztmpl' : gettext ( 'Container template' ),
445 'iso' : gettext ( 'ISO image' ),
446 'rootdir' : gettext ( 'Container' ),
447 'snippets' : gettext ( 'Snippets' )
452 name
: Proxmox
. Utils
. directoryText
,
453 ipanel
: 'DirInputPanel' ,
458 ipanel
: 'LVMInputPanel' ,
463 ipanel
: 'LvmThinInputPanel' ,
468 ipanel
: 'NFSInputPanel' ,
473 ipanel
: 'CIFSInputPanel' ,
478 ipanel
: 'GlusterFsInputPanel' ,
483 ipanel
: 'IScsiInputPanel' ,
488 ipanel
: 'SheepdogInputPanel' ,
494 ipanel
: 'CephFSInputPanel' ,
498 name
: 'CephFS (PVE)' ,
499 ipanel
: 'CephFSInputPanel' ,
505 ipanel
: 'RBDInputPanel' ,
510 ipanel
: 'RBDInputPanel' ,
515 name
: 'ZFS over iSCSI' ,
516 ipanel
: 'ZFSInputPanel' ,
521 ipanel
: 'ZFSPoolInputPanel' ,
530 format_storage_type : function ( value
, md
, record
) {
531 if ( value
=== 'rbd' ) {
532 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
533 } else if ( value
=== 'cephfs' ) {
534 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
537 var schema
= PVE
. Utils
. storageSchema
[ value
];
541 return Proxmox
. Utils
. unknownText
;
544 format_ha : function ( value
) {
545 var text
= Proxmox
. Utils
. noneText
;
548 text
= value
. state
|| Proxmox
. Utils
. noneText
;
550 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
551 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
557 format_content_types : function ( value
) {
558 return value
. split ( ',' ). sort (). map ( function ( ct
) {
559 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
563 render_storage_content : function ( value
, metaData
, record
) {
564 var data
= record
. data
;
565 if ( Ext
. isNumber ( data
. channel
) &&
566 Ext
. isNumber ( data
. id
) &&
567 Ext
. isNumber ( data
. lun
)) {
569 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
570 " ID " + data
. id
+ " LUN " + data
. lun
;
572 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
575 render_serverity : function ( value
) {
576 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
579 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
581 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
585 var maxcpu
= record
. data
. maxcpu
|| 1 ;
587 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
591 var per
= value
* 100 ;
593 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
596 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
597 /*jslint confusion: true */
599 if (! Ext
. isNumeric ( value
)) {
603 return Proxmox
. Utils
. format_size ( value
);
606 render_bandwidth : function ( value
) {
607 if (! Ext
. isNumeric ( value
)) {
611 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
614 render_timestamp_human_readable : function ( value
) {
615 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
618 render_duration : function ( value
) {
619 if ( value
=== undefined ) {
622 return PVE
. Utils
. format_duration_short ( value
);
625 calculate_mem_usage : function ( data
) {
626 if (! Ext
. isNumeric ( data
. mem
) ||
632 return ( data
. mem
/ data
. maxmem
);
635 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
636 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
640 // we got no percentage but bytes
642 var maxmem
= record
. data
. maxmem
;
643 if (! record
. data
. uptime
||
645 ! Ext
. isNumeric ( mem
)) {
649 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
651 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
654 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
657 var maxmem
= record
. data
. maxmem
;
659 if (! record
. data
. uptime
) {
663 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
667 return PVE
. Utils
. render_size ( value
);
670 calculate_disk_usage : function ( data
) {
672 if (! Ext
. isNumeric ( data
. disk
) ||
673 data
. type
=== 'qemu' ||
674 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
675 data
. maxdisk
=== 0 ) {
679 return ( data
. disk
/ data
. maxdisk
);
682 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
683 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
687 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
690 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
693 var maxdisk
= record
. data
. maxdisk
;
694 var type
= record
. data
. type
;
696 if (! Ext
. isNumeric ( disk
) ||
699 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
703 return PVE
. Utils
. render_size ( value
);
706 get_object_icon_class : function ( type
, record
) {
710 if ( type
=== 'type' ) {
712 objType
= record
. groupbyid
;
713 } else if ( record
. template
) {
715 objType
= 'template' ;
719 status
= record
. status
+ ' ha-' + record
. hastate
;
722 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
723 if ( defaults
&& defaults
. iconCls
) {
724 var retVal
= defaults
. iconCls
+ ' ' + status
;
731 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
733 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
735 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
739 render_support_level : function ( value
, metaData
, record
) {
740 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
743 render_upid : function ( value
, metaData
, record
) {
744 var type
= record
. data
. type
;
745 var id
= record
. data
. id
;
747 return Proxmox
. Utils
. format_task_description ( type
, id
);
750 /* render functions for new status panel */
752 render_usage : function ( val
) {
753 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
756 render_cpu_usage : function ( val
, max
) {
757 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
758 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
761 render_size_usage : function ( val
, max
) {
763 return gettext ( 'N/A' );
765 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
766 Ext
. String
. format ( gettext ( '{0} of {1}' ),
767 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
770 /* this is different for nodes */
771 render_node_cpu_usage : function ( value
, record
) {
772 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
775 /* this is different for nodes */
776 render_node_size_usage : function ( record
) {
777 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
780 render_optional_url : function ( value
) {
782 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
783 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
788 render_san : function ( value
) {
790 if ( Ext
. isArray ( value
)) {
791 value
. forEach ( function ( val
) {
792 if (! Ext
. isNumber ( val
)) {
796 return names
. join ( '<br>' );
801 render_full_name : function ( firstname
, metaData
, record
) {
802 var first
= firstname
|| '' ;
803 var last
= record
. data
. lastname
|| '' ;
804 return Ext
. htmlEncode ( first
+ " " + last
);
807 windowHostname : function () {
808 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
809 function ( m
, addr
, offset
, original
) { return addr
; });
812 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
813 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
814 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
, cmd
);
817 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
818 // kvm, lxc, shell, upgrade
820 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
821 throw "missing vmid" ;
825 throw "no nodename specified" ;
828 if ( viewer
=== 'html5' ) {
829 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
830 } else if ( viewer
=== 'xtermjs' ) {
831 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
832 } else if ( viewer
=== 'vv' ) {
834 var params
= { proxy
: PVE
. Utils
. windowHostname () };
835 if ( vmtype
=== 'kvm' ) {
836 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
837 PVE
. Utils
. openSpiceViewer ( url
, params
);
838 } else if ( vmtype
=== 'lxc' ) {
839 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
840 PVE
. Utils
. openSpiceViewer ( url
, params
);
841 } else if ( vmtype
=== 'shell' ) {
842 url
= '/nodes/' + nodename
+ '/spiceshell' ;
843 PVE
. Utils
. openSpiceViewer ( url
, params
);
844 } else if ( vmtype
=== 'upgrade' ) {
845 url
= '/nodes/' + nodename
+ '/spiceshell' ;
847 PVE
. Utils
. openSpiceViewer ( url
, params
);
848 } else if ( vmtype
=== 'cmd' ) {
849 url
= '/nodes/' + nodename
+ '/spiceshell' ;
851 PVE
. Utils
. openSpiceViewer ( url
, params
);
854 throw "unknown viewer type" ;
858 defaultViewer : function ( consoles
) {
860 var allowSpice
, allowXtermjs
;
862 if ( consoles
=== true ) {
865 } else if ( typeof consoles
=== 'object' ) {
866 allowSpice
= consoles
. spice
;
867 allowXtermjs
= !! consoles
. xtermjs
;
869 var vncdefault
= 'html5' ;
870 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
871 if (( dv
=== 'vv' && ! allowSpice
) || ( dv
=== 'xtermjs' && ! allowXtermjs
)) {
878 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
879 var url
= Ext
. Object
. toQueryString ({
880 console
: vmtype
, // kvm, lxc, upgrade or shell
888 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
894 openSpiceViewer : function ( url
, params
){
896 var downloadWithName = function ( uri
, name
) {
897 var link
= Ext
. DomHelper
. append ( document
. body
, {
900 css
: 'display:none;visibility:hidden;height:0px;'
903 // Note: we need to tell android the correct file name extension
904 // but we do not set 'download' tag for other environments, because
905 // It can have strange side effects (additional user prompt on firefox)
906 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
908 link
. download
= name
;
911 if ( link
. fireEvent
) {
912 link
. fireEvent ( 'onclick' );
914 var evt
= document
. createEvent ( "MouseEvents" );
915 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
916 link
. dispatchEvent ( evt
);
920 Proxmox
. Utils
. API2Request ({
924 failure : function ( response
, opts
){
925 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
927 success : function ( response
, opts
){
928 var raw
= "[virt-viewer] \n " ;
929 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
930 raw
+= k
+ "=" + v
+ " \n " ;
932 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
933 encodeURIComponent ( raw
);
935 downloadWithName ( url
, "pve-spice.vv" );
940 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
942 var nodename
= record
. data
. node
;
943 var vmid
= record
. data
. vmid
;
944 var vmname
= record
. data
. name
;
945 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
946 Proxmox
. Utils
. API2Request ({
947 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
948 failure : function ( response
, opts
) {
949 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
951 success : function ( response
, opts
) {
952 var allowSpice
= !! response
. result
. data
. spice
;
953 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
956 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
957 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
961 // test automation helper
962 call_menu_handler : function ( menu
, text
) {
964 var list
= menu
. query ( 'menuitem' );
966 Ext
. Array
. each ( list
, function ( item
) {
967 if ( item
. text
=== text
) {
978 createCmdMenu : function ( v
, record
, item
, index
, event
) {
980 if (!( v
instanceof Ext
. tree
. View
)) {
984 var template
= !! record
. data
. template
;
985 var type
= record
. data
. type
;
988 if ( type
=== 'qemu' || type
== 'lxc' ) {
989 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
993 } else if ( type
=== 'qemu' ||
996 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
998 nodename
: record
. data
. node
1004 menu
. showAt ( event
. getXY ());
1008 // helper for deleting field which are set to there default values
1009 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1010 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1012 if ( values
[ 'delete' ]) {
1013 values
[ 'delete' ] += ',' + fieldname
;
1015 values
[ 'delete' ] = fieldname
;
1019 delete values
[ fieldname
];
1023 loadSSHKeyFromFile : function ( file
, callback
) {
1024 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1025 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1026 // assume: 740*8 for max. 32kbit (5920 byte file)
1027 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1028 if ( file
. size
> 8192 ) {
1029 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1035 var reader
= new FileReader ();
1036 reader
. onload = function ( evt
) {
1037 callback ( evt
. target
. result
);
1039 reader
. readAsText ( file
);
1042 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
1044 // types is either undefined (all busses), an array of busses, or a single bus
1045 forEachBus : function ( types
, func
) {
1046 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
1047 var i
, j
, count
, cont
;
1049 if ( Ext
. isArray ( types
)) {
1051 } else if ( Ext
. isDefined ( types
)) {
1055 // check if we only have valid busses
1056 for ( i
= 0 ; i
< busses
. length
; i
++) {
1057 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
1058 throw "invalid bus: '" + busses
[ i
] + "'" ;
1062 for ( i
= 0 ; i
< busses
. length
; i
++) {
1063 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
1064 for ( j
= 0 ; j
< count
; j
++) {
1065 cont
= func ( busses
[ i
], j
);
1066 if (! cont
&& cont
!== undefined ) {
1073 mp_counts
: { mps
: 256 , unused
: 256 },
1075 forEachMP : function ( func
, includeUnused
) {
1077 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1078 cont
= func ( 'mp' , i
);
1079 if (! cont
&& cont
!== undefined ) {
1084 if (! includeUnused
) {
1088 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1089 cont
= func ( 'unused' , i
);
1090 if (! cont
&& cont
!== undefined ) {
1096 cleanEmptyObjectKeys : function ( obj
) {
1098 for ( propName
in obj
) {
1099 if ( obj
. hasOwnProperty ( propName
)) {
1100 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1101 delete obj
[ propName
];
1107 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1109 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1112 Proxmox
. Utils
. setErrorMask ( me
, false );
1117 if ( operation
. error
. statusText
) {
1118 if ( operation
. error
. statusText
. match ( regex
)) {
1119 callback ( me
, operation
. error
);
1122 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1125 msg
= gettext ( 'Connection error' );
1127 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1131 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1132 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1133 if ( msg
. match ( regex
)) {
1134 if ( Proxmox
. UserName
=== 'root@pam' ) {
1135 container
. el
. mask ();
1136 if (! container
. down ( 'pveCephInstallWindow' )){
1137 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1145 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) + gettext ( ' Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1155 constructor : function () {
1157 Ext
. apply ( me
, me
. utilities
);