]>
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 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 ( record
) {
110 iconCls
: PVE
. Utils
. get_health_icon (),
114 if (! record
|| ! record
. data
) {
118 var health
= PVE
. Utils
. map_ceph_health
[ record
. data
. health
. overall_status
];
120 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
121 state
. text
= record
. data
. health
. overall_status
;
126 render_kvm_ostype : function ( value
) {
128 return gettext ( 'Other OS types' );
130 var text
= PVE
. Utils
. kvm_ostypes
[ value
];
137 render_hotplug_features : function ( value
) {
140 if (! value
|| ( value
=== '0' )) {
141 return gettext ( 'disabled' );
145 value
= 'disk,network,usb' ;
148 Ext
. each ( value
. split ( ',' ), function ( el
) {
150 fa
. push ( gettext ( 'Disk' ));
151 } else if ( el
=== 'network' ) {
152 fa
. push ( gettext ( 'Network' ));
153 } else if ( el
=== 'usb' ) {
154 fa
. push ( gettext ( 'USB' ));
155 } else if ( el
=== 'memory' ) {
156 fa
. push ( gettext ( 'Memory' ));
157 } else if ( el
=== 'cpu' ) {
158 fa
. push ( gettext ( 'CPU' ));
164 return fa
. join ( ', ' );
167 network_iface_types
: {
168 eth
: gettext ( "Network Device" ),
169 bridge
: 'Linux Bridge' ,
171 OVSBridge
: 'OVS Bridge' ,
174 OVSIntPort
: 'OVS IntPort'
177 render_network_iface_type : function ( value
) {
178 return PVE
. Utils
. network_iface_types
[ value
] ||
179 PVE
. Utils
. unknownText
;
182 render_qemu_bios : function ( value
) {
184 return PVE
. Utils
. defaultText
+ ' (SeaBIOS)' ;
185 } else if ( value
=== 'seabios' ) {
187 } else if ( value
=== 'ovmf' ) {
188 return "OVMF (UEFI)" ;
194 render_scsihw : function ( value
) {
196 return PVE
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
197 } else if ( value
=== 'lsi' ) {
198 return 'LSI 53C895A' ;
199 } else if ( value
=== 'lsi53c810' ) {
201 } else if ( value
=== 'megasas' ) {
202 return 'MegaRAID SAS 8708EM2' ;
203 } else if ( value
=== 'virtio-scsi-pci' ) {
204 return 'VirtIO SCSI' ;
205 } else if ( value
=== 'virtio-scsi-single' ) {
206 return 'VirtIO SCSI single' ;
207 } else if ( value
=== 'pvscsi' ) {
208 return 'VMware PVSCSI' ;
214 // fixme: auto-generate this
215 // for now, please keep in sync with PVE::Tools::kvmkeymaps
220 'de-ch' : 'German (Swiss)' ,
221 'en-gb' : 'English (UK)' ,
222 'en-us' : 'English (USA)' ,
226 //fo: 'Faroe Islands',
228 'fr-be' : 'French (Belgium)' ,
229 'fr-ca' : 'French (Canada)' ,
230 'fr-ch' : 'French (Swiss)' ,
240 //'nl-be': 'Dutch (Belgium)',
244 'pt-br' : 'Portuguese (Brazil)' ,
253 std
: gettext ( 'Standard VGA' ),
254 vmware
: gettext ( 'VMware compatible' ),
255 cirrus
: 'Cirrus Logic GD5446' ,
257 qxl2
: 'SPICE dual monitor' ,
258 qxl3
: 'SPICE three monitors' ,
259 qxl4
: 'SPICE four monitors' ,
260 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
261 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
262 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
263 serial3
: gettext ( 'Serial terminal' ) + ' 3'
266 render_kvm_language : function ( value
) {
268 return PVE
. Utils
. defaultText
;
270 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
272 return text
+ ' (' + value
+ ')' ;
277 kvm_keymap_array : function () {
278 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
279 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
280 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
286 render_console_viewer : function ( value
) {
287 if (! value
|| value
=== '__default__' ) {
288 return PVE
. Utils
. defaultText
+ ' (HTML5)' ;
289 } else if ( value
=== 'vv' ) {
290 return 'SPICE (remote-viewer)' ;
291 } else if ( value
=== 'html5' ) {
292 return 'HTML5 (noVNC)' ;
303 eu
: 'Euskera (Basque)' ,
308 nb
: 'Norwegian (Bokmal)' ,
309 nn
: 'Norwegian (Nynorsk)' ,
310 fa
: 'Persian (Farsi)' ,
312 pt_BR
: 'Portuguese (Brazil)' ,
320 render_language : function ( value
) {
322 return PVE
. Utils
. defaultText
+ ' (English)' ;
324 var text
= PVE
. Utils
. language_map
[ value
];
326 return text
+ ' (' + value
+ ')' ;
331 language_array : function () {
332 var data
= [[ '__default__' , PVE
. Utils
. render_language ( '' )]];
333 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
334 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
340 render_kvm_vga_driver : function ( value
) {
342 return PVE
. Utils
. defaultText
;
344 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
346 return text
+ ' (' + value
+ ')' ;
351 kvm_vga_driver_array : function () {
352 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
353 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
354 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
360 render_kvm_startup : function ( value
) {
361 var startup
= PVE
. Parser
. parseStartup ( value
);
364 if ( startup
. order
=== undefined ) {
367 res
+= startup
. order
;
369 if ( startup
. up
!== undefined ) {
370 res
+= ',up=' + startup
. up
;
372 if ( startup
. down
!== undefined ) {
373 res
+= ',down=' + startup
. down
;
380 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
383 authClear : function () {
384 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
387 // fixme: remove - not needed?
388 gridLineHeigh : function () {
396 extractRequestError : function ( result
, verbose
) {
397 var msg
= gettext ( 'Successful' );
399 if (! result
. success
) {
400 msg
= gettext ( "Unknown error" );
401 if ( result
. message
) {
402 msg
= result
. message
;
404 msg
+= ' (' + result
. status
+ ')' ;
407 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
409 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
410 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
411 Ext
. htmlEncode ( desc
);
419 extractFormActionError : function ( action
) {
421 switch ( action
. failureType
) {
422 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
423 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
425 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
426 msg
= gettext ( 'Connection error' );
427 var resp
= action
. response
;
428 if ( resp
. status
&& resp
. statusText
) {
429 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
432 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
433 case Ext
. form
. action
. Action
. SERVER_INVALID
:
434 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
441 API2Request : function ( reqOpts
) {
443 var newopts
= Ext
. apply ({
444 waitMsg
: gettext ( 'Please wait...' )
447 if (! newopts
. url
. match ( /^\/api2/ )) {
448 newopts
. url
= '/api2/extjs' + newopts
. url
;
450 delete newopts
. callback
;
452 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
454 success : function ( response
, options
) {
455 if ( options
. waitMsgTarget
) {
456 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
457 options
. waitMsgTarget
. setMasked ( false );
459 options
. waitMsgTarget
. setLoading ( false );
462 var result
= Ext
. decode ( response
. responseText
);
463 response
. result
= result
;
464 if (! result
. success
) {
465 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
466 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
467 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
470 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
471 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
473 failure : function ( response
, options
) {
474 if ( options
. waitMsgTarget
) {
475 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
476 options
. waitMsgTarget
. setMasked ( false );
478 options
. waitMsgTarget
. setLoading ( false );
481 response
. result
= {};
483 response
. result
= Ext
. decode ( response
. responseText
);
485 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
486 if ( response
. aborted
) {
487 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
488 } else if ( response
. timedout
) {
489 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
490 } else if ( response
. status
&& response
. statusText
) {
491 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
493 response
. htmlStatus
= msg
;
494 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
495 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
500 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
502 var target
= newopts
. waitMsgTarget
;
504 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
505 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
} );
507 // Note: ExtJS bug - this does not work when component is not rendered
508 target
. setLoading ( newopts
. waitMsg
);
511 Ext
. Ajax
. request ( newopts
);
514 assemble_field_data : function ( values
, data
) {
515 if ( Ext
. isObject ( data
)) {
516 Ext
. Object
. each ( data
, function ( name
, val
) {
517 if ( values
. hasOwnProperty ( name
)) {
518 var bucket
= values
[ name
];
519 if (! Ext
. isArray ( bucket
)) {
520 bucket
= values
[ name
] = [ bucket
];
522 if ( Ext
. isArray ( val
)) {
523 values
[ name
] = bucket
. concat ( val
);
534 checked_command : function ( orig_cmd
) {
535 PVE
. Utils
. API2Request ({
536 url
: '/nodes/localhost/subscription' ,
539 failure : function ( response
, opts
) {
540 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
542 success : function ( response
, opts
) {
543 var data
= response
. result
. data
;
545 if ( data
. status
!== 'Active' ) {
547 title
: gettext ( 'No valid subscription' ),
548 icon
: Ext
. Msg
. WARNING
,
549 msg
: PVE
. Utils
. noSubKeyHtml
,
551 callback : function ( btn
) {
566 diskinit
: [ 'Disk' , gettext ( 'Initialize GPT' ) ],
567 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
568 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
569 vncshell
: [ '' , gettext ( 'Shell' ) ],
570 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
571 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
572 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
573 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
574 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
575 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
576 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
577 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
578 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
579 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
580 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
581 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
582 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
583 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
584 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
585 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
586 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
587 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
588 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' ) ],
589 vzrollback
: [ 'CT' , gettext ( 'Rollback' ) ],
590 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' ) ],
591 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
592 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
593 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
594 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
595 vzclone
: [ 'CT' , gettext ( 'Clone' ) ],
596 vztemplate
: [ 'CT' , gettext ( 'Convert to template' ) ],
597 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
598 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
599 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
600 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
601 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
602 vzsuspend
: [ 'CT' , gettext ( 'Suspend' ) ],
603 vzresume
: [ 'CT' , gettext ( 'Resume' ) ],
604 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
605 hastart
: [ 'HA' , gettext ( 'Start' ) ],
606 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
607 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
608 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
609 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
610 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
611 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' ) ],
612 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' ) ],
613 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' ) ],
614 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' ) ],
615 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
616 imgdel
: [ '' , gettext ( 'Erase data' ) ],
617 download
: [ '' , gettext ( 'Download' ) ],
618 vzdump
: [ '' , gettext ( 'Backup' ) ],
619 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
620 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
621 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
622 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
625 format_task_description : function ( type
, id
) {
626 var farray
= PVE
. Utils
. task_desc_table
[ type
];
630 var prefix
= farray
[ 0 ];
631 var text
= farray
[ 1 ];
633 return prefix
+ ' ' + id
+ ' - ' + text
;
638 parse_task_upid : function ( upid
) {
641 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]+):$/ );
643 throw "unable to parse upid '" + upid
+ "'" ;
646 task
. pid
= parseInt ( res
[ 2 ], 16 );
647 task
. pstart
= parseInt ( res
[ 3 ], 16 );
648 task
. starttime
= parseInt ( res
[ 4 ], 16 );
653 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
658 format_size : function ( size
) {
659 /*jslint confusion: true */
661 var units
= [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ];
664 while ( size
>= 1024 && (( num
++)+ 1 ) < units
. length
) {
668 return size
. toFixed (( num
> 0 )? 2 : 0 ) + " " + units
[ num
] + "B" ;
671 format_html_bar : function ( per
, text
) {
673 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
674 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
679 format_cpu_bar : function ( per1
, per2
, text
) {
681 return "<div class='pve-bar-border'>" +
682 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
683 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
684 "<div class='pve-bar-text'>" + text
+ "</div>" +
688 format_large_bar : function ( per
, text
) {
691 text
= per
. toFixed ( 1 ) + "%" ;
694 return "<div class='pve-largebar-border'>" +
695 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
696 "<div class='pve-largebar-text'>" + text
+ "</div>" +
700 format_duration_long : function ( ut
) {
702 var days
= Math
. floor ( ut
/ 86400 );
704 var hours
= Math
. floor ( ut
/ 3600 );
706 var mins
= Math
. floor ( ut
/ 60 );
709 var hours_str
= '00' + hours
. toString ();
710 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
711 var mins_str
= "00" + mins
. toString ();
712 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
713 var ut_str
= "00" + ut
. toString ();
714 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
717 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
718 return days
. toString () + ' ' + ds
+ ' ' +
719 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
721 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
725 format_duration_short : function ( ut
) {
728 return ut
. toString () + 's' ;
733 return mins
. toFixed ( 0 ) + 'm' ;
737 var hours
= ut
/ 3600 ;
738 return hours
. toFixed ( 0 ) + 'h' ;
741 var days
= ut
/ 86400 ;
742 return days
. toFixed ( 0 ) + 'd' ;
745 yesText
: gettext ( 'Yes' ),
746 noText
: gettext ( 'No' ),
747 noneText
: gettext ( 'none' ),
748 errorText
: gettext ( 'Error' ),
749 unknownText
: gettext ( 'Unknown' ),
750 defaultText
: gettext ( 'Default' ),
751 daysText
: gettext ( 'days' ),
752 dayText
: gettext ( 'day' ),
753 runningText
: gettext ( 'running' ),
754 stoppedText
: gettext ( 'stopped' ),
755 neverText
: gettext ( 'never' ),
756 totalText
: gettext ( 'Total' ),
757 usedText
: gettext ( 'Used' ),
758 directoryText
: gettext ( 'Directory' ),
759 imagesText
: gettext ( 'Disk image' ),
760 backupFileText
: gettext ( 'VZDump backup file' ),
761 vztmplText
: gettext ( 'Container template' ),
762 isoImageText
: gettext ( 'ISO image' ),
763 containersText
: gettext ( 'Container' ),
764 stateText
: gettext ( 'State' ),
765 groupText
: gettext ( 'Group' ),
767 format_expire : function ( date
) {
769 return PVE
. Utils
. neverText
;
771 return Ext
. Date
. format ( date
, "Y-m-d" );
774 format_storage_type : function ( value
) {
775 if ( value
=== 'dir' ) {
776 return PVE
. Utils
. directoryText
;
777 } else if ( value
=== 'nfs' ) {
779 } else if ( value
=== 'glusterfs' ) {
781 } else if ( value
=== 'lvm' ) {
783 } else if ( value
=== 'lvmthin' ) {
785 } else if ( value
=== 'iscsi' ) {
787 } else if ( value
=== 'rbd' ) {
789 } else if ( value
=== 'sheepdog' ) {
791 } else if ( value
=== 'zfs' ) {
792 return 'ZFS over iSCSI' ;
793 } else if ( value
=== 'zfspool' ) {
795 } else if ( value
=== 'iscsidirect' ) {
796 return 'iSCSIDirect' ;
797 } else if ( value
=== 'drbd' ) {
800 return PVE
. Utils
. unknownText
;
804 format_boolean_with_default : function ( value
) {
805 if ( Ext
. isDefined ( value
) && value
!== '__default__' ) {
806 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
808 return PVE
. Utils
. defaultText
;
811 format_boolean : function ( value
) {
812 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
815 format_neg_boolean : function ( value
) {
816 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
819 format_ha : function ( value
) {
820 var text
= PVE
. Utils
. format_boolean ( value
. managed
);
823 text
+= ', ' + PVE
. Utils
. stateText
+ ': ' ;
824 text
+= value
. state
|| PVE
. Utils
. noneText
;
826 text
+= ', ' + PVE
. Utils
. groupText
+ ': ' ;
827 text
+= value
. group
|| PVE
. Utils
. noneText
;
833 format_content_types : function ( value
) {
836 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
837 if ( ct
=== 'images' ) {
838 cta
. push ( PVE
. Utils
. imagesText
);
839 } else if ( ct
=== 'backup' ) {
840 cta
. push ( PVE
. Utils
. backupFileText
);
841 } else if ( ct
=== 'vztmpl' ) {
842 cta
. push ( PVE
. Utils
. vztmplText
);
843 } else if ( ct
=== 'iso' ) {
844 cta
. push ( PVE
. Utils
. isoImageText
);
845 } else if ( ct
=== 'rootdir' ) {
846 cta
. push ( PVE
. Utils
. containersText
);
850 return cta
. join ( ', ' );
853 render_storage_content : function ( value
, metaData
, record
) {
854 var data
= record
. data
;
855 if ( Ext
. isNumber ( data
. channel
) &&
856 Ext
. isNumber ( data
. id
) &&
857 Ext
. isNumber ( data
. lun
)) {
859 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
860 " ID " + data
. id
+ " LUN " + data
. lun
;
862 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
865 render_serverity : function ( value
) {
866 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
869 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
871 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
875 var maxcpu
= record
. data
. maxcpu
|| 1 ;
877 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
881 var per
= value
* 100 ;
883 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
886 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
887 /*jslint confusion: true */
889 if (! Ext
. isNumeric ( value
)) {
893 return PVE
. Utils
. format_size ( value
);
896 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
897 var servertime
= new Date ( value
* 1000 );
898 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
901 calculate_mem_usage : function ( data
) {
902 if (! Ext
. isNumeric ( data
. mem
) ||
908 return ( data
. mem
/ data
. maxmem
);
911 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
912 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
916 // we got no percentage but bytes
918 var maxmem
= record
. data
. maxmem
;
919 if (! record
. data
. uptime
||
921 ! Ext
. isNumeric ( mem
)) {
925 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
927 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
930 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
933 var maxmem
= record
. data
. maxmem
;
935 if (! record
. data
. uptime
) {
939 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
943 return PVE
. Utils
. render_size ( value
);
946 calculate_disk_usage : function ( data
) {
948 if (! Ext
. isNumeric ( data
. disk
) ||
949 data
. type
=== 'qemu' ||
950 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
951 data
. maxdisk
=== 0 ) {
955 return ( data
. disk
/ data
. maxdisk
);
958 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
959 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
963 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
966 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
969 var maxdisk
= record
. data
. maxdisk
;
970 var type
= record
. data
. type
;
972 if (! Ext
. isNumeric ( disk
) ||
975 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
979 return PVE
. Utils
. render_size ( value
);
982 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
988 case 'lxc' : icon
= 'cube' ;
989 gridcls
= '-stopped' ;
991 case 'qemu' : icon
= 'desktop' ;
992 gridcls
= '-stopped' ;
994 case 'node' : icon
= 'building' ;
995 gridcls
= '-offline' ;
997 case 'storage' : icon
= 'database' ; break ;
998 case 'pool' : icon
= 'tags' ; break ;
999 default : icon
= 'file' ;
1002 if ( value
=== 'lxc' || value
=== 'qemu' ) {
1003 if ( record
. data
. running
&& record
. data
. status
!== 'paused' ) {
1004 gridcls
= '-running' ;
1005 } else if ( record
. data
. running
) {
1006 gridcls
= '-paused' ;
1008 if ( record
. data
. template
) {
1010 gridcls
= '-template-' + value
;
1012 } else if ( value
=== 'node' ) {
1013 if ( record
. data
. running
) {
1014 gridcls
= '-online' ;
1018 // overwrite anything else
1019 if ( record
. data
. hastate
=== 'error' ) {
1020 gridcls
= '-offline' ;
1023 var fa
= '<i class="fa fa-fw x-fa-grid' + gridcls
+ ' fa-' + icon
+ '"></i> ' ;
1027 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1031 if ( uptime
=== undefined ) {
1039 return PVE
. Utils
. format_duration_long ( uptime
);
1042 render_support_level : function ( value
, metaData
, record
) {
1043 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
1046 render_upid : function ( value
, metaData
, record
) {
1047 var type
= record
. data
. type
;
1048 var id
= record
. data
. id
;
1050 return PVE
. Utils
. format_task_description ( type
, id
);
1053 /* render functions for new status panel */
1055 render_usage : function ( val
) {
1056 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
1059 render_cpu_usage : function ( val
, max
) {
1060 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
1061 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
1064 render_size_usage : function ( val
, max
) {
1066 return gettext ( 'N/A' );
1068 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
1069 Ext
. String
. format ( gettext ( '{0} of {1}' ),
1070 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
1073 /* this is different for nodes */
1074 render_node_cpu_usage : function ( value
, record
) {
1075 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
1078 /* this is different for nodes */
1079 render_node_size_usage : function ( record
) {
1080 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
1083 dialog_title : function ( subject
, create
, isAdd
) {
1086 return gettext ( 'Add' ) + ': ' + subject
;
1088 return gettext ( 'Create' ) + ': ' + subject
;
1091 return gettext ( 'Edit' ) + ': ' + subject
;
1095 windowHostname : function () {
1096 return window
. location
. hostname
. replace ( PVE
. Utils
. IP6_bracket_match
,
1097 function ( m
, addr
, offset
, original
) { return addr
; });
1100 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
1101 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
1102 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
1105 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
1106 // kvm, lxc, shell, upgrade
1108 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
1109 throw "missing vmid" ;
1113 throw "no nodename specified" ;
1116 if ( viewer
=== 'html5' ) {
1117 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
1118 } else if ( viewer
=== 'vv' ) {
1120 var params
= { proxy
: PVE
. Utils
. windowHostname () };
1121 if ( vmtype
=== 'kvm' ) {
1122 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1123 PVE
. Utils
. openSpiceViewer ( url
, params
);
1124 } else if ( vmtype
=== 'lxc' ) {
1125 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1126 PVE
. Utils
. openSpiceViewer ( url
, params
);
1127 } else if ( vmtype
=== 'shell' ) {
1128 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1129 PVE
. Utils
. openSpiceViewer ( url
, params
);
1130 } else if ( vmtype
=== 'upgrade' ) {
1131 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1133 PVE
. Utils
. openSpiceViewer ( url
, params
);
1136 throw "unknown viewer type" ;
1140 defaultViewer : function ( allowSpice
) {
1141 var vncdefault
= 'html5' ;
1142 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
1143 if ( dv
=== 'vv' && ! allowSpice
) {
1150 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
1151 var url
= Ext
. urlEncode ({
1152 console
: vmtype
, // kvm, lxc, upgrade or shell
1158 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1162 openSpiceViewer : function ( url
, params
){
1164 var downloadWithName = function ( uri
, name
) {
1165 var link
= Ext
. DomHelper
. append ( document
. body
, {
1168 css
: 'display:none;visibility:hidden;height:0px;'
1171 // Note: we need to tell android the correct file name extension
1172 // but we do not set 'download' tag for other environments, because
1173 // It can have strange side effects (additional user prompt on firefox)
1174 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1176 link
. download
= name
;
1179 if ( link
. fireEvent
) {
1180 link
. fireEvent ( 'onclick' );
1182 var evt
= document
. createEvent ( "MouseEvents" );
1183 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1184 link
. dispatchEvent ( evt
);
1188 PVE
. Utils
. API2Request ({
1192 failure : function ( response
, opts
){
1193 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1195 success : function ( response
, opts
){
1196 var raw
= "[virt-viewer] \n " ;
1197 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1198 raw
+= k
+ "=" + v
+ " \n " ;
1200 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1201 encodeURIComponent ( raw
);
1203 downloadWithName ( url
, "pve-spice.vv" );
1208 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1209 // use el.mask() instead
1210 setErrorMask : function ( comp
, msg
) {
1219 el
. mask ( gettext ( "Loading..." ));
1226 monStoreErrors : function ( me
, store
) {
1227 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1228 if (! me
. loadCount
) {
1229 me
. loadCount
= 0 ; // make sure it is numeric
1230 PVE
. Utils
. setErrorMask ( me
, true );
1234 // only works with 'pve' proxy
1235 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1239 PVE
. Utils
. setErrorMask ( me
, false );
1244 /*jslint nomen: true */
1245 var operation
= request
. _operation
;
1246 var error
= operation
. getError ();
1247 if ( error
. statusText
) {
1248 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1250 msg
= gettext ( 'Connection error' );
1252 PVE
. Utils
. setErrorMask ( me
, msg
);
1256 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1258 var nodename
= record
. data
. node
;
1259 var vmid
= record
. data
. vmid
;
1260 var vmname
= record
. data
. name
;
1261 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1262 PVE
. Utils
. API2Request ({
1263 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1264 failure : function ( response
, opts
) {
1265 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1267 success : function ( response
, opts
) {
1268 var allowSpice
= response
. result
. data
. spice
;
1269 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
1272 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1273 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1277 // test automation helper
1278 call_menu_handler : function ( menu
, text
) {
1280 var list
= menu
. query ( 'menuitem' );
1282 Ext
. Array
. each ( list
, function ( item
) {
1283 if ( item
. text
=== text
) {
1294 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1296 if (!( v
instanceof Ext
. tree
. View
)) {
1301 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1302 menu
= Ext
. create ( 'PVE.qemu.CmdMenu' , {
1305 } else if ( record
. data
. type
=== 'qemu' && record
. data
. template
) {
1306 menu
= Ext
. create ( 'PVE.qemu.TemplateMenu' , {
1309 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1310 menu
= Ext
. create ( 'PVE.lxc.CmdMenu' , {
1313 } else if ( record
. data
. type
=== 'lxc' && record
. data
. template
) {
1314 /* since clone does not work reliably, disable for now
1315 menu = Ext.create('PVE.lxc.TemplateMenu', {
1324 menu
. showAt ( event
. getXY ());
1327 // helper for deleting field which are set to there default values
1328 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1329 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1331 if ( values
[ 'delete' ]) {
1332 values
[ 'delete' ] += ',' + fieldname
;
1334 values
[ 'delete' ] = fieldname
;
1338 delete values
[ fieldname
];
1343 constructor : function () {
1345 Ext
. apply ( me
, me
. utilities
);
1347 var IPV4_OCTET
= "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])" ;
1348 var IPV4_REGEXP
= "(?:(?:" + IPV4_OCTET
+ " \\ .){3}" + IPV4_OCTET
+ ")" ;
1349 var IPV6_H16
= "(?:[0-9a-fA-F]{1,4})" ;
1350 var IPV6_LS32
= "(?:(?:" + IPV6_H16
+ ":" + IPV6_H16
+ ")|" + IPV4_REGEXP
+ ")" ;
1353 me
. IP4_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")$" );
1354 me
. IP4_cidr_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")\/([0-9]{1,2})$" );
1356 var IPV6_REGEXP
= "(?:" +
1357 "(?:(?:" + "(?:" + IPV6_H16
+ ":){6})" + IPV6_LS32
+ ")|" +
1358 "(?:(?:" + "::" + "(?:" + IPV6_H16
+ ":){5})" + IPV6_LS32
+ ")|" +
1359 "(?:(?:(?:" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){4})" + IPV6_LS32
+ ")|" +
1360 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,1}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){3})" + IPV6_LS32
+ ")|" +
1361 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,2}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){2})" + IPV6_LS32
+ ")|" +
1362 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,3}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){1})" + IPV6_LS32
+ ")|" +
1363 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,4}" + IPV6_H16
+ ")?::" + ")" + IPV6_LS32
+ ")|" +
1364 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,5}" + IPV6_H16
+ ")?::" + ")" + IPV6_H16
+ ")|" +
1365 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,7}" + IPV6_H16
+ ")?::" + ")" + ")" +
1368 me
. IP6_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")$" );
1369 me
. IP6_cidr_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")\/([0-9]{1,3})$" );
1370 me
. IP6_bracket_match
= new RegExp ( "^ \\ [(" + IPV6_REGEXP
+ ") \\ ]" );
1372 me
. IP64_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ ")$" );
1374 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])?))" ;
1375 me
. DnsName_match
= new RegExp ( "^" + DnsName_REGEXP
+ "$" );
1377 me
. HostPort_match
= new RegExp ( "^(" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ")(: \\ d+)?$" );
1378 me
. HostPortBrackets_match
= new RegExp ( "^ \\ [(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ") \\ ](: \\ d+)?$" );
1379 me
. IP6_dotnotation_match
= new RegExp ( "^" + IPV6_REGEXP
+ "( \\ . \\ d+)?$" );