]>
Commit | Line | Data |
---|---|---|
9b81768f | 1 | Ext.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, |
ed416f20 | 86 | loadNextGuestID: false, |
9f50d504 | 87 | store: vmidStore, |
9b81768f | 88 | validateExists: true |
b2f9a9e4 TL |
89 | }, |
90 | { | |
bf96f60d | 91 | xtype: 'proxmoxintegerfield', |
b2f9a9e4 TL |
92 | name: 'max_restart', |
93 | fieldLabel: gettext('Max. Restart'), | |
94 | value: 1, | |
95 | minValue: 0, | |
96 | maxValue: 10, | |
97 | allowBlank: false | |
98 | }, | |
99 | { | |
bf96f60d | 100 | xtype: 'proxmoxintegerfield', |
b2f9a9e4 TL |
101 | name: 'max_relocate', |
102 | fieldLabel: gettext('Max. Relocate'), | |
103 | value: 1, | |
104 | minValue: 0, | |
105 | maxValue: 10, | |
106 | allowBlank: false | |
9b81768f DM |
107 | } |
108 | ]; | |
a49cdcee | 109 | /*jslint confusion: false */ |
9b81768f DM |
110 | |
111 | me.column2 = [ | |
112 | { | |
113 | xtype: 'pveHAGroupSelector', | |
114 | name: 'group', | |
9b81768f DM |
115 | fieldLabel: gettext('Group') |
116 | }, | |
117 | { | |
09cacce7 | 118 | xtype: 'proxmoxKVComboBox', |
ecd45352 TL |
119 | name: 'state', |
120 | value: 'started', | |
121 | fieldLabel: gettext('Request State'), | |
122 | comboItems: [ | |
e49da95b DC |
123 | ['started', 'started'], |
124 | ['stopped', 'stopped'], | |
840cd466 | 125 | ['ignored', 'ignored'], |
e49da95b | 126 | ['disabled', 'disabled'] |
ecd45352 | 127 | ], |
390b8555 EK |
128 | listeners: { |
129 | 'change': function(field, newValue) { | |
ecd45352 | 130 | if (newValue === 'disabled') { |
390b8555 EK |
131 | disabledHint.setVisible(true); |
132 | } | |
133 | else { | |
134 | if (disabledHint.isVisible()) { | |
135 | disabledHint.setVisible(false); | |
136 | } | |
137 | } | |
138 | } | |
139 | } | |
140 | }, | |
141 | disabledHint | |
9b81768f DM |
142 | ]; |
143 | ||
144 | me.columnB = [ | |
145 | { | |
146 | xtype: 'textfield', | |
147 | name: 'comment', | |
148 | fieldLabel: gettext('Comment') | |
0a4651f0 EK |
149 | }, |
150 | fewVotesHint | |
9b81768f DM |
151 | ]; |
152 | ||
153 | me.callParent(); | |
154 | } | |
155 | }); | |
156 | ||
157 | Ext.define('PVE.ha.VMResourceEdit', { | |
9fccc702 | 158 | extend: 'Proxmox.window.Edit', |
9b81768f DM |
159 | |
160 | vmid: undefined, | |
ed416f20 | 161 | guestType: undefined, |
11480a8c | 162 | isCreate: undefined, |
9b81768f DM |
163 | |
164 | initComponent : function() { | |
165 | var me = this; | |
166 | ||
11480a8c TL |
167 | if (me.isCreate === undefined) { |
168 | me.isCreate = !me.vmid; | |
169 | } | |
9b81768f | 170 | |
d5e771ce | 171 | if (me.isCreate) { |
9b81768f DM |
172 | me.url = '/api2/extjs/cluster/ha/resources'; |
173 | me.method = 'POST'; | |
174 | } else { | |
175 | me.url = '/api2/extjs/cluster/ha/resources/' + me.vmid; | |
176 | me.method = 'PUT'; | |
177 | } | |
178 | ||
179 | var ipanel = Ext.create('PVE.ha.VMResourceInputPanel', { | |
d5e771ce | 180 | isCreate: me.isCreate, |
ed416f20 EK |
181 | vmid: me.vmid, |
182 | guestType: me.guestType | |
9b81768f DM |
183 | }); |
184 | ||
185 | Ext.apply(me, { | |
8f8ec25d EK |
186 | subject: gettext('Resource') + ': ' + gettext('Container') + |
187 | '/' + gettext('Virtual Machine'), | |
9b81768f DM |
188 | isAdd: true, |
189 | items: [ ipanel ] | |
190 | }); | |
191 | ||
192 | me.callParent(); | |
193 | ||
d5e771ce | 194 | if (!me.isCreate) { |
9b81768f DM |
195 | me.load({ |
196 | success: function(response, options) { | |
197 | var values = response.result.data; | |
198 | ||
9b81768f DM |
199 | var regex = /^(\S+):(\S+)$/; |
200 | var res = regex.exec(values.sid); | |
201 | ||
a764c5f7 DC |
202 | if (res[1] !== 'vm' && res[1] !== 'ct') { |
203 | throw "got unexpected resource type"; | |
204 | } | |
9b81768f DM |
205 | |
206 | values.vmid = res[2]; | |
207 | ||
208 | ipanel.setValues(values); | |
209 | } | |
210 | }); | |
211 | } | |
212 | } | |
213 | }); |