Commit 52815271 authored by Dietmar Maurer's avatar Dietmar Maurer

add ressource editor for openvz

parent 74d235cb
......@@ -415,14 +415,15 @@ __PACKAGE__->register_method({
}
$conf->{memory} = $veconf->{physpages}->{lim} ?
int($veconf->{physpages}->{lim} * 4096) : 512*1024*1024;
int(($veconf->{physpages}->{lim} * 4)/ 1024) : 512;
$conf->{swap} = $veconf->{swappages}->{lim} ?
int($veconf->{swappages}->{lim} * 4096) : 0;
int(($veconf->{swappages}->{lim} * 4)/1024) : 0;
my $diskspace = $veconf->{diskspace}->{bar} || LONG_MAX;
if ($diskspace == LONG_MAX) {
$conf->{disk} = 0;
} else {
$conf->{disk} = int($diskspace*1024);
$conf->{disk} = $diskspace/(1024*1024);
}
return $conf;
}});
......
......@@ -82,6 +82,8 @@ JSSRC= \
qemu/CreateWizard.js \
openvz/StatusView.js \
openvz/Summary.js \
openvz/RessourceEdit.js \
openvz/RessourceView.js \
openvz/Config.js \
openvz/CreateWizard.js \
storage/ContentView.js \
......
......@@ -27,6 +27,11 @@ Ext.define('PVE.openvz.Config', {
xtype: 'pveOpenVZSummary',
itemId: 'summary',
},
{
title: 'Ressources',
itemId: 'ressources',
xtype: 'pveOpenVZRessourceView'
},
{
title: 'Options',
itemId: 'options',
......
......@@ -124,50 +124,8 @@ Ext.define('PVE.openvz.CreateWizard', {
items: tmplsel
},
{
xtype: 'inputpanel',
xtype: 'pveOpenVZResourceInputPanel',
title: 'Resources',
column1: [
{
xtype: 'numberfield',
name: 'memory',
minValue: 32,
maxValue: 128*1024,
value: '512',
step: 32,
fieldLabel: 'Memory (MB)',
allowBlank: false
},
{
xtype: 'numberfield',
name: 'swap',
minValue: 0,
maxValue: 128*1024,
value: '512',
step: 32,
fieldLabel: 'Swap (MB)',
allowBlank: false
}
],
column2: [
{
xtype: 'numberfield',
name: 'disk',
minValue: 0.5,
value: '4',
step: 1,
fieldLabel: 'Disk space (GB)',
allowBlank: false
},
{
xtype: 'numberfield',
name: 'cpus',
minValue: 1,
value: '1',
step: 1,
fieldLabel: 'CPUs',
allowBlank: false
}
]
},
{
xtype: 'inputpanel',
......
Ext.define('PVE.openvz.RessourceInputPanel', {
extend: 'PVE.panel.InputPanel',
alias: 'widget.pveOpenVZResourceInputPanel',
insideWizard: false,
initComponent : function() {
var me = this;
me.column1 = [
{
xtype: 'numberfield',
name: 'memory',
minValue: 32,
maxValue: 128*1024,
value: '512',
step: 32,
fieldLabel: 'Memory (MB)',
allowBlank: false
},
{
xtype: 'numberfield',
name: 'swap',
minValue: 0,
maxValue: 128*1024,
value: '512',
step: 32,
fieldLabel: 'Swap (MB)',
allowBlank: false
}
];
me.column2 = [
{
xtype: 'numberfield',
name: 'disk',
minValue: 0.5,
value: '4',
step: 1,
fieldLabel: 'Disk space (GB)',
allowBlank: false
},
{
xtype: 'numberfield',
name: 'cpus',
minValue: 1,
value: '1',
step: 1,
fieldLabel: 'CPUs',
allowBlank: false
}
];
me.callParent();
}
});
Ext.define('PVE.openvz.RessourceEdit', {
extend: 'PVE.window.Edit',
initComponent : function() {
var me = this;
Ext.apply(me, {
title: "Edit ressource settings",
items: Ext.create('PVE.openvz.RessourceInputPanel')
});
me.callParent();
me.load();
}
});
\ No newline at end of file
// fixme: howto avoid jslint type confusion?
/*jslint confusion: true */
Ext.define('PVE.openvz.RessourceView', {
extend: 'PVE.grid.ObjectGrid',
alias: ['widget.pveOpenVZRessourceView'],
initComponent : function() {
var me = this;
var i, confid;
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 rows = {
memory: {
header: 'Memory',
editor: 'PVE.openvz.RessourceEdit',
never_delete: true,
renderer: function(value) {
return PVE.Utils.format_size(value*1024*1024);
}
},
swap: {
header: 'Swap',
editor: 'PVE.openvz.RessourceEdit',
never_delete: true,
renderer: function(value) {
return PVE.Utils.format_size(value*1024*1024);
}
},
cpus: {
header: 'Processors',
never_delete: true,
editor: 'PVE.openvz.RessourceEdit',
defaultValue: 1,
},
disk: {
header: 'Disk space',
editor: 'PVE.openvz.RessourceEdit',
never_delete: true,
renderer: function(value) {
return PVE.Utils.format_size(value*1024*1024*1024);
}
}
};
var reload = function() {
me.rstore.load();
};
var baseurl = 'nodes/' + nodename + '/openvz/' + vmid + '/config';
var run_editor = function() {
var sm = me.getSelectionModel();
var rec = sm.getSelection()[0];
if (!rec) {
return;
}
var rowdef = rows[rec.data.key];
if (!rowdef.editor) {
return;
}
var editor = rowdef.editor;
var win = Ext.create(editor, {
pveSelNode: me.pveSelNode,
confid: rec.data.key,
url: '/api2/extjs/' + baseurl
});
win.show();
win.on('destroy', reload);
};
var edit_btn = new Ext.Button({
text: 'Edit',
disabled: true,
handler: run_editor
});
var set_button_status = function() {
var sm = me.getSelectionModel();
var rec = sm.getSelection()[0];
if (!rec) {
edit_btn.disable();
return;
}
var rowdef = rows[rec.data.key];
edit_btn.setDisabled(!rowdef.editor);
};
Ext.applyIf(me, {
url: '/api2/json/' + baseurl,
cwidth1: 170,
tbar: [ edit_btn ],
rows: rows,
listeners: {
show: reload,
itemdblclick: run_editor,
selectionchange: set_button_status
}
});
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