2015-09-23 18:54:43 +03:00
Ext . define ( 'PVE.VMSummaryBase' , {
extend : 'PVE.Page' ,
nodename : undefined ,
vmid : undefined ,
vmtype : undefined , // qemu or lxc
// defines the key/value config keys do display
config _keys : undefined ,
vm _command : function ( cmd , params ) {
var me = this ;
2018-01-26 10:52:55 +03:00
Proxmox . Utils . API2Request ( {
2015-09-23 18:54:43 +03:00
params : params ,
url : '/nodes/' + me . nodename + '/' + me . vmtype + '/' + me . vmid +
'/status/' + cmd ,
method : 'POST' ,
success : function ( response , opts ) {
var upid = response . result . data ;
var page = 'nodes/' + me . nodename + '/tasks/' + upid ;
PVE . Workspace . gotoPage ( page ) ;
} ,
failure : function ( response , opts ) {
Ext . Msg . alert ( 'Error' , response . htmlStatus ) ;
2023-05-28 20:03:20 +03:00
} ,
2015-09-23 18:54:43 +03:00
} ) ;
} ,
config : {
items : [
{
2023-05-28 20:03:20 +03:00
xtype : 'pveTitleBar' ,
2015-09-23 18:54:43 +03:00
} ,
{
xtype : 'component' ,
itemId : 'vmstatus' ,
styleHtmlContent : true ,
style : 'background-color:white;' ,
tpl : [
'<table style="margin-bottom:0px;">' ,
'<tr><td>Status:</td><td>{[this.status(values)]}</td></tr>' ,
'<tr><td>Memory:</td><td>{[this.meminfo(values)]}</td></tr>' ,
'<tr><td>CPU:</td><td>{[this.cpuinfo(values)]}</td></tr>' ,
2018-01-15 17:18:09 +03:00
'<tr><td>Uptime:</td><td>{[Proxmox.Utils.format_duration_long' +
2015-09-23 18:54:43 +03:00
'(values.uptime)]}</td></tr>' ,
'</table>' ,
{
meminfo : function ( values ) {
if ( ! Ext . isDefined ( values . mem ) ) {
return '-' ;
}
2018-01-15 17:18:09 +03:00
return Proxmox . Utils . format _size ( values . mem || 0 ) + " of " +
Proxmox . Utils . format _size ( values . maxmem ) ;
2015-09-23 18:54:43 +03:00
} ,
cpuinfo : function ( values ) {
if ( ! Ext . isDefined ( values . cpu ) ) {
return '-' ;
}
var per = values . cpu * 100 ;
return per . toFixed ( 2 ) + "% (" + values . cpus + " CPUs)" ;
} ,
status : function ( values ) {
2023-05-28 20:03:20 +03:00
return values . qmpstatus ? values . qmpstatus
: values . status ;
} ,
} ,
] ,
2015-09-23 18:54:43 +03:00
} ,
{
xtype : 'component' ,
cls : 'dark' ,
padding : 5 ,
2023-05-28 20:03:20 +03:00
html : gettext ( 'Configuration' ) ,
2015-09-23 18:54:43 +03:00
} ,
{
xtype : 'container' ,
scrollable : 'both' ,
flex : 1 ,
styleHtmlContent : true ,
itemId : 'vmconfig' ,
style : 'background-color:white;white-space:pre' ,
tpl : [
'<table style="margin-bottom:0px;">' ,
'<tpl for=".">' ,
'<tr><td>{key}</td><td>{value}</td></tr>' ,
'</tpl>' ,
2023-05-28 20:03:20 +03:00
'</table>' ,
] ,
} ,
] ,
2015-09-23 18:54:43 +03:00
} ,
reload : function ( ) {
var me = this ;
var vm _stat = me . down ( '#vmstatus' ) ;
var error _handler = function ( response ) {
me . setMasked ( { xtype : 'loadmask' , message : response . htmlStatus } ) ;
} ;
2018-01-26 10:52:55 +03:00
Proxmox . Utils . API2Request ( {
2015-09-23 18:54:43 +03:00
url : '/nodes/' + me . nodename + '/' + me . vmtype + '/' + me . vmid +
'/status/current' ,
method : 'GET' ,
success : function ( response ) {
var d = response . result . data ;
me . render _menu ( d ) ;
vm _stat . setData ( d ) ;
} ,
2023-05-28 20:03:20 +03:00
failure : error _handler ,
2015-09-23 18:54:43 +03:00
} ) ;
var vm _cfg = me . down ( '#vmconfig' ) ;
2018-01-26 10:52:55 +03:00
Proxmox . Utils . API2Request ( {
2015-09-23 18:54:43 +03:00
url : '/nodes/' + me . nodename + '/' + me . vmtype + '/' + me . vmid +
'/config' ,
method : 'GET' ,
success : function ( response ) {
var d = response . result . data ;
var kv = PVE . Workspace . obj _to _kv ( d , me . config _keys ) ;
vm _cfg . setData ( kv ) ;
} ,
2023-05-28 20:03:20 +03:00
failure : error _handler ,
2015-09-23 18:54:43 +03:00
} ) ;
} ,
render _menu : function ( data ) {
var me = this ;
// use two item arrays for format reasons.
// display start, stop and migrate by default
var top _items = [
{
text : gettext ( 'Start' ) ,
handler : function ( ) {
me . vm _command ( "start" , { } ) ;
2023-05-28 20:03:20 +03:00
} ,
2015-09-23 18:54:43 +03:00
} ,
{
text : gettext ( 'Stop' ) ,
handler : function ( ) {
me . vm _command ( "stop" , { } ) ;
2023-05-28 20:03:20 +03:00
} ,
} ,
2015-09-23 18:54:43 +03:00
] ;
var bottom _items = [ {
text : gettext ( 'Migrate' ) ,
handler : function ( ) {
PVE . Workspace . gotoPage ( 'nodes/' + me . nodename + '/' + me . vmtype +
'/' + me . vmid + '/migrate' ) ;
2023-05-28 20:03:20 +03:00
} ,
2015-09-23 18:54:43 +03:00
} ] ;
// use qmpstatus with qemu, as it's exacter
2023-05-28 20:03:20 +03:00
var vm _status = me . vmtype === 'qemu' ? data . qmpstatus : data . status ;
2015-09-23 18:54:43 +03:00
2023-05-28 20:03:20 +03:00
if ( vm _status === 'running' ) {
2015-09-23 18:54:43 +03:00
top _items . push (
{
text : gettext ( 'Shutdown' ) ,
handler : function ( ) {
me . vm _command ( "shutdown" , { } ) ;
2023-05-28 20:03:20 +03:00
} ,
2015-09-23 18:54:43 +03:00
} ,
{
text : gettext ( 'Suspend' ) ,
handler : function ( ) {
me . vm _command ( "suspend" , { } ) ;
2023-05-28 20:03:20 +03:00
} ,
} ,
2015-09-23 18:54:43 +03:00
) ;
bottom _items . push ( {
text : gettext ( 'Console' ) ,
handler : function ( ) {
var vmtype = me . vmtype === 'qemu' ? 'kvm' : me . vmtype ;
PVE . Utils . openConsoleWindow ( 'html5' , vmtype , me . vmid ,
me . nodename ) ;
2023-05-28 20:03:20 +03:00
} ,
2015-09-23 18:54:43 +03:00
} ) ;
2023-05-28 20:03:20 +03:00
if ( data . spice || me . vmtype === 'lxc' ) {
2015-09-23 18:54:43 +03:00
bottom _items . push ( {
text : gettext ( 'Spice' ) ,
handler : function ( ) {
var vmtype = me . vmtype === 'qemu' ? 'kvm' : me . vmtype ;
PVE . Utils . openConsoleWindow ( 'vv' , vmtype , me . vmid ,
me . nodename ) ;
2023-05-28 20:03:20 +03:00
} ,
2015-09-23 18:54:43 +03:00
} ) ;
}
2023-05-28 20:03:20 +03:00
} else if ( vm _status === 'paused' ) {
2015-09-23 18:54:43 +03:00
top _items . push ( {
text : gettext ( 'Resume' ) ,
handler : function ( ) {
me . vm _command ( "resume" , { } ) ;
2023-05-28 20:03:20 +03:00
} ,
2015-09-23 18:54:43 +03:00
} ) ;
}
// concat our item arrays and add them to the menu
me . down ( 'pveMenuButton' ) . setMenuItems ( top _items . concat ( bottom _items ) ) ;
} ,
initialize : function ( ) {
var me = this ;
me . reload ( ) ;
this . callParent ( ) ;
2023-05-28 20:03:20 +03:00
} ,
2015-09-23 18:54:43 +03:00
} ) ;