]>
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="https://www.proxmox.com/products/proxmox-ve/subscription-service-plans">www.proxmox.com</a> to get a list of available options.' ,
53 { desc
: '5.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-refresh' ;
90 icon
= 'warning fa-exclamation' ;
93 icon
= 'critical fa-times' ;
105 parse_ceph_version : function ( service
) {
106 if ( service
. ceph_version_short
) {
107 return service
. ceph_version_short
;
110 if ( service
. ceph_version
) {
111 var match
= service
. ceph_version
. match ( /version (\d+(\.\d+)*)/ );
120 compare_ceph_versions : function ( a
, b
) {
124 let avers
= a
. toString (). split ( '.' );
125 let bvers
= b
. toString (). split ( '.' );
128 let av
= avers
. shift ();
129 let bv
= bvers
. shift ();
131 if ( av
=== undefined && bv
=== undefined ) {
133 } else if ( av
=== undefined ) {
135 } else if ( bv
=== undefined ) {
138 let diff
= parseInt ( av
, 10 ) - parseInt ( bv
, 10 );
139 if ( diff
!= 0 ) return diff
;
140 // else we need to look at the next parts
146 get_ceph_icon_html : function ( health
, fw
) {
147 var state
= PVE
. Utils
. map_ceph_health
[ health
];
148 var cls
= PVE
. Utils
. get_health_icon ( state
);
152 return "<i class='fa " + cls
+ "'></i> " ;
158 'HEALTH_WARN' : 'warning' ,
159 'HEALTH_ERR' : 'critical'
162 render_ceph_health : function ( healthObj
) {
164 iconCls
: PVE
. Utils
. get_health_icon (),
168 if (! healthObj
|| ! healthObj
. status
) {
172 var health
= PVE
. Utils
. map_ceph_health
[ healthObj
. status
];
174 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
175 state
. text
= healthObj
. status
;
180 render_zfs_health : function ( value
) {
181 if ( typeof value
== 'undefined' ){
184 var iconCls
= 'question-circle' ;
188 iconCls
= 'check-circle good' ;
192 iconCls
= 'exclamation-circle warning' ;
197 iconCls
= 'times-circle critical' ;
202 return '<i class="fa fa-' + iconCls
+ '"></i> ' + value
;
206 get_kvm_osinfo : function ( value
) {
207 var info
= { base
: 'Other' }; // default
209 Ext
. each ( Object
. keys ( PVE
. Utils
. kvm_ostypes
), function ( k
) {
210 Ext
. each ( PVE
. Utils
. kvm_ostypes
[ k
], function ( e
) {
211 if ( e
. val
=== value
) {
212 info
= { desc
: e
. desc
, base
: k
};
220 render_kvm_ostype : function ( value
) {
221 var osinfo
= PVE
. Utils
. get_kvm_osinfo ( value
);
222 if ( osinfo
. desc
&& osinfo
. desc
!== '-' ) {
223 return osinfo
. base
+ ' ' + osinfo
. desc
;
229 render_hotplug_features : function ( value
) {
232 if (! value
|| ( value
=== '0' )) {
233 return gettext ( 'Disabled' );
237 value
= 'disk,network,usb' ;
240 Ext
. each ( value
. split ( ',' ), function ( el
) {
242 fa
. push ( gettext ( 'Disk' ));
243 } else if ( el
=== 'network' ) {
244 fa
. push ( gettext ( 'Network' ));
245 } else if ( el
=== 'usb' ) {
247 } else if ( el
=== 'memory' ) {
248 fa
. push ( gettext ( 'Memory' ));
249 } else if ( el
=== 'cpu' ) {
250 fa
. push ( gettext ( 'CPU' ));
256 return fa
. join ( ', ' );
259 render_qga_features : function ( value
) {
261 return Proxmox
. Utils
. defaultText
+ ' (' + Proxmox
. Utils
. disabledText
+ ')' ;
263 var props
= PVE
. Parser
. parsePropertyString ( value
, 'enabled' );
264 if (! PVE
. Parser
. parseBoolean ( props
. enabled
)) {
265 return Proxmox
. Utils
. disabledText
;
268 delete props
. enabled
;
269 var agentstring
= Proxmox
. Utils
. enabledText
;
271 Ext
. Object
. each ( props
, function ( key
, value
) {
273 agentstring
+= ', ' + key
+ ': ' ;
275 if ( PVE
. Parser
. parseBoolean ( value
)) {
276 agentstring
+= Proxmox
. Utils
. enabledText
;
278 agentstring
+= Proxmox
. Utils
. disabledText
;
285 render_qemu_machine : function ( value
) {
286 return value
|| ( Proxmox
. Utils
. defaultText
+ ' (i440fx)' );
289 render_qemu_bios : function ( value
) {
291 return Proxmox
. Utils
. defaultText
+ ' (SeaBIOS)' ;
292 } else if ( value
=== 'seabios' ) {
294 } else if ( value
=== 'ovmf' ) {
295 return "OVMF (UEFI)" ;
301 render_dc_ha_opts : function ( value
) {
303 return Proxmox
. Utils
. defaultText
;
305 return PVE
. Parser
. printPropertyString ( value
);
308 render_as_property_string : function ( value
) {
309 return (! value
) ? Proxmox
. Utils
. defaultText
310 : PVE
. Parser
. printPropertyString ( value
);
313 render_scsihw : function ( value
) {
315 return Proxmox
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
316 } else if ( value
=== 'lsi' ) {
317 return 'LSI 53C895A' ;
318 } else if ( value
=== 'lsi53c810' ) {
320 } else if ( value
=== 'megasas' ) {
321 return 'MegaRAID SAS 8708EM2' ;
322 } else if ( value
=== 'virtio-scsi-pci' ) {
323 return 'VirtIO SCSI' ;
324 } else if ( value
=== 'virtio-scsi-single' ) {
325 return 'VirtIO SCSI single' ;
326 } else if ( value
=== 'pvscsi' ) {
327 return 'VMware PVSCSI' ;
333 // fixme: auto-generate this
334 // for now, please keep in sync with PVE::Tools::kvmkeymaps
339 'de-ch' : 'German (Swiss)' ,
340 'en-gb' : 'English (UK)' ,
341 'en-us' : 'English (USA)' ,
345 //fo: 'Faroe Islands',
347 'fr-be' : 'French (Belgium)' ,
348 'fr-ca' : 'French (Canada)' ,
349 'fr-ch' : 'French (Swiss)' ,
359 //'nl-be': 'Dutch (Belgium)',
363 'pt-br' : 'Portuguese (Brazil)' ,
372 std
: gettext ( 'Standard VGA' ),
373 vmware
: gettext ( 'VMware compatible' ),
375 qxl2
: 'SPICE dual monitor' ,
376 qxl3
: 'SPICE three monitors' ,
377 qxl4
: 'SPICE four monitors' ,
378 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
379 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
380 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
381 serial3
: gettext ( 'Serial terminal' ) + ' 3' ,
382 virtio
: 'VirtIO-GPU' ,
383 none
: Proxmox
. Utils
. noneText
386 render_kvm_language : function ( value
) {
387 if (! value
|| value
=== '__default__' ) {
388 return Proxmox
. Utils
. defaultText
;
390 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
392 return text
+ ' (' + value
+ ')' ;
397 kvm_keymap_array : function () {
398 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
399 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
400 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
407 '__default__' : Proxmox
. Utils
. defaultText
+ ' (xterm.js)' ,
408 'vv' : 'SPICE (remote-viewer)' ,
409 'html5' : 'HTML5 (noVNC)' ,
410 'xtermjs' : 'xterm.js'
413 render_console_viewer : function ( value
) {
414 value
= value
|| '__default__' ;
415 if ( PVE
. Utils
. console_map
[ value
]) {
416 return PVE
. Utils
. console_map
[ value
];
421 console_viewer_array : function () {
422 return Ext
. Array
. map ( Object
. keys ( PVE
. Utils
. console_map
), function ( v
) {
423 return [ v
, PVE
. Utils
. render_console_viewer ( v
)];
427 render_kvm_vga_driver : function ( value
) {
429 return Proxmox
. Utils
. defaultText
;
431 var vga
= PVE
. Parser
. parsePropertyString ( value
, 'type' );
432 var text
= PVE
. Utils
. kvm_vga_drivers
[ vga
. type
];
434 text
= Proxmox
. Utils
. defaultText
;
437 return text
+ ' (' + value
+ ')' ;
442 kvm_vga_driver_array : function () {
443 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
444 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
445 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
451 render_kvm_startup : function ( value
) {
452 var startup
= PVE
. Parser
. parseStartup ( value
);
455 if ( startup
. order
=== undefined ) {
458 res
+= startup
. order
;
460 if ( startup
. up
!== undefined ) {
461 res
+= ',up=' + startup
. up
;
463 if ( startup
. down
!== undefined ) {
464 res
+= ',down=' + startup
. down
;
470 extractFormActionError : function ( action
) {
472 switch ( action
. failureType
) {
473 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
474 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
476 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
477 msg
= gettext ( 'Connection error' );
478 var resp
= action
. response
;
479 if ( resp
. status
&& resp
. statusText
) {
480 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
483 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
484 case Ext
. form
. action
. Action
. SERVER_INVALID
:
485 msg
= Proxmox
. Utils
. extractRequestError ( action
. result
, true );
491 format_duration_short : function ( ut
) {
494 return ut
. toFixed ( 1 ) + 's' ;
499 return mins
. toFixed ( 1 ) + 'm' ;
503 var hours
= ut
/ 3600 ;
504 return hours
. toFixed ( 1 ) + 'h' ;
507 var days
= ut
/ 86400 ;
508 return days
. toFixed ( 1 ) + 'd' ;
512 'images' : gettext ( 'Disk image' ),
513 'backup' : gettext ( 'VZDump backup file' ),
514 'vztmpl' : gettext ( 'Container template' ),
515 'iso' : gettext ( 'ISO image' ),
516 'rootdir' : gettext ( 'Container' ),
517 'snippets' : gettext ( 'Snippets' )
522 name
: Proxmox
. Utils
. directoryText
,
523 ipanel
: 'DirInputPanel' ,
528 ipanel
: 'LVMInputPanel' ,
533 ipanel
: 'LvmThinInputPanel' ,
538 ipanel
: 'NFSInputPanel' ,
543 ipanel
: 'CIFSInputPanel' ,
548 ipanel
: 'GlusterFsInputPanel' ,
553 ipanel
: 'IScsiInputPanel' ,
558 ipanel
: 'CephFSInputPanel' ,
562 name
: 'CephFS (PVE)' ,
563 ipanel
: 'CephFSInputPanel' ,
569 ipanel
: 'RBDInputPanel' ,
574 ipanel
: 'RBDInputPanel' ,
579 name
: 'ZFS over iSCSI' ,
580 ipanel
: 'ZFSInputPanel' ,
585 ipanel
: 'ZFSPoolInputPanel' ,
594 format_storage_type : function ( value
, md
, record
) {
595 if ( value
=== 'rbd' ) {
596 value
= (! record
|| record
. get ( 'monhost' ) ? 'rbd' : 'pveceph' );
597 } else if ( value
=== 'cephfs' ) {
598 value
= (! record
|| record
. get ( 'monhost' ) ? 'cephfs' : 'pvecephfs' );
601 var schema
= PVE
. Utils
. storageSchema
[ value
];
605 return Proxmox
. Utils
. unknownText
;
608 format_ha : function ( value
) {
609 var text
= Proxmox
. Utils
. noneText
;
612 text
= value
. state
|| Proxmox
. Utils
. noneText
;
614 text
+= ', ' + Proxmox
. Utils
. groupText
+ ': ' ;
615 text
+= value
. group
|| Proxmox
. Utils
. noneText
;
621 format_content_types : function ( value
) {
622 return value
. split ( ',' ). sort (). map ( function ( ct
) {
623 return PVE
. Utils
. contentTypes
[ ct
] || ct
;
627 render_storage_content : function ( value
, metaData
, record
) {
628 var data
= record
. data
;
629 if ( Ext
. isNumber ( data
. channel
) &&
630 Ext
. isNumber ( data
. id
) &&
631 Ext
. isNumber ( data
. lun
)) {
633 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
634 " ID " + data
. id
+ " LUN " + data
. lun
;
636 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
639 render_serverity : function ( value
) {
640 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
643 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
645 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
649 var maxcpu
= record
. data
. maxcpu
|| 1 ;
651 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
655 var per
= value
* 100 ;
657 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
660 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
661 /*jslint confusion: true */
663 if (! Ext
. isNumeric ( value
)) {
667 return Proxmox
. Utils
. format_size ( value
);
670 render_bandwidth : function ( value
) {
671 if (! Ext
. isNumeric ( value
)) {
675 return Proxmox
. Utils
. format_size ( value
) + '/s' ;
678 render_timestamp_human_readable : function ( value
) {
679 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
682 render_duration : function ( value
) {
683 if ( value
=== undefined ) {
686 return PVE
. Utils
. format_duration_short ( value
);
689 calculate_mem_usage : function ( data
) {
690 if (! Ext
. isNumeric ( data
. mem
) ||
696 return ( data
. mem
/ data
. maxmem
);
699 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
700 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
704 // we got no percentage but bytes
706 var maxmem
= record
. data
. maxmem
;
707 if (! record
. data
. uptime
||
709 ! Ext
. isNumeric ( mem
)) {
713 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
715 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
718 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
721 var maxmem
= record
. data
. maxmem
;
723 if (! record
. data
. uptime
) {
727 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
731 return PVE
. Utils
. render_size ( value
);
734 calculate_disk_usage : function ( data
) {
736 if (! Ext
. isNumeric ( data
. disk
) ||
737 data
. type
=== 'qemu' ||
738 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
739 data
. maxdisk
=== 0 ) {
743 return ( data
. disk
/ data
. maxdisk
);
746 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
747 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
751 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
754 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
757 var maxdisk
= record
. data
. maxdisk
;
758 var type
= record
. data
. type
;
760 if (! Ext
. isNumeric ( disk
) ||
763 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
767 return PVE
. Utils
. render_size ( value
);
770 get_object_icon_class : function ( type
, record
) {
774 if ( type
=== 'type' ) {
776 objType
= record
. groupbyid
;
777 } else if ( record
. template
) {
779 objType
= 'template' ;
783 status
= record
. status
+ ' ha-' + record
. hastate
;
787 status
+= ' locked lock-' + record
. lock
;
790 var defaults
= PVE
. tree
. ResourceTree
. typeDefaults
[ objType
];
791 if ( defaults
&& defaults
. iconCls
) {
792 var retVal
= defaults
. iconCls
+ ' ' + status
;
799 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
801 var cls
= PVE
. Utils
. get_object_icon_class ( value
, record
. data
);
803 var fa
= '<i class="fa-fw x-grid-icon-custom ' + cls
+ '"></i> ' ;
807 render_support_level : function ( value
, metaData
, record
) {
808 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
811 render_upid : function ( value
, metaData
, record
) {
812 var type
= record
. data
. type
;
813 var id
= record
. data
. id
;
815 return Proxmox
. Utils
. format_task_description ( type
, id
);
818 /* render functions for new status panel */
820 render_usage : function ( val
) {
821 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
824 render_cpu_usage : function ( val
, max
) {
825 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
826 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
829 render_size_usage : function ( val
, max
) {
831 return gettext ( 'N/A' );
833 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
834 Ext
. String
. format ( gettext ( '{0} of {1}' ),
835 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
838 /* this is different for nodes */
839 render_node_cpu_usage : function ( value
, record
) {
840 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
843 /* this is different for nodes */
844 render_node_size_usage : function ( record
) {
845 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
848 render_optional_url : function ( value
) {
850 if ( value
&& ( match
= value
. match ( /^https?:\/\// )) !== null ) {
851 return '<a target="_blank" href="' + value
+ '">' + value
+ '</a>' ;
856 render_san : function ( value
) {
858 if ( Ext
. isArray ( value
)) {
859 value
. forEach ( function ( val
) {
860 if (! Ext
. isNumber ( val
)) {
864 return names
. join ( '<br>' );
869 render_full_name : function ( firstname
, metaData
, record
) {
870 var first
= firstname
|| '' ;
871 var last
= record
. data
. lastname
|| '' ;
872 return Ext
. htmlEncode ( first
+ " " + last
);
875 render_u2f_error : function ( error
) {
877 '1' : gettext ( 'Other Error' ),
878 '2' : gettext ( 'Bad Request' ),
879 '3' : gettext ( 'Configuration Unsupported' ),
880 '4' : gettext ( 'Device Ineligible' ),
881 '5' : gettext ( 'Timeout' )
883 return "U2F Error: " + ErrorNames
[ error
] || Proxmox
. Utils
. unknownText
;
886 windowHostname : function () {
887 return window
. location
. hostname
. replace ( Proxmox
. Utils
. IP6_bracket_match
,
888 function ( m
, addr
, offset
, original
) { return addr
; });
891 openDefaultConsoleWindow : function ( consoles
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
892 var dv
= PVE
. Utils
. defaultViewer ( consoles
);
893 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
, cmd
);
896 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
, cmd
) {
897 // kvm, lxc, shell, upgrade
899 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
900 throw "missing vmid" ;
904 throw "no nodename specified" ;
907 if ( viewer
=== 'html5' ) {
908 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
909 } else if ( viewer
=== 'xtermjs' ) {
910 Proxmox
. Utils
. openXtermJsViewer ( vmtype
, vmid
, nodename
, vmname
, cmd
);
911 } else if ( viewer
=== 'vv' ) {
913 var params
= { proxy
: PVE
. Utils
. windowHostname () };
914 if ( vmtype
=== 'kvm' ) {
915 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
916 PVE
. Utils
. openSpiceViewer ( url
, params
);
917 } else if ( vmtype
=== 'lxc' ) {
918 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
919 PVE
. Utils
. openSpiceViewer ( url
, params
);
920 } else if ( vmtype
=== 'shell' ) {
921 url
= '/nodes/' + nodename
+ '/spiceshell' ;
922 PVE
. Utils
. openSpiceViewer ( url
, params
);
923 } else if ( vmtype
=== 'upgrade' ) {
924 url
= '/nodes/' + nodename
+ '/spiceshell' ;
926 PVE
. Utils
. openSpiceViewer ( url
, params
);
927 } else if ( vmtype
=== 'cmd' ) {
928 url
= '/nodes/' + nodename
+ '/spiceshell' ;
930 PVE
. Utils
. openSpiceViewer ( url
, params
);
933 throw "unknown viewer type" ;
937 defaultViewer : function ( consoles
) {
939 var allowSpice
, allowXtermjs
;
941 if ( consoles
=== true ) {
944 } else if ( typeof consoles
=== 'object' ) {
945 allowSpice
= consoles
. spice
;
946 allowXtermjs
= !! consoles
. xtermjs
;
948 var dv
= PVE
. VersionInfo
. console
|| 'xtermjs' ;
949 if (( dv
=== 'vv' && ! allowSpice
) || ( dv
=== 'xtermjs' && ! allowXtermjs
)) {
956 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, cmd
) {
957 var url
= Ext
. Object
. toQueryString ({
958 console
: vmtype
, // kvm, lxc, upgrade or shell
966 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
972 openSpiceViewer : function ( url
, params
){
974 var downloadWithName = function ( uri
, name
) {
975 var link
= Ext
. DomHelper
. append ( document
. body
, {
978 css
: 'display:none;visibility:hidden;height:0px;'
981 // Note: we need to tell android the correct file name extension
982 // but we do not set 'download' tag for other environments, because
983 // It can have strange side effects (additional user prompt on firefox)
984 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
986 link
. download
= name
;
989 if ( link
. fireEvent
) {
990 link
. fireEvent ( 'onclick' );
992 var evt
= document
. createEvent ( "MouseEvents" );
993 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
994 link
. dispatchEvent ( evt
);
998 Proxmox
. Utils
. API2Request ({
1002 failure : function ( response
, opts
){
1003 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1005 success : function ( response
, opts
){
1006 var raw
= "[virt-viewer] \n " ;
1007 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1008 raw
+= k
+ "=" + v
+ " \n " ;
1010 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1011 encodeURIComponent ( raw
);
1013 downloadWithName ( url
, "pve-spice.vv" );
1018 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1020 var nodename
= record
. data
. node
;
1021 var vmid
= record
. data
. vmid
;
1022 var vmname
= record
. data
. name
;
1023 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1024 Proxmox
. Utils
. API2Request ({
1025 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1026 failure : function ( response
, opts
) {
1027 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1029 success : function ( response
, opts
) {
1030 var allowSpice
= !! response
. result
. data
. spice
;
1031 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
1034 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1035 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1039 // test automation helper
1040 call_menu_handler : function ( menu
, text
) {
1042 var list
= menu
. query ( 'menuitem' );
1044 Ext
. Array
. each ( list
, function ( item
) {
1045 if ( item
. text
=== text
) {
1056 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1058 if (!( v
instanceof Ext
. tree
. View
)) {
1062 var template
= !! record
. data
. template
;
1063 var type
= record
. data
. type
;
1066 if ( type
=== 'qemu' || type
== 'lxc' ) {
1067 menu
= Ext
. create ( 'PVE.menu.TemplateMenu' , {
1071 } else if ( type
=== 'qemu' ||
1074 menu
= Ext
. create ( 'PVE.' + type
+ '.CmdMenu' , {
1076 nodename
: record
. data
. node
1082 menu
. showAt ( event
. getXY ());
1086 // helper for deleting field which are set to there default values
1087 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1088 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1090 if ( values
[ 'delete' ]) {
1091 values
[ 'delete' ] += ',' + fieldname
;
1093 values
[ 'delete' ] = fieldname
;
1097 delete values
[ fieldname
];
1101 loadSSHKeyFromFile : function ( file
, callback
) {
1102 // ssh-keygen produces 740 bytes for an average 4096 bit rsa key, with
1103 // a user@host comment, 1420 for 8192 bits; current max is 16kbit
1104 // assume: 740*8 for max. 32kbit (5920 byte file)
1105 // round upwards to nearest nice number => 8192 bytes, leaves lots of comment space
1106 if ( file
. size
> 8192 ) {
1107 Ext
. Msg
. alert ( gettext ( 'Error' ), gettext ( "Invalid file size: " ) + file
. size
);
1113 var reader
= new FileReader ();
1114 reader
. onload = function ( evt
) {
1115 callback ( evt
. target
. result
);
1117 reader
. readAsText ( file
);
1120 bus_counts
: { ide
: 4 , sata
: 6 , scsi
: 16 , virtio
: 16 },
1122 // types is either undefined (all busses), an array of busses, or a single bus
1123 forEachBus : function ( types
, func
) {
1124 var busses
= Object
. keys ( PVE
. Utils
. bus_counts
);
1125 var i
, j
, count
, cont
;
1127 if ( Ext
. isArray ( types
)) {
1129 } else if ( Ext
. isDefined ( types
)) {
1133 // check if we only have valid busses
1134 for ( i
= 0 ; i
< busses
. length
; i
++) {
1135 if (! PVE
. Utils
. bus_counts
[ busses
[ i
]]) {
1136 throw "invalid bus: '" + busses
[ i
] + "'" ;
1140 for ( i
= 0 ; i
< busses
. length
; i
++) {
1141 count
= PVE
. Utils
. bus_counts
[ busses
[ i
]];
1142 for ( j
= 0 ; j
< count
; j
++) {
1143 cont
= func ( busses
[ i
], j
);
1144 if (! cont
&& cont
!== undefined ) {
1151 mp_counts
: { mps
: 256 , unused
: 256 },
1153 forEachMP : function ( func
, includeUnused
) {
1155 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. mps
; i
++) {
1156 cont
= func ( 'mp' , i
);
1157 if (! cont
&& cont
!== undefined ) {
1162 if (! includeUnused
) {
1166 for ( i
= 0 ; i
< PVE
. Utils
. mp_counts
. unused
; i
++) {
1167 cont
= func ( 'unused' , i
);
1168 if (! cont
&& cont
!== undefined ) {
1174 cleanEmptyObjectKeys : function ( obj
) {
1176 for ( propName
in obj
) {
1177 if ( obj
. hasOwnProperty ( propName
)) {
1178 if ( obj
[ propName
] === null || obj
[ propName
] === undefined ) {
1179 delete obj
[ propName
];
1185 handleStoreErrorOrMask : function ( me
, store
, regex
, callback
) {
1187 me
. mon ( store
, 'load' , function ( proxy
, response
, success
, operation
) {
1190 Proxmox
. Utils
. setErrorMask ( me
, false );
1195 if ( operation
. error
. statusText
) {
1196 if ( operation
. error
. statusText
. match ( regex
)) {
1197 callback ( me
, operation
. error
);
1200 msg
= operation
. error
. statusText
+ ' (' + operation
. error
. status
+ ')' ;
1203 msg
= gettext ( 'Connection error' );
1205 Proxmox
. Utils
. setErrorMask ( me
, msg
);
1209 showCephInstallOrMask : function ( container
, msg
, nodename
, callback
){
1210 var regex
= new RegExp ( "not (installed|initialized)" , "i" );
1211 if ( msg
. match ( regex
)) {
1212 if ( Proxmox
. UserName
=== 'root@pam' ) {
1213 container
. el
. mask ();
1214 if (! container
. down ( 'pveCephInstallWindow' )){
1215 var isInstalled
= msg
. match ( /not initialized/i ) ? true : false ;
1216 var win
= Ext
. create ( 'PVE.ceph.Install' , {
1219 win
. getViewModel (). set ( 'isInstalled' , isInstalled
);
1225 container
. mask ( Ext
. String
. format ( gettext ( '{0} not installed.' ) +
1226 ' ' + gettext ( 'Log in as root to install.' ), 'Ceph' ), [ 'pve-static-mask' ]);
1236 constructor : function () {
1238 Ext
. apply ( me
, me
. utilities
);