]>
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 var IPV4_OCTET
= "(?:25[0-5]|(?:[1-9]|1[0-9]|2[0-4])?[0-9])" ;
33 var IPV4_REGEXP
= "(?:(?:" + IPV4_OCTET
+ " \\ .){3}" + IPV4_OCTET
+ ")" ;
34 var IPV6_H16
= "(?:[0-9a-fA-F]{1,4})" ;
35 var IPV6_LS32
= "(?:(?:" + IPV6_H16
+ ":" + IPV6_H16
+ ")|" + IPV4_REGEXP
+ ")" ;
38 var IP4_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")$" );
39 var IP4_cidr_match
= new RegExp ( "^(?:" + IPV4_REGEXP
+ ")\/([0-9]{1,2})$" );
41 var IPV6_REGEXP
= "(?:" +
42 "(?:(?:" + "(?:" + IPV6_H16
+ ":){6})" + IPV6_LS32
+ ")|" +
43 "(?:(?:" + "::" + "(?:" + IPV6_H16
+ ":){5})" + IPV6_LS32
+ ")|" +
44 "(?:(?:(?:" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){4})" + IPV6_LS32
+ ")|" +
45 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,1}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){3})" + IPV6_LS32
+ ")|" +
46 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,2}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){2})" + IPV6_LS32
+ ")|" +
47 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,3}" + IPV6_H16
+ ")?::" + "(?:" + IPV6_H16
+ ":){1})" + IPV6_LS32
+ ")|" +
48 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,4}" + IPV6_H16
+ ")?::" + ")" + IPV6_LS32
+ ")|" +
49 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,5}" + IPV6_H16
+ ")?::" + ")" + IPV6_H16
+ ")|" +
50 "(?:(?:(?:(?:" + IPV6_H16
+ ":){0,7}" + IPV6_H16
+ ")?::" + ")" + ")" +
53 var IP6_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")$" );
54 var IP6_cidr_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ ")\/([0-9]{1,3})$" );
55 var IP6_bracket_match
= new RegExp ( "^ \\ [(" + IPV6_REGEXP
+ ") \\ ]" );
57 var IP64_match
= new RegExp ( "^(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ ")$" );
59 Ext
. define ( 'PVE.Utils' , { statics
: {
61 // this class only contains static functions
63 toolkit
: undefined , // (extjs|touch), set inside Toolkit.js
77 'c' : gettext ( 'Community' ),
78 'b' : gettext ( 'Basic' ),
79 's' : gettext ( 'Standard' ),
80 'p' : gettext ( 'Premium' )
83 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.' ,
86 other
: gettext ( 'Other OS types' ),
87 wxp
: 'Microsoft Windows XP/2003' ,
88 w2k
: 'Microsoft Windows 2000' ,
89 w2k8
: 'Microsoft Windows Vista/2008' ,
90 win7
: 'Microsoft Windows 7/2008r2' ,
91 win8
: 'Microsoft Windows 8.x/10/2012/r2' ,
92 l24
: 'Linux 2.4 Kernel' ,
93 l26
: 'Linux 4.X/3.X/2.6 Kernel' ,
94 solaris
: 'Solaris Kernel'
97 render_kvm_ostype : function ( value
) {
99 return gettext ( 'Other OS types' );
101 var text
= PVE
. Utils
. kvm_ostypes
[ value
];
108 render_hotplug_features : function ( value
) {
111 if (! value
|| ( value
=== '0' )) {
112 return gettext ( 'disabled' );
116 value
= 'disk,network,usb' ;
119 Ext
. each ( value
. split ( ',' ), function ( el
) {
121 fa
. push ( gettext ( 'Disk' ));
122 } else if ( el
=== 'network' ) {
123 fa
. push ( gettext ( 'Network' ));
124 } else if ( el
=== 'usb' ) {
125 fa
. push ( gettext ( 'USB' ));
126 } else if ( el
=== 'memory' ) {
127 fa
. push ( gettext ( 'Memory' ));
128 } else if ( el
=== 'cpu' ) {
129 fa
. push ( gettext ( 'CPU' ));
135 return fa
. join ( ', ' );
138 network_iface_types
: {
139 eth
: gettext ( "Network Device" ),
140 bridge
: 'Linux Bridge' ,
142 OVSBridge
: 'OVS Bridge' ,
145 OVSIntPort
: 'OVS IntPort'
148 render_network_iface_type : function ( value
) {
149 return PVE
. Utils
. network_iface_types
[ value
] ||
150 PVE
. Utils
. unknownText
;
153 render_qemu_bios : function ( value
) {
155 return PVE
. Utils
. defaultText
+ ' (SeaBIOS)' ;
156 } else if ( value
=== 'seabios' ) {
158 } else if ( value
=== 'ovmf' ) {
159 return "OVMF (UEFI)" ;
165 render_scsihw : function ( value
) {
167 return PVE
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
168 } else if ( value
=== 'lsi' ) {
169 return 'LSI 53C895A' ;
170 } else if ( value
=== 'lsi53c810' ) {
172 } else if ( value
=== 'megasas' ) {
173 return 'MegaRAID SAS 8708EM2' ;
174 } else if ( value
=== 'virtio-scsi-pci' ) {
176 } else if ( value
=== 'pvscsi' ) {
177 return 'VMware PVSCSI' ;
183 // fixme: auto-generate this
184 // for now, please keep in sync with PVE::Tools::kvmkeymaps
189 'de-ch' : 'German (Swiss)' ,
190 'en-gb' : 'English (UK)' ,
191 'en-us' : 'English (USA)' ,
195 //fo: 'Faroe Islands',
197 'fr-be' : 'French (Belgium)' ,
198 'fr-ca' : 'French (Canada)' ,
199 'fr-ch' : 'French (Swiss)' ,
209 //'nl-be': 'Dutch (Belgium)',
213 'pt-br' : 'Portuguese (Brazil)' ,
222 std
: gettext ( 'Standard VGA' ),
223 vmware
: gettext ( 'VMWare compatible' ),
224 cirrus
: 'Cirrus Logic GD5446' ,
226 qxl2
: 'SPICE dual monitor' ,
227 qxl3
: 'SPICE three monitors' ,
228 qxl4
: 'SPICE four monitors' ,
229 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
230 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
231 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
232 serial3
: gettext ( 'Serial terminal' ) + ' 3'
235 render_kvm_language : function ( value
) {
237 return PVE
. Utils
. defaultText
;
239 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
241 return text
+ ' (' + value
+ ')' ;
246 kvm_keymap_array : function () {
247 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
248 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
249 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
255 render_console_viewer : function ( value
) {
256 if (! value
|| value
=== '__default__' ) {
257 return PVE
. Utils
. defaultText
+ ' (HTML5)' ;
258 } else if ( value
=== 'vv' ) {
259 return 'SPICE (remote-viewer)' ;
260 } else if ( value
=== 'html5' ) {
261 return 'HTML5 (noVNC)' ;
272 eu
: 'Euskera (Basque)' ,
277 nb
: 'Norwegian (Bokmal)' ,
278 nn
: 'Norwegian (Nynorsk)' ,
279 fa
: 'Persian (Farsi)' ,
281 pt_BR
: 'Portuguese (Brazil)' ,
289 render_language : function ( value
) {
291 return PVE
. Utils
. defaultText
+ ' (English)' ;
293 var text
= PVE
. Utils
. language_map
[ value
];
295 return text
+ ' (' + value
+ ')' ;
300 language_array : function () {
301 var data
= [[ '__default__' , PVE
. Utils
. render_language ( '' )]];
302 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
303 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
309 render_kvm_vga_driver : function ( value
) {
311 return PVE
. Utils
. defaultText
;
313 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
315 return text
+ ' (' + value
+ ')' ;
320 kvm_vga_driver_array : function () {
321 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
322 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
323 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
329 render_kvm_startup : function ( value
) {
330 var startup
= PVE
. Parser
. parseStartup ( value
);
333 if ( startup
. order
=== undefined ) {
336 res
+= startup
. order
;
338 if ( startup
. up
!== undefined ) {
339 res
+= ',up=' + startup
. up
;
341 if ( startup
. down
!== undefined ) {
342 res
+= ',down=' + startup
. down
;
349 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
352 authClear : function () {
353 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
356 // fixme: remove - not needed?
357 gridLineHeigh : function () {
365 extractRequestError : function ( result
, verbose
) {
366 var msg
= gettext ( 'Successful' );
368 if (! result
. success
) {
369 msg
= gettext ( "Unknown error" );
370 if ( result
. message
) {
371 msg
= result
. message
;
373 msg
+= ' (' + result
. status
+ ')' ;
376 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
378 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
379 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
380 Ext
. htmlEncode ( desc
);
388 extractFormActionError : function ( action
) {
390 switch ( action
. failureType
) {
391 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
392 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
394 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
395 msg
= gettext ( 'Connection error' );
396 var resp
= action
. response
;
397 if ( resp
. status
&& resp
. statusText
) {
398 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
401 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
402 case Ext
. form
. action
. Action
. SERVER_INVALID
:
403 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
410 API2Request : function ( reqOpts
) {
412 var newopts
= Ext
. apply ({
413 waitMsg
: gettext ( 'Please wait...' )
416 if (! newopts
. url
. match ( /^\/api2/ )) {
417 newopts
. url
= '/api2/extjs' + newopts
. url
;
419 delete newopts
. callback
;
421 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
423 success : function ( response
, options
) {
424 if ( options
. waitMsgTarget
) {
425 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
426 options
. waitMsgTarget
. setMasked ( false );
428 options
. waitMsgTarget
. setLoading ( false );
431 var result
= Ext
. decode ( response
. responseText
);
432 response
. result
= result
;
433 if (! result
. success
) {
434 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
435 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
436 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
439 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
440 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
442 failure : function ( response
, options
) {
443 if ( options
. waitMsgTarget
) {
444 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
445 options
. waitMsgTarget
. setMasked ( false );
447 options
. waitMsgTarget
. setLoading ( false );
450 response
. result
= {};
452 response
. result
= Ext
. decode ( response
. responseText
);
454 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
455 if ( response
. aborted
) {
456 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
457 } else if ( response
. timedout
) {
458 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
459 } else if ( response
. status
&& response
. statusText
) {
460 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
462 response
. htmlStatus
= msg
;
463 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
464 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
469 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
471 var target
= newopts
. waitMsgTarget
;
473 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
474 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
} );
476 // Note: ExtJS bug - this does not work when component is not rendered
477 target
. setLoading ( newopts
. waitMsg
);
480 Ext
. Ajax
. request ( newopts
);
483 assemble_field_data : function ( values
, data
) {
484 if ( Ext
. isObject ( data
)) {
485 Ext
. Object
. each ( data
, function ( name
, val
) {
486 if ( values
. hasOwnProperty ( name
)) {
487 var bucket
= values
[ name
];
488 if (! Ext
. isArray ( bucket
)) {
489 bucket
= values
[ name
] = [ bucket
];
491 if ( Ext
. isArray ( val
)) {
492 values
[ name
] = bucket
. concat ( val
);
503 checked_command : function ( orig_cmd
) {
504 PVE
. Utils
. API2Request ({
505 url
: '/nodes/localhost/subscription' ,
508 failure : function ( response
, opts
) {
509 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
511 success : function ( response
, opts
) {
512 var data
= response
. result
. data
;
514 if ( data
. status
!== 'Active' ) {
516 title
: gettext ( 'No valid subscription' ),
517 icon
: Ext
. Msg
. WARNING
,
518 msg
: PVE
. Utils
. noSubKeyHtml
,
520 callback : function ( btn
) {
535 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
536 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
537 vncshell
: [ '' , gettext ( 'Shell' ) ],
538 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
539 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
540 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
541 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
542 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
543 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
544 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
545 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
546 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
547 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
548 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
549 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
550 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
551 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
552 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
553 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
554 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
555 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
556 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' ) ],
557 vzrollback
: [ 'CT' , gettext ( 'Rollback' ) ],
558 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' ) ],
559 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
560 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
561 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
562 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
563 vzclone
: [ 'CT' , gettext ( 'Clone' ) ],
564 vztemplate
: [ 'CT' , gettext ( 'Convert to template' ) ],
565 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
566 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
567 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
568 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
569 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
570 vzsuspend
: [ 'CT' , gettext ( 'Suspend' ) ],
571 vzresume
: [ 'CT' , gettext ( 'Resume' ) ],
572 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
573 hastart
: [ 'HA' , gettext ( 'Start' ) ],
574 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
575 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
576 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
577 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
578 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
579 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' ) ],
580 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' ) ],
581 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' ) ],
582 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' ) ],
583 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
584 imgdel
: [ '' , gettext ( 'Erase data' ) ],
585 download
: [ '' , gettext ( 'Download' ) ],
586 vzdump
: [ '' , gettext ( 'Backup' ) ],
587 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
588 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
589 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
590 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
593 format_task_description : function ( type
, id
) {
594 var farray
= PVE
. Utils
. task_desc_table
[ type
];
598 var prefix
= farray
[ 0 ];
599 var text
= farray
[ 1 ];
601 return prefix
+ ' ' + id
+ ' - ' + text
;
606 parse_task_upid : function ( upid
) {
609 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]+):$/ );
611 throw "unable to parse upid '" + upid
+ "'" ;
614 task
. pid
= parseInt ( res
[ 2 ], 16 );
615 task
. pstart
= parseInt ( res
[ 3 ], 16 );
616 task
. starttime
= parseInt ( res
[ 4 ], 16 );
621 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
626 format_size : function ( size
) {
627 /*jslint confusion: true */
629 var units
= [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ];
632 while ( size
>= 1024 && (( num
++)+ 1 ) < units
. length
) {
636 return size
. toFixed (( num
> 0 )? 2 : 0 ) + " " + units
[ num
] + "B" ;
639 format_html_bar : function ( per
, text
) {
641 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
642 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
647 format_cpu_bar : function ( per1
, per2
, text
) {
649 return "<div class='pve-bar-border'>" +
650 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
651 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
652 "<div class='pve-bar-text'>" + text
+ "</div>" +
656 format_large_bar : function ( per
, text
) {
659 text
= per
. toFixed ( 1 ) + "%" ;
662 return "<div class='pve-largebar-border'>" +
663 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
664 "<div class='pve-largebar-text'>" + text
+ "</div>" +
668 format_duration_long : function ( ut
) {
670 var days
= Math
. floor ( ut
/ 86400 );
672 var hours
= Math
. floor ( ut
/ 3600 );
674 var mins
= Math
. floor ( ut
/ 60 );
677 var hours_str
= '00' + hours
. toString ();
678 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
679 var mins_str
= "00" + mins
. toString ();
680 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
681 var ut_str
= "00" + ut
. toString ();
682 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
685 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
686 return days
. toString () + ' ' + ds
+ ' ' +
687 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
689 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
693 format_duration_short : function ( ut
) {
696 return ut
. toString () + 's' ;
701 return mins
. toFixed ( 0 ) + 'm' ;
705 var hours
= ut
/ 3600 ;
706 return hours
. toFixed ( 0 ) + 'h' ;
709 var days
= ut
/ 86400 ;
710 return days
. toFixed ( 0 ) + 'd' ;
713 yesText
: gettext ( 'Yes' ),
714 noText
: gettext ( 'No' ),
715 noneText
: gettext ( 'none' ),
716 errorText
: gettext ( 'Error' ),
717 unknownText
: gettext ( 'Unknown' ),
718 defaultText
: gettext ( 'Default' ),
719 daysText
: gettext ( 'days' ),
720 dayText
: gettext ( 'day' ),
721 runningText
: gettext ( 'running' ),
722 stoppedText
: gettext ( 'stopped' ),
723 neverText
: gettext ( 'never' ),
724 totalText
: gettext ( 'Total' ),
725 usedText
: gettext ( 'Used' ),
726 directoryText
: gettext ( 'Directory' ),
727 imagesText
: gettext ( 'Disk image' ),
728 backupFileText
: gettext ( 'VZDump backup file' ),
729 vztmplText
: gettext ( 'Container template' ),
730 isoImageText
: gettext ( 'ISO image' ),
731 containersText
: gettext ( 'Container' ),
732 stateText
: gettext ( 'State' ),
733 groupText
: gettext ( 'Group' ),
735 format_expire : function ( date
) {
737 return PVE
. Utils
. neverText
;
739 return Ext
. Date
. format ( date
, "Y-m-d" );
742 format_storage_type : function ( value
) {
743 if ( value
=== 'dir' ) {
744 return PVE
. Utils
. directoryText
;
745 } else if ( value
=== 'nfs' ) {
747 } else if ( value
=== 'glusterfs' ) {
749 } else if ( value
=== 'lvm' ) {
751 } else if ( value
=== 'lvmthin' ) {
753 } else if ( value
=== 'iscsi' ) {
755 } else if ( value
=== 'rbd' ) {
757 } else if ( value
=== 'sheepdog' ) {
759 } else if ( value
=== 'zfs' ) {
760 return 'ZFS over iSCSI' ;
761 } else if ( value
=== 'zfspool' ) {
763 } else if ( value
=== 'iscsidirect' ) {
764 return 'iSCSIDirect' ;
765 } else if ( value
=== 'drbd' ) {
768 return PVE
. Utils
. unknownText
;
772 format_boolean_with_default : function ( value
) {
773 if ( Ext
. isDefined ( value
) && value
!== '__default__' ) {
774 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
776 return PVE
. Utils
. defaultText
;
779 format_boolean : function ( value
) {
780 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
783 format_neg_boolean : function ( value
) {
784 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
787 format_ha : function ( value
) {
788 var text
= PVE
. Utils
. format_boolean ( value
. managed
);
791 text
+= ', ' + PVE
. Utils
. stateText
+ ': ' ;
792 text
+= value
. state
|| PVE
. Utils
. noneText
;
794 text
+= ', ' + PVE
. Utils
. groupText
+ ': ' ;
795 text
+= value
. group
|| PVE
. Utils
. noneText
;
801 format_content_types : function ( value
) {
804 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
805 if ( ct
=== 'images' ) {
806 cta
. push ( PVE
. Utils
. imagesText
);
807 } else if ( ct
=== 'backup' ) {
808 cta
. push ( PVE
. Utils
. backupFileText
);
809 } else if ( ct
=== 'vztmpl' ) {
810 cta
. push ( PVE
. Utils
. vztmplText
);
811 } else if ( ct
=== 'iso' ) {
812 cta
. push ( PVE
. Utils
. isoImageText
);
813 } else if ( ct
=== 'rootdir' ) {
814 cta
. push ( PVE
. Utils
. containersText
);
818 return cta
. join ( ', ' );
821 render_storage_content : function ( value
, metaData
, record
) {
822 var data
= record
. data
;
823 if ( Ext
. isNumber ( data
. channel
) &&
824 Ext
. isNumber ( data
. id
) &&
825 Ext
. isNumber ( data
. lun
)) {
827 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
828 " ID " + data
. id
+ " LUN " + data
. lun
;
830 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
833 render_serverity : function ( value
) {
834 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
837 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
839 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
843 var maxcpu
= record
. data
. maxcpu
|| 1 ;
845 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
849 var per
= value
* 100 ;
851 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
854 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
855 /*jslint confusion: true */
857 if (! Ext
. isNumeric ( value
)) {
861 return PVE
. Utils
. format_size ( value
);
864 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
865 var servertime
= new Date ( value
* 1000 );
866 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
869 calculate_mem_usage : function ( data
) {
870 if (! Ext
. isNumeric ( data
. mem
) ||
876 return ( data
. mem
/ data
. maxmem
);
879 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
880 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
884 // we got no percentage but bytes
886 var maxmem
= record
. data
. maxmem
;
887 if (! record
. data
. uptime
||
889 ! Ext
. isNumeric ( mem
)) {
893 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
895 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
898 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
901 var maxmem
= record
. data
. maxmem
;
903 if (! record
. data
. uptime
) {
907 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
911 return PVE
. Utils
. render_size ( value
);
914 calculate_disk_usage : function ( data
) {
916 if (! Ext
. isNumeric ( data
. disk
) ||
917 data
. type
=== 'qemu' ||
918 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
919 data
. maxdisk
=== 0 ) {
923 return ( data
. disk
/ data
. maxdisk
);
926 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
927 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
931 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
934 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
937 var maxdisk
= record
. data
. maxdisk
;
938 var type
= record
. data
. type
;
940 if (! Ext
. isNumeric ( disk
) ||
943 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
947 return PVE
. Utils
. render_size ( value
);
950 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
956 case 'lxc' : icon
= 'cube' ;
957 gridcls
= '-stopped' ;
959 case 'qemu' : icon
= 'desktop' ;
960 gridcls
= '-stopped' ;
962 case 'node' : icon
= 'building' ;
963 gridcls
= '-offline' ;
965 case 'storage' : icon
= 'database' ; break ;
966 case 'pool' : icon
= 'tags' ; break ;
967 default : icon
= 'file' ;
970 if ( value
=== 'lxc' || value
=== 'qemu' ) {
971 if ( record
. data
. running
&& record
. data
. status
!== 'paused' ) {
972 gridcls
= '-running' ;
973 } else if ( record
. data
. running
) {
976 if ( record
. data
. template
) {
978 gridcls
= '-template-' + value
;
980 } else if ( value
=== 'node' ) {
981 if ( record
. data
. running
) {
986 var fa
= '<i class="fa fa-fw x-fa-grid' + gridcls
+ ' fa-' + icon
+ '"></i> ' ;
990 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
994 if ( uptime
=== undefined ) {
1002 return PVE
. Utils
. format_duration_long ( uptime
);
1005 render_support_level : function ( value
, metaData
, record
) {
1006 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
1009 render_upid : function ( value
, metaData
, record
) {
1010 var type
= record
. data
. type
;
1011 var id
= record
. data
. id
;
1013 return PVE
. Utils
. format_task_description ( type
, id
);
1016 dialog_title : function ( subject
, create
, isAdd
) {
1019 return gettext ( 'Add' ) + ': ' + subject
;
1021 return gettext ( 'Create' ) + ': ' + subject
;
1024 return gettext ( 'Edit' ) + ': ' + subject
;
1028 windowHostname : function () {
1029 return window
. location
. hostname
. replace ( IP6_bracket_match
,
1030 function ( m
, addr
, offset
, original
) { return addr
; });
1033 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
1034 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
1035 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
1038 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
1039 // kvm, lxc, shell, upgrade
1041 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
1042 throw "missing vmid" ;
1046 throw "no nodename specified" ;
1049 if ( viewer
=== 'html5' ) {
1050 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
1051 } else if ( viewer
=== 'vv' ) {
1053 var params
= { proxy
: PVE
. Utils
. windowHostname () };
1054 if ( vmtype
=== 'kvm' ) {
1055 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1056 PVE
. Utils
. openSpiceViewer ( url
, params
);
1057 } else if ( vmtype
=== 'lxc' ) {
1058 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1059 PVE
. Utils
. openSpiceViewer ( url
, params
);
1060 } else if ( vmtype
=== 'shell' ) {
1061 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1062 PVE
. Utils
. openSpiceViewer ( url
, params
);
1063 } else if ( vmtype
=== 'upgrade' ) {
1064 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1066 PVE
. Utils
. openSpiceViewer ( url
, params
);
1069 throw "unknown viewer type" ;
1073 defaultViewer : function ( allowSpice
) {
1074 var vncdefault
= 'html5' ;
1075 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
1076 if ( dv
=== 'vv' && ! allowSpice
) {
1083 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
1084 var url
= Ext
. urlEncode ({
1085 console
: vmtype
, // kvm, lxc, upgrade or shell
1091 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1095 openSpiceViewer : function ( url
, params
){
1097 var downloadWithName = function ( uri
, name
) {
1098 var link
= Ext
. DomHelper
. append ( document
. body
, {
1101 css
: 'display:none;visibility:hidden;height:0px;'
1104 // Note: we need to tell android the correct file name extension
1105 // but we do not set 'download' tag for other environments, because
1106 // It can have strange side effects (additional user prompt on firefox)
1107 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1109 link
. download
= name
;
1112 if ( link
. fireEvent
) {
1113 link
. fireEvent ( 'onclick' );
1115 var evt
= document
. createEvent ( "MouseEvents" );
1116 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1117 link
. dispatchEvent ( evt
);
1121 PVE
. Utils
. API2Request ({
1125 failure : function ( response
, opts
){
1126 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1128 success : function ( response
, opts
){
1129 var raw
= "[virt-viewer] \n " ;
1130 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1131 raw
+= k
+ "=" + v
+ " \n " ;
1133 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1134 encodeURIComponent ( raw
);
1136 downloadWithName ( url
, "pve-spice.vv" );
1141 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1142 // use el.mask() instead
1143 setErrorMask : function ( comp
, msg
) {
1152 el
. mask ( gettext ( "Loading..." ));
1159 monStoreErrors : function ( me
, store
) {
1160 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1161 if (! me
. loadCount
) {
1162 me
. loadCount
= 0 ; // make sure it is numeric
1163 PVE
. Utils
. setErrorMask ( me
, true );
1167 // only works with 'pve' proxy
1168 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1172 PVE
. Utils
. setErrorMask ( me
, false );
1177 /*jslint nomen: true */
1178 var operation
= request
. _operation
;
1179 var error
= operation
. getError ();
1180 if ( error
. statusText
) {
1181 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1183 msg
= gettext ( 'Connection error' );
1185 PVE
. Utils
. setErrorMask ( me
, msg
);
1189 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1191 if (!( v
instanceof Ext
. tree
. View
)) {
1196 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1197 menu
= Ext
. create ( 'PVE.qemu.CmdMenu' , {
1200 } else if ( record
. data
. type
=== 'qemu' && record
. data
. template
) {
1201 menu
= Ext
. create ( 'PVE.qemu.TemplateMenu' , {
1204 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1205 menu
= Ext
. create ( 'PVE.lxc.CmdMenu' , {
1208 } else if ( record
. data
. type
=== 'lxc' && record
. data
. template
) {
1209 /* since clone does not work reliably, disable for now
1210 menu = Ext.create('PVE.lxc.TemplateMenu', {
1219 menu
. showAt ( event
. getXY ());