]>
git.proxmox.com Git - pve-manager.git/blob - www/manager/Utils.js
3 // avoid errors when running without development tools
4 if (! Ext
. isDefined ( Ext
. global
. console
)) {
10 console
. log ( "Starting PVE Manager" );
12 Ext
. Ajax
. defaultHeaders
= {
13 'Accept' : 'application/json'
16 Ext
. Ajax
. on ( 'beforerequest' , function ( conn
, options
) {
17 if ( PVE
. CSRFPreventionToken
) {
18 if (! options
. headers
) {
21 options
. headers
. CSRFPreventionToken
= PVE
. CSRFPreventionToken
;
25 var IPV4_OCTET
= "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])" ;
26 var IPV4_REGEXP
= "(?:(?:" + IPV4_OCTET
+ " \\ .){3}" + IPV4_OCTET
+ ")" ;
27 var IPV6_H16
= "(?:[0-9a-fA-F]{1,4})" ;
28 var IPV6_LS32
= "(?:(?:" + IPV6_H16
+ ":" + IPV6_H16
+ ")|" + IPV4_REGEXP
+ ")" ;
30 var IP4_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")$" );
31 var IP4_cidr_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")\/[1-3][0-9]?$" );
33 var IPV6_REGEXP
= "(?:" +
34 "(?:(?:" + "(?:" + IPV6_H16
+ ":){6})" + IPV6_LS32
+ ")|" +
35 "(?:(?:" + "::" + "(?:" + IPV6_H16
+ ":){5})" + IPV6_LS32
+ ")|" +
36 "(?:(?:(?:" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){4})" + IPV6_LS32
+ ")|" +
37 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,1}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){3})" + IPV6_LS32
+ ")|" +
38 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,2}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){2})" + IPV6_LS32
+ ")|" +
39 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,3}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){1})" + IPV6_LS32
+ ")|" +
40 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,4}" + IPV6_H16
+ ")?::" + ")" + IPV6_LS32
+ ")|" +
41 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,5}" + IPV6_H16
+ ")?::" + ")" + IPV6_H16
+ ")|" +
42 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,7}" + IPV6_H16
+ ")?::" + ")" + ")" +
45 var IP6_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")$" );
46 var IP6_cidr_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")\/[0-9]{1,3}?$" );
47 var IP6_bracket_match
= new RegExp ( "^ \\ [(" + IPV6_REGEXP
+ ") \\ ]" );
49 var IP64_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ ")$" );
51 Ext
. define ( 'PVE.Utils' , { statics
: {
53 // this class only contains static functions
55 toolkit
: undefined , // (extjs|touch), set inside Toolkit.js
69 'c' : gettext ( 'Community' ),
70 'b' : gettext ( 'Basic' ),
71 's' : gettext ( 'Standard' ),
72 'p' : gettext ( 'Premium' )
75 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.' ,
78 other
: gettext ( 'Other OS types' ),
79 wxp
: 'Microsoft Windows XP/2003' ,
80 w2k
: 'Microsoft Windows 2000' ,
81 w2k8
: 'Microsoft Windows Vista/2008' ,
82 win7
: 'Microsoft Windows 7/2008r2' ,
83 win8
: 'Microsoft Windows 8/2012' ,
84 l24
: 'Linux 2.4 Kernel' ,
85 l26
: 'Linux 3.X/2.6 Kernel' ,
86 solaris
: 'Solaris Kernel'
89 render_kvm_ostype : function ( value
) {
91 return gettext ( 'Other OS types' );
93 var text
= PVE
. Utils
. kvm_ostypes
[ value
];
95 return text
+ ' (' + value
+ ')' ;
100 render_hotplug_features : function ( value
) {
103 if (! value
|| ( value
=== '0' )) {
104 return gettext ( 'disabled' );
107 Ext
. each ( value
. split ( ',' ), function ( el
) {
109 fa
. push ( gettext ( 'Disk' ));
110 } else if ( el
=== 'network' ) {
111 fa
. push ( gettext ( 'Network' ));
112 } else if ( el
=== 'usb' ) {
113 fa
. push ( gettext ( 'USB' ));
114 } else if ( el
=== 'memory' ) {
115 fa
. push ( gettext ( 'Memory' ));
116 } else if ( el
=== 'cpu' ) {
117 fa
. push ( gettext ( 'CPU' ));
123 return fa
. join ( ', ' );
126 network_iface_types
: {
127 eth
: gettext ( "Network Device" ),
128 bridge
: 'Linux Bridge' ,
130 vlan
: 'Linux Vlan interface' ,
131 OVSBridge
: 'OVS Bridge' ,
134 OVSIntPort
: 'OVS IntPort'
137 render_network_iface_type : function ( value
) {
138 return PVE
. Utils
. network_iface_types
[ value
] ||
139 PVE
. Utils
. unknownText
;
142 render_scsihw : function ( value
) {
144 return PVE
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
145 } else if ( value
=== 'lsi' ) {
146 return 'LSI 53C895A' ;
147 } else if ( value
=== 'lsi53c810' ) {
149 } else if ( value
=== 'megasas' ) {
150 return 'MegaRAID SAS 8708EM2' ;
151 } else if ( value
=== 'virtio-scsi-pci' ) {
153 } else if ( value
=== 'virtio-scsi-single' ) {
154 return 'VIRTIO single' ;
155 } else if ( value
=== 'pvscsi' ) {
156 return 'VMware PVSCSI' ;
162 // fixme: auto-generate this
163 // for now, please keep in sync with PVE::Tools::kvmkeymaps
168 'de-ch' : 'German (Swiss)' ,
169 'en-gb' : 'English (UK)' ,
170 'en-us' : 'English (USA)' ,
174 //fo: 'Faroe Islands',
176 'fr-be' : 'French (Belgium)' ,
177 'fr-ca' : 'French (Canada)' ,
178 'fr-ch' : 'French (Swiss)' ,
188 //'nl-be': 'Dutch (Belgium)',
192 'pt-br' : 'Portuguese (Brazil)' ,
201 std
: gettext ( 'Standard VGA' ),
202 vmware
: gettext ( 'VMWare compatible' ),
203 cirrus
: 'Cirrus Logic GD5446' ,
205 qxl2
: 'SPICE dual monitor' ,
206 qxl3
: 'SPICE three monitors' ,
207 qxl4
: 'SPICE four monitors' ,
208 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
209 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
210 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
211 serial3
: gettext ( 'Serial terminal' ) + ' 3'
214 render_kvm_language : function ( value
) {
216 return PVE
. Utils
. defaultText
;
218 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
220 return text
+ ' (' + value
+ ')' ;
225 kvm_keymap_array : function () {
226 var data
= [[ '' , PVE
. Utils
. render_kvm_language ( '' )]];
227 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
228 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
234 render_console_viewer : function ( value
) {
236 return PVE
. Utils
. defaultText
+ ' (HTML5)' ;
237 } else if ( value
=== 'vv' ) {
238 return 'SPICE (remote-viewer)' ;
239 } else if ( value
=== 'applet' || value
=== 'html5' ) {
240 return 'HTML5 (noVNC)' ;
251 eu
: 'Euskera (Basque)' ,
256 nb
: 'Norwegian (Bokmal)' ,
257 nn
: 'Norwegian (Nynorsk)' ,
258 fa
: 'Persian (Farsi)' ,
260 pt_BR
: 'Portuguese (Brazil)' ,
268 render_language : function ( value
) {
270 return PVE
. Utils
. defaultText
+ ' (English)' ;
272 var text
= PVE
. Utils
. language_map
[ value
];
274 return text
+ ' (' + value
+ ')' ;
279 language_array : function () {
280 var data
= [[ '' , PVE
. Utils
. render_language ( '' )]];
281 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
282 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
288 render_kvm_vga_driver : function ( value
) {
290 return PVE
. Utils
. defaultText
;
292 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
294 return text
+ ' (' + value
+ ')' ;
299 kvm_vga_driver_array : function () {
300 var data
= [[ '' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
301 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
302 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
308 render_kvm_startup : function ( value
) {
309 var startup
= PVE
. Parser
. parseStartup ( value
);
312 if ( startup
. order
=== undefined ) {
315 res
+= startup
. order
;
317 if ( startup
. up
!== undefined ) {
318 res
+= ',up=' + startup
. up
;
320 if ( startup
. down
!== undefined ) {
321 res
+= ',down=' + startup
. down
;
328 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
331 authClear : function () {
332 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
335 // fixme: remove - not needed?
336 gridLineHeigh : function () {
344 extractRequestError : function ( result
, verbose
) {
345 var msg
= gettext ( 'Successful' );
347 if (! result
. success
) {
348 msg
= gettext ( "Unknown error" );
349 if ( result
. message
) {
350 msg
= result
. message
;
352 msg
+= ' (' + result
. status
+ ')' ;
355 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
357 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
358 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
359 Ext
. htmlEncode ( desc
);
367 extractFormActionError : function ( action
) {
369 switch ( action
. failureType
) {
370 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
371 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
373 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
374 msg
= gettext ( 'Connection error' );
375 var resp
= action
. response
;
376 if ( resp
. status
&& resp
. statusText
) {
377 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
380 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
381 case Ext
. form
. action
. Action
. SERVER_INVALID
:
382 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
389 API2Request : function ( reqOpts
) {
391 var newopts
= Ext
. apply ({
392 waitMsg
: gettext ( 'Please wait...' )
395 if (! newopts
. url
. match ( /^\/api2/ )) {
396 newopts
. url
= '/api2/extjs' + newopts
. url
;
398 delete newopts
. callback
;
400 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
402 success : function ( response
, options
) {
403 if ( options
. waitMsgTarget
) {
404 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
405 options
. waitMsgTarget
. setMasked ( false );
407 options
. waitMsgTarget
. setLoading ( false );
410 var result
= Ext
. decode ( response
. responseText
);
411 response
. result
= result
;
412 if (! result
. success
) {
413 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
414 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
415 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
418 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
419 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
421 failure : function ( response
, options
) {
422 if ( options
. waitMsgTarget
) {
423 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
424 options
. waitMsgTarget
. setMasked ( false );
426 options
. waitMsgTarget
. setLoading ( false );
429 response
. result
= {};
431 response
. result
= Ext
. decode ( response
. responseText
);
433 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
434 if ( response
. aborted
) {
435 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
436 } else if ( response
. timedout
) {
437 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
438 } else if ( response
. status
&& response
. statusText
) {
439 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
441 response
. htmlStatus
= msg
;
442 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
443 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
448 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
450 var target
= newopts
. waitMsgTarget
;
452 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
453 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
} );
455 // Note: ExtJS bug - this does not work when component is not rendered
456 target
. setLoading ( newopts
. waitMsg
);
459 Ext
. Ajax
. request ( newopts
);
462 assemble_field_data : function ( values
, data
) {
463 if ( Ext
. isObject ( data
)) {
464 Ext
. Object
. each ( data
, function ( name
, val
) {
465 if ( values
. hasOwnProperty ( name
)) {
466 var bucket
= values
[ name
];
467 if (! Ext
. isArray ( bucket
)) {
468 bucket
= values
[ name
] = [ bucket
];
470 if ( Ext
. isArray ( val
)) {
471 values
[ name
] = bucket
. concat ( val
);
482 checked_command : function ( orig_cmd
) {
483 PVE
. Utils
. API2Request ({
484 url
: '/nodes/localhost/subscription' ,
487 failure : function ( response
, opts
) {
488 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
490 success : function ( response
, opts
) {
491 var data
= response
. result
. data
;
493 if ( data
. status
!== 'Active' ) {
495 title
: gettext ( 'No valid subscription' ),
496 icon
: Ext
. Msg
. WARNING
,
497 msg
: PVE
. Utils
. noSubKeyHtml
,
499 callback : function ( btn
) {
514 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
515 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
516 vncshell
: [ '' , gettext ( 'Shell' ) ],
517 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
518 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
519 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
520 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
521 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
522 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
523 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
524 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
525 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
526 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
527 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
528 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
529 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
530 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
531 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
532 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
533 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
534 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
535 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
536 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
537 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
538 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
539 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
540 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
541 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
542 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
543 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
544 vzsuspend
: [ 'CT' , gettext ( 'Suspend' ) ],
545 vzresume
: [ 'CT' , gettext ( 'Resume' ) ],
546 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' ) ],
547 vzrollback
: [ 'CT' , gettext ( 'Rollback' ) ],
548 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' ) ],
549 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
550 hastart
: [ 'HA' , gettext ( 'Start' ) ],
551 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
552 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
553 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
554 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
555 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
556 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' ) ],
557 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' ) ],
558 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' ) ],
559 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' ) ],
560 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
561 imgdel
: [ '' , gettext ( 'Erase data' ) ],
562 download
: [ '' , gettext ( 'Download' ) ],
563 vzdump
: [ '' , gettext ( 'Backup' ) ],
564 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
565 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
566 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
567 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
570 format_task_description : function ( type
, id
) {
571 var farray
= PVE
. Utils
. task_desc_table
[ type
];
575 var prefix
= farray
[ 0 ];
576 var text
= farray
[ 1 ];
578 return prefix
+ ' ' + id
+ ' - ' + text
;
583 parse_task_upid : function ( upid
) {
586 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]+):$/ );
588 throw "unable to parse upid '" + upid
+ "'" ;
591 task
. pid
= parseInt ( res
[ 2 ], 16 );
592 task
. pstart
= parseInt ( res
[ 3 ], 16 );
593 task
. starttime
= parseInt ( res
[ 4 ], 16 );
598 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
603 format_size : function ( size
) {
604 /*jslint confusion: true */
610 var kb
= size
/ 1024 ;
613 return kb
. toFixed ( 0 ) + "KB" ;
616 var mb
= size
/ ( 1024 * 1024 );
619 return mb
. toFixed ( 0 ) + "MB" ;
625 return gb
. toFixed ( 2 ) + "GB" ;
630 return tb
. toFixed ( 2 ) + "TB" ;
634 format_html_bar : function ( per
, text
) {
636 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
637 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
642 format_cpu_bar : function ( per1
, per2
, text
) {
644 return "<div class='pve-bar-border'>" +
645 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
646 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
647 "<div class='pve-bar-text'>" + text
+ "</div>" +
651 format_large_bar : function ( per
, text
) {
654 text
= per
. toFixed ( 1 ) + "%" ;
657 return "<div class='pve-largebar-border'>" +
658 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
659 "<div class='pve-largebar-text'>" + text
+ "</div>" +
663 format_duration_long : function ( ut
) {
665 var days
= Math
. floor ( ut
/ 86400 );
667 var hours
= Math
. floor ( ut
/ 3600 );
669 var mins
= Math
. floor ( ut
/ 60 );
672 var hours_str
= '00' + hours
. toString ();
673 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
674 var mins_str
= "00" + mins
. toString ();
675 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
676 var ut_str
= "00" + ut
. toString ();
677 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
680 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
681 return days
. toString () + ' ' + ds
+ ' ' +
682 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
684 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
688 format_duration_short : function ( ut
) {
691 return ut
. toString () + 's' ;
696 return mins
. toFixed ( 0 ) + 'm' ;
700 var hours
= ut
/ 3600 ;
701 return hours
. toFixed ( 0 ) + 'h' ;
704 var days
= ut
/ 86400 ;
705 return days
. toFixed ( 0 ) + 'd' ;
708 yesText
: gettext ( 'Yes' ),
709 noText
: gettext ( 'No' ),
710 noneText
: gettext ( 'none' ),
711 errorText
: gettext ( 'Error' ),
712 unknownText
: gettext ( 'Unknown' ),
713 defaultText
: gettext ( 'Default' ),
714 daysText
: gettext ( 'days' ),
715 dayText
: gettext ( 'day' ),
716 runningText
: gettext ( 'running' ),
717 stoppedText
: gettext ( 'stopped' ),
718 neverText
: gettext ( 'never' ),
719 totalText
: gettext ( 'Total' ),
720 usedText
: gettext ( 'Used' ),
721 directoryText
: gettext ( 'Directory' ),
722 imagesText
: gettext ( 'Disk image' ),
723 backupFileText
: gettext ( 'VZDump backup file' ),
724 vztmplText
: gettext ( 'Container template' ),
725 isoImageText
: gettext ( 'ISO image' ),
726 containersText
: gettext ( 'Container' ),
728 format_expire : function ( date
) {
730 return PVE
. Utils
. neverText
;
732 return Ext
. Date
. format ( date
, "Y-m-d" );
735 format_storage_type : function ( value
) {
736 if ( value
=== 'dir' ) {
737 return PVE
. Utils
. directoryText
;
738 } else if ( value
=== 'nfs' ) {
740 } else if ( value
=== 'glusterfs' ) {
742 } else if ( value
=== 'lvm' ) {
744 } else if ( value
=== 'iscsi' ) {
746 } else if ( value
=== 'rbd' ) {
748 } else if ( value
=== 'sheepdog' ) {
750 } else if ( value
=== 'zfs' ) {
751 return 'ZFS over iSCSI' ;
752 } else if ( value
=== 'zfspool' ) {
754 } else if ( value
=== 'iscsidirect' ) {
755 return 'iSCSIDirect' ;
757 return PVE
. Utils
. unknownText
;
761 format_boolean_with_default : function ( value
) {
762 if ( Ext
. isDefined ( value
) && value
!== '' ) {
763 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
765 return PVE
. Utils
. defaultText
;
768 format_boolean : function ( value
) {
769 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
772 format_neg_boolean : function ( value
) {
773 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
776 format_content_types : function ( value
) {
779 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
780 if ( ct
=== 'images' ) {
781 cta
. push ( PVE
. Utils
. imagesText
);
782 } else if ( ct
=== 'backup' ) {
783 cta
. push ( PVE
. Utils
. backupFileText
);
784 } else if ( ct
=== 'vztmpl' ) {
785 cta
. push ( PVE
. Utils
. vztmplText
);
786 } else if ( ct
=== 'iso' ) {
787 cta
. push ( PVE
. Utils
. isoImageText
);
788 } else if ( ct
=== 'rootdir' ) {
789 cta
. push ( PVE
. Utils
. containersText
);
793 return cta
. join ( ', ' );
796 render_storage_content : function ( value
, metaData
, record
) {
797 var data
= record
. data
;
798 if ( Ext
. isNumber ( data
. channel
) &&
799 Ext
. isNumber ( data
. id
) &&
800 Ext
. isNumber ( data
. lun
)) {
802 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
803 " ID " + data
. id
+ " LUN " + data
. lun
;
805 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
808 render_serverity : function ( value
) {
809 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
812 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
814 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
818 var maxcpu
= record
. data
. maxcpu
|| 1 ;
820 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
824 var per
= value
* 100 ;
826 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
829 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
830 /*jslint confusion: true */
832 if (! Ext
. isNumeric ( value
)) {
836 return PVE
. Utils
. format_size ( value
);
839 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
840 var servertime
= new Date ( value
* 1000 );
841 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
844 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
847 var maxmem
= record
. data
. maxmem
;
849 if (! record
. data
. uptime
) {
853 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
857 var per
= ( mem
* 100 ) / maxmem
;
859 return per
. toFixed ( 1 ) + '%' ;
862 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
865 var maxdisk
= record
. data
. maxdisk
;
867 if (!( Ext
. isNumeric ( disk
) && maxdisk
)) {
871 var per
= ( disk
* 100 ) / maxdisk
;
873 return per
. toFixed ( 1 ) + '%' ;
876 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
878 var cls
= 'pve-itype-icon-' + value
;
880 if ( record
. data
. running
) {
881 metaData
. tdCls
= cls
+ "-running" ;
882 } else if ( record
. data
. template
) {
883 metaData
. tdCls
= cls
+ "-template" ;
885 metaData
. tdCls
= cls
;
891 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
895 if ( uptime
=== undefined ) {
903 return PVE
. Utils
. format_duration_long ( uptime
);
906 render_support_level : function ( value
, metaData
, record
) {
907 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
910 render_upid : function ( value
, metaData
, record
) {
911 var type
= record
. data
. type
;
912 var id
= record
. data
. id
;
914 return PVE
. Utils
. format_task_description ( type
, id
);
917 dialog_title : function ( subject
, create
, isAdd
) {
920 return gettext ( 'Add' ) + ': ' + subject
;
922 return gettext ( 'Create' ) + ': ' + subject
;
925 return gettext ( 'Edit' ) + ': ' + subject
;
929 windowHostname : function () {
930 return window
. location
. hostname
. replace ( IP6_bracket_match
,
931 function ( m
, addr
, offset
, original
) { return addr
; });
934 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
935 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
936 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
939 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
940 // kvm, lxc, shell, upgrade
942 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
943 throw "missing vmid" ;
947 throw "no nodename specified" ;
950 if ( viewer
=== 'applet' || viewer
=== 'html5' ) {
951 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, true );
952 } else if ( viewer
=== 'vv' ) {
954 var params
= { proxy
: PVE
. Utils
. windowHostname () };
955 if ( vmtype
=== 'kvm' ) {
956 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
957 PVE
. Utils
. openSpiceViewer ( url
, params
);
958 } else if ( vmtype
=== 'lxc' ) {
959 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
960 PVE
. Utils
. openSpiceViewer ( url
, params
);
961 } else if ( vmtype
=== 'shell' ) {
962 url
= '/nodes/' + nodename
+ '/spiceshell' ;
963 PVE
. Utils
. openSpiceViewer ( url
, params
);
964 } else if ( vmtype
=== 'upgrade' ) {
965 url
= '/nodes/' + nodename
+ '/spiceshell' ;
967 PVE
. Utils
. openSpiceViewer ( url
, params
);
970 throw "unknown viewer type" ;
974 defaultViewer : function ( allowSpice
) {
975 var vncdefault
= 'html5' ;
976 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
977 if ( dv
=== 'vv' && ! allowSpice
) {
984 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, novnc
) {
985 var url
= Ext
. urlEncode ({
986 console
: vmtype
, // kvm, lxc, upgrade or shell
987 novnc
: novnc
? 1 : 0 ,
992 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
996 openSpiceViewer : function ( url
, params
){
998 var downloadWithName = function ( uri
, name
) {
999 var link
= Ext
. DomHelper
. append ( document
. body
, {
1002 css
: 'display:none;visibility:hidden;height:0px;'
1005 // Note: we need to tell android the correct file name extension
1006 // but we do not set 'download' tag for other environments, because
1007 // It can have strange side effects (additional user prompt on firefox)
1008 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1010 link
. download
= name
;
1013 if ( link
. fireEvent
) {
1014 link
. fireEvent ( 'onclick' );
1016 var evt
= document
. createEvent ( "MouseEvents" );
1017 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1018 link
. dispatchEvent ( evt
);
1022 PVE
. Utils
. API2Request ({
1026 failure : function ( response
, opts
){
1027 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1029 success : function ( response
, opts
){
1030 var raw
= "[virt-viewer] \n " ;
1031 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1032 raw
+= k
+ "=" + v
+ " \n " ;
1034 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1035 encodeURIComponent ( raw
);
1037 downloadWithName ( url
, "pve-spice.vv" );
1042 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1043 // use el.mask() instead
1044 setErrorMask : function ( comp
, msg
) {
1053 el
. mask ( gettext ( "Loading..." ));
1060 monStoreErrors : function ( me
, store
) {
1061 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1062 if (! me
. loadCount
) {
1063 me
. loadCount
= 0 ; // make sure it is numeric
1064 PVE
. Utils
. setErrorMask ( me
, true );
1068 // only works with 'pve' proxy
1069 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1073 PVE
. Utils
. setErrorMask ( me
, false );
1078 var operation
= request
. operation
;
1079 var error
= operation
. getError ();
1080 if ( error
. statusText
) {
1081 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1083 msg
= gettext ( 'Connection error' );
1085 PVE
. Utils
. setErrorMask ( me
, msg
);