]>
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
)) {
17 console
. log ( "Starting PVE Manager" );
19 Ext
. Ajax
. defaultHeaders
= {
20 'Accept' : 'application/json'
23 Ext
. Ajax
. on ( 'beforerequest' , function ( conn
, options
) {
24 if ( PVE
. CSRFPreventionToken
) {
25 if (! options
. headers
) {
28 options
. headers
. CSRFPreventionToken
= PVE
. CSRFPreventionToken
;
32 Ext
. define ( 'PVE.Utils' , { utilities
: {
34 // this singleton contains miscellaneous utilities
36 toolkit
: undefined , // (extjs|touch), set inside Toolkit.js
38 bus_match
: /^(ide|sata|virtio|scsi)\d+$/ ,
52 'c' : gettext ( 'Community' ),
53 'b' : gettext ( 'Basic' ),
54 's' : gettext ( 'Standard' ),
55 'p' : gettext ( 'Premium' )
58 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.' ,
61 other
: gettext ( 'Other OS types' ),
62 wxp
: 'Microsoft Windows XP/2003' ,
63 w2k
: 'Microsoft Windows 2000' ,
64 w2k8
: 'Microsoft Windows Vista/2008' ,
65 win7
: 'Microsoft Windows 7/2008r2' ,
66 win8
: 'Microsoft Windows 8.x/10/2012/r2' ,
67 l24
: 'Linux 2.4 Kernel' ,
68 l26
: 'Linux 4.X/3.X/2.6 Kernel' ,
69 solaris
: 'Solaris Kernel'
72 render_kvm_ostype : function ( value
) {
74 return gettext ( 'Other OS types' );
76 var text
= PVE
. Utils
. kvm_ostypes
[ value
];
83 render_hotplug_features : function ( value
) {
86 if (! value
|| ( value
=== '0' )) {
87 return gettext ( 'disabled' );
91 value
= 'disk,network,usb' ;
94 Ext
. each ( value
. split ( ',' ), function ( el
) {
96 fa
. push ( gettext ( 'Disk' ));
97 } else if ( el
=== 'network' ) {
98 fa
. push ( gettext ( 'Network' ));
99 } else if ( el
=== 'usb' ) {
100 fa
. push ( gettext ( 'USB' ));
101 } else if ( el
=== 'memory' ) {
102 fa
. push ( gettext ( 'Memory' ));
103 } else if ( el
=== 'cpu' ) {
104 fa
. push ( gettext ( 'CPU' ));
110 return fa
. join ( ', ' );
113 network_iface_types
: {
114 eth
: gettext ( "Network Device" ),
115 bridge
: 'Linux Bridge' ,
117 OVSBridge
: 'OVS Bridge' ,
120 OVSIntPort
: 'OVS IntPort'
123 render_network_iface_type : function ( value
) {
124 return PVE
. Utils
. network_iface_types
[ value
] ||
125 PVE
. Utils
. unknownText
;
128 render_qemu_bios : function ( value
) {
130 return PVE
. Utils
. defaultText
+ ' (SeaBIOS)' ;
131 } else if ( value
=== 'seabios' ) {
133 } else if ( value
=== 'ovmf' ) {
134 return "OVMF (UEFI)" ;
140 render_scsihw : function ( value
) {
142 return PVE
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
143 } else if ( value
=== 'lsi' ) {
144 return 'LSI 53C895A' ;
145 } else if ( value
=== 'lsi53c810' ) {
147 } else if ( value
=== 'megasas' ) {
148 return 'MegaRAID SAS 8708EM2' ;
149 } else if ( value
=== 'virtio-scsi-pci' ) {
150 return 'VirtIO SCSI' ;
151 } else if ( value
=== 'virtio-scsi-single' ) {
152 return 'VirtIO SCSI single' ;
153 } else if ( value
=== 'pvscsi' ) {
154 return 'VMware PVSCSI' ;
160 // fixme: auto-generate this
161 // for now, please keep in sync with PVE::Tools::kvmkeymaps
166 'de-ch' : 'German (Swiss)' ,
167 'en-gb' : 'English (UK)' ,
168 'en-us' : 'English (USA)' ,
172 //fo: 'Faroe Islands',
174 'fr-be' : 'French (Belgium)' ,
175 'fr-ca' : 'French (Canada)' ,
176 'fr-ch' : 'French (Swiss)' ,
186 //'nl-be': 'Dutch (Belgium)',
190 'pt-br' : 'Portuguese (Brazil)' ,
199 std
: gettext ( 'Standard VGA' ),
200 vmware
: gettext ( 'VMware compatible' ),
201 cirrus
: 'Cirrus Logic GD5446' ,
203 qxl2
: 'SPICE dual monitor' ,
204 qxl3
: 'SPICE three monitors' ,
205 qxl4
: 'SPICE four monitors' ,
206 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
207 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
208 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
209 serial3
: gettext ( 'Serial terminal' ) + ' 3'
212 render_kvm_language : function ( value
) {
214 return PVE
. Utils
. defaultText
;
216 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
218 return text
+ ' (' + value
+ ')' ;
223 kvm_keymap_array : function () {
224 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
225 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
226 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
232 render_console_viewer : function ( value
) {
233 if (! value
|| value
=== '__default__' ) {
234 return PVE
. Utils
. defaultText
+ ' (HTML5)' ;
235 } else if ( value
=== 'vv' ) {
236 return 'SPICE (remote-viewer)' ;
237 } else if ( value
=== 'html5' ) {
238 return 'HTML5 (noVNC)' ;
249 eu
: 'Euskera (Basque)' ,
254 nb
: 'Norwegian (Bokmal)' ,
255 nn
: 'Norwegian (Nynorsk)' ,
256 fa
: 'Persian (Farsi)' ,
258 pt_BR
: 'Portuguese (Brazil)' ,
266 render_language : function ( value
) {
268 return PVE
. Utils
. defaultText
+ ' (English)' ;
270 var text
= PVE
. Utils
. language_map
[ value
];
272 return text
+ ' (' + value
+ ')' ;
277 language_array : function () {
278 var data
= [[ '__default__' , PVE
. Utils
. render_language ( '' )]];
279 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
280 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
286 render_kvm_vga_driver : function ( value
) {
288 return PVE
. Utils
. defaultText
;
290 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
292 return text
+ ' (' + value
+ ')' ;
297 kvm_vga_driver_array : function () {
298 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
299 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
300 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
306 render_kvm_startup : function ( value
) {
307 var startup
= PVE
. Parser
. parseStartup ( value
);
310 if ( startup
. order
=== undefined ) {
313 res
+= startup
. order
;
315 if ( startup
. up
!== undefined ) {
316 res
+= ',up=' + startup
. up
;
318 if ( startup
. down
!== undefined ) {
319 res
+= ',down=' + startup
. down
;
326 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
329 authClear : function () {
330 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
333 // fixme: remove - not needed?
334 gridLineHeigh : function () {
342 extractRequestError : function ( result
, verbose
) {
343 var msg
= gettext ( 'Successful' );
345 if (! result
. success
) {
346 msg
= gettext ( "Unknown error" );
347 if ( result
. message
) {
348 msg
= result
. message
;
350 msg
+= ' (' + result
. status
+ ')' ;
353 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
355 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
356 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
357 Ext
. htmlEncode ( desc
);
365 extractFormActionError : function ( action
) {
367 switch ( action
. failureType
) {
368 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
369 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
371 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
372 msg
= gettext ( 'Connection error' );
373 var resp
= action
. response
;
374 if ( resp
. status
&& resp
. statusText
) {
375 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
378 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
379 case Ext
. form
. action
. Action
. SERVER_INVALID
:
380 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
387 API2Request : function ( reqOpts
) {
389 var newopts
= Ext
. apply ({
390 waitMsg
: gettext ( 'Please wait...' )
393 if (! newopts
. url
. match ( /^\/api2/ )) {
394 newopts
. url
= '/api2/extjs' + newopts
. url
;
396 delete newopts
. callback
;
398 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
400 success : function ( response
, options
) {
401 if ( options
. waitMsgTarget
) {
402 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
403 options
. waitMsgTarget
. setMasked ( false );
405 options
. waitMsgTarget
. setLoading ( false );
408 var result
= Ext
. decode ( response
. responseText
);
409 response
. result
= result
;
410 if (! result
. success
) {
411 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
412 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
413 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
416 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
417 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
419 failure : function ( response
, options
) {
420 if ( options
. waitMsgTarget
) {
421 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
422 options
. waitMsgTarget
. setMasked ( false );
424 options
. waitMsgTarget
. setLoading ( false );
427 response
. result
= {};
429 response
. result
= Ext
. decode ( response
. responseText
);
431 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
432 if ( response
. aborted
) {
433 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
434 } else if ( response
. timedout
) {
435 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
436 } else if ( response
. status
&& response
. statusText
) {
437 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
439 response
. htmlStatus
= msg
;
440 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
441 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
446 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
448 var target
= newopts
. waitMsgTarget
;
450 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
451 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
} );
453 // Note: ExtJS bug - this does not work when component is not rendered
454 target
. setLoading ( newopts
. waitMsg
);
457 Ext
. Ajax
. request ( newopts
);
460 assemble_field_data : function ( values
, data
) {
461 if ( Ext
. isObject ( data
)) {
462 Ext
. Object
. each ( data
, function ( name
, val
) {
463 if ( values
. hasOwnProperty ( name
)) {
464 var bucket
= values
[ name
];
465 if (! Ext
. isArray ( bucket
)) {
466 bucket
= values
[ name
] = [ bucket
];
468 if ( Ext
. isArray ( val
)) {
469 values
[ name
] = bucket
. concat ( val
);
480 checked_command : function ( orig_cmd
) {
481 PVE
. Utils
. API2Request ({
482 url
: '/nodes/localhost/subscription' ,
485 failure : function ( response
, opts
) {
486 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
488 success : function ( response
, opts
) {
489 var data
= response
. result
. data
;
491 if ( data
. status
!== 'Active' ) {
493 title
: gettext ( 'No valid subscription' ),
494 icon
: Ext
. Msg
. WARNING
,
495 msg
: PVE
. Utils
. noSubKeyHtml
,
497 callback : function ( btn
) {
512 diskinit
: [ 'Disk' , gettext ( 'Initialize GPT' ) ],
513 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
514 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
515 vncshell
: [ '' , gettext ( 'Shell' ) ],
516 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
517 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
518 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
519 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
520 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
521 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
522 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
523 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
524 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
525 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
526 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
527 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
528 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
529 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
530 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
531 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
532 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
533 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
534 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' ) ],
535 vzrollback
: [ 'CT' , gettext ( 'Rollback' ) ],
536 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' ) ],
537 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
538 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
539 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
540 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
541 vzclone
: [ 'CT' , gettext ( 'Clone' ) ],
542 vztemplate
: [ 'CT' , gettext ( 'Convert to template' ) ],
543 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
544 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
545 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
546 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
547 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
548 vzsuspend
: [ 'CT' , gettext ( 'Suspend' ) ],
549 vzresume
: [ 'CT' , gettext ( 'Resume' ) ],
550 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
551 hastart
: [ 'HA' , gettext ( 'Start' ) ],
552 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
553 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
554 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
555 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
556 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
557 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' ) ],
558 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' ) ],
559 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' ) ],
560 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' ) ],
561 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
562 imgdel
: [ '' , gettext ( 'Erase data' ) ],
563 download
: [ '' , gettext ( 'Download' ) ],
564 vzdump
: [ '' , gettext ( 'Backup' ) ],
565 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
566 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
567 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
568 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
571 format_task_description : function ( type
, id
) {
572 var farray
= PVE
. Utils
. task_desc_table
[ type
];
576 var prefix
= farray
[ 0 ];
577 var text
= farray
[ 1 ];
579 return prefix
+ ' ' + id
+ ' - ' + text
;
584 parse_task_upid : function ( upid
) {
587 var res
= upid
. match ( /^UPID:(\S+):([0-9A-Fa-f]{8}):([0-9A-Fa-f]{8,9}):([0-9A-Fa-f]{8}):([^:\s]+):([^:\s]*):([^:\s]+):$/ );
589 throw "unable to parse upid '" + upid
+ "'" ;
592 task
. pid
= parseInt ( res
[ 2 ], 16 );
593 task
. pstart
= parseInt ( res
[ 3 ], 16 );
594 task
. starttime
= parseInt ( res
[ 4 ], 16 );
599 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
604 format_size : function ( size
) {
605 /*jslint confusion: true */
607 var units
= [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ];
610 while ( size
>= 1024 && (( num
++)+ 1 ) < units
. length
) {
614 return size
. toFixed (( num
> 0 )? 2 : 0 ) + " " + units
[ num
] + "B" ;
617 format_html_bar : function ( per
, text
) {
619 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
620 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
625 format_cpu_bar : function ( per1
, per2
, text
) {
627 return "<div class='pve-bar-border'>" +
628 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
629 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
630 "<div class='pve-bar-text'>" + text
+ "</div>" +
634 format_large_bar : function ( per
, text
) {
637 text
= per
. toFixed ( 1 ) + "%" ;
640 return "<div class='pve-largebar-border'>" +
641 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
642 "<div class='pve-largebar-text'>" + text
+ "</div>" +
646 format_duration_long : function ( ut
) {
648 var days
= Math
. floor ( ut
/ 86400 );
650 var hours
= Math
. floor ( ut
/ 3600 );
652 var mins
= Math
. floor ( ut
/ 60 );
655 var hours_str
= '00' + hours
. toString ();
656 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
657 var mins_str
= "00" + mins
. toString ();
658 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
659 var ut_str
= "00" + ut
. toString ();
660 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
663 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
664 return days
. toString () + ' ' + ds
+ ' ' +
665 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
667 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
671 format_duration_short : function ( ut
) {
674 return ut
. toString () + 's' ;
679 return mins
. toFixed ( 0 ) + 'm' ;
683 var hours
= ut
/ 3600 ;
684 return hours
. toFixed ( 0 ) + 'h' ;
687 var days
= ut
/ 86400 ;
688 return days
. toFixed ( 0 ) + 'd' ;
691 yesText
: gettext ( 'Yes' ),
692 noText
: gettext ( 'No' ),
693 noneText
: gettext ( 'none' ),
694 errorText
: gettext ( 'Error' ),
695 unknownText
: gettext ( 'Unknown' ),
696 defaultText
: gettext ( 'Default' ),
697 daysText
: gettext ( 'days' ),
698 dayText
: gettext ( 'day' ),
699 runningText
: gettext ( 'running' ),
700 stoppedText
: gettext ( 'stopped' ),
701 neverText
: gettext ( 'never' ),
702 totalText
: gettext ( 'Total' ),
703 usedText
: gettext ( 'Used' ),
704 directoryText
: gettext ( 'Directory' ),
705 imagesText
: gettext ( 'Disk image' ),
706 backupFileText
: gettext ( 'VZDump backup file' ),
707 vztmplText
: gettext ( 'Container template' ),
708 isoImageText
: gettext ( 'ISO image' ),
709 containersText
: gettext ( 'Container' ),
710 stateText
: gettext ( 'State' ),
711 groupText
: gettext ( 'Group' ),
713 format_expire : function ( date
) {
715 return PVE
. Utils
. neverText
;
717 return Ext
. Date
. format ( date
, "Y-m-d" );
720 format_storage_type : function ( value
) {
721 if ( value
=== 'dir' ) {
722 return PVE
. Utils
. directoryText
;
723 } else if ( value
=== 'nfs' ) {
725 } else if ( value
=== 'glusterfs' ) {
727 } else if ( value
=== 'lvm' ) {
729 } else if ( value
=== 'lvmthin' ) {
731 } else if ( value
=== 'iscsi' ) {
733 } else if ( value
=== 'rbd' ) {
735 } else if ( value
=== 'sheepdog' ) {
737 } else if ( value
=== 'zfs' ) {
738 return 'ZFS over iSCSI' ;
739 } else if ( value
=== 'zfspool' ) {
741 } else if ( value
=== 'iscsidirect' ) {
742 return 'iSCSIDirect' ;
743 } else if ( value
=== 'drbd' ) {
746 return PVE
. Utils
. unknownText
;
750 format_boolean_with_default : function ( value
) {
751 if ( Ext
. isDefined ( value
) && value
!== '__default__' ) {
752 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
754 return PVE
. Utils
. defaultText
;
757 format_boolean : function ( value
) {
758 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
761 format_neg_boolean : function ( value
) {
762 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
765 format_ha : function ( value
) {
766 var text
= PVE
. Utils
. format_boolean ( value
. managed
);
769 text
+= ', ' + PVE
. Utils
. stateText
+ ': ' ;
770 text
+= value
. state
|| PVE
. Utils
. noneText
;
772 text
+= ', ' + PVE
. Utils
. groupText
+ ': ' ;
773 text
+= value
. group
|| PVE
. Utils
. noneText
;
779 format_content_types : function ( value
) {
782 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
783 if ( ct
=== 'images' ) {
784 cta
. push ( PVE
. Utils
. imagesText
);
785 } else if ( ct
=== 'backup' ) {
786 cta
. push ( PVE
. Utils
. backupFileText
);
787 } else if ( ct
=== 'vztmpl' ) {
788 cta
. push ( PVE
. Utils
. vztmplText
);
789 } else if ( ct
=== 'iso' ) {
790 cta
. push ( PVE
. Utils
. isoImageText
);
791 } else if ( ct
=== 'rootdir' ) {
792 cta
. push ( PVE
. Utils
. containersText
);
796 return cta
. join ( ', ' );
799 render_storage_content : function ( value
, metaData
, record
) {
800 var data
= record
. data
;
801 if ( Ext
. isNumber ( data
. channel
) &&
802 Ext
. isNumber ( data
. id
) &&
803 Ext
. isNumber ( data
. lun
)) {
805 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
806 " ID " + data
. id
+ " LUN " + data
. lun
;
808 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
811 render_serverity : function ( value
) {
812 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
815 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
817 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
821 var maxcpu
= record
. data
. maxcpu
|| 1 ;
823 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
827 var per
= value
* 100 ;
829 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
832 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
833 /*jslint confusion: true */
835 if (! Ext
. isNumeric ( value
)) {
839 return PVE
. Utils
. format_size ( value
);
842 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
843 var servertime
= new Date ( value
* 1000 );
844 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
847 calculate_mem_usage : function ( data
) {
848 if (! Ext
. isNumeric ( data
. mem
) ||
854 return ( data
. mem
/ data
. maxmem
);
857 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
858 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
862 // we got no percentage but bytes
864 var maxmem
= record
. data
. maxmem
;
865 if (! record
. data
. uptime
||
867 ! Ext
. isNumeric ( mem
)) {
871 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
873 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
876 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
879 var maxmem
= record
. data
. maxmem
;
881 if (! record
. data
. uptime
) {
885 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
889 return PVE
. Utils
. render_size ( value
);
892 calculate_disk_usage : function ( data
) {
894 if (! Ext
. isNumeric ( data
. disk
) ||
895 data
. type
=== 'qemu' ||
896 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
897 data
. maxdisk
=== 0 ) {
901 return ( data
. disk
/ data
. maxdisk
);
904 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
905 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
909 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
912 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
915 var maxdisk
= record
. data
. maxdisk
;
916 var type
= record
. data
. type
;
918 if (! Ext
. isNumeric ( disk
) ||
921 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
925 return PVE
. Utils
. render_size ( value
);
928 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
934 case 'lxc' : icon
= 'cube' ;
935 gridcls
= '-stopped' ;
937 case 'qemu' : icon
= 'desktop' ;
938 gridcls
= '-stopped' ;
940 case 'node' : icon
= 'building' ;
941 gridcls
= '-offline' ;
943 case 'storage' : icon
= 'database' ; break ;
944 case 'pool' : icon
= 'tags' ; break ;
945 default : icon
= 'file' ;
948 if ( value
=== 'lxc' || value
=== 'qemu' ) {
949 if ( record
. data
. running
&& record
. data
. status
!== 'paused' ) {
950 gridcls
= '-running' ;
951 } else if ( record
. data
. running
) {
954 if ( record
. data
. template
) {
956 gridcls
= '-template-' + value
;
958 } else if ( value
=== 'node' ) {
959 if ( record
. data
. running
) {
964 // overwrite anything else
965 if ( record
. data
. hastate
=== 'error' ) {
966 gridcls
= '-offline' ;
969 var fa
= '<i class="fa fa-fw x-fa-grid' + gridcls
+ ' fa-' + icon
+ '"></i> ' ;
973 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
977 if ( uptime
=== undefined ) {
985 return PVE
. Utils
. format_duration_long ( uptime
);
988 render_support_level : function ( value
, metaData
, record
) {
989 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
992 render_upid : function ( value
, metaData
, record
) {
993 var type
= record
. data
. type
;
994 var id
= record
. data
. id
;
996 return PVE
. Utils
. format_task_description ( type
, id
);
999 /* render functions for new status panel */
1001 render_usage : function ( val
) {
1002 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
1005 render_cpu_usage : function ( val
, max
) {
1006 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
1007 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
1010 render_size_usage : function ( val
, max
) {
1012 return gettext ( 'N/A' );
1014 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
1015 Ext
. String
. format ( gettext ( '{0} of {1}' ),
1016 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
1019 /* this is different for nodes */
1020 render_node_cpu_usage : function ( value
, record
) {
1021 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
1024 /* this is different for nodes */
1025 render_node_size_usage : function ( record
) {
1026 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
1029 dialog_title : function ( subject
, create
, isAdd
) {
1032 return gettext ( 'Add' ) + ': ' + subject
;
1034 return gettext ( 'Create' ) + ': ' + subject
;
1037 return gettext ( 'Edit' ) + ': ' + subject
;
1041 windowHostname : function () {
1042 return window
. location
. hostname
. replace ( PVE
. Utils
. IP6_bracket_match
,
1043 function ( m
, addr
, offset
, original
) { return addr
; });
1046 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
1047 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
1048 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
1051 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
1052 // kvm, lxc, shell, upgrade
1054 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
1055 throw "missing vmid" ;
1059 throw "no nodename specified" ;
1062 if ( viewer
=== 'html5' ) {
1063 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
1064 } else if ( viewer
=== 'vv' ) {
1066 var params
= { proxy
: PVE
. Utils
. windowHostname () };
1067 if ( vmtype
=== 'kvm' ) {
1068 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1069 PVE
. Utils
. openSpiceViewer ( url
, params
);
1070 } else if ( vmtype
=== 'lxc' ) {
1071 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1072 PVE
. Utils
. openSpiceViewer ( url
, params
);
1073 } else if ( vmtype
=== 'shell' ) {
1074 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1075 PVE
. Utils
. openSpiceViewer ( url
, params
);
1076 } else if ( vmtype
=== 'upgrade' ) {
1077 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1079 PVE
. Utils
. openSpiceViewer ( url
, params
);
1082 throw "unknown viewer type" ;
1086 defaultViewer : function ( allowSpice
) {
1087 var vncdefault
= 'html5' ;
1088 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
1089 if ( dv
=== 'vv' && ! allowSpice
) {
1096 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
1097 var url
= Ext
. urlEncode ({
1098 console
: vmtype
, // kvm, lxc, upgrade or shell
1104 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1108 openSpiceViewer : function ( url
, params
){
1110 var downloadWithName = function ( uri
, name
) {
1111 var link
= Ext
. DomHelper
. append ( document
. body
, {
1114 css
: 'display:none;visibility:hidden;height:0px;'
1117 // Note: we need to tell android the correct file name extension
1118 // but we do not set 'download' tag for other environments, because
1119 // It can have strange side effects (additional user prompt on firefox)
1120 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1122 link
. download
= name
;
1125 if ( link
. fireEvent
) {
1126 link
. fireEvent ( 'onclick' );
1128 var evt
= document
. createEvent ( "MouseEvents" );
1129 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1130 link
. dispatchEvent ( evt
);
1134 PVE
. Utils
. API2Request ({
1138 failure : function ( response
, opts
){
1139 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1141 success : function ( response
, opts
){
1142 var raw
= "[virt-viewer] \n " ;
1143 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1144 raw
+= k
+ "=" + v
+ " \n " ;
1146 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1147 encodeURIComponent ( raw
);
1149 downloadWithName ( url
, "pve-spice.vv" );
1154 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1155 // use el.mask() instead
1156 setErrorMask : function ( comp
, msg
) {
1165 el
. mask ( gettext ( "Loading..." ));
1172 monStoreErrors : function ( me
, store
) {
1173 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1174 if (! me
. loadCount
) {
1175 me
. loadCount
= 0 ; // make sure it is numeric
1176 PVE
. Utils
. setErrorMask ( me
, true );
1180 // only works with 'pve' proxy
1181 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1185 PVE
. Utils
. setErrorMask ( me
, false );
1190 /*jslint nomen: true */
1191 var operation
= request
. _operation
;
1192 var error
= operation
. getError ();
1193 if ( error
. statusText
) {
1194 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1196 msg
= gettext ( 'Connection error' );
1198 PVE
. Utils
. setErrorMask ( me
, msg
);
1202 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1204 var nodename
= record
. data
. node
;
1205 var vmid
= record
. data
. vmid
;
1206 var vmname
= record
. data
. name
;
1207 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1208 PVE
. Utils
. API2Request ({
1209 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1210 failure : function ( response
, opts
) {
1211 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1213 success : function ( response
, opts
) {
1214 var allowSpice
= response
. result
. data
. spice
;
1215 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
1218 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1219 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1223 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1225 if (!( v
instanceof Ext
. tree
. View
)) {
1230 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1231 menu
= Ext
. create ( 'PVE.qemu.CmdMenu' , {
1234 } else if ( record
. data
. type
=== 'qemu' && record
. data
. template
) {
1235 menu
= Ext
. create ( 'PVE.qemu.TemplateMenu' , {
1238 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1239 menu
= Ext
. create ( 'PVE.lxc.CmdMenu' , {
1242 } else if ( record
. data
. type
=== 'lxc' && record
. data
. template
) {
1243 /* since clone does not work reliably, disable for now
1244 menu = Ext.create('PVE.lxc.TemplateMenu', {
1253 menu
. showAt ( event
. getXY ());
1256 // helper for deleting field which are set to there default values
1257 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1258 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1260 if ( values
[ 'delete' ]) {
1261 values
[ 'delete' ] += ',' + fieldname
;
1263 values
[ 'delete' ] = fieldname
;
1267 delete values
[ fieldname
];
1272 constructor : function () {
1274 Ext
. apply ( me
, me
. utilities
);
1276 var IPV4_OCTET
= "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])" ;
1277 var IPV4_REGEXP
= "(?:(?:" + IPV4_OCTET
+ " \\ .){3}" + IPV4_OCTET
+ ")" ;
1278 var IPV6_H16
= "(?:[0-9a-fA-F]{1,4})" ;
1279 var IPV6_LS32
= "(?:(?:" + IPV6_H16
+ ":" + IPV6_H16
+ ")|" + IPV4_REGEXP
+ ")" ;
1282 me
. IP4_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")$" );
1283 me
. IP4_cidr_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")\/([0-9]{1,2})$" );
1285 var IPV6_REGEXP
= "(?:" +
1286 "(?:(?:" + "(?:" + IPV6_H16
+ ":){6})" + IPV6_LS32
+ ")|" +
1287 "(?:(?:" + "::" + "(?:" + IPV6_H16
+ ":){5})" + IPV6_LS32
+ ")|" +
1288 "(?:(?:(?:" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){4})" + IPV6_LS32
+ ")|" +
1289 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,1}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){3})" + IPV6_LS32
+ ")|" +
1290 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,2}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){2})" + IPV6_LS32
+ ")|" +
1291 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,3}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){1})" + IPV6_LS32
+ ")|" +
1292 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,4}" + IPV6_H16
+ ")?::" + ")" + IPV6_LS32
+ ")|" +
1293 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,5}" + IPV6_H16
+ ")?::" + ")" + IPV6_H16
+ ")|" +
1294 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,7}" + IPV6_H16
+ ")?::" + ")" + ")" +
1297 me
. IP6_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")$" );
1298 me
. IP6_cidr_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")\/([0-9]{1,3})$" );
1299 me
. IP6_bracket_match
= new RegExp ( "^ \\ [(" + IPV6_REGEXP
+ ") \\ ]" );
1301 me
. IP64_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ ")$" );
1303 var DnsName_REGEXP
= "(?:(([a-zA-Z0-9]([a-zA-Z0-9 \\ -]*[a-zA-Z0-9])?) \\ .)*([A-Za-z0-9]([A-Za-z0-9 \\ -]*[A-Za-z0-9])?))" ;
1304 me
. DnsName_match
= new RegExp ( "^" + DnsName_REGEXP
+ "$" );
1306 me
. HostPort_match
= new RegExp ( "^(" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ")(: \\ d+)?$" );
1307 me
. HostPortBrackets_match
= new RegExp ( "^ \\ [(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ") \\ ](: \\ d+)?$" );
1308 me
. IP6_dotnotation_match
= new RegExp ( "^" + IPV6_REGEXP
+ "( \\ . \\ d+)?$" );