Commit 95855a83 authored by Dietmar Maurer's avatar Dietmar Maurer

implement Summary/Status view for OpenVZ

And add start/stop/shutdown/remove/console buttons.
parent 77b046eb
......@@ -80,7 +80,9 @@ JSSRC= \
qemu/Options.js \
qemu/Config.js \
qemu/CreateWizard.js \
openvz/Config.js \
openvz/StatusView.js \
openvz/Summary.js \
openvz/Config.js \
openvz/CreateWizard.js \
storage/ContentView.js \
storage/StatusView.js \
......
......@@ -24,9 +24,8 @@ Ext.define('PVE.openvz.Config', {
items: [
{
title: 'Summary',
//xtype: 'pveOpenvzSummary',
xtype: 'pveOpenVZSummary',
itemId: 'summary',
html: 'OpenVZ summary - not inplemented!'
},
{
title: 'Options',
......
Ext.define('PVE.openvz.StatusView', {
extend: 'PVE.grid.ObjectGrid',
initComponent : function() {
var me = this;
var nodename = me.pveSelNode.data.node;
if (!nodename) {
throw "no node name specified";
}
var vmid = me.pveSelNode.data.vmid;
if (!vmid) {
throw "no VM ID specified";
}
var render_cpu = function(value, metaData, record, rowIndex, colIndex, store) {
if (!me.getObjectValue('uptime')) {
return '-';
}
var maxcpu = me.getObjectValue('cpus', 1);
if (!(Ext.isNumeric(value) && Ext.isNumeric(maxcpu) && (maxcpu >= 1))) {
return '-';
}
var per = (value * 100) / maxcpu;
return per.toFixed(1) + '% of ' + maxcpu.toString() + (maxcpu > 1 ? 'CPUs' : 'CPU');
};
var render_mem = function(value, metaData, record, rowIndex, colIndex, store) {
var maxmem = me.getObjectValue('maxmem', 0);
var per = (value / maxmem)*100;
var text = "<div>Total: " + PVE.Utils.format_size(maxmem) + "</div>" +
"<div>Used: " + PVE.Utils.format_size(value) + "</div>";
return text;
};
var rows = {
name: { header: 'Name', defaultValue: 'no name specified' },
status: { header: 'Status', defaultValue: 'unknown' },
cpu: { header: 'CPU usage', required: true, renderer: render_cpu },
cpus: { visible: false },
mem: { header: 'Memory usage', required: true, renderer: render_mem },
maxmem: { visible: false },
uptime: { header: 'Uptime', required: true, renderer: PVE.Utils.render_uptime }
};
Ext.applyIf(me, {
url: "/api2/json/nodes/" + nodename + "/openvz/" + vmid + "/status/current",
cwidth1: 150,
height: 145,
interval: 1000,
rows: rows
});
me.callParent();
}
});
Ext.define('PVE.openvz.Summary', {
extend: 'Ext.panel.Panel',
alias: 'widget.pveOpenVZSummary',
initComponent: function() {
var me = this;
var nodename = me.pveSelNode.data.node;
if (!nodename) {
throw "no node name specified";
}
var vmid = me.pveSelNode.data.vmid;
if (!vmid) {
throw "no VM ID specified";
}
if (!me.workspace) {
throw "no workspace specified";
}
var statusview = Ext.create('PVE.openvz.StatusView', {
title: 'Status',
pveSelNode: me.pveSelNode,
width: 400
});
var rstore = statusview.rstore;
var rrdurl = "/api2/png/nodes/" + nodename + "/openvz/" + vmid + "/rrd";
var vm_command = function(cmd, params) {
PVE.Utils.API2Request({
params: params,
url: '/nodes/' + nodename + '/openvz/' + vmid + "/status/" + cmd,
waitMsgTarget: me,
method: 'POST',
failure: function(response, opts) {
Ext.Msg.alert('Error', response.htmlStatus);
}
});
};
var tbar = Ext.create('Ext.toolbar.Toolbar', {
items: [
{
itemId: 'start',
text: 'Start',
handler: function() {
vm_command('start');
}
},
{
itemId: 'stop',
text: 'Stop',
handler: function() {
var msg = "Do you really want to stop the VM?";
Ext.Msg.confirm('Confirm', msg, function(btn) {
if (btn !== 'yes') {
return;
}
vm_command("stop", { fast: 1 });
});
}
},
{
itemId: 'shutdown',
text: 'Shutdown',
handler: function() {
var msg = "Do you really want to shutdown the VM?";
Ext.Msg.confirm('Confirm', msg, function(btn) {
if (btn !== 'yes') {
return;
}
vm_command('stop');
});
}
},
{
itemId: 'remove',
text: 'Remove',
handler: function() {
var msg = 'Are you sure you want to remove VM ' +
vmid + '? This will permanently erase all VM data.';
Ext.Msg.confirm('Confirm', msg, function(btn) {
if (btn !== 'yes') {
return;
}
PVE.Utils.API2Request({
url: '/nodes/' + nodename + '/openvz/' + vmid,
method: 'DELETE',
waitMsgTarget: me,
failure: function(response, opts) {
Ext.Msg.alert('Error', response.htmlStatus);
}
});
});
}
},
{
itemId: 'console',
text: 'Console',
handler: function() {
var url = Ext.urlEncode({
console: 'kvm',
vmid: vmid,
node: nodename
});
var nw = window.open("?" + url, '_blank',
"innerWidth=745,innerheight=427");
nw.focus();
}
}, '->',
{
xtype: 'pveRRDTypeSelector'
}
]
});
me.mon(rstore, 'load', function(s, records, success) {
var status;
if (!success) {
me.workspace.checkVmMigration(me.pveSelNode);
status = 'unknown';
} else {
var rec = s.data.get('status');
status = rec ? rec.data.value : 'unknown';
}
tbar.down('#start').setDisabled(status === 'running');
tbar.down('#shutdown').setDisabled(status !== 'running');
tbar.down('#stop').setDisabled(status === 'stopped');
tbar.down('#console').setDisabled(status !== 'running');
tbar.down('#remove').setDisabled(status !== 'stopped');
});
var notesview = Ext.create('PVE.qemu.NotesView', {
pveSelNode: me.pveSelNode,
flex: 1
});
Ext.apply(me, {
tbar: tbar,
autoScroll: true,
bodyStyle: 'padding:10px',
defaults: {
style: 'padding-top:10px',
width: 800
},
items: [
{
style: 'padding-top:0px',
layout: {
type: 'hbox',
align: 'stretchmax'
},
border: false,
items: [ statusview, notesview ]
},
{
xtype: 'pveRRDView',
title: "CPU usage %",
pveSelNode: me.pveSelNode,
datasource: 'cpu',
rrdurl: rrdurl
},
{
xtype: 'pveRRDView',
title: "Memory usage",
pveSelNode: me.pveSelNode,
datasource: 'mem,maxmem',
rrdurl: rrdurl
},
]
});
me.on('show', function() {
rstore.startUpdate();
notesview.load();
});
me.on('hide', rstore.stopUpdate);
me.on('destroy', rstore.stopUpdate);
me.callParent();
}
});
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment