]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/ha/ResourceEdit.js
remove non-existant property
[pve-manager.git] / www / manager6 / ha / ResourceEdit.js
CommitLineData
9b81768f 1Ext.define('PVE.ha.VMResourceInputPanel', {
ef4ef788 2 extend: 'Proxmox.panel.InputPanel',
95cf0210 3 onlineHelp: 'ha_manager_resource_config',
9b81768f
DM
4 vmid: undefined,
5
6 onGetValues: function(values) {
7 var me = this;
8
11480a8c 9 if (values.vmid) {
9b81768f
DM
10 values.sid = values.vmid;
11 }
9b81768f
DM
12 delete values.vmid;
13
d5e771ce
EK
14 PVE.Utils.delete_if_default(values, 'group', '', me.isCreate);
15 PVE.Utils.delete_if_default(values, 'max_restart', '1', me.isCreate);
16 PVE.Utils.delete_if_default(values, 'max_relocate', '1', me.isCreate);
b2f9a9e4 17
9b81768f
DM
18 return values;
19 },
20
21 initComponent : function() {
22 var me = this;
0a4651f0 23 var MIN_QUORUM_VOTES = 3;
9b81768f 24
390b8555 25 var disabledHint = Ext.createWidget({
1c289bc8 26 xtype: 'displayfield', // won't get submitted by default
390b8555 27 userCls: 'pve-hint',
49e19905
DC
28 value: 'Disabling the resource will stop the guest system. ' +
29 'See the online help for details.',
390b8555
EK
30 hidden: true
31 });
32
0a4651f0
EK
33 var fewVotesHint = Ext.createWidget({
34 itemId: 'fewVotesHint',
35 xtype: 'displayfield',
36 userCls: 'pve-hint',
1c289bc8 37 value: 'At least three quorum votes are recommended for reliable HA.',
0a4651f0
EK
38 hidden: true
39 });
40
e7ade592 41 Proxmox.Utils.API2Request({
0a4651f0
EK
42 url: '/cluster/config/nodes',
43 method: 'GET',
44 failure: function(response) {
45 Ext.Msg.alert(gettext('Error'), response.htmlStatus);
46 },
47 success: function(response) {
48 var nodes = response.result.data;
49 var votes = 0;
50 Ext.Array.forEach(nodes, function(node) {
51 var vote = parseInt(node.quorum_votes, 10); // parse as base 10
52 votes += vote || 0; // parseInt might return NaN, which is false
53 });
54
55 if (votes < MIN_QUORUM_VOTES) {
0a4651f0
EK
56 fewVotesHint.setVisible(true);
57 }
58 }
59 });
60
a49cdcee 61 /*jslint confusion: true */
9f50d504
TL
62 var vmidStore = (me.vmid) ? {} : {
63 model: 'PVEResources',
64 autoLoad: true,
65 sorters: 'vmid',
66 filters: [
67 {
68 property: 'type',
69 value: /lxc|qemu/
70 },
71 {
72 property: 'hastate',
73 value: /unmanaged/
74 }
75 ]
76 };
77
78 // value is a string above, but a number below
9b81768f
DM
79 me.column1 = [
80 {
9f50d504
TL
81 xtype: me.vmid ? 'displayfield' : 'vmComboSelector',
82 submitValue: me.isCreate,
9b81768f 83 name: 'vmid',
ed416f20 84 fieldLabel: (me.vmid && me.guestType === 'ct') ? 'CT' : 'VM',
9b81768f 85 value: me.vmid,
9f50d504 86 store: vmidStore,
9b81768f 87 validateExists: true
b2f9a9e4
TL
88 },
89 {
bf96f60d 90 xtype: 'proxmoxintegerfield',
b2f9a9e4
TL
91 name: 'max_restart',
92 fieldLabel: gettext('Max. Restart'),
93 value: 1,
94 minValue: 0,
95 maxValue: 10,
96 allowBlank: false
97 },
98 {
bf96f60d 99 xtype: 'proxmoxintegerfield',
b2f9a9e4
TL
100 name: 'max_relocate',
101 fieldLabel: gettext('Max. Relocate'),
102 value: 1,
103 minValue: 0,
104 maxValue: 10,
105 allowBlank: false
9b81768f
DM
106 }
107 ];
a49cdcee 108 /*jslint confusion: false */
9b81768f
DM
109
110 me.column2 = [
111 {
112 xtype: 'pveHAGroupSelector',
113 name: 'group',
9b81768f
DM
114 fieldLabel: gettext('Group')
115 },
116 {
09cacce7 117 xtype: 'proxmoxKVComboBox',
ecd45352
TL
118 name: 'state',
119 value: 'started',
120 fieldLabel: gettext('Request State'),
121 comboItems: [
e49da95b
DC
122 ['started', 'started'],
123 ['stopped', 'stopped'],
840cd466 124 ['ignored', 'ignored'],
e49da95b 125 ['disabled', 'disabled']
ecd45352 126 ],
390b8555
EK
127 listeners: {
128 'change': function(field, newValue) {
ecd45352 129 if (newValue === 'disabled') {
390b8555
EK
130 disabledHint.setVisible(true);
131 }
132 else {
133 if (disabledHint.isVisible()) {
134 disabledHint.setVisible(false);
135 }
136 }
137 }
138 }
139 },
140 disabledHint
9b81768f
DM
141 ];
142
143 me.columnB = [
144 {
145 xtype: 'textfield',
146 name: 'comment',
147 fieldLabel: gettext('Comment')
0a4651f0
EK
148 },
149 fewVotesHint
9b81768f
DM
150 ];
151
152 me.callParent();
153 }
154});
155
156Ext.define('PVE.ha.VMResourceEdit', {
9fccc702 157 extend: 'Proxmox.window.Edit',
9b81768f
DM
158
159 vmid: undefined,
ed416f20 160 guestType: undefined,
11480a8c 161 isCreate: undefined,
9b81768f
DM
162
163 initComponent : function() {
164 var me = this;
165
11480a8c
TL
166 if (me.isCreate === undefined) {
167 me.isCreate = !me.vmid;
168 }
9b81768f 169
d5e771ce 170 if (me.isCreate) {
9b81768f
DM
171 me.url = '/api2/extjs/cluster/ha/resources';
172 me.method = 'POST';
173 } else {
174 me.url = '/api2/extjs/cluster/ha/resources/' + me.vmid;
175 me.method = 'PUT';
176 }
177
178 var ipanel = Ext.create('PVE.ha.VMResourceInputPanel', {
d5e771ce 179 isCreate: me.isCreate,
ed416f20
EK
180 vmid: me.vmid,
181 guestType: me.guestType
9b81768f
DM
182 });
183
184 Ext.apply(me, {
8f8ec25d
EK
185 subject: gettext('Resource') + ': ' + gettext('Container') +
186 '/' + gettext('Virtual Machine'),
9b81768f
DM
187 isAdd: true,
188 items: [ ipanel ]
189 });
190
191 me.callParent();
192
d5e771ce 193 if (!me.isCreate) {
9b81768f
DM
194 me.load({
195 success: function(response, options) {
196 var values = response.result.data;
197
9b81768f
DM
198 var regex = /^(\S+):(\S+)$/;
199 var res = regex.exec(values.sid);
200
a764c5f7
DC
201 if (res[1] !== 'vm' && res[1] !== 'ct') {
202 throw "got unexpected resource type";
203 }
9b81768f
DM
204
205 values.vmid = res[2];
206
207 ipanel.setValues(values);
208 }
209 });
210 }
211 }
212});