]>
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 var DnsName_REGEXP
= "(?:(([a-zA-Z0-9]([a-zA-Z0-9 \\ -]*[a-zA-Z0-9])?) \\ .)*([A-Za-z0-9]([A-Za-z0-9 \\ -]*[A-Za-z0-9])?))" ;
60 var DnsName_match
= new RegExp ( "^" + DnsName_REGEXP
+ "$" );
62 var HostPort_match
= new RegExp ( "^(" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ")(: \\ d+)?$" );
63 var HostPortBrackets_match
= new RegExp ( "^ \\ [(?:" + IPV6_REGEXP
+ "|" + IPV4_REGEXP
+ "|" + DnsName_REGEXP
+ ") \\ ](: \\ d+)?$" );
64 var IP6_dotnotation_match
= new RegExp ( "^" + IPV6_REGEXP
+ "( \\ . \\ d+)?$" );
66 Ext
. define ( 'PVE.Utils' , { utilities
: {
68 // this singleton contains miscellaneous utilities
70 toolkit
: undefined , // (extjs|touch), set inside Toolkit.js
72 bus_match
: /^(ide|sata|virtio|scsi)\d+$/ ,
86 'c' : gettext ( 'Community' ),
87 'b' : gettext ( 'Basic' ),
88 's' : gettext ( 'Standard' ),
89 'p' : gettext ( 'Premium' )
92 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.' ,
95 other
: gettext ( 'Other OS types' ),
96 wxp
: 'Microsoft Windows XP/2003' ,
97 w2k
: 'Microsoft Windows 2000' ,
98 w2k8
: 'Microsoft Windows Vista/2008' ,
99 win7
: 'Microsoft Windows 7/2008r2' ,
100 win8
: 'Microsoft Windows 8.x/10/2012/r2' ,
101 l24
: 'Linux 2.4 Kernel' ,
102 l26
: 'Linux 4.X/3.X/2.6 Kernel' ,
103 solaris
: 'Solaris Kernel'
106 render_kvm_ostype : function ( value
) {
108 return gettext ( 'Other OS types' );
110 var text
= PVE
. Utils
. kvm_ostypes
[ value
];
117 render_hotplug_features : function ( value
) {
120 if (! value
|| ( value
=== '0' )) {
121 return gettext ( 'disabled' );
125 value
= 'disk,network,usb' ;
128 Ext
. each ( value
. split ( ',' ), function ( el
) {
130 fa
. push ( gettext ( 'Disk' ));
131 } else if ( el
=== 'network' ) {
132 fa
. push ( gettext ( 'Network' ));
133 } else if ( el
=== 'usb' ) {
134 fa
. push ( gettext ( 'USB' ));
135 } else if ( el
=== 'memory' ) {
136 fa
. push ( gettext ( 'Memory' ));
137 } else if ( el
=== 'cpu' ) {
138 fa
. push ( gettext ( 'CPU' ));
144 return fa
. join ( ', ' );
147 network_iface_types
: {
148 eth
: gettext ( "Network Device" ),
149 bridge
: 'Linux Bridge' ,
151 OVSBridge
: 'OVS Bridge' ,
154 OVSIntPort
: 'OVS IntPort'
157 render_network_iface_type : function ( value
) {
158 return PVE
. Utils
. network_iface_types
[ value
] ||
159 PVE
. Utils
. unknownText
;
162 render_qemu_bios : function ( value
) {
164 return PVE
. Utils
. defaultText
+ ' (SeaBIOS)' ;
165 } else if ( value
=== 'seabios' ) {
167 } else if ( value
=== 'ovmf' ) {
168 return "OVMF (UEFI)" ;
174 render_scsihw : function ( value
) {
176 return PVE
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
177 } else if ( value
=== 'lsi' ) {
178 return 'LSI 53C895A' ;
179 } else if ( value
=== 'lsi53c810' ) {
181 } else if ( value
=== 'megasas' ) {
182 return 'MegaRAID SAS 8708EM2' ;
183 } else if ( value
=== 'virtio-scsi-pci' ) {
184 return 'VirtIO SCSI' ;
185 } else if ( value
=== 'virtio-scsi-single' ) {
186 return 'VirtIO SCSI single' ;
187 } else if ( value
=== 'pvscsi' ) {
188 return 'VMware PVSCSI' ;
194 // fixme: auto-generate this
195 // for now, please keep in sync with PVE::Tools::kvmkeymaps
200 'de-ch' : 'German (Swiss)' ,
201 'en-gb' : 'English (UK)' ,
202 'en-us' : 'English (USA)' ,
206 //fo: 'Faroe Islands',
208 'fr-be' : 'French (Belgium)' ,
209 'fr-ca' : 'French (Canada)' ,
210 'fr-ch' : 'French (Swiss)' ,
220 //'nl-be': 'Dutch (Belgium)',
224 'pt-br' : 'Portuguese (Brazil)' ,
233 std
: gettext ( 'Standard VGA' ),
234 vmware
: gettext ( 'VMware compatible' ),
235 cirrus
: 'Cirrus Logic GD5446' ,
237 qxl2
: 'SPICE dual monitor' ,
238 qxl3
: 'SPICE three monitors' ,
239 qxl4
: 'SPICE four monitors' ,
240 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
241 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
242 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
243 serial3
: gettext ( 'Serial terminal' ) + ' 3'
246 render_kvm_language : function ( value
) {
248 return PVE
. Utils
. defaultText
;
250 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
252 return text
+ ' (' + value
+ ')' ;
257 kvm_keymap_array : function () {
258 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
259 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
260 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
266 render_console_viewer : function ( value
) {
267 if (! value
|| value
=== '__default__' ) {
268 return PVE
. Utils
. defaultText
+ ' (HTML5)' ;
269 } else if ( value
=== 'vv' ) {
270 return 'SPICE (remote-viewer)' ;
271 } else if ( value
=== 'html5' ) {
272 return 'HTML5 (noVNC)' ;
283 eu
: 'Euskera (Basque)' ,
288 nb
: 'Norwegian (Bokmal)' ,
289 nn
: 'Norwegian (Nynorsk)' ,
290 fa
: 'Persian (Farsi)' ,
292 pt_BR
: 'Portuguese (Brazil)' ,
300 render_language : function ( value
) {
302 return PVE
. Utils
. defaultText
+ ' (English)' ;
304 var text
= PVE
. Utils
. language_map
[ value
];
306 return text
+ ' (' + value
+ ')' ;
311 language_array : function () {
312 var data
= [[ '__default__' , PVE
. Utils
. render_language ( '' )]];
313 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
314 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
320 render_kvm_vga_driver : function ( value
) {
322 return PVE
. Utils
. defaultText
;
324 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
326 return text
+ ' (' + value
+ ')' ;
331 kvm_vga_driver_array : function () {
332 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
333 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
334 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
340 render_kvm_startup : function ( value
) {
341 var startup
= PVE
. Parser
. parseStartup ( value
);
344 if ( startup
. order
=== undefined ) {
347 res
+= startup
. order
;
349 if ( startup
. up
!== undefined ) {
350 res
+= ',up=' + startup
. up
;
352 if ( startup
. down
!== undefined ) {
353 res
+= ',down=' + startup
. down
;
360 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
363 authClear : function () {
364 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
367 // fixme: remove - not needed?
368 gridLineHeigh : function () {
376 extractRequestError : function ( result
, verbose
) {
377 var msg
= gettext ( 'Successful' );
379 if (! result
. success
) {
380 msg
= gettext ( "Unknown error" );
381 if ( result
. message
) {
382 msg
= result
. message
;
384 msg
+= ' (' + result
. status
+ ')' ;
387 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
389 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
390 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
391 Ext
. htmlEncode ( desc
);
399 extractFormActionError : function ( action
) {
401 switch ( action
. failureType
) {
402 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
403 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
405 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
406 msg
= gettext ( 'Connection error' );
407 var resp
= action
. response
;
408 if ( resp
. status
&& resp
. statusText
) {
409 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
412 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
413 case Ext
. form
. action
. Action
. SERVER_INVALID
:
414 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
421 API2Request : function ( reqOpts
) {
423 var newopts
= Ext
. apply ({
424 waitMsg
: gettext ( 'Please wait...' )
427 if (! newopts
. url
. match ( /^\/api2/ )) {
428 newopts
. url
= '/api2/extjs' + newopts
. url
;
430 delete newopts
. callback
;
432 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
434 success : function ( response
, options
) {
435 if ( options
. waitMsgTarget
) {
436 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
437 options
. waitMsgTarget
. setMasked ( false );
439 options
. waitMsgTarget
. setLoading ( false );
442 var result
= Ext
. decode ( response
. responseText
);
443 response
. result
= result
;
444 if (! result
. success
) {
445 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
446 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
447 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
450 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
451 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
453 failure : function ( response
, options
) {
454 if ( options
. waitMsgTarget
) {
455 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
456 options
. waitMsgTarget
. setMasked ( false );
458 options
. waitMsgTarget
. setLoading ( false );
461 response
. result
= {};
463 response
. result
= Ext
. decode ( response
. responseText
);
465 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
466 if ( response
. aborted
) {
467 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
468 } else if ( response
. timedout
) {
469 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
470 } else if ( response
. status
&& response
. statusText
) {
471 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
473 response
. htmlStatus
= msg
;
474 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
475 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
480 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
482 var target
= newopts
. waitMsgTarget
;
484 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
485 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
} );
487 // Note: ExtJS bug - this does not work when component is not rendered
488 target
. setLoading ( newopts
. waitMsg
);
491 Ext
. Ajax
. request ( newopts
);
494 assemble_field_data : function ( values
, data
) {
495 if ( Ext
. isObject ( data
)) {
496 Ext
. Object
. each ( data
, function ( name
, val
) {
497 if ( values
. hasOwnProperty ( name
)) {
498 var bucket
= values
[ name
];
499 if (! Ext
. isArray ( bucket
)) {
500 bucket
= values
[ name
] = [ bucket
];
502 if ( Ext
. isArray ( val
)) {
503 values
[ name
] = bucket
. concat ( val
);
514 checked_command : function ( orig_cmd
) {
515 PVE
. Utils
. API2Request ({
516 url
: '/nodes/localhost/subscription' ,
519 failure : function ( response
, opts
) {
520 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
522 success : function ( response
, opts
) {
523 var data
= response
. result
. data
;
525 if ( data
. status
!== 'Active' ) {
527 title
: gettext ( 'No valid subscription' ),
528 icon
: Ext
. Msg
. WARNING
,
529 msg
: PVE
. Utils
. noSubKeyHtml
,
531 callback : function ( btn
) {
546 diskinit
: [ 'Disk' , gettext ( 'Initialize GPT' ) ],
547 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
548 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
549 vncshell
: [ '' , gettext ( 'Shell' ) ],
550 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
551 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
552 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
553 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
554 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
555 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
556 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
557 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
558 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
559 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
560 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
561 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
562 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
563 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
564 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
565 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
566 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
567 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
568 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' ) ],
569 vzrollback
: [ 'CT' , gettext ( 'Rollback' ) ],
570 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' ) ],
571 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
572 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
573 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
574 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
575 vzclone
: [ 'CT' , gettext ( 'Clone' ) ],
576 vztemplate
: [ 'CT' , gettext ( 'Convert to template' ) ],
577 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
578 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
579 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
580 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
581 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
582 vzsuspend
: [ 'CT' , gettext ( 'Suspend' ) ],
583 vzresume
: [ 'CT' , gettext ( 'Resume' ) ],
584 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
585 hastart
: [ 'HA' , gettext ( 'Start' ) ],
586 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
587 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
588 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
589 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
590 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
591 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' ) ],
592 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' ) ],
593 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' ) ],
594 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' ) ],
595 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
596 imgdel
: [ '' , gettext ( 'Erase data' ) ],
597 download
: [ '' , gettext ( 'Download' ) ],
598 vzdump
: [ '' , gettext ( 'Backup' ) ],
599 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
600 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
601 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
602 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
605 format_task_description : function ( type
, id
) {
606 var farray
= PVE
. Utils
. task_desc_table
[ type
];
610 var prefix
= farray
[ 0 ];
611 var text
= farray
[ 1 ];
613 return prefix
+ ' ' + id
+ ' - ' + text
;
618 parse_task_upid : function ( upid
) {
621 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]+):$/ );
623 throw "unable to parse upid '" + upid
+ "'" ;
626 task
. pid
= parseInt ( res
[ 2 ], 16 );
627 task
. pstart
= parseInt ( res
[ 3 ], 16 );
628 task
. starttime
= parseInt ( res
[ 4 ], 16 );
633 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
638 format_size : function ( size
) {
639 /*jslint confusion: true */
641 var units
= [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ];
644 while ( size
>= 1024 && (( num
++)+ 1 ) < units
. length
) {
648 return size
. toFixed (( num
> 0 )? 2 : 0 ) + " " + units
[ num
] + "B" ;
651 format_html_bar : function ( per
, text
) {
653 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
654 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
659 format_cpu_bar : function ( per1
, per2
, text
) {
661 return "<div class='pve-bar-border'>" +
662 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
663 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
664 "<div class='pve-bar-text'>" + text
+ "</div>" +
668 format_large_bar : function ( per
, text
) {
671 text
= per
. toFixed ( 1 ) + "%" ;
674 return "<div class='pve-largebar-border'>" +
675 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
676 "<div class='pve-largebar-text'>" + text
+ "</div>" +
680 format_duration_long : function ( ut
) {
682 var days
= Math
. floor ( ut
/ 86400 );
684 var hours
= Math
. floor ( ut
/ 3600 );
686 var mins
= Math
. floor ( ut
/ 60 );
689 var hours_str
= '00' + hours
. toString ();
690 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
691 var mins_str
= "00" + mins
. toString ();
692 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
693 var ut_str
= "00" + ut
. toString ();
694 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
697 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
698 return days
. toString () + ' ' + ds
+ ' ' +
699 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
701 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
705 format_duration_short : function ( ut
) {
708 return ut
. toString () + 's' ;
713 return mins
. toFixed ( 0 ) + 'm' ;
717 var hours
= ut
/ 3600 ;
718 return hours
. toFixed ( 0 ) + 'h' ;
721 var days
= ut
/ 86400 ;
722 return days
. toFixed ( 0 ) + 'd' ;
725 yesText
: gettext ( 'Yes' ),
726 noText
: gettext ( 'No' ),
727 noneText
: gettext ( 'none' ),
728 errorText
: gettext ( 'Error' ),
729 unknownText
: gettext ( 'Unknown' ),
730 defaultText
: gettext ( 'Default' ),
731 daysText
: gettext ( 'days' ),
732 dayText
: gettext ( 'day' ),
733 runningText
: gettext ( 'running' ),
734 stoppedText
: gettext ( 'stopped' ),
735 neverText
: gettext ( 'never' ),
736 totalText
: gettext ( 'Total' ),
737 usedText
: gettext ( 'Used' ),
738 directoryText
: gettext ( 'Directory' ),
739 imagesText
: gettext ( 'Disk image' ),
740 backupFileText
: gettext ( 'VZDump backup file' ),
741 vztmplText
: gettext ( 'Container template' ),
742 isoImageText
: gettext ( 'ISO image' ),
743 containersText
: gettext ( 'Container' ),
744 stateText
: gettext ( 'State' ),
745 groupText
: gettext ( 'Group' ),
747 format_expire : function ( date
) {
749 return PVE
. Utils
. neverText
;
751 return Ext
. Date
. format ( date
, "Y-m-d" );
754 format_storage_type : function ( value
) {
755 if ( value
=== 'dir' ) {
756 return PVE
. Utils
. directoryText
;
757 } else if ( value
=== 'nfs' ) {
759 } else if ( value
=== 'glusterfs' ) {
761 } else if ( value
=== 'lvm' ) {
763 } else if ( value
=== 'lvmthin' ) {
765 } else if ( value
=== 'iscsi' ) {
767 } else if ( value
=== 'rbd' ) {
769 } else if ( value
=== 'sheepdog' ) {
771 } else if ( value
=== 'zfs' ) {
772 return 'ZFS over iSCSI' ;
773 } else if ( value
=== 'zfspool' ) {
775 } else if ( value
=== 'iscsidirect' ) {
776 return 'iSCSIDirect' ;
777 } else if ( value
=== 'drbd' ) {
780 return PVE
. Utils
. unknownText
;
784 format_boolean_with_default : function ( value
) {
785 if ( Ext
. isDefined ( value
) && value
!== '__default__' ) {
786 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
788 return PVE
. Utils
. defaultText
;
791 format_boolean : function ( value
) {
792 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
795 format_neg_boolean : function ( value
) {
796 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
799 format_ha : function ( value
) {
800 var text
= PVE
. Utils
. format_boolean ( value
. managed
);
803 text
+= ', ' + PVE
. Utils
. stateText
+ ': ' ;
804 text
+= value
. state
|| PVE
. Utils
. noneText
;
806 text
+= ', ' + PVE
. Utils
. groupText
+ ': ' ;
807 text
+= value
. group
|| PVE
. Utils
. noneText
;
813 format_content_types : function ( value
) {
816 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
817 if ( ct
=== 'images' ) {
818 cta
. push ( PVE
. Utils
. imagesText
);
819 } else if ( ct
=== 'backup' ) {
820 cta
. push ( PVE
. Utils
. backupFileText
);
821 } else if ( ct
=== 'vztmpl' ) {
822 cta
. push ( PVE
. Utils
. vztmplText
);
823 } else if ( ct
=== 'iso' ) {
824 cta
. push ( PVE
. Utils
. isoImageText
);
825 } else if ( ct
=== 'rootdir' ) {
826 cta
. push ( PVE
. Utils
. containersText
);
830 return cta
. join ( ', ' );
833 render_storage_content : function ( value
, metaData
, record
) {
834 var data
= record
. data
;
835 if ( Ext
. isNumber ( data
. channel
) &&
836 Ext
. isNumber ( data
. id
) &&
837 Ext
. isNumber ( data
. lun
)) {
839 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
840 " ID " + data
. id
+ " LUN " + data
. lun
;
842 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
845 render_serverity : function ( value
) {
846 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
849 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
851 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
855 var maxcpu
= record
. data
. maxcpu
|| 1 ;
857 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
861 var per
= value
* 100 ;
863 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
866 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
867 /*jslint confusion: true */
869 if (! Ext
. isNumeric ( value
)) {
873 return PVE
. Utils
. format_size ( value
);
876 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
877 var servertime
= new Date ( value
* 1000 );
878 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
881 calculate_mem_usage : function ( data
) {
882 if (! Ext
. isNumeric ( data
. mem
) ||
888 return ( data
. mem
/ data
. maxmem
);
891 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
892 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
896 // we got no percentage but bytes
898 var maxmem
= record
. data
. maxmem
;
899 if (! record
. data
. uptime
||
901 ! Ext
. isNumeric ( mem
)) {
905 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
907 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
910 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
913 var maxmem
= record
. data
. maxmem
;
915 if (! record
. data
. uptime
) {
919 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
923 return PVE
. Utils
. render_size ( value
);
926 calculate_disk_usage : function ( data
) {
928 if (! Ext
. isNumeric ( data
. disk
) ||
929 data
. type
=== 'qemu' ||
930 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
931 data
. maxdisk
=== 0 ) {
935 return ( data
. disk
/ data
. maxdisk
);
938 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
939 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
943 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
946 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
949 var maxdisk
= record
. data
. maxdisk
;
950 var type
= record
. data
. type
;
952 if (! Ext
. isNumeric ( disk
) ||
955 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
959 return PVE
. Utils
. render_size ( value
);
962 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
968 case 'lxc' : icon
= 'cube' ;
969 gridcls
= '-stopped' ;
971 case 'qemu' : icon
= 'desktop' ;
972 gridcls
= '-stopped' ;
974 case 'node' : icon
= 'building' ;
975 gridcls
= '-offline' ;
977 case 'storage' : icon
= 'database' ; break ;
978 case 'pool' : icon
= 'tags' ; break ;
979 default : icon
= 'file' ;
982 if ( value
=== 'lxc' || value
=== 'qemu' ) {
983 if ( record
. data
. running
&& record
. data
. status
!== 'paused' ) {
984 gridcls
= '-running' ;
985 } else if ( record
. data
. running
) {
988 if ( record
. data
. template
) {
990 gridcls
= '-template-' + value
;
992 } else if ( value
=== 'node' ) {
993 if ( record
. data
. running
) {
998 var fa
= '<i class="fa fa-fw x-fa-grid' + gridcls
+ ' fa-' + icon
+ '"></i> ' ;
1002 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1006 if ( uptime
=== undefined ) {
1014 return PVE
. Utils
. format_duration_long ( uptime
);
1017 render_support_level : function ( value
, metaData
, record
) {
1018 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
1021 render_upid : function ( value
, metaData
, record
) {
1022 var type
= record
. data
. type
;
1023 var id
= record
. data
. id
;
1025 return PVE
. Utils
. format_task_description ( type
, id
);
1028 /* render functions for new status panel */
1030 render_usage : function ( val
) {
1031 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
1034 render_cpu_usage : function ( val
, max
) {
1035 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
1036 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
1039 render_size_usage : function ( val
, max
) {
1040 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
1041 Ext
. String
. format ( gettext ( '{0} of {1}' ),
1042 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
1045 /* this is different for nodes */
1046 render_node_cpu_usage : function ( value
, record
) {
1047 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
1050 /* this is different for nodes */
1051 render_node_size_usage : function ( record
) {
1052 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
1055 dialog_title : function ( subject
, create
, isAdd
) {
1058 return gettext ( 'Add' ) + ': ' + subject
;
1060 return gettext ( 'Create' ) + ': ' + subject
;
1063 return gettext ( 'Edit' ) + ': ' + subject
;
1067 windowHostname : function () {
1068 return window
. location
. hostname
. replace ( IP6_bracket_match
,
1069 function ( m
, addr
, offset
, original
) { return addr
; });
1072 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
1073 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
1074 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
1077 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
1078 // kvm, lxc, shell, upgrade
1080 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
1081 throw "missing vmid" ;
1085 throw "no nodename specified" ;
1088 if ( viewer
=== 'html5' ) {
1089 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
1090 } else if ( viewer
=== 'vv' ) {
1092 var params
= { proxy
: PVE
. Utils
. windowHostname () };
1093 if ( vmtype
=== 'kvm' ) {
1094 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1095 PVE
. Utils
. openSpiceViewer ( url
, params
);
1096 } else if ( vmtype
=== 'lxc' ) {
1097 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1098 PVE
. Utils
. openSpiceViewer ( url
, params
);
1099 } else if ( vmtype
=== 'shell' ) {
1100 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1101 PVE
. Utils
. openSpiceViewer ( url
, params
);
1102 } else if ( vmtype
=== 'upgrade' ) {
1103 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1105 PVE
. Utils
. openSpiceViewer ( url
, params
);
1108 throw "unknown viewer type" ;
1112 defaultViewer : function ( allowSpice
) {
1113 var vncdefault
= 'html5' ;
1114 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
1115 if ( dv
=== 'vv' && ! allowSpice
) {
1122 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
1123 var url
= Ext
. urlEncode ({
1124 console
: vmtype
, // kvm, lxc, upgrade or shell
1130 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1134 openSpiceViewer : function ( url
, params
){
1136 var downloadWithName = function ( uri
, name
) {
1137 var link
= Ext
. DomHelper
. append ( document
. body
, {
1140 css
: 'display:none;visibility:hidden;height:0px;'
1143 // Note: we need to tell android the correct file name extension
1144 // but we do not set 'download' tag for other environments, because
1145 // It can have strange side effects (additional user prompt on firefox)
1146 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1148 link
. download
= name
;
1151 if ( link
. fireEvent
) {
1152 link
. fireEvent ( 'onclick' );
1154 var evt
= document
. createEvent ( "MouseEvents" );
1155 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1156 link
. dispatchEvent ( evt
);
1160 PVE
. Utils
. API2Request ({
1164 failure : function ( response
, opts
){
1165 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1167 success : function ( response
, opts
){
1168 var raw
= "[virt-viewer] \n " ;
1169 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1170 raw
+= k
+ "=" + v
+ " \n " ;
1172 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1173 encodeURIComponent ( raw
);
1175 downloadWithName ( url
, "pve-spice.vv" );
1180 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1181 // use el.mask() instead
1182 setErrorMask : function ( comp
, msg
) {
1191 el
. mask ( gettext ( "Loading..." ));
1198 monStoreErrors : function ( me
, store
) {
1199 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1200 if (! me
. loadCount
) {
1201 me
. loadCount
= 0 ; // make sure it is numeric
1202 PVE
. Utils
. setErrorMask ( me
, true );
1206 // only works with 'pve' proxy
1207 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1211 PVE
. Utils
. setErrorMask ( me
, false );
1216 /*jslint nomen: true */
1217 var operation
= request
. _operation
;
1218 var error
= operation
. getError ();
1219 if ( error
. statusText
) {
1220 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1222 msg
= gettext ( 'Connection error' );
1224 PVE
. Utils
. setErrorMask ( me
, msg
);
1228 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1230 var nodename
= record
. data
. node
;
1231 var vmid
= record
. data
. vmid
;
1232 var vmname
= record
. data
. name
;
1233 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1234 PVE
. Utils
. API2Request ({
1235 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1236 failure : function ( response
, opts
) {
1237 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1239 success : function ( response
, opts
) {
1240 var allowSpice
= response
. result
. data
. spice
;
1241 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
1244 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1245 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1249 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1251 if (!( v
instanceof Ext
. tree
. View
)) {
1256 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1257 menu
= Ext
. create ( 'PVE.qemu.CmdMenu' , {
1260 } else if ( record
. data
. type
=== 'qemu' && record
. data
. template
) {
1261 menu
= Ext
. create ( 'PVE.qemu.TemplateMenu' , {
1264 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1265 menu
= Ext
. create ( 'PVE.lxc.CmdMenu' , {
1268 } else if ( record
. data
. type
=== 'lxc' && record
. data
. template
) {
1269 /* since clone does not work reliably, disable for now
1270 menu = Ext.create('PVE.lxc.TemplateMenu', {
1279 menu
. showAt ( event
. getXY ());
1283 constructor : function () {
1285 Ext
. apply ( me
, me
. utilities
);