]>
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+)?$" );
67 'pve-admin-guide.html' : 'Proxmox VE Administration Guide' ,
68 'chapter-sysadmin.html' : 'Host System Administration' ,
69 'chapter-pvecm.html' : 'Cluster Manager' ,
70 'chapter-pmxcfs.html' : 'Proxmox Cluster File System (pmxcfs)' ,
71 'chapter-pvesm.html' : 'Proxmox VE Storage' ,
72 'chapter-qm.html' : 'Qemu/KVM Virtual Machines' ,
73 'chapter-pve-firewall.html' : 'Proxmox VE Firewall' ,
74 'chapter-pveum.html' : 'User Management' ,
75 'chapter-pct.html' : 'Proxmox Container Toolkit' ,
76 'chapter-ha-manager.html' : 'High Availability' ,
77 'chapter-vzdump.html' : 'Backup and Restore' ,
78 'chapter-pve-faq.html' : 'Frequently Asked Questions' ,
79 'chapter-pve-bibliography.html' : 'Bibliography' ,
80 'qm.1.html' : 'Qemu/KVM Virtual Machine Manager' ,
81 'qmrestore.1.html' : 'Restore QemuServer vzdump Backups' ,
82 'pct.1.html' : 'Tool to manage Linux Containers (LXC) on Proxmox VE' ,
83 'pveam.1.html' : 'Proxmox VE Appliance Manager' ,
84 'pveceph.1.html' : 'Manage CEPH Services on Proxmox VE Nodes' ,
85 'pvecm.1.html' : 'Proxmox VE Cluster Manager' ,
86 'pveum.1.html' : 'Proxmox VE User Manager' ,
87 'pvesm.1.html' : 'Proxmox VE Storage Manager' ,
88 'pvesubscription.1.html' : 'Proxmox VE Subscription Manager' ,
89 'vzdump.1.html' : 'Backup Utility for VMs and Containers' ,
90 'ha-manager.1.html' : 'Proxmox VE HA Manager' ,
92 'datacenter.cfg.5.html' : 'Proxmox VE Datacenter Configuration'
96 '_vm_container_configuration' : 'VM/Container configuration' ,
97 '_ip_aliases' : 'IP Aliases' ,
100 Ext
. define ( 'PVE.Utils' , { statics
: {
102 // this class only contains static functions
104 toolkit
: undefined , // (extjs|touch), set inside Toolkit.js
117 support_level_hash
: {
118 'c' : gettext ( 'Community' ),
119 'b' : gettext ( 'Basic' ),
120 's' : gettext ( 'Standard' ),
121 'p' : gettext ( 'Premium' )
124 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.' ,
127 other
: gettext ( 'Other OS types' ),
128 wxp
: 'Microsoft Windows XP/2003' ,
129 w2k
: 'Microsoft Windows 2000' ,
130 w2k8
: 'Microsoft Windows Vista/2008' ,
131 win7
: 'Microsoft Windows 7/2008r2' ,
132 win8
: 'Microsoft Windows 8.x/10/2012/r2' ,
133 l24
: 'Linux 2.4 Kernel' ,
134 l26
: 'Linux 4.X/3.X/2.6 Kernel' ,
135 solaris
: 'Solaris Kernel'
138 render_kvm_ostype : function ( value
) {
140 return gettext ( 'Other OS types' );
142 var text
= PVE
. Utils
. kvm_ostypes
[ value
];
149 render_hotplug_features : function ( value
) {
152 if (! value
|| ( value
=== '0' )) {
153 return gettext ( 'disabled' );
157 value
= 'disk,network,usb' ;
160 Ext
. each ( value
. split ( ',' ), function ( el
) {
162 fa
. push ( gettext ( 'Disk' ));
163 } else if ( el
=== 'network' ) {
164 fa
. push ( gettext ( 'Network' ));
165 } else if ( el
=== 'usb' ) {
166 fa
. push ( gettext ( 'USB' ));
167 } else if ( el
=== 'memory' ) {
168 fa
. push ( gettext ( 'Memory' ));
169 } else if ( el
=== 'cpu' ) {
170 fa
. push ( gettext ( 'CPU' ));
176 return fa
. join ( ', ' );
179 network_iface_types
: {
180 eth
: gettext ( "Network Device" ),
181 bridge
: 'Linux Bridge' ,
183 OVSBridge
: 'OVS Bridge' ,
186 OVSIntPort
: 'OVS IntPort'
189 render_network_iface_type : function ( value
) {
190 return PVE
. Utils
. network_iface_types
[ value
] ||
191 PVE
. Utils
. unknownText
;
194 render_qemu_bios : function ( value
) {
196 return PVE
. Utils
. defaultText
+ ' (SeaBIOS)' ;
197 } else if ( value
=== 'seabios' ) {
199 } else if ( value
=== 'ovmf' ) {
200 return "OVMF (UEFI)" ;
206 render_scsihw : function ( value
) {
208 return PVE
. Utils
. defaultText
+ ' (LSI 53C895A)' ;
209 } else if ( value
=== 'lsi' ) {
210 return 'LSI 53C895A' ;
211 } else if ( value
=== 'lsi53c810' ) {
213 } else if ( value
=== 'megasas' ) {
214 return 'MegaRAID SAS 8708EM2' ;
215 } else if ( value
=== 'virtio-scsi-pci' ) {
216 return 'VirtIO SCSI' ;
217 } else if ( value
=== 'virtio-scsi-single' ) {
218 return 'VirtIO SCSI single' ;
219 } else if ( value
=== 'pvscsi' ) {
220 return 'VMware PVSCSI' ;
226 // fixme: auto-generate this
227 // for now, please keep in sync with PVE::Tools::kvmkeymaps
232 'de-ch' : 'German (Swiss)' ,
233 'en-gb' : 'English (UK)' ,
234 'en-us' : 'English (USA)' ,
238 //fo: 'Faroe Islands',
240 'fr-be' : 'French (Belgium)' ,
241 'fr-ca' : 'French (Canada)' ,
242 'fr-ch' : 'French (Swiss)' ,
252 //'nl-be': 'Dutch (Belgium)',
256 'pt-br' : 'Portuguese (Brazil)' ,
265 std
: gettext ( 'Standard VGA' ),
266 vmware
: gettext ( 'VMware compatible' ),
267 cirrus
: 'Cirrus Logic GD5446' ,
269 qxl2
: 'SPICE dual monitor' ,
270 qxl3
: 'SPICE three monitors' ,
271 qxl4
: 'SPICE four monitors' ,
272 serial0
: gettext ( 'Serial terminal' ) + ' 0' ,
273 serial1
: gettext ( 'Serial terminal' ) + ' 1' ,
274 serial2
: gettext ( 'Serial terminal' ) + ' 2' ,
275 serial3
: gettext ( 'Serial terminal' ) + ' 3'
278 render_kvm_language : function ( value
) {
280 return PVE
. Utils
. defaultText
;
282 var text
= PVE
. Utils
. kvm_keymaps
[ value
];
284 return text
+ ' (' + value
+ ')' ;
289 kvm_keymap_array : function () {
290 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_language ( '' )]];
291 Ext
. Object
. each ( PVE
. Utils
. kvm_keymaps
, function ( key
, value
) {
292 data
. push ([ key
, PVE
. Utils
. render_kvm_language ( value
)]);
298 render_console_viewer : function ( value
) {
299 if (! value
|| value
=== '__default__' ) {
300 return PVE
. Utils
. defaultText
+ ' (HTML5)' ;
301 } else if ( value
=== 'vv' ) {
302 return 'SPICE (remote-viewer)' ;
303 } else if ( value
=== 'html5' ) {
304 return 'HTML5 (noVNC)' ;
315 eu
: 'Euskera (Basque)' ,
320 nb
: 'Norwegian (Bokmal)' ,
321 nn
: 'Norwegian (Nynorsk)' ,
322 fa
: 'Persian (Farsi)' ,
324 pt_BR
: 'Portuguese (Brazil)' ,
332 render_language : function ( value
) {
334 return PVE
. Utils
. defaultText
+ ' (English)' ;
336 var text
= PVE
. Utils
. language_map
[ value
];
338 return text
+ ' (' + value
+ ')' ;
343 language_array : function () {
344 var data
= [[ '__default__' , PVE
. Utils
. render_language ( '' )]];
345 Ext
. Object
. each ( PVE
. Utils
. language_map
, function ( key
, value
) {
346 data
. push ([ key
, PVE
. Utils
. render_language ( value
)]);
352 render_kvm_vga_driver : function ( value
) {
354 return PVE
. Utils
. defaultText
;
356 var text
= PVE
. Utils
. kvm_vga_drivers
[ value
];
358 return text
+ ' (' + value
+ ')' ;
363 kvm_vga_driver_array : function () {
364 var data
= [[ '__default__' , PVE
. Utils
. render_kvm_vga_driver ( '' )]];
365 Ext
. Object
. each ( PVE
. Utils
. kvm_vga_drivers
, function ( key
, value
) {
366 data
. push ([ key
, PVE
. Utils
. render_kvm_vga_driver ( value
)]);
372 render_kvm_startup : function ( value
) {
373 var startup
= PVE
. Parser
. parseStartup ( value
);
376 if ( startup
. order
=== undefined ) {
379 res
+= startup
. order
;
381 if ( startup
. up
!== undefined ) {
382 res
+= ',up=' + startup
. up
;
384 if ( startup
. down
!== undefined ) {
385 res
+= ',down=' + startup
. down
;
392 return Ext
. util
. Cookies
. get ( 'PVEAuthCookie' );
395 authClear : function () {
396 Ext
. util
. Cookies
. clear ( "PVEAuthCookie" );
399 // fixme: remove - not needed?
400 gridLineHeigh : function () {
408 extractRequestError : function ( result
, verbose
) {
409 var msg
= gettext ( 'Successful' );
411 if (! result
. success
) {
412 msg
= gettext ( "Unknown error" );
413 if ( result
. message
) {
414 msg
= result
. message
;
416 msg
+= ' (' + result
. status
+ ')' ;
419 if ( verbose
&& Ext
. isObject ( result
. errors
)) {
421 Ext
. Object
. each ( result
. errors
, function ( prop
, desc
) {
422 msg
+= "<br><b>" + Ext
. htmlEncode ( prop
) + "</b>: " +
423 Ext
. htmlEncode ( desc
);
431 extractFormActionError : function ( action
) {
433 switch ( action
. failureType
) {
434 case Ext
. form
. action
. Action
. CLIENT_INVALID
:
435 msg
= gettext ( 'Form fields may not be submitted with invalid values' );
437 case Ext
. form
. action
. Action
. CONNECT_FAILURE
:
438 msg
= gettext ( 'Connection error' );
439 var resp
= action
. response
;
440 if ( resp
. status
&& resp
. statusText
) {
441 msg
+= " " + resp
. status
+ ": " + resp
. statusText
;
444 case Ext
. form
. action
. Action
. LOAD_FAILURE
:
445 case Ext
. form
. action
. Action
. SERVER_INVALID
:
446 msg
= PVE
. Utils
. extractRequestError ( action
. result
, true );
453 API2Request : function ( reqOpts
) {
455 var newopts
= Ext
. apply ({
456 waitMsg
: gettext ( 'Please wait...' )
459 if (! newopts
. url
. match ( /^\/api2/ )) {
460 newopts
. url
= '/api2/extjs' + newopts
. url
;
462 delete newopts
. callback
;
464 var createWrapper = function ( successFn
, callbackFn
, failureFn
) {
466 success : function ( response
, options
) {
467 if ( options
. waitMsgTarget
) {
468 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
469 options
. waitMsgTarget
. setMasked ( false );
471 options
. waitMsgTarget
. setLoading ( false );
474 var result
= Ext
. decode ( response
. responseText
);
475 response
. result
= result
;
476 if (! result
. success
) {
477 response
. htmlStatus
= PVE
. Utils
. extractRequestError ( result
, true );
478 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
479 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
482 Ext
. callback ( callbackFn
, options
. scope
, [ options
, true , response
]);
483 Ext
. callback ( successFn
, options
. scope
, [ response
, options
]);
485 failure : function ( response
, options
) {
486 if ( options
. waitMsgTarget
) {
487 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
488 options
. waitMsgTarget
. setMasked ( false );
490 options
. waitMsgTarget
. setLoading ( false );
493 response
. result
= {};
495 response
. result
= Ext
. decode ( response
. responseText
);
497 var msg
= gettext ( 'Connection error' ) + ' - server offline?' ;
498 if ( response
. aborted
) {
499 msg
= gettext ( 'Connection error' ) + ' - aborted.' ;
500 } else if ( response
. timedout
) {
501 msg
= gettext ( 'Connection error' ) + ' - Timeout.' ;
502 } else if ( response
. status
&& response
. statusText
) {
503 msg
= gettext ( 'Connection error' ) + ' ' + response
. status
+ ': ' + response
. statusText
;
505 response
. htmlStatus
= msg
;
506 Ext
. callback ( callbackFn
, options
. scope
, [ options
, false , response
]);
507 Ext
. callback ( failureFn
, options
. scope
, [ response
, options
]);
512 createWrapper ( reqOpts
. success
, reqOpts
. callback
, reqOpts
. failure
);
514 var target
= newopts
. waitMsgTarget
;
516 if ( PVE
. Utils
. toolkit
=== 'touch' ) {
517 target
. setMasked ({ xtype
: 'loadmask' , message
: newopts
. waitMsg
} );
519 // Note: ExtJS bug - this does not work when component is not rendered
520 target
. setLoading ( newopts
. waitMsg
);
523 Ext
. Ajax
. request ( newopts
);
526 assemble_field_data : function ( values
, data
) {
527 if ( Ext
. isObject ( data
)) {
528 Ext
. Object
. each ( data
, function ( name
, val
) {
529 if ( values
. hasOwnProperty ( name
)) {
530 var bucket
= values
[ name
];
531 if (! Ext
. isArray ( bucket
)) {
532 bucket
= values
[ name
] = [ bucket
];
534 if ( Ext
. isArray ( val
)) {
535 values
[ name
] = bucket
. concat ( val
);
546 checked_command : function ( orig_cmd
) {
547 PVE
. Utils
. API2Request ({
548 url
: '/nodes/localhost/subscription' ,
551 failure : function ( response
, opts
) {
552 Ext
. Msg
. alert ( gettext ( 'Error' ), response
. htmlStatus
);
554 success : function ( response
, opts
) {
555 var data
= response
. result
. data
;
557 if ( data
. status
!== 'Active' ) {
559 title
: gettext ( 'No valid subscription' ),
560 icon
: Ext
. Msg
. WARNING
,
561 msg
: PVE
. Utils
. noSubKeyHtml
,
563 callback : function ( btn
) {
578 diskinit
: [ 'Disk' , gettext ( 'Initialize GPT' ) ],
579 vncproxy
: [ 'VM/CT' , gettext ( 'Console' ) ],
580 spiceproxy
: [ 'VM/CT' , gettext ( 'Console' ) + ' (Spice)' ],
581 vncshell
: [ '' , gettext ( 'Shell' ) ],
582 spiceshell
: [ '' , gettext ( 'Shell' ) + ' (Spice)' ],
583 qmsnapshot
: [ 'VM' , gettext ( 'Snapshot' ) ],
584 qmrollback
: [ 'VM' , gettext ( 'Rollback' ) ],
585 qmdelsnapshot
: [ 'VM' , gettext ( 'Delete Snapshot' ) ],
586 qmcreate
: [ 'VM' , gettext ( 'Create' ) ],
587 qmrestore
: [ 'VM' , gettext ( 'Restore' ) ],
588 qmdestroy
: [ 'VM' , gettext ( 'Destroy' ) ],
589 qmigrate
: [ 'VM' , gettext ( 'Migrate' ) ],
590 qmclone
: [ 'VM' , gettext ( 'Clone' ) ],
591 qmmove
: [ 'VM' , gettext ( 'Move disk' ) ],
592 qmtemplate
: [ 'VM' , gettext ( 'Convert to template' ) ],
593 qmstart
: [ 'VM' , gettext ( 'Start' ) ],
594 qmstop
: [ 'VM' , gettext ( 'Stop' ) ],
595 qmreset
: [ 'VM' , gettext ( 'Reset' ) ],
596 qmshutdown
: [ 'VM' , gettext ( 'Shutdown' ) ],
597 qmsuspend
: [ 'VM' , gettext ( 'Suspend' ) ],
598 qmresume
: [ 'VM' , gettext ( 'Resume' ) ],
599 qmconfig
: [ 'VM' , gettext ( 'Configure' ) ],
600 vzsnapshot
: [ 'CT' , gettext ( 'Snapshot' ) ],
601 vzrollback
: [ 'CT' , gettext ( 'Rollback' ) ],
602 vzdelsnapshot
: [ 'CT' , gettext ( 'Delete Snapshot' ) ],
603 vzcreate
: [ 'CT' , gettext ( 'Create' ) ],
604 vzrestore
: [ 'CT' , gettext ( 'Restore' ) ],
605 vzdestroy
: [ 'CT' , gettext ( 'Destroy' ) ],
606 vzmigrate
: [ 'CT' , gettext ( 'Migrate' ) ],
607 vzclone
: [ 'CT' , gettext ( 'Clone' ) ],
608 vztemplate
: [ 'CT' , gettext ( 'Convert to template' ) ],
609 vzstart
: [ 'CT' , gettext ( 'Start' ) ],
610 vzstop
: [ 'CT' , gettext ( 'Stop' ) ],
611 vzmount
: [ 'CT' , gettext ( 'Mount' ) ],
612 vzumount
: [ 'CT' , gettext ( 'Unmount' ) ],
613 vzshutdown
: [ 'CT' , gettext ( 'Shutdown' ) ],
614 vzsuspend
: [ 'CT' , gettext ( 'Suspend' ) ],
615 vzresume
: [ 'CT' , gettext ( 'Resume' ) ],
616 hamigrate
: [ 'HA' , gettext ( 'Migrate' ) ],
617 hastart
: [ 'HA' , gettext ( 'Start' ) ],
618 hastop
: [ 'HA' , gettext ( 'Stop' ) ],
619 srvstart
: [ 'SRV' , gettext ( 'Start' ) ],
620 srvstop
: [ 'SRV' , gettext ( 'Stop' ) ],
621 srvrestart
: [ 'SRV' , gettext ( 'Restart' ) ],
622 srvreload
: [ 'SRV' , gettext ( 'Reload' ) ],
623 cephcreatemon
: [ 'Ceph Monitor' , gettext ( 'Create' ) ],
624 cephdestroymon
: [ 'Ceph Monitor' , gettext ( 'Destroy' ) ],
625 cephcreateosd
: [ 'Ceph OSD' , gettext ( 'Create' ) ],
626 cephdestroyosd
: [ 'Ceph OSD' , gettext ( 'Destroy' ) ],
627 imgcopy
: [ '' , gettext ( 'Copy data' ) ],
628 imgdel
: [ '' , gettext ( 'Erase data' ) ],
629 download
: [ '' , gettext ( 'Download' ) ],
630 vzdump
: [ '' , gettext ( 'Backup' ) ],
631 aptupdate
: [ '' , gettext ( 'Update package database' ) ],
632 startall
: [ '' , gettext ( 'Start all VMs and Containers' ) ],
633 stopall
: [ '' , gettext ( 'Stop all VMs and Containers' ) ],
634 migrateall
: [ '' , gettext ( 'Migrate all VMs and Containers' ) ]
637 format_task_description : function ( type
, id
) {
638 var farray
= PVE
. Utils
. task_desc_table
[ type
];
642 var prefix
= farray
[ 0 ];
643 var text
= farray
[ 1 ];
645 return prefix
+ ' ' + id
+ ' - ' + text
;
650 parse_task_upid : function ( upid
) {
653 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]+):$/ );
655 throw "unable to parse upid '" + upid
+ "'" ;
658 task
. pid
= parseInt ( res
[ 2 ], 16 );
659 task
. pstart
= parseInt ( res
[ 3 ], 16 );
660 task
. starttime
= parseInt ( res
[ 4 ], 16 );
665 task
. desc
= PVE
. Utils
. format_task_description ( task
. type
, task
. id
);
670 format_size : function ( size
) {
671 /*jslint confusion: true */
673 var units
= [ '' , 'Ki' , 'Mi' , 'Gi' , 'Ti' , 'Pi' , 'Ei' , 'Zi' , 'Yi' ];
676 while ( size
>= 1024 && (( num
++)+ 1 ) < units
. length
) {
680 return size
. toFixed (( num
> 0 )? 2 : 0 ) + " " + units
[ num
] + "B" ;
683 format_html_bar : function ( per
, text
) {
685 return "<div class='pve-bar-wrap'>" + text
+ "<div class='pve-bar-border'>" +
686 "<div class='pve-bar-inner' style='width:" + per
+ "%;'></div>" +
691 format_cpu_bar : function ( per1
, per2
, text
) {
693 return "<div class='pve-bar-border'>" +
694 "<div class='pve-bar-inner' style='width:" + per1
+ "%;'></div>" +
695 "<div class='pve-bar-inner2' style='width:" + per2
+ "%;'></div>" +
696 "<div class='pve-bar-text'>" + text
+ "</div>" +
700 format_large_bar : function ( per
, text
) {
703 text
= per
. toFixed ( 1 ) + "%" ;
706 return "<div class='pve-largebar-border'>" +
707 "<div class='pve-largebar-inner' style='width:" + per
+ "%;'></div>" +
708 "<div class='pve-largebar-text'>" + text
+ "</div>" +
712 format_duration_long : function ( ut
) {
714 var days
= Math
. floor ( ut
/ 86400 );
716 var hours
= Math
. floor ( ut
/ 3600 );
718 var mins
= Math
. floor ( ut
/ 60 );
721 var hours_str
= '00' + hours
. toString ();
722 hours_str
= hours_str
. substr ( hours_str
. length
- 2 );
723 var mins_str
= "00" + mins
. toString ();
724 mins_str
= mins_str
. substr ( mins_str
. length
- 2 );
725 var ut_str
= "00" + ut
. toString ();
726 ut_str
= ut_str
. substr ( ut_str
. length
- 2 );
729 var ds
= days
> 1 ? PVE
. Utils
. daysText
: PVE
. Utils
. dayText
;
730 return days
. toString () + ' ' + ds
+ ' ' +
731 hours_str
+ ':' + mins_str
+ ':' + ut_str
;
733 return hours_str
+ ':' + mins_str
+ ':' + ut_str
;
737 format_duration_short : function ( ut
) {
740 return ut
. toString () + 's' ;
745 return mins
. toFixed ( 0 ) + 'm' ;
749 var hours
= ut
/ 3600 ;
750 return hours
. toFixed ( 0 ) + 'h' ;
753 var days
= ut
/ 86400 ;
754 return days
. toFixed ( 0 ) + 'd' ;
757 yesText
: gettext ( 'Yes' ),
758 noText
: gettext ( 'No' ),
759 noneText
: gettext ( 'none' ),
760 errorText
: gettext ( 'Error' ),
761 unknownText
: gettext ( 'Unknown' ),
762 defaultText
: gettext ( 'Default' ),
763 daysText
: gettext ( 'days' ),
764 dayText
: gettext ( 'day' ),
765 runningText
: gettext ( 'running' ),
766 stoppedText
: gettext ( 'stopped' ),
767 neverText
: gettext ( 'never' ),
768 totalText
: gettext ( 'Total' ),
769 usedText
: gettext ( 'Used' ),
770 directoryText
: gettext ( 'Directory' ),
771 imagesText
: gettext ( 'Disk image' ),
772 backupFileText
: gettext ( 'VZDump backup file' ),
773 vztmplText
: gettext ( 'Container template' ),
774 isoImageText
: gettext ( 'ISO image' ),
775 containersText
: gettext ( 'Container' ),
776 stateText
: gettext ( 'State' ),
777 groupText
: gettext ( 'Group' ),
779 format_expire : function ( date
) {
781 return PVE
. Utils
. neverText
;
783 return Ext
. Date
. format ( date
, "Y-m-d" );
786 format_storage_type : function ( value
) {
787 if ( value
=== 'dir' ) {
788 return PVE
. Utils
. directoryText
;
789 } else if ( value
=== 'nfs' ) {
791 } else if ( value
=== 'glusterfs' ) {
793 } else if ( value
=== 'lvm' ) {
795 } else if ( value
=== 'lvmthin' ) {
797 } else if ( value
=== 'iscsi' ) {
799 } else if ( value
=== 'rbd' ) {
801 } else if ( value
=== 'sheepdog' ) {
803 } else if ( value
=== 'zfs' ) {
804 return 'ZFS over iSCSI' ;
805 } else if ( value
=== 'zfspool' ) {
807 } else if ( value
=== 'iscsidirect' ) {
808 return 'iSCSIDirect' ;
809 } else if ( value
=== 'drbd' ) {
812 return PVE
. Utils
. unknownText
;
816 format_boolean_with_default : function ( value
) {
817 if ( Ext
. isDefined ( value
) && value
!== '__default__' ) {
818 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
820 return PVE
. Utils
. defaultText
;
823 format_boolean : function ( value
) {
824 return value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
827 format_neg_boolean : function ( value
) {
828 return ! value
? PVE
. Utils
. yesText
: PVE
. Utils
. noText
;
831 format_ha : function ( value
) {
832 var text
= PVE
. Utils
. format_boolean ( value
. managed
);
835 text
+= ', ' + PVE
. Utils
. stateText
+ ': ' ;
836 text
+= value
. state
|| PVE
. Utils
. noneText
;
838 text
+= ', ' + PVE
. Utils
. groupText
+ ': ' ;
839 text
+= value
. group
|| PVE
. Utils
. noneText
;
845 format_content_types : function ( value
) {
848 Ext
. each ( value
. split ( ',' ). sort (), function ( ct
) {
849 if ( ct
=== 'images' ) {
850 cta
. push ( PVE
. Utils
. imagesText
);
851 } else if ( ct
=== 'backup' ) {
852 cta
. push ( PVE
. Utils
. backupFileText
);
853 } else if ( ct
=== 'vztmpl' ) {
854 cta
. push ( PVE
. Utils
. vztmplText
);
855 } else if ( ct
=== 'iso' ) {
856 cta
. push ( PVE
. Utils
. isoImageText
);
857 } else if ( ct
=== 'rootdir' ) {
858 cta
. push ( PVE
. Utils
. containersText
);
862 return cta
. join ( ', ' );
865 render_storage_content : function ( value
, metaData
, record
) {
866 var data
= record
. data
;
867 if ( Ext
. isNumber ( data
. channel
) &&
868 Ext
. isNumber ( data
. id
) &&
869 Ext
. isNumber ( data
. lun
)) {
871 Ext
. String
. leftPad ( data
. channel
, 2 , '0' ) +
872 " ID " + data
. id
+ " LUN " + data
. lun
;
874 return data
. volid
. replace ( /^.*:(.*\/)?/ , '' );
877 render_serverity : function ( value
) {
878 return PVE
. Utils
. log_severity_hash
[ value
] || value
;
881 render_cpu : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
883 if (!( record
. data
. uptime
&& Ext
. isNumeric ( value
))) {
887 var maxcpu
= record
. data
. maxcpu
|| 1 ;
889 if (! Ext
. isNumeric ( maxcpu
) && ( maxcpu
>= 1 )) {
893 var per
= value
* 100 ;
895 return per
. toFixed ( 1 ) + '% of ' + maxcpu
. toString () + ( maxcpu
> 1 ? 'CPUs' : 'CPU' );
898 render_size : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
899 /*jslint confusion: true */
901 if (! Ext
. isNumeric ( value
)) {
905 return PVE
. Utils
. format_size ( value
);
908 render_timestamp : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
909 var servertime
= new Date ( value
* 1000 );
910 return Ext
. Date
. format ( servertime
, 'Y-m-d H:i:s' );
913 calculate_mem_usage : function ( data
) {
914 if (! Ext
. isNumeric ( data
. mem
) ||
920 return ( data
. mem
/ data
. maxmem
);
923 render_mem_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
924 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
928 // we got no percentage but bytes
930 var maxmem
= record
. data
. maxmem
;
931 if (! record
. data
. uptime
||
933 ! Ext
. isNumeric ( mem
)) {
937 return (( mem
* 100 )/ maxmem
). toFixed ( 1 ) + " %" ;
939 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
942 render_mem_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
945 var maxmem
= record
. data
. maxmem
;
947 if (! record
. data
. uptime
) {
951 if (!( Ext
. isNumeric ( mem
) && maxmem
)) {
955 return PVE
. Utils
. render_size ( value
);
958 calculate_disk_usage : function ( data
) {
960 if (! Ext
. isNumeric ( data
. disk
) ||
961 data
. type
=== 'qemu' ||
962 ( data
. type
=== 'lxc' && data
. uptime
=== 0 ) ||
963 data
. maxdisk
=== 0 ) {
967 return ( data
. disk
/ data
. maxdisk
);
970 render_disk_usage_percent : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
971 if (! Ext
. isNumeric ( value
) || value
=== - 1 ) {
975 return ( value
* 100 ). toFixed ( 1 ) + " %" ;
978 render_disk_usage : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
981 var maxdisk
= record
. data
. maxdisk
;
982 var type
= record
. data
. type
;
984 if (! Ext
. isNumeric ( disk
) ||
987 ( type
=== 'lxc' && record
. data
. uptime
=== 0 )) {
991 return PVE
. Utils
. render_size ( value
);
994 render_resource_type : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1000 case 'lxc' : icon
= 'cube' ;
1001 gridcls
= '-stopped' ;
1003 case 'qemu' : icon
= 'desktop' ;
1004 gridcls
= '-stopped' ;
1006 case 'node' : icon
= 'building' ;
1007 gridcls
= '-offline' ;
1009 case 'storage' : icon
= 'database' ; break ;
1010 case 'pool' : icon
= 'tags' ; break ;
1011 default : icon
= 'file' ;
1014 if ( value
=== 'lxc' || value
=== 'qemu' ) {
1015 if ( record
. data
. running
&& record
. data
. status
!== 'paused' ) {
1016 gridcls
= '-running' ;
1017 } else if ( record
. data
. running
) {
1018 gridcls
= '-paused' ;
1020 if ( record
. data
. template
) {
1022 gridcls
= '-template-' + value
;
1024 } else if ( value
=== 'node' ) {
1025 if ( record
. data
. running
) {
1026 gridcls
= '-online' ;
1030 var fa
= '<i class="fa fa-fw x-fa-grid' + gridcls
+ ' fa-' + icon
+ '"></i> ' ;
1034 render_uptime : function ( value
, metaData
, record
, rowIndex
, colIndex
, store
) {
1038 if ( uptime
=== undefined ) {
1046 return PVE
. Utils
. format_duration_long ( uptime
);
1049 render_support_level : function ( value
, metaData
, record
) {
1050 return PVE
. Utils
. support_level_hash
[ value
] || '-' ;
1053 render_upid : function ( value
, metaData
, record
) {
1054 var type
= record
. data
. type
;
1055 var id
= record
. data
. id
;
1057 return PVE
. Utils
. format_task_description ( type
, id
);
1060 /* render functions for new status panel */
1062 render_usage : function ( val
) {
1063 return ( val
* 100 ). toFixed ( 2 ) + '%' ;
1066 render_cpu_usage : function ( val
, max
) {
1067 return Ext
. String
. format ( gettext ( '{0}% of {1}' ) +
1068 ' ' + gettext ( 'CPU(s)' ), ( val
* 100 ). toFixed ( 2 ), max
);
1071 render_size_usage : function ( val
, max
) {
1072 return ( val
* 100 / max
). toFixed ( 2 ) + '% ' + '(' +
1073 Ext
. String
. format ( gettext ( '{0} of {1}' ),
1074 PVE
. Utils
. render_size ( val
), PVE
. Utils
. render_size ( max
)) + ')' ;
1077 /* this is different for nodes */
1078 render_node_cpu_usage : function ( value
, record
) {
1079 return PVE
. Utils
. render_cpu_usage ( value
, record
. cpus
);
1082 /* this is different for nodes */
1083 render_node_size_usage : function ( record
) {
1084 return PVE
. Utils
. render_size_usage ( record
. used
, record
. total
);
1087 dialog_title : function ( subject
, create
, isAdd
) {
1090 return gettext ( 'Add' ) + ': ' + subject
;
1092 return gettext ( 'Create' ) + ': ' + subject
;
1095 return gettext ( 'Edit' ) + ': ' + subject
;
1099 windowHostname : function () {
1100 return window
. location
. hostname
. replace ( IP6_bracket_match
,
1101 function ( m
, addr
, offset
, original
) { return addr
; });
1104 openDefaultConsoleWindow : function ( allowSpice
, vmtype
, vmid
, nodename
, vmname
) {
1105 var dv
= PVE
. Utils
. defaultViewer ( allowSpice
);
1106 PVE
. Utils
. openConsoleWindow ( dv
, vmtype
, vmid
, nodename
, vmname
);
1109 openConsoleWindow : function ( viewer
, vmtype
, vmid
, nodename
, vmname
) {
1110 // kvm, lxc, shell, upgrade
1112 if ( vmid
== undefined && ( vmtype
=== 'kvm' || vmtype
=== 'lxc' )) {
1113 throw "missing vmid" ;
1117 throw "no nodename specified" ;
1120 if ( viewer
=== 'html5' ) {
1121 PVE
. Utils
. openVNCViewer ( vmtype
, vmid
, nodename
, vmname
);
1122 } else if ( viewer
=== 'vv' ) {
1124 var params
= { proxy
: PVE
. Utils
. windowHostname () };
1125 if ( vmtype
=== 'kvm' ) {
1126 url
= '/nodes/' + nodename
+ '/qemu/' + vmid
. toString () + '/spiceproxy' ;
1127 PVE
. Utils
. openSpiceViewer ( url
, params
);
1128 } else if ( vmtype
=== 'lxc' ) {
1129 url
= '/nodes/' + nodename
+ '/lxc/' + vmid
. toString () + '/spiceproxy' ;
1130 PVE
. Utils
. openSpiceViewer ( url
, params
);
1131 } else if ( vmtype
=== 'shell' ) {
1132 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1133 PVE
. Utils
. openSpiceViewer ( url
, params
);
1134 } else if ( vmtype
=== 'upgrade' ) {
1135 url
= '/nodes/' + nodename
+ '/spiceshell' ;
1137 PVE
. Utils
. openSpiceViewer ( url
, params
);
1140 throw "unknown viewer type" ;
1144 defaultViewer : function ( allowSpice
) {
1145 var vncdefault
= 'html5' ;
1146 var dv
= PVE
. VersionInfo
. console
|| vncdefault
;
1147 if ( dv
=== 'vv' && ! allowSpice
) {
1154 openVNCViewer : function ( vmtype
, vmid
, nodename
, vmname
) {
1155 var url
= Ext
. urlEncode ({
1156 console
: vmtype
, // kvm, lxc, upgrade or shell
1162 var nw
= window
. open ( "?" + url
, '_blank' , "innerWidth=745,innerheight=427" );
1166 openSpiceViewer : function ( url
, params
){
1168 var downloadWithName = function ( uri
, name
) {
1169 var link
= Ext
. DomHelper
. append ( document
. body
, {
1172 css
: 'display:none;visibility:hidden;height:0px;'
1175 // Note: we need to tell android the correct file name extension
1176 // but we do not set 'download' tag for other environments, because
1177 // It can have strange side effects (additional user prompt on firefox)
1178 var andriod
= navigator
. userAgent
. match ( /Android/i ) ? true : false ;
1180 link
. download
= name
;
1183 if ( link
. fireEvent
) {
1184 link
. fireEvent ( 'onclick' );
1186 var evt
= document
. createEvent ( "MouseEvents" );
1187 evt
. initMouseEvent ( 'click' , true , true , window
, 1 , 0 , 0 , 0 , 0 , false , false , false , false , 0 , null );
1188 link
. dispatchEvent ( evt
);
1192 PVE
. Utils
. API2Request ({
1196 failure : function ( response
, opts
){
1197 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1199 success : function ( response
, opts
){
1200 var raw
= "[virt-viewer] \n " ;
1201 Ext
. Object
. each ( response
. result
. data
, function ( k
, v
) {
1202 raw
+= k
+ "=" + v
+ " \n " ;
1204 var url
= 'data:application/x-virt-viewer;charset=UTF-8,' +
1205 encodeURIComponent ( raw
);
1207 downloadWithName ( url
, "pve-spice.vv" );
1212 // comp.setLoading() is buggy in ExtJS 4.0.7, so we
1213 // use el.mask() instead
1214 setErrorMask : function ( comp
, msg
) {
1223 el
. mask ( gettext ( "Loading..." ));
1230 monStoreErrors : function ( me
, store
) {
1231 me
. mon ( store
, 'beforeload' , function ( s
, operation
, eOpts
) {
1232 if (! me
. loadCount
) {
1233 me
. loadCount
= 0 ; // make sure it is numeric
1234 PVE
. Utils
. setErrorMask ( me
, true );
1238 // only works with 'pve' proxy
1239 me
. mon ( store
. proxy
, 'afterload' , function ( proxy
, request
, success
) {
1243 PVE
. Utils
. setErrorMask ( me
, false );
1248 /*jslint nomen: true */
1249 var operation
= request
. _operation
;
1250 var error
= operation
. getError ();
1251 if ( error
. statusText
) {
1252 msg
= error
. statusText
+ ' (' + error
. status
+ ')' ;
1254 msg
= gettext ( 'Connection error' );
1256 PVE
. Utils
. setErrorMask ( me
, msg
);
1260 openTreeConsole : function ( tree
, record
, item
, index
, e
) {
1262 var nodename
= record
. data
. node
;
1263 var vmid
= record
. data
. vmid
;
1264 var vmname
= record
. data
. name
;
1265 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1266 PVE
. Utils
. API2Request ({
1267 url
: '/nodes/' + nodename
+ '/qemu/' + vmid
+ '/status/current' ,
1268 failure : function ( response
, opts
) {
1269 Ext
. Msg
. alert ( 'Error' , response
. htmlStatus
);
1271 success : function ( response
, opts
) {
1272 var allowSpice
= response
. result
. data
. spice
;
1273 PVE
. Utils
. openDefaultConsoleWindow ( allowSpice
, 'kvm' , vmid
, nodename
, vmname
);
1276 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1277 PVE
. Utils
. openDefaultConsoleWindow ( true , 'lxc' , vmid
, nodename
, vmname
);
1281 createCmdMenu : function ( v
, record
, item
, index
, event
) {
1283 if (!( v
instanceof Ext
. tree
. View
)) {
1288 if ( record
. data
. type
=== 'qemu' && ! record
. data
. template
) {
1289 menu
= Ext
. create ( 'PVE.qemu.CmdMenu' , {
1292 } else if ( record
. data
. type
=== 'qemu' && record
. data
. template
) {
1293 menu
= Ext
. create ( 'PVE.qemu.TemplateMenu' , {
1296 } else if ( record
. data
. type
=== 'lxc' && ! record
. data
. template
) {
1297 menu
= Ext
. create ( 'PVE.lxc.CmdMenu' , {
1300 } else if ( record
. data
. type
=== 'lxc' && record
. data
. template
) {
1301 /* since clone does not work reliably, disable for now
1302 menu = Ext.create('PVE.lxc.TemplateMenu', {
1311 menu
. showAt ( event
. getXY ());
1314 mapDocsUrlToTitle : function ( url
) {
1315 var title
, subtitle
;
1316 // if there is a subtitle
1317 if ( url
. indexOf ( '#' ) !== - 1 ) {
1318 title
= DocsPages
[ url
. split ( '#' )[ 0 ]] || '' ;
1319 subtitle
= DocsSubTitles
[ url
. split ( '#' )[ 1 ]];
1321 // if we do not find the subtitle,
1322 // capitalize the beginning of every word
1323 // and replace '_' with ' '
1325 // '_my_text' -> 'My Text'
1327 subtitle
= url
. split ( '#' )[ 1 ]. replace ( /_(\w)/gi , function ( match
, p1
){
1328 return ' ' + p1
. toUpperCase ();
1338 title
= DocsPages
[ url
] || '' ;