]>
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' ) {
175 return 'VirtIO SCSI' ;
176 } else if ( value
=== 'virtio-scsi-single' ) {
177 return 'VirtIO SCSI single' ;
178 } else if ( value
=== 'pvscsi' ) {
179 return 'VMware PVSCSI' ;
185 // fixme: auto-generate this
186 // for now, please keep in sync with PVE::Tools::kvmkeymaps
191 'de-ch' : 'German (Swiss)' ,
192 'en-gb' : 'English (UK)' ,
193 'en-us' : 'English (USA)' ,
197 //fo: 'Faroe Islands',
199 'fr-be' : 'French (Belgium)' ,
200 'fr-ca' : 'French (Canada)' ,
201 'fr-ch' : 'French (Swiss)' ,
211 //'nl-be': 'Dutch (Belgium)',
215 'pt-br' : 'Portuguese (Brazil)' ,
224 std
: gettext ( 'Standard VGA' ),
225 vmware
: gettext ( 'VMware compatible' ),
226 cirrus
: 'Cirrus Logic GD5446' ,
228 qxl2
: 'SPICE dual monitor' ,
229 qxl3
: 'SPICE three monitors' ,
230 qxl4
: 'SPICE four monitors' ,
231 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
232 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
233 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
234 serial3
: gettext ( 'Serial terminal' ) + ' 3'
237 render_kvm_language : function ( value
) {
239 return PVE
. Utils
. defaultText
;
241 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
243 return text
+ ' (' + value
+ ')' ;
248 kvm_keymap_array : function () {
249 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
250 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
251 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
257 render_console_viewer : function ( value
) {
258 if (! value
|| value
=== '__default__' ) {
259 return PVE
. Utils
. defaultText
+ ' (HTML5)' ;
260 } else if ( value
=== 'vv' ) {
261 return 'SPICE (remote-viewer)' ;
262 } else if ( value
=== 'html5' ) {
263 return 'HTML5 (noVNC)' ;
274 eu
: 'Euskera (Basque)' ,
279 nb
: 'Norwegian (Bokmal)' ,
280 nn
: 'Norwegian (Nynorsk)' ,
281 fa
: 'Persian (Farsi)' ,
283 pt_BR
: 'Portuguese (Brazil)' ,
291 render_language : function ( value
) {
293 return PVE
. Utils
. defaultText
+ ' (English)' ;
295 var text
= PVE
. Utils
. language_map
[ value
];
297 return text
+ ' (' + value
+ ')' ;
302 language_array : function () {
303 var data
= [[ '__default__' , PVE
. Utils
. render_language ( '' )]];
304 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
305 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
311 render_kvm_vga_driver : function ( value
) {
313 return PVE
. Utils
. defaultText
;
315 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
317 return text
+ ' (' + value
+ ')' ;
322 kvm_vga_driver_array : function () {
323 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
324 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
325 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
331 render_kvm_startup : function ( value
) {
332 var startup
= PVE
. Parser
. parseStartup ( value
);
335 if ( startup
. order
=== undefined ) {
338 res
+= startup
. order
;
340 if ( startup
. up
!== undefined ) {
341 res
+= ',up=' + startup
. up
;
343 if ( startup
. down
!== undefined ) {
344 res
+= ',down=' + startup
. down
;
351 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
354 authClear : function () {
355 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
358 // fixme: remove - not needed?
359 gridLineHeigh : function () {
367 extractRequestError : function ( result
, verbose
) {
368 var msg
= gettext ( 'Successful' );
370 if (! result
. success
) {
371 msg
= gettext ( "Unknown error" );
372 if ( result
. message
) {
373 msg
= result
. message
;
375 msg
+= ' (' + result
. status
+ ')' ;
378 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
380 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
381 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
382 Ext
. htmlEncode ( desc
);
390 extractFormActionError : function ( action
) {
392 switch ( action
. failureType
) {
393 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
394 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
396 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
397 msg
= gettext ( 'Connection error' );
398 var resp
= action
. response
;
399 if ( resp
. status
&& resp
. statusText
) {
400 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
403 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
404 case Ext
. form
. action
. Action
. SERVER_INVALID
:
405 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
412 API2Request : function ( reqOpts
) {
414 var newopts
= Ext
. apply ({
415 waitMsg
: gettext ( 'Please wait...' )
418 if (! newopts
. url
. match ( /^\/api2/ )) {
419 newopts
. url
= '/api2/extjs' + newopts
. url
;
421 delete newopts
. callback
;
423 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
425 success : function ( response
, options
) {
426 if ( options
. waitMsgTarget
) {
427 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
428 options
. waitMsgTarget
. setMasked ( false );
430 options
. waitMsgTarget
. setLoading ( false );
433 var result
= Ext
. decode ( response
. responseText
);
434 response
. result
= result
;
435 if (! result
. success
) {
436 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
437 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
438 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
441 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
442 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
444 failure : function ( response
, options
) {
445 if ( options
. waitMsgTarget
) {
446 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
447 options
. waitMsgTarget
. setMasked ( false );
449 options
. waitMsgTarget
. setLoading ( false );
452 response
. result
= {};
454 response
. result
= Ext
. decode ( response
. responseText
);
456 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
457 if ( response
. aborted
) {
458 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
459 } else if ( response
. timedout
) {
460 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
461 } else if ( response
. status
&& response
. statusText
) {
462 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
464 response
. htmlStatus
= msg
;
465 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
466 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
471 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
473 var target
= newopts
. waitMsgTarget
;
475 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
476 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
} );
478 // Note: ExtJS bug - this does not work when component is not rendered
479 target
. setLoading ( newopts
. waitMsg
);
482 Ext
. Ajax
. request ( newopts
);
485 assemble_field_data : function ( values
, data
) {
486 if ( Ext
. isObject ( data
)) {
487 Ext
. Object
. each ( data
, function ( name
, val
) {
488 if ( values
. hasOwnProperty ( name
)) {
489 var bucket
= values
[ name
];
490 if (! Ext
. isArray ( bucket
)) {
491 bucket
= values
[ name
] = [ bucket
];
493 if ( Ext
. isArray ( val
)) {
494 values
[ name
] = bucket
. concat ( val
);
505 checked_command : function ( orig_cmd
) {
506 PVE
. Utils
. API2Request ({
507 url
: '/nodes/localhost/subscription' ,
510 failure : function ( response
, opts
) {
511 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
513 success : function ( response
, opts
) {
514 var data
= response
. result
. data
;
516 if ( data
. status
!== 'Active' ) {
518 title
: gettext ( 'No valid subscription' ),
519 icon
: Ext
. Msg
. WARNING
,
520 msg
: PVE
. Utils
. noSubKeyHtml
,
522 callback : function ( btn
) {
537 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
538 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
539 vncshell
: [ '' , gettext ( 'Shell' ) ],
540 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
541 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
542 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
543 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
544 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
545 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
546 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
547 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
548 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
549 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
550 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
551 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
552 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
553 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
554 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
555 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
556 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
557 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
558 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' ) ],
559 vzrollback
: [ 'CT' , gettext ( 'Rollback' ) ],
560 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' ) ],
561 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
562 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
563 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
564 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
565 vzclone
: [ 'CT' , gettext ( 'Clone' ) ],
566 vztemplate
: [ 'CT' , gettext ( 'Convert to template' ) ],
567 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
568 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
569 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
570 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
571 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
572 vzsuspend
: [ 'CT' , gettext ( 'Suspend' ) ],
573 vzresume
: [ 'CT' , gettext ( 'Resume' ) ],
574 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
575 hastart
: [ 'HA' , gettext ( 'Start' ) ],
576 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
577 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
578 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
579 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
580 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
581 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' ) ],
582 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' ) ],
583 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' ) ],
584 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' ) ],
585 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
586 imgdel
: [ '' , gettext ( 'Erase data' ) ],
587 download
: [ '' , gettext ( 'Download' ) ],
588 vzdump
: [ '' , gettext ( 'Backup' ) ],
589 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
590 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
591 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
592 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
595 format_task_description : function ( type
, id
) {
596 var farray
= PVE
. Utils
. task_desc_table
[ type
];
600 var prefix
= farray
[ 0 ];
601 var text
= farray
[ 1 ];
603 return prefix
+ ' ' + id
+ ' - ' + text
;
608 parse_task_upid : function ( upid
) {
611 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]+):$/ );
613 throw "unable to parse upid '" + upid
+ "'" ;
616 task
. pid
= parseInt ( res
[ 2 ], 16 );
617 task
. pstart
= parseInt ( res
[ 3 ], 16 );
618 task
. starttime
= parseInt ( res
[ 4 ], 16 );
623 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
628 format_size : function ( size
) {
629 /*jslint confusion: true */
631 var units
= [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ];
634 while ( size
>= 1024 && (( num
++)+ 1 ) < units
. length
) {
638 return size
. toFixed (( num
> 0 )? 2 : 0 ) + " " + units
[ num
] + "B" ;
641 format_html_bar : function ( per
, text
) {
643 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
644 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
649 format_cpu_bar : function ( per1
, per2
, text
) {
651 return "<div class='pve-bar-border'>" +
652 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
653 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
654 "<div class='pve-bar-text'>" + text
+ "</div>" +
658 format_large_bar : function ( per
, text
) {
661 text
= per
. toFixed ( 1 ) + "%" ;
664 return "<div class='pve-largebar-border'>" +
665 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
666 "<div class='pve-largebar-text'>" + text
+ "</div>" +
670 format_duration_long : function ( ut
) {
672 var days
= Math
. floor ( ut
/ 86400 );
674 var hours
= Math
. floor ( ut
/ 3600 );
676 var mins
= Math
. floor ( ut
/ 60 );
679 var hours_str
= '00' + hours
. toString ();
680 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
681 var mins_str
= "00" + mins
. toString ();
682 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
683 var ut_str
= "00" + ut
. toString ();
684 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
687 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
688 return days
. toString () + ' ' + ds
+ ' ' +
689 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
691 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
695 format_duration_short : function ( ut
) {
698 return ut
. toString () + 's' ;
703 return mins
. toFixed ( 0 ) + 'm' ;
707 var hours
= ut
/ 3600 ;
708 return hours
. toFixed ( 0 ) + 'h' ;
711 var days
= ut
/ 86400 ;
712 return days
. toFixed ( 0 ) + 'd' ;
715 yesText
: gettext ( 'Yes' ),
716 noText
: gettext ( 'No' ),
717 noneText
: gettext ( 'none' ),
718 errorText
: gettext ( 'Error' ),
719 unknownText
: gettext ( 'Unknown' ),
720 defaultText
: gettext ( 'Default' ),
721 daysText
: gettext ( 'days' ),
722 dayText
: gettext ( 'day' ),
723 runningText
: gettext ( 'running' ),
724 stoppedText
: gettext ( 'stopped' ),
725 neverText
: gettext ( 'never' ),
726 totalText
: gettext ( 'Total' ),
727 usedText
: gettext ( 'Used' ),
728 directoryText
: gettext ( 'Directory' ),
729 imagesText
: gettext ( 'Disk image' ),
730 backupFileText
: gettext ( 'VZDump backup file' ),
731 vztmplText
: gettext ( 'Container template' ),
732 isoImageText
: gettext ( 'ISO image' ),
733 containersText
: gettext ( 'Container' ),
734 stateText
: gettext ( 'State' ),
735 groupText
: gettext ( 'Group' ),
737 format_expire : function ( date
) {
739 return PVE
. Utils
. neverText
;
741 return Ext
. Date
. format ( date
, "Y-m-d" );
744 format_storage_type : function ( value
) {
745 if ( value
=== 'dir' ) {
746 return PVE
. Utils
. directoryText
;
747 } else if ( value
=== 'nfs' ) {
749 } else if ( value
=== 'glusterfs' ) {
751 } else if ( value
=== 'lvm' ) {
753 } else if ( value
=== 'lvmthin' ) {
755 } else if ( value
=== 'iscsi' ) {
757 } else if ( value
=== 'rbd' ) {
759 } else if ( value
=== 'sheepdog' ) {
761 } else if ( value
=== 'zfs' ) {
762 return 'ZFS over iSCSI' ;
763 } else if ( value
=== 'zfspool' ) {
765 } else if ( value
=== 'iscsidirect' ) {
766 return 'iSCSIDirect' ;
767 } else if ( value
=== 'drbd' ) {
770 return PVE
. Utils
. unknownText
;
774 format_boolean_with_default : function ( value
) {
775 if ( Ext
. isDefined ( value
) && value
!== '__default__' ) {
776 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
778 return PVE
. Utils
. defaultText
;
781 format_boolean : function ( value
) {
782 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
785 format_neg_boolean : function ( value
) {
786 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
789 format_ha : function ( value
) {
790 var text
= PVE
. Utils
. format_boolean ( value
. managed
);
793 text
+= ', ' + PVE
. Utils
. stateText
+ ': ' ;
794 text
+= value
. state
|| PVE
. Utils
. noneText
;
796 text
+= ', ' + PVE
. Utils
. groupText
+ ': ' ;
797 text
+= value
. group
|| PVE
. Utils
. noneText
;
803 format_content_types : function ( value
) {
806 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
807 if ( ct
=== 'images' ) {
808 cta
. push ( PVE
. Utils
. imagesText
);
809 } else if ( ct
=== 'backup' ) {
810 cta
. push ( PVE
. Utils
. backupFileText
);
811 } else if ( ct
=== 'vztmpl' ) {
812 cta
. push ( PVE
. Utils
. vztmplText
);
813 } else if ( ct
=== 'iso' ) {
814 cta
. push ( PVE
. Utils
. isoImageText
);
815 } else if ( ct
=== 'rootdir' ) {
816 cta
. push ( PVE
. Utils
. containersText
);
820 return cta
. join ( ', ' );
823 render_storage_content : function ( value
, metaData
, record
) {
824 var data
= record
. data
;
825 if ( Ext
. isNumber ( data
. channel
) &&
826 Ext
. isNumber ( data
. id
) &&
827 Ext
. isNumber ( data
. lun
)) {
829 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
830 " ID " + data
. id
+ " LUN " + data
. lun
;
832 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
835 render_serverity : function ( value
) {
836 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
839 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
841 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
845 var maxcpu
= record
. data
. maxcpu
|| 1 ;
847 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
851 var per
= value
* 100 ;
853 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
856 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
857 /*jslint confusion: true */
859 if (! Ext
. isNumeric ( value
)) {
863 return PVE
. Utils
. format_size ( value
);
866 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
867 var servertime
= new Date ( value
* 1000 );
868 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
871 calculate_mem_usage : function ( data
) {
872 if (! Ext
. isNumeric ( data
. mem
) ||
878 return ( data
. mem
/ data
. maxmem
);
881 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
882 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
886 // we got no percentage but bytes
888 var maxmem
= record
. data
. maxmem
;
889 if (! record
. data
. uptime
||
891 ! Ext
. isNumeric ( mem
)) {
895 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
897 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
900 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
903 var maxmem
= record
. data
. maxmem
;
905 if (! record
. data
. uptime
) {
909 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
913 return PVE
. Utils
. render_size ( value
);
916 calculate_disk_usage : function ( data
) {
918 if (! Ext
. isNumeric ( data
. disk
) ||
919 data
. type
=== 'qemu' ||
920 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
921 data
. maxdisk
=== 0 ) {
925 return ( data
. disk
/ data
. maxdisk
);
928 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
929 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
933 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
936 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
939 var maxdisk
= record
. data
. maxdisk
;
940 var type
= record
. data
. type
;
942 if (! Ext
. isNumeric ( disk
) ||
945 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
949 return PVE
. Utils
. render_size ( value
);
952 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
958 case 'lxc' : icon
= 'cube' ;
959 gridcls
= '-stopped' ;
961 case 'qemu' : icon
= 'desktop' ;
962 gridcls
= '-stopped' ;
964 case 'node' : icon
= 'building' ;
965 gridcls
= '-offline' ;
967 case 'storage' : icon
= 'database' ; break ;
968 case 'pool' : icon
= 'tags' ; break ;
969 default : icon
= 'file' ;
972 if ( value
=== 'lxc' || value
=== 'qemu' ) {
973 if ( record
. data
. running
&& record
. data
. status
!== 'paused' ) {
974 gridcls
= '-running' ;
975 } else if ( record
. data
. running
) {
978 if ( record
. data
. template
) {
980 gridcls
= '-template-' + value
;
982 } else if ( value
=== 'node' ) {
983 if ( record
. data
. running
) {
988 var fa
= '<i class="fa fa-fw x-fa-grid' + gridcls
+ ' fa-' + icon
+ '"></i> ' ;
992 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
996 if ( uptime
=== undefined ) {
1004 return PVE
. Utils
. format_duration_long ( uptime
);
1007 render_support_level : function ( value
, metaData
, record
) {
1008 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
1011 render_upid : function ( value
, metaData
, record
) {
1012 var type
= record
. data
. type
;
1013 var id
= record
. data
. id
;
1015 return PVE
. Utils
. format_task_description ( type
, id
);
1018 dialog_title : function ( subject
, create
, isAdd
) {
1021 return gettext ( 'Add' ) + ': ' + subject
;
1023 return gettext ( 'Create' ) + ': ' + subject
;
1026 return gettext ( 'Edit' ) + ': ' + subject
;
1030 windowHostname : function () {
1031 return window
. location
. hostname
. replace ( IP6_bracket_match
,
1032 function ( m
, addr
, offset
, original
) { return addr
; });
1035 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
1036 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
1037 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
1040 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
1041 // kvm, lxc, shell, upgrade
1043 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
1044 throw "missing vmid" ;
1048 throw "no nodename specified" ;
1051 if ( viewer
=== 'html5' ) {
1052 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
1053 } else if ( viewer
=== 'vv' ) {
1055 var params
= { proxy
: PVE
. Utils
. windowHostname () };
1056 if ( vmtype
=== 'kvm' ) {
1057 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1058 PVE
. Utils
. openSpiceViewer ( url
, params
);
1059 } else if ( vmtype
=== 'lxc' ) {
1060 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1061 PVE
. Utils
. openSpiceViewer ( url
, params
);
1062 } else if ( vmtype
=== 'shell' ) {
1063 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1064 PVE
. Utils
. openSpiceViewer ( url
, params
);
1065 } else if ( vmtype
=== 'upgrade' ) {
1066 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1068 PVE
. Utils
. openSpiceViewer ( url
, params
);
1071 throw "unknown viewer type" ;
1075 defaultViewer : function ( allowSpice
) {
1076 var vncdefault
= 'html5' ;
1077 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
1078 if ( dv
=== 'vv' && ! allowSpice
) {
1085 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
1086 var url
= Ext
. urlEncode ({
1087 console
: vmtype
, // kvm, lxc, upgrade or shell
1093 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1097 openSpiceViewer : function ( url
, params
){
1099 var downloadWithName = function ( uri
, name
) {
1100 var link
= Ext
. DomHelper
. append ( document
. body
, {
1103 css
: 'display:none;visibility:hidden;height:0px;'
1106 // Note: we need to tell android the correct file name extension
1107 // but we do not set 'download' tag for other environments, because
1108 // It can have strange side effects (additional user prompt on firefox)
1109 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1111 link
. download
= name
;
1114 if ( link
. fireEvent
) {
1115 link
. fireEvent ( 'onclick' );
1117 var evt
= document
. createEvent ( "MouseEvents" );
1118 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1119 link
. dispatchEvent ( evt
);
1123 PVE
. Utils
. API2Request ({
1127 failure : function ( response
, opts
){
1128 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1130 success : function ( response
, opts
){
1131 var raw
= "[virt-viewer] \n " ;
1132 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1133 raw
+= k
+ "=" + v
+ " \n " ;
1135 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1136 encodeURIComponent ( raw
);
1138 downloadWithName ( url
, "pve-spice.vv" );
1143 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1144 // use el.mask() instead
1145 setErrorMask : function ( comp
, msg
) {
1154 el
. mask ( gettext ( "Loading..." ));
1161 monStoreErrors : function ( me
, store
) {
1162 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1163 if (! me
. loadCount
) {
1164 me
. loadCount
= 0 ; // make sure it is numeric
1165 PVE
. Utils
. setErrorMask ( me
, true );
1169 // only works with 'pve' proxy
1170 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1174 PVE
. Utils
. setErrorMask ( me
, false );
1179 /*jslint nomen: true */
1180 var operation
= request
. _operation
;
1181 var error
= operation
. getError ();
1182 if ( error
. statusText
) {
1183 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1185 msg
= gettext ( 'Connection error' );
1187 PVE
. Utils
. setErrorMask ( me
, msg
);
1191 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1193 if (!( v
instanceof Ext
. tree
. View
)) {
1198 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1199 menu
= Ext
. create ( 'PVE.qemu.CmdMenu' , {
1202 } else if ( record
. data
. type
=== 'qemu' && record
. data
. template
) {
1203 menu
= Ext
. create ( 'PVE.qemu.TemplateMenu' , {
1206 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1207 menu
= Ext
. create ( 'PVE.lxc.CmdMenu' , {
1210 } else if ( record
. data
. type
=== 'lxc' && record
. data
. template
) {
1211 /* since clone does not work reliably, disable for now
1212 menu = Ext.create('PVE.lxc.TemplateMenu', {
1221 menu
. showAt ( event
. getXY ());