]>
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 OVSBridge
: 'OVS Bridge' ,
133 OVSIntPort
: 'OVS IntPort'
136 render_network_iface_type : function ( value
) {
137 return PVE
. Utils
. network_iface_types
[ value
] ||
138 PVE
. Utils
. unknownText
;
141 render_scsihw : function ( value
) {
143 return PVE
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
144 } else if ( value
=== 'lsi' ) {
145 return 'LSI 53C895A' ;
146 } else if ( value
=== 'lsi53c810' ) {
148 } else if ( value
=== 'megasas' ) {
149 return 'MegaRAID SAS 8708EM2' ;
150 } else if ( value
=== 'virtio-scsi-pci' ) {
152 } else if ( value
=== 'pvscsi' ) {
153 return 'VMware PVSCSI' ;
159 // fixme: auto-generate this
160 // for now, please keep in sync with PVE::Tools::kvmkeymaps
165 'de-ch' : 'German (Swiss)' ,
166 'en-gb' : 'English (UK)' ,
167 'en-us' : 'English (USA' ,
171 //fo: 'Faroe Islands',
173 'fr-be' : 'French (Belgium)' ,
174 'fr-ca' : 'French (Canada)' ,
175 'fr-ch' : 'French (Swiss)' ,
185 //'nl-be': 'Dutch (Belgium)',
189 'pt-br' : 'Portuguese (Brazil)' ,
198 std
: gettext ( 'Standard VGA' ),
199 vmware
: gettext ( 'VMWare compatible' ),
200 cirrus
: 'Cirrus Logic GD5446' ,
202 qxl2
: 'SPICE dual monitor' ,
203 qxl3
: 'SPICE three monitors' ,
204 qxl4
: 'SPICE four monitors' ,
205 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
206 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
207 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
208 serial3
: gettext ( 'Serial terminal' ) + ' 3'
211 render_kvm_language : function ( value
) {
213 return PVE
. Utils
. defaultText
;
215 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
217 return text
+ ' (' + value
+ ')' ;
222 kvm_keymap_array : function () {
223 var data
= [[ '' , PVE
. Utils
. render_kvm_language ( '' )]];
224 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
225 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
231 render_console_viewer : function ( value
) {
233 return PVE
. Utils
. defaultText
+ ' (HTML5)' ;
234 } else if ( value
=== 'applet' ) {
235 return 'Java VNC Applet' ;
236 } else if ( value
=== 'vv' ) {
237 return 'SPICE (remote-viewer)' ;
238 } else if ( value
=== 'html5' ) {
239 return 'HTML5 (noVNC)' ;
250 eu
: 'Euskera (Basque)' ,
255 nb
: 'Norwegian (Bokmal)' ,
256 nn
: 'Norwegian (Nynorsk)' ,
257 fa
: 'Persian (Farsi)' ,
259 pt_BR
: 'Portuguese (Brazil)' ,
267 render_language : function ( value
) {
269 return PVE
. Utils
. defaultText
+ ' (English)' ;
271 var text
= PVE
. Utils
. language_map
[ value
];
273 return text
+ ' (' + value
+ ')' ;
278 language_array : function () {
279 var data
= [[ '' , PVE
. Utils
. render_language ( '' )]];
280 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
281 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
287 render_kvm_vga_driver : function ( value
) {
289 return PVE
. Utils
. defaultText
;
291 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
293 return text
+ ' (' + value
+ ')' ;
298 kvm_vga_driver_array : function () {
299 var data
= [[ '' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
300 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
301 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
307 render_kvm_startup : function ( value
) {
308 var startup
= PVE
. Parser
. parseStartup ( value
);
311 if ( startup
. order
=== undefined ) {
314 res
+= startup
. order
;
316 if ( startup
. up
!== undefined ) {
317 res
+= ',up=' + startup
. up
;
319 if ( startup
. down
!== undefined ) {
320 res
+= ',down=' + startup
. down
;
327 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
330 authClear : function () {
331 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
334 // fixme: remove - not needed?
335 gridLineHeigh : function () {
343 extractRequestError : function ( result
, verbose
) {
344 var msg
= gettext ( 'Successful' );
346 if (! result
. success
) {
347 msg
= gettext ( "Unknown error" );
348 if ( result
. message
) {
349 msg
= result
. message
;
351 msg
+= ' (' + result
. status
+ ')' ;
354 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
356 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
357 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
358 Ext
. htmlEncode ( desc
);
366 extractFormActionError : function ( action
) {
368 switch ( action
. failureType
) {
369 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
370 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
372 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
373 msg
= gettext ( 'Connection error' );
374 var resp
= action
. response
;
375 if ( resp
. status
&& resp
. statusText
) {
376 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
379 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
380 case Ext
. form
. action
. Action
. SERVER_INVALID
:
381 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
388 API2Request : function ( reqOpts
) {
390 var newopts
= Ext
. apply ({
391 waitMsg
: gettext ( 'Please wait...' )
394 if (! newopts
. url
. match ( /^\/api2/ )) {
395 newopts
. url
= '/api2/extjs' + newopts
. url
;
397 delete newopts
. callback
;
399 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
401 success : function ( response
, options
) {
402 if ( options
. waitMsgTarget
) {
403 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
404 options
. waitMsgTarget
. setMasked ( false );
406 options
. waitMsgTarget
. setLoading ( false );
409 var result
= Ext
. decode ( response
. responseText
);
410 response
. result
= result
;
411 if (! result
. success
) {
412 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
413 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
414 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
417 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
418 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
420 failure : function ( response
, options
) {
421 if ( options
. waitMsgTarget
) {
422 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
423 options
. waitMsgTarget
. setMasked ( false );
425 options
. waitMsgTarget
. setLoading ( false );
428 response
. result
= {};
430 response
. result
= Ext
. decode ( response
. responseText
);
432 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
433 if ( response
. aborted
) {
434 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
435 } else if ( response
. timedout
) {
436 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
437 } else if ( response
. status
&& response
. statusText
) {
438 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
440 response
. htmlStatus
= msg
;
441 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
442 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
447 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
449 var target
= newopts
. waitMsgTarget
;
451 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
452 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
} );
454 // Note: ExtJS bug - this does not work when component is not rendered
455 target
. setLoading ( newopts
. waitMsg
);
458 Ext
. Ajax
. request ( newopts
);
461 assemble_field_data : function ( values
, data
) {
462 if ( Ext
. isObject ( data
)) {
463 Ext
. Object
. each ( data
, function ( name
, val
) {
464 if ( values
. hasOwnProperty ( name
)) {
465 var bucket
= values
[ name
];
466 if (! Ext
. isArray ( bucket
)) {
467 bucket
= values
[ name
] = [ bucket
];
469 if ( Ext
. isArray ( val
)) {
470 values
[ name
] = bucket
. concat ( val
);
481 checked_command : function ( orig_cmd
) {
482 PVE
. Utils
. API2Request ({
483 url
: '/nodes/localhost/subscription' ,
486 failure : function ( response
, opts
) {
487 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
489 success : function ( response
, opts
) {
490 var data
= response
. result
. data
;
492 if ( data
. status
!== 'Active' ) {
494 title
: gettext ( 'No valid subscription' ),
495 icon
: Ext
. Msg
. WARNING
,
496 msg
: PVE
. Utils
. noSubKeyHtml
,
498 callback : function ( btn
) {
513 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
514 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
515 vncshell
: [ '' , gettext ( 'Shell' ) ],
516 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
517 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
518 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
519 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
520 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
521 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
522 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
523 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
524 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
525 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
526 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
527 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
528 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
529 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
530 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
531 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
532 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
533 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
534 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
535 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
536 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
537 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
538 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
539 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
540 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
541 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
542 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
543 vzsuspend
: [ 'CT' , gettext ( 'Suspend' ) ],
544 vzresume
: [ 'CT' , gettext ( 'Resume' ) ],
545 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
546 hastart
: [ 'HA' , gettext ( 'Start' ) ],
547 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
548 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
549 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
550 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
551 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
552 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' ) ],
553 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' ) ],
554 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' ) ],
555 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' ) ],
556 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
557 imgdel
: [ '' , gettext ( 'Erase data' ) ],
558 download
: [ '' , gettext ( 'Download' ) ],
559 vzdump
: [ '' , gettext ( 'Backup' ) ],
560 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
561 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
562 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
563 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
566 format_task_description : function ( type
, id
) {
567 var farray
= PVE
. Utils
. task_desc_table
[ type
];
571 var prefix
= farray
[ 0 ];
572 var text
= farray
[ 1 ];
574 return prefix
+ ' ' + id
+ ' - ' + text
;
579 parse_task_upid : function ( upid
) {
582 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]+):$/ );
584 throw "unable to parse upid '" + upid
+ "'" ;
587 task
. pid
= parseInt ( res
[ 2 ], 16 );
588 task
. pstart
= parseInt ( res
[ 3 ], 16 );
589 task
. starttime
= parseInt ( res
[ 4 ], 16 );
594 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
599 format_size : function ( size
) {
600 /*jslint confusion: true */
606 var kb
= size
/ 1024 ;
609 return kb
. toFixed ( 0 ) + "KB" ;
612 var mb
= size
/ ( 1024 * 1024 );
615 return mb
. toFixed ( 0 ) + "MB" ;
621 return gb
. toFixed ( 2 ) + "GB" ;
626 return tb
. toFixed ( 2 ) + "TB" ;
630 format_html_bar : function ( per
, text
) {
632 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
633 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
638 format_cpu_bar : function ( per1
, per2
, text
) {
640 return "<div class='pve-bar-border'>" +
641 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
642 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
643 "<div class='pve-bar-text'>" + text
+ "</div>" +
647 format_large_bar : function ( per
, text
) {
650 text
= per
. toFixed ( 1 ) + "%" ;
653 return "<div class='pve-largebar-border'>" +
654 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
655 "<div class='pve-largebar-text'>" + text
+ "</div>" +
659 format_duration_long : function ( ut
) {
661 var days
= Math
. floor ( ut
/ 86400 );
663 var hours
= Math
. floor ( ut
/ 3600 );
665 var mins
= Math
. floor ( ut
/ 60 );
668 var hours_str
= '00' + hours
. toString ();
669 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
670 var mins_str
= "00" + mins
. toString ();
671 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
672 var ut_str
= "00" + ut
. toString ();
673 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
676 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
677 return days
. toString () + ' ' + ds
+ ' ' +
678 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
680 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
684 format_duration_short : function ( ut
) {
687 return ut
. toString () + 's' ;
692 return mins
. toFixed ( 0 ) + 'm' ;
696 var hours
= ut
/ 3600 ;
697 return hours
. toFixed ( 0 ) + 'h' ;
700 var days
= ut
/ 86400 ;
701 return days
. toFixed ( 0 ) + 'd' ;
704 yesText
: gettext ( 'Yes' ),
705 noText
: gettext ( 'No' ),
706 noneText
: gettext ( 'none' ),
707 errorText
: gettext ( 'Error' ),
708 unknownText
: gettext ( 'Unknown' ),
709 defaultText
: gettext ( 'Default' ),
710 daysText
: gettext ( 'days' ),
711 dayText
: gettext ( 'day' ),
712 runningText
: gettext ( 'running' ),
713 stoppedText
: gettext ( 'stopped' ),
714 neverText
: gettext ( 'never' ),
715 totalText
: gettext ( 'Total' ),
716 usedText
: gettext ( 'Used' ),
717 directoryText
: gettext ( 'Directory' ),
718 imagesText
: gettext ( 'Disk image' ),
719 backupFileText
: gettext ( 'VZDump backup file' ),
720 vztmplText
: gettext ( 'Container template' ),
721 isoImageText
: gettext ( 'ISO image' ),
722 containersText
: gettext ( 'Container' ),
724 format_expire : function ( date
) {
726 return PVE
. Utils
. neverText
;
728 return Ext
. Date
. format ( date
, "Y-m-d" );
731 format_storage_type : function ( value
) {
732 if ( value
=== 'dir' ) {
733 return PVE
. Utils
. directoryText
;
734 } else if ( value
=== 'nfs' ) {
736 } else if ( value
=== 'glusterfs' ) {
738 } else if ( value
=== 'lvm' ) {
740 } else if ( value
=== 'iscsi' ) {
742 } else if ( value
=== 'rbd' ) {
744 } else if ( value
=== 'sheepdog' ) {
746 } else if ( value
=== 'zfs' ) {
747 return 'ZFS over iSCSI' ;
748 } else if ( value
=== 'zfspool' ) {
750 } else if ( value
=== 'iscsidirect' ) {
751 return 'iSCSIDirect' ;
753 return PVE
. Utils
. unknownText
;
757 format_boolean_with_default : function ( value
) {
758 if ( Ext
. isDefined ( value
) && value
!== '' ) {
759 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
761 return PVE
. Utils
. defaultText
;
764 format_boolean : function ( value
) {
765 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
768 format_neg_boolean : function ( value
) {
769 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
772 format_content_types : function ( value
) {
775 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
776 if ( ct
=== 'images' ) {
777 cta
. push ( PVE
. Utils
. imagesText
);
778 } else if ( ct
=== 'backup' ) {
779 cta
. push ( PVE
. Utils
. backupFileText
);
780 } else if ( ct
=== 'vztmpl' ) {
781 cta
. push ( PVE
. Utils
. vztmplText
);
782 } else if ( ct
=== 'iso' ) {
783 cta
. push ( PVE
. Utils
. isoImageText
);
784 } else if ( ct
=== 'rootdir' ) {
785 cta
. push ( PVE
. Utils
. containersText
);
789 return cta
. join ( ', ' );
792 render_storage_content : function ( value
, metaData
, record
) {
793 var data
= record
. data
;
794 if ( Ext
. isNumber ( data
. channel
) &&
795 Ext
. isNumber ( data
. id
) &&
796 Ext
. isNumber ( data
. lun
)) {
798 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
799 " ID " + data
. id
+ " LUN " + data
. lun
;
801 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
804 render_serverity : function ( value
) {
805 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
808 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
810 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
814 var maxcpu
= record
. data
. maxcpu
|| 1 ;
816 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
820 var per
= value
* 100 ;
822 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
825 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
826 /*jslint confusion: true */
828 if (! Ext
. isNumeric ( value
)) {
832 return PVE
. Utils
. format_size ( value
);
835 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
836 var servertime
= new Date ( value
* 1000 );
837 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
840 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
843 var maxmem
= record
. data
. maxmem
;
845 if (! record
. data
. uptime
) {
849 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
853 var per
= ( mem
* 100 ) / maxmem
;
855 return per
. toFixed ( 1 ) + '%' ;
858 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
861 var maxdisk
= record
. data
. maxdisk
;
863 if (!( Ext
. isNumeric ( disk
) && maxdisk
)) {
867 var per
= ( disk
* 100 ) / maxdisk
;
869 return per
. toFixed ( 1 ) + '%' ;
872 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
874 var cls
= 'pve-itype-icon-' + value
;
876 if ( record
. data
. running
) {
877 metaData
. tdCls
= cls
+ "-running" ;
878 } else if ( record
. data
. template
) {
879 metaData
. tdCls
= cls
+ "-template" ;
881 metaData
. tdCls
= cls
;
887 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
891 if ( uptime
=== undefined ) {
899 return PVE
. Utils
. format_duration_long ( uptime
);
902 render_support_level : function ( value
, metaData
, record
) {
903 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
906 render_upid : function ( value
, metaData
, record
) {
907 var type
= record
. data
. type
;
908 var id
= record
. data
. id
;
910 return PVE
. Utils
. format_task_description ( type
, id
);
913 dialog_title : function ( subject
, create
, isAdd
) {
916 return gettext ( 'Add' ) + ': ' + subject
;
918 return gettext ( 'Create' ) + ': ' + subject
;
921 return gettext ( 'Edit' ) + ': ' + subject
;
925 windowHostname : function () {
926 return window
. location
. hostname
. replace ( IP6_bracket_match
,
927 function ( m
, addr
, offset
, original
) { return addr
; });
930 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
931 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
932 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
935 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
936 // kvm, lxc, shell, upgrade
938 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
939 throw "missing vmid" ;
943 throw "no nodename specified" ;
946 if ( viewer
=== 'applet' || viewer
=== 'html5' ) {
947 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
, viewer
=== 'html5' );
948 } else if ( viewer
=== 'vv' ) {
950 var params
= { proxy
: PVE
. Utils
. windowHostname () };
951 if ( vmtype
=== 'kvm' ) {
952 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
953 PVE
. Utils
. openSpiceViewer ( url
, params
);
954 } else if ( vmtype
=== 'lxc' ) {
955 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
956 PVE
. Utils
. openSpiceViewer ( url
, params
);
957 } else if ( vmtype
=== 'shell' ) {
958 url
= '/nodes/' + nodename
+ '/spiceshell' ;
959 PVE
. Utils
. openSpiceViewer ( url
, params
);
960 } else if ( vmtype
=== 'upgrade' ) {
961 url
= '/nodes/' + nodename
+ '/spiceshell' ;
963 PVE
. Utils
. openSpiceViewer ( url
, params
);
966 throw "unknown viewer type" ;
970 defaultViewer : function ( allowSpice
) {
971 var vncdefault
= 'html5' ;
972 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
973 if ( dv
=== 'vv' && ! allowSpice
) {
980 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
, novnc
) {
981 var url
= Ext
. urlEncode ({
982 console
: vmtype
, // kvm, lxc, upgrade or shell
983 novnc
: novnc
? 1 : 0 ,
988 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
992 openSpiceViewer : function ( url
, params
){
994 var downloadWithName = function ( uri
, name
) {
995 var link
= Ext
. DomHelper
. append ( document
. body
, {
998 css
: 'display:none;visibility:hidden;height:0px;'
1001 // Note: we need to tell android the correct file name extension
1002 // but we do not set 'download' tag for other environments, because
1003 // It can have strange side effects (additional user prompt on firefox)
1004 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1006 link
. download
= name
;
1009 if ( link
. fireEvent
) {
1010 link
. fireEvent ( 'onclick' );
1012 var evt
= document
. createEvent ( "MouseEvents" );
1013 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1014 link
. dispatchEvent ( evt
);
1018 PVE
. Utils
. API2Request ({
1022 failure : function ( response
, opts
){
1023 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1025 success : function ( response
, opts
){
1026 var raw
= "[virt-viewer] \n " ;
1027 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1028 raw
+= k
+ "=" + v
+ " \n " ;
1030 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1031 encodeURIComponent ( raw
);
1033 downloadWithName ( url
, "pve-spice.vv" );
1038 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1039 // use el.mask() instead
1040 setErrorMask : function ( comp
, msg
) {
1049 el
. mask ( gettext ( "Loading..." ));
1056 monStoreErrors : function ( me
, store
) {
1057 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1058 if (! me
. loadCount
) {
1059 me
. loadCount
= 0 ; // make sure it is numeric
1060 PVE
. Utils
. setErrorMask ( me
, true );
1064 // only works with 'pve' proxy
1065 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1069 PVE
. Utils
. setErrorMask ( me
, false );
1074 var operation
= request
. operation
;
1075 var error
= operation
. getError ();
1076 if ( error
. statusText
) {
1077 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1079 msg
= gettext ( 'Connection error' );
1081 PVE
. Utils
. setErrorMask ( me
, msg
);