]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/MemoryEdit.js
fix #1629: improve min/max memory handling
[pve-manager.git] / www / manager6 / qemu / MemoryEdit.js
1 Ext.define('PVE.qemu.MemoryInputPanel', {
2 extend: 'Proxmox.panel.InputPanel',
3 alias: 'widget.pveQemuMemoryPanel',
4 onlineHelp: 'qm_memory',
5
6 insideWizard: false,
7
8 onGetValues: function(values) {
9 var me = this;
10
11 var res;
12
13 if (values.memoryType === 'fixed') {
14 res = { memory: values.memory };
15 if (values.ballooning === '1') {
16 // if balloning is active if it is not explicitely set
17 res['delete'] = "balloon,shares";
18 } else {
19 res['delete'] = "shares";
20 res.balloon = 0;
21 }
22 } else {
23 res = {
24 memory: values.maxmemory,
25 balloon: values.balloon
26 };
27 if (Ext.isDefined(values.shares) && (values.shares !== "")) {
28 res.shares = values.shares;
29 } else {
30 res['delete'] = "shares";
31 }
32 }
33
34 return res;
35 },
36
37 initComponent : function() {
38 var me = this;
39 var labelWidth = 160;
40
41 var items = [
42 {
43 xtype: 'radiofield',
44 name: 'memoryType',
45 inputValue: 'fixed',
46 boxLabel: gettext('Use fixed size memory'),
47 checked: true,
48 listeners: {
49 change: function(f, value) {
50 if (!me.rendered) {
51 return;
52 }
53 me.down('field[name=memory]').setDisabled(!value);
54 me.down('field[name=ballooning]').setDisabled(!value);
55 me.down('field[name=maxmemory]').setDisabled(value);
56 me.down('field[name=balloon]').setDisabled(value);
57 me.down('field[name=shares]').setDisabled(value);
58 }
59 }
60 },
61 {
62 xtype: 'pveMemoryField',
63 name: 'memory',
64 hotplug: me.hotplug,
65 fieldLabel: gettext('Memory') + ' (MiB)',
66 labelAlign: 'right',
67 labelWidth: labelWidth
68 },
69 {
70 xtype: 'proxmoxcheckbox',
71 hotplug: me.hotplug,
72 name: 'ballooning',
73 value: '1',
74 labelAlign: 'right',
75 labelWidth: labelWidth,
76 fieldLabel: gettext('Ballooning')
77 },
78 {
79 xtype: 'radiofield',
80 name: 'memoryType',
81 inputValue: 'dynamic',
82 boxLabel: gettext('Automatically allocate memory within this range'),
83 listeners: {
84 change: function(f, value) {
85 if (!me.rendered) {
86 return;
87 }
88 }
89 }
90 },
91 {
92 xtype: 'pveMemoryField',
93 name: 'maxmemory',
94 hotplug: me.hotplug,
95 disabled: true,
96 value: '1024',
97 fieldLabel: gettext('Maximum memory') + ' (MiB)',
98 labelAlign: 'right',
99 labelWidth: labelWidth,
100 listeners: {
101 change: function(f, value) {
102 var bf = me.down('field[name=balloon]');
103 var balloon = bf.getValue();
104 bf.setMaxValue(value);
105 bf.validate();
106 },
107 blur: function(f) {
108 var value = f.getValue();
109 var bf = me.down('field[name=balloon]');
110 var balloon = bf.getValue();
111 if (balloon > value) {
112 bf.setValue(value);
113 }
114 }
115 }
116 },
117 {
118 xtype: 'proxmoxintegerfield',
119 name: 'balloon',
120 disabled: true,
121 minValue: 0,
122 maxValue: 512*1024,
123 value: '512',
124 step: 32,
125 fieldLabel: gettext('Minimum memory') + ' (MiB)',
126 labelAlign: 'right',
127 labelWidth: labelWidth,
128 allowBlank: false
129 },
130 {
131 xtype: 'proxmoxintegerfield',
132 name: 'shares',
133 disabled: true,
134 minValue: 0,
135 maxValue: 50000,
136 value: '',
137 step: 10,
138 fieldLabel: gettext('Shares'),
139 labelAlign: 'right',
140 labelWidth: labelWidth,
141 allowBlank: true,
142 emptyText: Proxmox.Utils.defaultText + ' (1000)',
143 submitEmptyText: false
144 }
145 ];
146
147 if (me.insideWizard) {
148 me.column1 = items;
149 } else {
150 me.items = items;
151 }
152
153 me.callParent();
154 }
155 });
156
157 Ext.define('PVE.qemu.MemoryEdit', {
158 extend: 'Proxmox.window.Edit',
159
160 initComponent : function() {
161 var me = this;
162
163 var memoryhotplug;
164 if(me.hotplug) {
165 Ext.each(me.hotplug.split(','), function(el) {
166 if (el === 'memory') {
167 memoryhotplug = 1;
168 }
169 });
170 }
171
172 var ipanel = Ext.create('PVE.qemu.MemoryInputPanel', {
173 hotplug: memoryhotplug
174 });
175
176 Ext.apply(me, {
177 subject: gettext('Memory'),
178 items: [ ipanel ],
179 // uncomment the following to use the async configiguration API
180 // backgroundDelay: 5,
181 width: 400
182 });
183
184 me.callParent();
185
186 me.load({
187 success: function(response, options) {
188 var data = response.result.data;
189
190 var values = {
191 memory: data.memory,
192 maxmemory: data.memory,
193 balloon: data.balloon,
194 ballooning: data.balloon === 0 ? '0' : '1',
195 shares: data.shares,
196 memoryType: data.balloon ? 'dynamic' : 'fixed'
197 };
198 ipanel.setValues(values);
199 }
200 });
201 }
202 });