]>
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 cephdestroypool
: [ 'Ceph Pool' , gettext ( 'Destroy' ) ],
617 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
618 imgdel
: [ '' , gettext ( 'Erase data' ) ],
619 download
: [ '' , gettext ( 'Download' ) ],
620 vzdump
: [ '' , gettext ( 'Backup' ) ],
621 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
622 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
623 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
624 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
627 format_task_description : function ( type
, id
) {
628 var farray
= PVE
. Utils
. task_desc_table
[ type
];
632 var prefix
= farray
[ 0 ];
633 var text
= farray
[ 1 ];
635 return prefix
+ ' ' + id
+ ' - ' + text
;
640 parse_task_upid : function ( upid
) {
643 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]+):$/ );
645 throw "unable to parse upid '" + upid
+ "'" ;
648 task
. pid
= parseInt ( res
[ 2 ], 16 );
649 task
. pstart
= parseInt ( res
[ 3 ], 16 );
650 task
. starttime
= parseInt ( res
[ 4 ], 16 );
655 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
660 format_size : function ( size
) {
661 /*jslint confusion: true */
663 var units
= [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ];
666 while ( size
>= 1024 && (( num
++)+ 1 ) < units
. length
) {
670 return size
. toFixed (( num
> 0 )? 2 : 0 ) + " " + units
[ num
] + "B" ;
673 format_html_bar : function ( per
, text
) {
675 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
676 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
681 format_cpu_bar : function ( per1
, per2
, text
) {
683 return "<div class='pve-bar-border'>" +
684 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
685 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
686 "<div class='pve-bar-text'>" + text
+ "</div>" +
690 format_large_bar : function ( per
, text
) {
693 text
= per
. toFixed ( 1 ) + "%" ;
696 return "<div class='pve-largebar-border'>" +
697 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
698 "<div class='pve-largebar-text'>" + text
+ "</div>" +
702 format_duration_long : function ( ut
) {
704 var days
= Math
. floor ( ut
/ 86400 );
706 var hours
= Math
. floor ( ut
/ 3600 );
708 var mins
= Math
. floor ( ut
/ 60 );
711 var hours_str
= '00' + hours
. toString ();
712 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
713 var mins_str
= "00" + mins
. toString ();
714 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
715 var ut_str
= "00" + ut
. toString ();
716 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
719 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
720 return days
. toString () + ' ' + ds
+ ' ' +
721 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
723 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
727 format_duration_short : function ( ut
) {
730 return ut
. toString () + 's' ;
735 return mins
. toFixed ( 0 ) + 'm' ;
739 var hours
= ut
/ 3600 ;
740 return hours
. toFixed ( 0 ) + 'h' ;
743 var days
= ut
/ 86400 ;
744 return days
. toFixed ( 0 ) + 'd' ;
747 yesText
: gettext ( 'Yes' ),
748 noText
: gettext ( 'No' ),
749 enabledText
: gettext ( 'Enabled' ),
750 disabledText
: gettext ( 'Disabled' ),
751 noneText
: gettext ( 'none' ),
752 errorText
: gettext ( 'Error' ),
753 unknownText
: gettext ( 'Unknown' ),
754 defaultText
: gettext ( 'Default' ),
755 daysText
: gettext ( 'days' ),
756 dayText
: gettext ( 'day' ),
757 runningText
: gettext ( 'running' ),
758 stoppedText
: gettext ( 'stopped' ),
759 neverText
: gettext ( 'never' ),
760 totalText
: gettext ( 'Total' ),
761 usedText
: gettext ( 'Used' ),
762 directoryText
: gettext ( 'Directory' ),
763 imagesText
: gettext ( 'Disk image' ),
764 backupFileText
: gettext ( 'VZDump backup file' ),
765 vztmplText
: gettext ( 'Container template' ),
766 isoImageText
: gettext ( 'ISO image' ),
767 containersText
: gettext ( 'Container' ),
768 stateText
: gettext ( 'State' ),
769 groupText
: gettext ( 'Group' ),
771 format_expire : function ( date
) {
773 return PVE
. Utils
. neverText
;
775 return Ext
. Date
. format ( date
, "Y-m-d" );
778 format_storage_type : function ( value
) {
779 if ( value
=== 'dir' ) {
780 return PVE
. Utils
. directoryText
;
781 } else if ( value
=== 'nfs' ) {
783 } else if ( value
=== 'glusterfs' ) {
785 } else if ( value
=== 'lvm' ) {
787 } else if ( value
=== 'lvmthin' ) {
789 } else if ( value
=== 'iscsi' ) {
791 } else if ( value
=== 'rbd' ) {
793 } else if ( value
=== 'sheepdog' ) {
795 } else if ( value
=== 'zfs' ) {
796 return 'ZFS over iSCSI' ;
797 } else if ( value
=== 'zfspool' ) {
799 } else if ( value
=== 'iscsidirect' ) {
800 return 'iSCSIDirect' ;
801 } else if ( value
=== 'drbd' ) {
804 return PVE
. Utils
. unknownText
;
808 format_boolean_with_default : function ( value
) {
809 if ( Ext
. isDefined ( value
) && value
!== '__default__' ) {
810 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
812 return PVE
. Utils
. defaultText
;
815 format_boolean : function ( value
) {
816 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
819 format_neg_boolean : function ( value
) {
820 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
823 format_enabled_toggle : function ( value
) {
824 return value
? PVE
. Utils
. enabledText
: PVE
. Utils
. disabledText
;
827 format_ha : function ( value
) {
828 var text
= PVE
. Utils
. format_boolean ( value
. managed
);
831 text
+= ', ' + PVE
. Utils
. stateText
+ ': ' ;
832 text
+= value
. state
|| PVE
. Utils
. noneText
;
834 text
+= ', ' + PVE
. Utils
. groupText
+ ': ' ;
835 text
+= value
. group
|| PVE
. Utils
. noneText
;
841 format_content_types : function ( value
) {
844 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
845 if ( ct
=== 'images' ) {
846 cta
. push ( PVE
. Utils
. imagesText
);
847 } else if ( ct
=== 'backup' ) {
848 cta
. push ( PVE
. Utils
. backupFileText
);
849 } else if ( ct
=== 'vztmpl' ) {
850 cta
. push ( PVE
. Utils
. vztmplText
);
851 } else if ( ct
=== 'iso' ) {
852 cta
. push ( PVE
. Utils
. isoImageText
);
853 } else if ( ct
=== 'rootdir' ) {
854 cta
. push ( PVE
. Utils
. containersText
);
858 return cta
. join ( ', ' );
861 render_storage_content : function ( value
, metaData
, record
) {
862 var data
= record
. data
;
863 if ( Ext
. isNumber ( data
. channel
) &&
864 Ext
. isNumber ( data
. id
) &&
865 Ext
. isNumber ( data
. lun
)) {
867 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
868 " ID " + data
. id
+ " LUN " + data
. lun
;
870 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
873 render_serverity : function ( value
) {
874 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
877 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
879 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
883 var maxcpu
= record
. data
. maxcpu
|| 1 ;
885 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
889 var per
= value
* 100 ;
891 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
894 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
895 /*jslint confusion: true */
897 if (! Ext
. isNumeric ( value
)) {
901 return PVE
. Utils
. format_size ( value
);
904 render_bandwidth : function ( value
) {
905 if (! Ext
. isNumeric ( value
)) {
909 return PVE
. Utils
. format_size ( value
) + '/s' ;
912 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
913 var servertime
= new Date ( value
* 1000 );
914 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
917 render_timestamp_human_readable : function ( value
) {
918 return Ext
. Date
. format ( new Date ( value
* 1000 ), 'l d F Y H:i:s' );
921 calculate_mem_usage : function ( data
) {
922 if (! Ext
. isNumeric ( data
. mem
) ||
928 return ( data
. mem
/ data
. maxmem
);
931 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
932 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
936 // we got no percentage but bytes
938 var maxmem
= record
. data
. maxmem
;
939 if (! record
. data
. uptime
||
941 ! Ext
. isNumeric ( mem
)) {
945 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
947 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
950 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
953 var maxmem
= record
. data
. maxmem
;
955 if (! record
. data
. uptime
) {
959 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
963 return PVE
. Utils
. render_size ( value
);
966 calculate_disk_usage : function ( data
) {
968 if (! Ext
. isNumeric ( data
. disk
) ||
969 data
. type
=== 'qemu' ||
970 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
971 data
. maxdisk
=== 0 ) {
975 return ( data
. disk
/ data
. maxdisk
);
978 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
979 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
983 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
986 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
989 var maxdisk
= record
. data
. maxdisk
;
990 var type
= record
. data
. type
;
992 if (! Ext
. isNumeric ( disk
) ||
995 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
999 return PVE
. Utils
. render_size ( value
);
1002 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1008 case 'lxc' : icon
= 'cube' ;
1009 gridcls
= '-stopped' ;
1011 case 'qemu' : icon
= 'desktop' ;
1012 gridcls
= '-stopped' ;
1014 case 'node' : icon
= 'building' ;
1015 gridcls
= '-offline' ;
1017 case 'storage' : icon
= 'database' ; break ;
1018 case 'pool' : icon
= 'tags' ; break ;
1019 default : icon
= 'file' ;
1022 if ( value
=== 'lxc' || value
=== 'qemu' ) {
1023 if ( record
. data
. running
&& record
. data
. status
!== 'paused' ) {
1024 gridcls
= '-running' ;
1025 } else if ( record
. data
. running
) {
1026 gridcls
= '-paused' ;
1028 if ( record
. data
. template
) {
1030 gridcls
= '-template-' + value
;
1032 } else if ( value
=== 'node' ) {
1033 if ( record
. data
. running
) {
1034 gridcls
= '-online' ;
1038 // overwrite anything else
1039 if ( record
. data
. hastate
=== 'error' ) {
1040 gridcls
= '-offline' ;
1043 var fa
= '<i class="fa fa-fw x-fa-grid' + gridcls
+ ' fa-' + icon
+ '"></i> ' ;
1047 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1051 if ( uptime
=== undefined ) {
1059 return PVE
. Utils
. format_duration_long ( uptime
);
1062 render_support_level : function ( value
, metaData
, record
) {
1063 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
1066 render_upid : function ( value
, metaData
, record
) {
1067 var type
= record
. data
. type
;
1068 var id
= record
. data
. id
;
1070 return PVE
. Utils
. format_task_description ( type
, id
);
1073 /* render functions for new status panel */
1075 render_usage : function ( val
) {
1076 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
1079 render_cpu_usage : function ( val
, max
) {
1080 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
1081 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
1084 render_size_usage : function ( val
, max
) {
1086 return gettext ( 'N/A' );
1088 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
1089 Ext
. String
. format ( gettext ( '{0} of {1}' ),
1090 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
1093 /* this is different for nodes */
1094 render_node_cpu_usage : function ( value
, record
) {
1095 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
1098 /* this is different for nodes */
1099 render_node_size_usage : function ( record
) {
1100 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
1103 dialog_title : function ( subject
, create
, isAdd
) {
1106 return gettext ( 'Add' ) + ': ' + subject
;
1108 return gettext ( 'Create' ) + ': ' + subject
;
1111 return gettext ( 'Edit' ) + ': ' + subject
;
1115 windowHostname : function () {
1116 return window
. location
. hostname
. replace ( PVE
. Utils
. IP6_bracket_match
,
1117 function ( m
, addr
, offset
, original
) { return addr
; });
1120 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
1121 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
1122 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
1125 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
1126 // kvm, lxc, shell, upgrade
1128 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
1129 throw "missing vmid" ;
1133 throw "no nodename specified" ;
1136 if ( viewer
=== 'html5' ) {
1137 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
1138 } else if ( viewer
=== 'vv' ) {
1140 var params
= { proxy
: PVE
. Utils
. windowHostname () };
1141 if ( vmtype
=== 'kvm' ) {
1142 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1143 PVE
. Utils
. openSpiceViewer ( url
, params
);
1144 } else if ( vmtype
=== 'lxc' ) {
1145 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1146 PVE
. Utils
. openSpiceViewer ( url
, params
);
1147 } else if ( vmtype
=== 'shell' ) {
1148 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1149 PVE
. Utils
. openSpiceViewer ( url
, params
);
1150 } else if ( vmtype
=== 'upgrade' ) {
1151 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1153 PVE
. Utils
. openSpiceViewer ( url
, params
);
1156 throw "unknown viewer type" ;
1160 defaultViewer : function ( allowSpice
) {
1161 var vncdefault
= 'html5' ;
1162 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
1163 if ( dv
=== 'vv' && ! allowSpice
) {
1170 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
1171 var url
= Ext
. urlEncode ({
1172 console
: vmtype
, // kvm, lxc, upgrade or shell
1178 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1182 openSpiceViewer : function ( url
, params
){
1184 var downloadWithName = function ( uri
, name
) {
1185 var link
= Ext
. DomHelper
. append ( document
. body
, {
1188 css
: 'display:none;visibility:hidden;height:0px;'
1191 // Note: we need to tell android the correct file name extension
1192 // but we do not set 'download' tag for other environments, because
1193 // It can have strange side effects (additional user prompt on firefox)
1194 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1196 link
. download
= name
;
1199 if ( link
. fireEvent
) {
1200 link
. fireEvent ( 'onclick' );
1202 var evt
= document
. createEvent ( "MouseEvents" );
1203 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1204 link
. dispatchEvent ( evt
);
1208 PVE
. Utils
. API2Request ({
1212 failure : function ( response
, opts
){
1213 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1215 success : function ( response
, opts
){
1216 var raw
= "[virt-viewer] \n " ;
1217 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1218 raw
+= k
+ "=" + v
+ " \n " ;
1220 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1221 encodeURIComponent ( raw
);
1223 downloadWithName ( url
, "pve-spice.vv" );
1228 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1229 // use el.mask() instead
1230 setErrorMask : function ( comp
, msg
) {
1239 el
. mask ( gettext ( "Loading..." ));
1246 monStoreErrors : function ( me
, store
) {
1247 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1248 if (! me
. loadCount
) {
1249 me
. loadCount
= 0 ; // make sure it is numeric
1250 PVE
. Utils
. setErrorMask ( me
, true );
1254 // only works with 'pve' proxy
1255 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1259 PVE
. Utils
. setErrorMask ( me
, false );
1264 /*jslint nomen: true */
1265 var operation
= request
. _operation
;
1266 var error
= operation
. getError ();
1267 if ( error
. statusText
) {
1268 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1270 msg
= gettext ( 'Connection error' );
1272 PVE
. Utils
. setErrorMask ( me
, msg
);
1276 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1278 var nodename
= record
. data
. node
;
1279 var vmid
= record
. data
. vmid
;
1280 var vmname
= record
. data
. name
;
1281 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1282 PVE
. Utils
. API2Request ({
1283 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1284 failure : function ( response
, opts
) {
1285 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1287 success : function ( response
, opts
) {
1288 var allowSpice
= response
. result
. data
. spice
;
1289 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
1292 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1293 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1297 // test automation helper
1298 call_menu_handler : function ( menu
, text
) {
1300 var list
= menu
. query ( 'menuitem' );
1302 Ext
. Array
. each ( list
, function ( item
) {
1303 if ( item
. text
=== text
) {
1314 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1316 if (!( v
instanceof Ext
. tree
. View
)) {
1321 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1322 menu
= Ext
. create ( 'PVE.qemu.CmdMenu' , {
1325 } else if ( record
. data
. type
=== 'qemu' && record
. data
. template
) {
1326 menu
= Ext
. create ( 'PVE.qemu.TemplateMenu' , {
1329 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1330 menu
= Ext
. create ( 'PVE.lxc.CmdMenu' , {
1333 } else if ( record
. data
. type
=== 'lxc' && record
. data
. template
) {
1334 /* since clone does not work reliably, disable for now
1335 menu = Ext.create('PVE.lxc.TemplateMenu', {
1341 } else if ( record
. data
. type
=== 'node' ){
1342 menu
= Ext
. create ( 'PVE.node.CmdMenu' , {
1343 nodename
: record
. data
. node
1350 menu
. showAt ( event
. getXY ());
1353 // helper for deleting field which are set to there default values
1354 delete_if_default : function ( values
, fieldname
, default_val
, create
) {
1355 if ( values
[ fieldname
] === '' || values
[ fieldname
] === default_val
) {
1357 if ( values
[ 'delete' ]) {
1358 values
[ 'delete' ] += ',' + fieldname
;
1360 values
[ 'delete' ] = fieldname
;
1364 delete values
[ fieldname
];
1369 constructor : function () {
1371 Ext
. apply ( me
, me
. utilities
);
1373 var IPV4_OCTET
= "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])" ;
1374 var IPV4_REGEXP
= "(?:(?:" + IPV4_OCTET
+ " \\ .){3}" + IPV4_OCTET
+ ")" ;
1375 var IPV6_H16
= "(?:[0-9a-fA-F]{1,4})" ;
1376 var IPV6_LS32
= "(?:(?:" + IPV6_H16
+ ":" + IPV6_H16
+ ")|" + IPV4_REGEXP
+ ")" ;
1379 me
. IP4_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")$" );
1380 me
. IP4_cidr_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")\/([0-9]{1,2})$" );
1382 var IPV6_REGEXP
= "(?:" +
1383 "(?:(?:" + "(?:" + IPV6_H16
+ ":){6})" + IPV6_LS32
+ ")|" +
1384 "(?:(?:" + "::" + "(?:" + IPV6_H16
+ ":){5})" + IPV6_LS32
+ ")|" +
1385 "(?:(?:(?:" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){4})" + IPV6_LS32
+ ")|" +
1386 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,1}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){3})" + IPV6_LS32
+ ")|" +
1387 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,2}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){2})" + IPV6_LS32
+ ")|" +
1388 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,3}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){1})" + IPV6_LS32
+ ")|" +
1389 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,4}" + IPV6_H16
+ ")?::" + ")" + IPV6_LS32
+ ")|" +
1390 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,5}" + IPV6_H16
+ ")?::" + ")" + IPV6_H16
+ ")|" +
1391 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,7}" + IPV6_H16
+ ")?::" + ")" + ")" +
1394 me
. IP6_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")$" );
1395 me
. IP6_cidr_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")\/([0-9]{1,3})$" );
1396 me
. IP6_bracket_match
= new RegExp ( "^ \\ [(" + IPV6_REGEXP
+ ") \\ ]" );
1398 me
. IP64_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ ")$" );
1400 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])?))" ;
1401 me
. DnsName_match
= new RegExp ( "^" + DnsName_REGEXP
+ "$" );
1403 me
. HostPort_match
= new RegExp ( "^(" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ")(: \\ d+)?$" );
1404 me
. HostPortBrackets_match
= new RegExp ( "^ \\ [(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ") \\ ](: \\ d+)?$" );
1405 me
. IP6_dotnotation_match
= new RegExp ( "^" + IPV6_REGEXP
+ "( \\ . \\ d+)?$" );