]>
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/2012/2012r2' ,
67 win10
: 'Microsoft Windows 10/2016' ,
68 l24
: 'Linux 2.4 Kernel' ,
69 l26
: 'Linux 4.X/3.X/2.6 Kernel' ,
70 solaris
: 'Solaris Kernel'
73 get_health_icon : function ( state
, circle
) {
74 if ( circle
=== undefined ) {
78 if ( state
=== undefined ) {
82 var icon
= 'faded fa-question' ;
85 icon
= 'good fa-check' ;
88 icon
= 'warning fa-exclamation' ;
91 icon
= 'critical fa-times' ;
105 'HEALTH_WARN' : 'warning' ,
106 'HEALTH_ERR' : 'critical'
109 render_ceph_health : function ( record
) {
111 iconCls
: PVE
. Utils
. get_health_icon (),
115 if (! record
|| ! record
. data
) {
119 var health
= PVE
. Utils
. map_ceph_health
[ record
. data
. health
. overall_status
];
121 state
. iconCls
= PVE
. Utils
. get_health_icon ( health
, true );
122 state
. text
= record
. data
. health
. overall_status
;
127 render_kvm_ostype : function ( value
) {
129 return gettext ( 'Other OS types' );
131 var text
= PVE
. Utils
. kvm_ostypes
[ value
];
138 render_hotplug_features : function ( value
) {
141 if (! value
|| ( value
=== '0' )) {
142 return gettext ( 'Disabled' );
146 value
= 'disk,network,usb' ;
149 Ext
. each ( value
. split ( ',' ), function ( el
) {
151 fa
. push ( gettext ( 'Disk' ));
152 } else if ( el
=== 'network' ) {
153 fa
. push ( gettext ( 'Network' ));
154 } else if ( el
=== 'usb' ) {
156 } else if ( el
=== 'memory' ) {
157 fa
. push ( gettext ( 'Memory' ));
158 } else if ( el
=== 'cpu' ) {
159 fa
. push ( gettext ( 'CPU' ));
165 return fa
. join ( ', ' );
168 network_iface_types
: {
169 eth
: gettext ( "Network Device" ),
170 bridge
: 'Linux Bridge' ,
172 OVSBridge
: 'OVS Bridge' ,
175 OVSIntPort
: 'OVS IntPort'
178 render_network_iface_type : function ( value
) {
179 return PVE
. Utils
. network_iface_types
[ value
] ||
180 PVE
. Utils
. unknownText
;
183 render_qemu_bios : function ( value
) {
185 return PVE
. Utils
. defaultText
+ ' (SeaBIOS)' ;
186 } else if ( value
=== 'seabios' ) {
188 } else if ( value
=== 'ovmf' ) {
189 return "OVMF (UEFI)" ;
195 render_scsihw : function ( value
) {
197 return PVE
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
198 } else if ( value
=== 'lsi' ) {
199 return 'LSI 53C895A' ;
200 } else if ( value
=== 'lsi53c810' ) {
202 } else if ( value
=== 'megasas' ) {
203 return 'MegaRAID SAS 8708EM2' ;
204 } else if ( value
=== 'virtio-scsi-pci' ) {
205 return 'VirtIO SCSI' ;
206 } else if ( value
=== 'virtio-scsi-single' ) {
207 return 'VirtIO SCSI single' ;
208 } else if ( value
=== 'pvscsi' ) {
209 return 'VMware PVSCSI' ;
215 // fixme: auto-generate this
216 // for now, please keep in sync with PVE::Tools::kvmkeymaps
221 'de-ch' : 'German (Swiss)' ,
222 'en-gb' : 'English (UK)' ,
223 'en-us' : 'English (USA)' ,
227 //fo: 'Faroe Islands',
229 'fr-be' : 'French (Belgium)' ,
230 'fr-ca' : 'French (Canada)' ,
231 'fr-ch' : 'French (Swiss)' ,
241 //'nl-be': 'Dutch (Belgium)',
245 'pt-br' : 'Portuguese (Brazil)' ,
254 std
: gettext ( 'Standard VGA' ),
255 vmware
: gettext ( 'VMware compatible' ),
256 cirrus
: 'Cirrus Logic GD5446' ,
258 qxl2
: 'SPICE dual monitor' ,
259 qxl3
: 'SPICE three monitors' ,
260 qxl4
: 'SPICE four monitors' ,
261 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
262 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
263 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
264 serial3
: gettext ( 'Serial terminal' ) + ' 3'
267 render_kvm_language : function ( value
) {
269 return PVE
. Utils
. defaultText
;
271 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
273 return text
+ ' (' + value
+ ')' ;
278 kvm_keymap_array : function () {
279 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
280 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
281 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
287 render_console_viewer : function ( value
) {
288 if (! value
|| value
=== '__default__' ) {
289 return PVE
. Utils
. defaultText
+ ' (HTML5)' ;
290 } else if ( value
=== 'vv' ) {
291 return 'SPICE (remote-viewer)' ;
292 } else if ( value
=== 'html5' ) {
293 return 'HTML5 (noVNC)' ;
304 eu
: 'Euskera (Basque)' ,
309 nb
: 'Norwegian (Bokmal)' ,
310 nn
: 'Norwegian (Nynorsk)' ,
311 fa
: 'Persian (Farsi)' ,
313 pt_BR
: 'Portuguese (Brazil)' ,
321 render_language : function ( value
) {
323 return PVE
. Utils
. defaultText
+ ' (English)' ;
325 var text
= PVE
. Utils
. language_map
[ value
];
327 return text
+ ' (' + value
+ ')' ;
332 language_array : function () {
333 var data
= [[ '__default__' , PVE
. Utils
. render_language ( '' )]];
334 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
335 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
341 render_kvm_vga_driver : function ( value
) {
343 return PVE
. Utils
. defaultText
;
345 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
347 return text
+ ' (' + value
+ ')' ;
352 kvm_vga_driver_array : function () {
353 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
354 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
355 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
361 render_kvm_startup : function ( value
) {
362 var startup
= PVE
. Parser
. parseStartup ( value
);
365 if ( startup
. order
=== undefined ) {
368 res
+= startup
. order
;
370 if ( startup
. up
!== undefined ) {
371 res
+= ',up=' + startup
. up
;
373 if ( startup
. down
!== undefined ) {
374 res
+= ',down=' + startup
. down
;
381 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
384 authClear : function () {
385 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
388 // fixme: remove - not needed?
389 gridLineHeigh : function () {
397 extractRequestError : function ( result
, verbose
) {
398 var msg
= gettext ( 'Successful' );
400 if (! result
. success
) {
401 msg
= gettext ( "Unknown error" );
402 if ( result
. message
) {
403 msg
= result
. message
;
405 msg
+= ' (' + result
. status
+ ')' ;
408 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
410 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
411 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
412 Ext
. htmlEncode ( desc
);
420 extractFormActionError : function ( action
) {
422 switch ( action
. failureType
) {
423 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
424 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
426 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
427 msg
= gettext ( 'Connection error' );
428 var resp
= action
. response
;
429 if ( resp
. status
&& resp
. statusText
) {
430 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
433 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
434 case Ext
. form
. action
. Action
. SERVER_INVALID
:
435 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
442 API2Request : function ( reqOpts
) {
444 var newopts
= Ext
. apply ({
445 waitMsg
: gettext ( 'Please wait...' )
448 if (! newopts
. url
. match ( /^\/api2/ )) {
449 newopts
. url
= '/api2/extjs' + newopts
. url
;
451 delete newopts
. callback
;
453 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
455 success : function ( response
, options
) {
456 if ( options
. waitMsgTarget
) {
457 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
458 options
. waitMsgTarget
. setMasked ( false );
460 options
. waitMsgTarget
. setLoading ( false );
463 var result
= Ext
. decode ( response
. responseText
);
464 response
. result
= result
;
465 if (! result
. success
) {
466 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
467 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
468 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
471 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
472 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
474 failure : function ( response
, options
) {
475 if ( options
. waitMsgTarget
) {
476 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
477 options
. waitMsgTarget
. setMasked ( false );
479 options
. waitMsgTarget
. setLoading ( false );
482 response
. result
= {};
484 response
. result
= Ext
. decode ( response
. responseText
);
486 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
487 if ( response
. aborted
) {
488 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
489 } else if ( response
. timedout
) {
490 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
491 } else if ( response
. status
&& response
. statusText
) {
492 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
494 response
. htmlStatus
= msg
;
495 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
496 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
501 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
503 var target
= newopts
. waitMsgTarget
;
505 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
506 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
} );
508 // Note: ExtJS bug - this does not work when component is not rendered
509 target
. setLoading ( newopts
. waitMsg
);
512 Ext
. Ajax
. request ( newopts
);
515 assemble_field_data : function ( values
, data
) {
516 if ( Ext
. isObject ( data
)) {
517 Ext
. Object
. each ( data
, function ( name
, val
) {
518 if ( values
. hasOwnProperty ( name
)) {
519 var bucket
= values
[ name
];
520 if (! Ext
. isArray ( bucket
)) {
521 bucket
= values
[ name
] = [ bucket
];
523 if ( Ext
. isArray ( val
)) {
524 values
[ name
] = bucket
. concat ( val
);
535 checked_command : function ( orig_cmd
) {
536 PVE
. Utils
. API2Request ({
537 url
: '/nodes/localhost/subscription' ,
540 failure : function ( response
, opts
) {
541 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
543 success : function ( response
, opts
) {
544 var data
= response
. result
. data
;
546 if ( data
. status
!== 'Active' ) {
548 title
: gettext ( 'No valid subscription' ),
549 icon
: Ext
. Msg
. WARNING
,
550 msg
: PVE
. Utils
. noSubKeyHtml
,
552 callback : function ( btn
) {
567 diskinit
: [ 'Disk' , gettext ( 'Initialize Disk with GPT' ) ],
568 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
569 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
570 vncshell
: [ '' , gettext ( 'Shell' ) ],
571 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
572 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
573 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
574 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
575 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
576 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
577 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
578 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
579 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
580 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
581 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
582 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
583 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
584 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
585 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
586 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
587 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
588 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
589 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' ) ],
590 vzrollback
: [ 'CT' , gettext ( 'Rollback' ) ],
591 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' ) ],
592 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
593 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
594 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
595 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
596 vzclone
: [ 'CT' , gettext ( 'Clone' ) ],
597 vztemplate
: [ 'CT' , gettext ( 'Convert to template' ) ],
598 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
599 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
600 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
601 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
602 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
603 vzsuspend
: [ 'CT' , gettext ( 'Suspend' ) ],
604 vzresume
: [ 'CT' , gettext ( 'Resume' ) ],
605 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
606 hastart
: [ 'HA' , gettext ( 'Start' ) ],
607 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
608 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
609 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
610 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
611 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
612 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' ) ],
613 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' ) ],
614 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' ) ],
615 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' ) ],
616 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
617 imgdel
: [ '' , gettext ( 'Erase data' ) ],
618 download
: [ '' , gettext ( 'Download' ) ],
619 vzdump
: [ '' , gettext ( 'Backup' ) ],
620 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
621 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
622 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
623 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
626 format_task_description : function ( type
, id
) {
627 var farray
= PVE
. Utils
. task_desc_table
[ type
];
631 var prefix
= farray
[ 0 ];
632 var text
= farray
[ 1 ];
634 return prefix
+ ' ' + id
+ ' - ' + text
;
639 parse_task_upid : function ( upid
) {
642 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]+):$/ );
644 throw "unable to parse upid '" + upid
+ "'" ;
647 task
. pid
= parseInt ( res
[ 2 ], 16 );
648 task
. pstart
= parseInt ( res
[ 3 ], 16 );
649 task
. starttime
= parseInt ( res
[ 4 ], 16 );
654 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
659 format_size : function ( size
) {
660 /*jslint confusion: true */
662 var units
= [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ];
665 while ( size
>= 1024 && (( num
++)+ 1 ) < units
. length
) {
669 return size
. toFixed (( num
> 0 )? 2 : 0 ) + " " + units
[ num
] + "B" ;
672 format_html_bar : function ( per
, text
) {
674 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
675 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
680 format_cpu_bar : function ( per1
, per2
, text
) {
682 return "<div class='pve-bar-border'>" +
683 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
684 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
685 "<div class='pve-bar-text'>" + text
+ "</div>" +
689 format_large_bar : function ( per
, text
) {
692 text
= per
. toFixed ( 1 ) + "%" ;
695 return "<div class='pve-largebar-border'>" +
696 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
697 "<div class='pve-largebar-text'>" + text
+ "</div>" +
701 format_duration_long : function ( ut
) {
703 var days
= Math
. floor ( ut
/ 86400 );
705 var hours
= Math
. floor ( ut
/ 3600 );
707 var mins
= Math
. floor ( ut
/ 60 );
710 var hours_str
= '00' + hours
. toString ();
711 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
712 var mins_str
= "00" + mins
. toString ();
713 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
714 var ut_str
= "00" + ut
. toString ();
715 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
718 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
719 return days
. toString () + ' ' + ds
+ ' ' +
720 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
722 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
726 format_duration_short : function ( ut
) {
729 return ut
. toString () + 's' ;
734 return mins
. toFixed ( 0 ) + 'm' ;
738 var hours
= ut
/ 3600 ;
739 return hours
. toFixed ( 0 ) + 'h' ;
742 var days
= ut
/ 86400 ;
743 return days
. toFixed ( 0 ) + 'd' ;
746 yesText
: gettext ( 'Yes' ),
747 noText
: gettext ( 'No' ),
748 enabledText
: gettext ( 'Enabled' ),
749 disabledText
: gettext ( 'Disabled' ),
750 noneText
: gettext ( 'none' ),
751 errorText
: gettext ( 'Error' ),
752 unknownText
: gettext ( 'Unknown' ),
753 defaultText
: gettext ( 'Default' ),
754 daysText
: gettext ( 'days' ),
755 dayText
: gettext ( 'day' ),
756 runningText
: gettext ( 'running' ),
757 stoppedText
: gettext ( 'stopped' ),
758 neverText
: gettext ( 'never' ),
759 totalText
: gettext ( 'Total' ),
760 usedText
: gettext ( 'Used' ),
761 directoryText
: gettext ( 'Directory' ),
762 imagesText
: gettext ( 'Disk image' ),
763 backupFileText
: gettext ( 'VZDump backup file' ),
764 vztmplText
: gettext ( 'Container template' ),
765 isoImageText
: gettext ( 'ISO image' ),
766 containersText
: gettext ( 'Container' ),
767 stateText
: gettext ( 'State' ),
768 groupText
: gettext ( 'Group' ),
770 format_expire : function ( date
) {
772 return PVE
. Utils
. neverText
;
774 return Ext
. Date
. format ( date
, "Y-m-d" );
777 format_storage_type : function ( value
) {
778 if ( value
=== 'dir' ) {
779 return PVE
. Utils
. directoryText
;
780 } else if ( value
=== 'nfs' ) {
782 } else if ( value
=== 'glusterfs' ) {
784 } else if ( value
=== 'lvm' ) {
786 } else if ( value
=== 'lvmthin' ) {
788 } else if ( value
=== 'iscsi' ) {
790 } else if ( value
=== 'rbd' ) {
792 } else if ( value
=== 'sheepdog' ) {
794 } else if ( value
=== 'zfs' ) {
795 return 'ZFS over iSCSI' ;
796 } else if ( value
=== 'zfspool' ) {
798 } else if ( value
=== 'iscsidirect' ) {
799 return 'iSCSIDirect' ;
800 } else if ( value
=== 'drbd' ) {
803 return PVE
. Utils
. unknownText
;
807 format_boolean_with_default : function ( value
) {
808 if ( Ext
. isDefined ( value
) && value
!== '__default__' ) {
809 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
811 return PVE
. Utils
. defaultText
;
814 format_boolean : function ( value
) {
815 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
818 format_neg_boolean : function ( value
) {
819 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
822 format_enabled_toggle : function ( value
) {
823 return value
? PVE
. Utils
. enabledText
: PVE
. Utils
. disabledText
;
826 format_ha : function ( value
) {
827 var text
= PVE
. Utils
. format_boolean ( value
. managed
);
830 text
+= ', ' + PVE
. Utils
. stateText
+ ': ' ;
831 text
+= value
. state
|| PVE
. Utils
. noneText
;
833 text
+= ', ' + PVE
. Utils
. groupText
+ ': ' ;
834 text
+= value
. group
|| PVE
. Utils
. noneText
;
840 format_content_types : function ( value
) {
843 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
844 if ( ct
=== 'images' ) {
845 cta
. push ( PVE
. Utils
. imagesText
);
846 } else if ( ct
=== 'backup' ) {
847 cta
. push ( PVE
. Utils
. backupFileText
);
848 } else if ( ct
=== 'vztmpl' ) {
849 cta
. push ( PVE
. Utils
. vztmplText
);
850 } else if ( ct
=== 'iso' ) {
851 cta
. push ( PVE
. Utils
. isoImageText
);
852 } else if ( ct
=== 'rootdir' ) {
853 cta
. push ( PVE
. Utils
. containersText
);
857 return cta
. join ( ', ' );
860 render_storage_content : function ( value
, metaData
, record
) {
861 var data
= record
. data
;
862 if ( Ext
. isNumber ( data
. channel
) &&
863 Ext
. isNumber ( data
. id
) &&
864 Ext
. isNumber ( data
. lun
)) {
866 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
867 " ID " + data
. id
+ " LUN " + data
. lun
;
869 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
872 render_serverity : function ( value
) {
873 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
876 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
878 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
882 var maxcpu
= record
. data
. maxcpu
|| 1 ;
884 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
888 var per
= value
* 100 ;
890 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
893 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
894 /*jslint confusion: true */
896 if (! Ext
. isNumeric ( value
)) {
900 return PVE
. Utils
. format_size ( value
);
903 render_bandwidth : function ( value
) {
904 if (! Ext
. isNumeric ( value
)) {
908 return PVE
. Utils
. format_size ( value
) + '/s' ;
911 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
912 var servertime
= new Date ( value
* 1000 );
913 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
916 render_timestamp_human_readable : function ( value
) {
917 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
920 calculate_mem_usage : function ( data
) {
921 if (! Ext
. isNumeric ( data
. mem
) ||
927 return ( data
. mem
/ data
. maxmem
);
930 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
931 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
935 // we got no percentage but bytes
937 var maxmem
= record
. data
. maxmem
;
938 if (! record
. data
. uptime
||
940 ! Ext
. isNumeric ( mem
)) {
944 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
946 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
949 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
952 var maxmem
= record
. data
. maxmem
;
954 if (! record
. data
. uptime
) {
958 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
962 return PVE
. Utils
. render_size ( value
);
965 calculate_disk_usage : function ( data
) {
967 if (! Ext
. isNumeric ( data
. disk
) ||
968 data
. type
=== 'qemu' ||
969 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
970 data
. maxdisk
=== 0 ) {
974 return ( data
. disk
/ data
. maxdisk
);
977 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
978 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
982 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
985 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
988 var maxdisk
= record
. data
. maxdisk
;
989 var type
= record
. data
. type
;
991 if (! Ext
. isNumeric ( disk
) ||
994 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
998 return PVE
. Utils
. render_size ( value
);
1001 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1007 case 'lxc' : icon
= 'cube' ;
1008 gridcls
= '-stopped' ;
1010 case 'qemu' : icon
= 'desktop' ;
1011 gridcls
= '-stopped' ;
1013 case 'node' : icon
= 'building' ;
1014 gridcls
= '-offline' ;
1016 case 'storage' : icon
= 'database' ; break ;
1017 case 'pool' : icon
= 'tags' ; break ;
1018 default : icon
= 'file' ;
1021 if ( value
=== 'lxc' || value
=== 'qemu' ) {
1022 if ( record
. data
. running
&& record
. data
. status
!== 'paused' ) {
1023 gridcls
= '-running' ;
1024 } else if ( record
. data
. running
) {
1025 gridcls
= '-paused' ;
1027 if ( record
. data
. template
) {
1029 gridcls
= '-template-' + value
;
1031 } else if ( value
=== 'node' ) {
1032 if ( record
. data
. running
) {
1033 gridcls
= '-online' ;
1037 // overwrite anything else
1038 if ( record
. data
. hastate
=== 'error' ) {
1039 gridcls
= '-offline' ;
1042 var fa
= '<i class="fa fa-fw x-fa-grid' + gridcls
+ ' fa-' + icon
+ '"></i> ' ;
1046 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1050 if ( uptime
=== undefined ) {
1058 return PVE
. Utils
. format_duration_long ( uptime
);
1061 render_support_level : function ( value
, metaData
, record
) {
1062 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
1065 render_upid : function ( value
, metaData
, record
) {
1066 var type
= record
. data
. type
;
1067 var id
= record
. data
. id
;
1069 return PVE
. Utils
. format_task_description ( type
, id
);
1072 /* render functions for new status panel */
1074 render_usage : function ( val
) {
1075 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
1078 render_cpu_usage : function ( val
, max
) {
1079 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
1080 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
1083 render_size_usage : function ( val
, max
) {
1085 return gettext ( 'N/A' );
1087 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
1088 Ext
. String
. format ( gettext ( '{0} of {1}' ),
1089 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
1092 /* this is different for nodes */
1093 render_node_cpu_usage : function ( value
, record
) {
1094 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
1097 /* this is different for nodes */
1098 render_node_size_usage : function ( record
) {
1099 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
1102 dialog_title : function ( subject
, create
, isAdd
) {
1105 return gettext ( 'Add' ) + ': ' + subject
;
1107 return gettext ( 'Create' ) + ': ' + subject
;
1110 return gettext ( 'Edit' ) + ': ' + subject
;
1114 windowHostname : function () {
1115 return window
. location
. hostname
. replace ( PVE
. Utils
. IP6_bracket_match
,
1116 function ( m
, addr
, offset
, original
) { return addr
; });
1119 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
1120 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
1121 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
1124 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
1125 // kvm, lxc, shell, upgrade
1127 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
1128 throw "missing vmid" ;
1132 throw "no nodename specified" ;
1135 if ( viewer
=== 'html5' ) {
1136 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
1137 } else if ( viewer
=== 'vv' ) {
1139 var params
= { proxy
: PVE
. Utils
. windowHostname () };
1140 if ( vmtype
=== 'kvm' ) {
1141 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1142 PVE
. Utils
. openSpiceViewer ( url
, params
);
1143 } else if ( vmtype
=== 'lxc' ) {
1144 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1145 PVE
. Utils
. openSpiceViewer ( url
, params
);
1146 } else if ( vmtype
=== 'shell' ) {
1147 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1148 PVE
. Utils
. openSpiceViewer ( url
, params
);
1149 } else if ( vmtype
=== 'upgrade' ) {
1150 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1152 PVE
. Utils
. openSpiceViewer ( url
, params
);
1155 throw "unknown viewer type" ;
1159 defaultViewer : function ( allowSpice
) {
1160 var vncdefault
= 'html5' ;
1161 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
1162 if ( dv
=== 'vv' && ! allowSpice
) {
1169 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
1170 var url
= Ext
. urlEncode ({
1171 console
: vmtype
, // kvm, lxc, upgrade or shell
1177 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1181 openSpiceViewer : function ( url
, params
){
1183 var downloadWithName = function ( uri
, name
) {
1184 var link
= Ext
. DomHelper
. append ( document
. body
, {
1187 css
: 'display:none;visibility:hidden;height:0px;'
1190 // Note: we need to tell android the correct file name extension
1191 // but we do not set 'download' tag for other environments, because
1192 // It can have strange side effects (additional user prompt on firefox)
1193 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1195 link
. download
= name
;
1198 if ( link
. fireEvent
) {
1199 link
. fireEvent ( 'onclick' );
1201 var evt
= document
. createEvent ( "MouseEvents" );
1202 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1203 link
. dispatchEvent ( evt
);
1207 PVE
. Utils
. API2Request ({
1211 failure : function ( response
, opts
){
1212 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1214 success : function ( response
, opts
){
1215 var raw
= "[virt-viewer] \n " ;
1216 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1217 raw
+= k
+ "=" + v
+ " \n " ;
1219 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1220 encodeURIComponent ( raw
);
1222 downloadWithName ( url
, "pve-spice.vv" );
1227 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1228 // use el.mask() instead
1229 setErrorMask : function ( comp
, msg
) {
1238 el
. mask ( gettext ( "Loading..." ));
1245 monStoreErrors : function ( me
, store
) {
1246 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1247 if (! me
. loadCount
) {
1248 me
. loadCount
= 0 ; // make sure it is numeric
1249 PVE
. Utils
. setErrorMask ( me
, true );
1253 // only works with 'pve' proxy
1254 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1258 PVE
. Utils
. setErrorMask ( me
, false );
1263 /*jslint nomen: true */
1264 var operation
= request
. _operation
;
1265 var error
= operation
. getError ();
1266 if ( error
. statusText
) {
1267 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1269 msg
= gettext ( 'Connection error' );
1271 PVE
. Utils
. setErrorMask ( me
, msg
);
1275 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1277 var nodename
= record
. data
. node
;
1278 var vmid
= record
. data
. vmid
;
1279 var vmname
= record
. data
. name
;
1280 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1281 PVE
. Utils
. API2Request ({
1282 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1283 failure : function ( response
, opts
) {
1284 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1286 success : function ( response
, opts
) {
1287 var allowSpice
= response
. result
. data
. spice
;
1288 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
1291 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1292 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1296 // test automation helper
1297 call_menu_handler : function ( menu
, text
) {
1299 var list
= menu
. query ( 'menuitem' );
1301 Ext
. Array
. each ( list
, function ( item
) {
1302 if ( item
. text
=== text
) {
1313 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1315 if (!( v
instanceof Ext
. tree
. View
)) {
1320 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1321 menu
= Ext
. create ( 'PVE.qemu.CmdMenu' , {
1324 } else if ( record
. data
. type
=== 'qemu' && record
. data
. template
) {
1325 menu
= Ext
. create ( 'PVE.qemu.TemplateMenu' , {
1328 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1329 menu
= Ext
. create ( 'PVE.lxc.CmdMenu' , {
1332 } else if ( record
. data
. type
=== 'lxc' && record
. data
. template
) {
1333 /* since clone does not work reliably, disable for now
1334 menu = Ext.create('PVE.lxc.TemplateMenu', {
1340 } else if ( record
. data
. type
=== 'node' ){
1341 menu
= Ext
. create ( 'PVE.node.CmdMenu' , {
1342 nodename
: record
. data
. node
1349 menu
. showAt ( event
. getXY ());
1352 // helper for deleting field which are set to there default values
1353 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1354 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1356 if ( values
[ 'delete' ]) {
1357 values
[ 'delete' ] += ',' + fieldname
;
1359 values
[ 'delete' ] = fieldname
;
1363 delete values
[ fieldname
];
1368 constructor : function () {
1370 Ext
. apply ( me
, me
. utilities
);
1372 var IPV4_OCTET
= "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])" ;
1373 var IPV4_REGEXP
= "(?:(?:" + IPV4_OCTET
+ " \\ .){3}" + IPV4_OCTET
+ ")" ;
1374 var IPV6_H16
= "(?:[0-9a-fA-F]{1,4})" ;
1375 var IPV6_LS32
= "(?:(?:" + IPV6_H16
+ ":" + IPV6_H16
+ ")|" + IPV4_REGEXP
+ ")" ;
1378 me
. IP4_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")$" );
1379 me
. IP4_cidr_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")\/([0-9]{1,2})$" );
1381 var IPV6_REGEXP
= "(?:" +
1382 "(?:(?:" + "(?:" + IPV6_H16
+ ":){6})" + IPV6_LS32
+ ")|" +
1383 "(?:(?:" + "::" + "(?:" + IPV6_H16
+ ":){5})" + IPV6_LS32
+ ")|" +
1384 "(?:(?:(?:" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){4})" + IPV6_LS32
+ ")|" +
1385 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,1}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){3})" + IPV6_LS32
+ ")|" +
1386 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,2}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){2})" + IPV6_LS32
+ ")|" +
1387 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,3}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){1})" + IPV6_LS32
+ ")|" +
1388 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,4}" + IPV6_H16
+ ")?::" + ")" + IPV6_LS32
+ ")|" +
1389 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,5}" + IPV6_H16
+ ")?::" + ")" + IPV6_H16
+ ")|" +
1390 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,7}" + IPV6_H16
+ ")?::" + ")" + ")" +
1393 me
. IP6_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")$" );
1394 me
. IP6_cidr_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")\/([0-9]{1,3})$" );
1395 me
. IP6_bracket_match
= new RegExp ( "^ \\ [(" + IPV6_REGEXP
+ ") \\ ]" );
1397 me
. IP64_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ ")$" );
1399 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])?))" ;
1400 me
. DnsName_match
= new RegExp ( "^" + DnsName_REGEXP
+ "$" );
1402 me
. HostPort_match
= new RegExp ( "^(" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ")(: \\ d+)?$" );
1403 me
. HostPortBrackets_match
= new RegExp ( "^ \\ [(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ") \\ ](: \\ d+)?$" );
1404 me
. IP6_dotnotation_match
= new RegExp ( "^" + IPV6_REGEXP
+ "( \\ . \\ d+)?$" );