]> git.proxmox.com Git - proxmox-widget-toolkit.git/blame - src/node/NetworkEdit.js
vlan edit: Move example from default value to tooltip
[proxmox-widget-toolkit.git] / src / node / NetworkEdit.js
CommitLineData
a58001dd
DM
1Ext.define('Proxmox.node.NetworkEdit', {
2 extend: 'Proxmox.window.Edit',
3 alias: ['widget.proxmoxNodeNetworkEdit'],
4
01031528 5 initComponent: function() {
05a977a2 6 let me = this;
a58001dd
DM
7
8 if (!me.nodename) {
9 throw "no node name specified";
10 }
11
12 if (!me.iftype) {
13 throw "no network device type specified";
14 }
15
b33f451f 16 me.isCreate = !me.iface;
a58001dd 17
05a977a2 18 let iface_vtype;
a58001dd
DM
19
20 if (me.iftype === 'bridge') {
21 iface_vtype = 'BridgeName';
22 } else if (me.iftype === 'bond') {
23 iface_vtype = 'BondName';
b33f451f 24 } else if (me.iftype === 'eth' && !me.isCreate) {
a58001dd 25 iface_vtype = 'InterfaceName';
8aefd47c
AD
26 } else if (me.iftype === 'vlan') {
27 iface_vtype = 'VlanName';
a58001dd
DM
28 } else if (me.iftype === 'OVSBridge') {
29 iface_vtype = 'BridgeName';
30 } else if (me.iftype === 'OVSBond') {
31 iface_vtype = 'BondName';
32 } else if (me.iftype === 'OVSIntPort') {
33 iface_vtype = 'InterfaceName';
34 } else if (me.iftype === 'OVSPort') {
35 iface_vtype = 'InterfaceName';
36 } else {
37 console.log(me.iftype);
38 throw "unknown network device type specified";
39 }
40
41 me.subject = Proxmox.Utils.render_network_iface_type(me.iftype);
42
5c833def
TL
43 let column1 = [],
44 column2 = [],
1aaba242 45 columnB = [],
5c833def
TL
46 advancedColumn1 = [],
47 advancedColumn2 = [];
a58001dd 48
5c833def 49 if (!(me.iftype === 'OVSIntPort' || me.iftype === 'OVSPort' || me.iftype === 'OVSBond')) {
a58001dd 50 column2.push({
fccec7c6 51 xtype: 'proxmoxcheckbox',
a58001dd
DM
52 fieldLabel: gettext('Autostart'),
53 name: 'autostart',
54 uncheckedValue: 0,
01031528 55 checked: me.isCreate ? true : undefined,
a58001dd
DM
56 });
57 }
58
59 if (me.iftype === 'bridge') {
60 column2.push({
fccec7c6 61 xtype: 'proxmoxcheckbox',
a58001dd
DM
62 fieldLabel: gettext('VLAN aware'),
63 name: 'bridge_vlan_aware',
01031528 64 deleteEmpty: !me.isCreate,
a58001dd
DM
65 });
66 column2.push({
67 xtype: 'textfield',
68 fieldLabel: gettext('Bridge ports'),
01031528 69 name: 'bridge_ports',
a58001dd
DM
70 });
71 } else if (me.iftype === 'OVSBridge') {
72 column2.push({
73 xtype: 'textfield',
74 fieldLabel: gettext('Bridge ports'),
01031528 75 name: 'ovs_ports',
a58001dd
DM
76 });
77 column2.push({
78 xtype: 'textfield',
79 fieldLabel: gettext('OVS options'),
01031528 80 name: 'ovs_options',
a58001dd
DM
81 });
82 } else if (me.iftype === 'OVSPort' || me.iftype === 'OVSIntPort') {
83 column2.push({
b33f451f 84 xtype: me.isCreate ? 'PVE.form.BridgeSelector' : 'displayfield',
a58001dd
DM
85 fieldLabel: Proxmox.Utils.render_network_iface_type('OVSBridge'),
86 allowBlank: false,
87 nodename: me.nodename,
88 bridgeType: 'OVSBridge',
01031528 89 name: 'ovs_bridge',
a58001dd
DM
90 });
91 column2.push({
92 xtype: 'pveVlanField',
b33f451f 93 deleteEmpty: !me.isCreate,
a58001dd 94 name: 'ovs_tag',
01031528 95 value: '',
a58001dd
DM
96 });
97 column2.push({
98 xtype: 'textfield',
99 fieldLabel: gettext('OVS options'),
01031528 100 name: 'ovs_options',
a58001dd 101 });
8aefd47c 102 } else if (me.iftype === 'vlan') {
ea7da80c 103 if (!me.isCreate) {
ea7da80c
TL
104 me.disablevlanid = false;
105 me.disablevlanrawdevice = false;
106 me.vlanrawdevicevalue = '';
107 me.vlanidvalue = '';
8aefd47c 108
ea7da80c
TL
109 if (Proxmox.Utils.VlanInterface_match.test(me.iface)) {
110 me.disablevlanid = true;
111 me.disablevlanrawdevice = true;
05a977a2 112 let arr = Proxmox.Utils.VlanInterface_match.exec(me.iface);
ea7da80c
TL
113 me.vlanrawdevicevalue = arr[1];
114 me.vlanidvalue = arr[2];
ea7da80c
TL
115 } else if (Proxmox.Utils.Vlan_match.test(me.iface)) {
116 me.disablevlanid = true;
05a977a2 117 let arr = Proxmox.Utils.Vlan_match.exec(me.iface);
ea7da80c
TL
118 me.vlanidvalue = arr[1];
119 }
120 } else {
ea7da80c
TL
121 me.disablevlanid = true;
122 me.disablevlanrawdevice = true;
8aefd47c
AD
123 }
124
125 column2.push({
126 xtype: 'textfield',
127 fieldLabel: gettext('Vlan raw device'),
128 name: 'vlan-raw-device',
ea7da80c 129 value: me.vlanrawdevicevalue,
01031528 130 disabled: me.disablevlanrawdevice,
418ec858 131 allowBlank: false,
8aefd47c
AD
132 });
133
134 column2.push({
135 xtype: 'pveVlanField',
136 name: 'vlan-id',
ea7da80c 137 value: me.vlanidvalue,
01031528 138 disabled: me.disablevlanid,
1aaba242 139 });
8aefd47c 140
1aaba242
TL
141 columnB.push({
142 xtype: 'label',
143 userCls: 'pmx-hint',
144 text: 'Either add the VLAN number to an existing interface name, or choose your own name and set the VLAN raw device (for the latter ifupdown1 supports vlanXY naming only)',
8aefd47c 145 });
a58001dd
DM
146 } else if (me.iftype === 'bond') {
147 column2.push({
148 xtype: 'textfield',
149 fieldLabel: gettext('Slaves'),
01031528 150 name: 'slaves',
a58001dd
DM
151 });
152
05a977a2 153 let policySelector = Ext.createWidget('bondPolicySelector', {
a58001dd
DM
154 fieldLabel: gettext('Hash policy'),
155 name: 'bond_xmit_hash_policy',
b33f451f 156 deleteEmpty: !me.isCreate,
01031528 157 disabled: true,
a58001dd
DM
158 });
159
05a977a2 160 let primaryfield = Ext.createWidget('textfield', {
0915cbb1 161 fieldLabel: 'bond-primary',
b154853a
AD
162 name: 'bond-primary',
163 value: '',
01031528 164 disabled: true,
b154853a
AD
165 });
166
a58001dd
DM
167 column2.push({
168 xtype: 'bondModeSelector',
169 fieldLabel: gettext('Mode'),
170 name: 'bond_mode',
b33f451f 171 value: me.isCreate ? 'balance-rr' : undefined,
a58001dd
DM
172 listeners: {
173 change: function(f, value) {
174 if (value === 'balance-xor' ||
175 value === '802.3ad') {
176 policySelector.setDisabled(false);
b154853a
AD
177 primaryfield.setDisabled(true);
178 primaryfield.setValue('');
179 } else if (value === 'active-backup') {
180 primaryfield.setDisabled(false);
181 policySelector.setDisabled(true);
182 policySelector.setValue('');
a58001dd
DM
183 } else {
184 policySelector.setDisabled(true);
185 policySelector.setValue('');
b154853a
AD
186 primaryfield.setDisabled(true);
187 primaryfield.setValue('');
a58001dd 188 }
01031528 189 },
a58001dd 190 },
01031528 191 allowBlank: false,
a58001dd
DM
192 });
193
194 column2.push(policySelector);
b154853a 195 column2.push(primaryfield);
a58001dd
DM
196 } else if (me.iftype === 'OVSBond') {
197 column2.push({
b33f451f 198 xtype: me.isCreate ? 'PVE.form.BridgeSelector' : 'displayfield',
a58001dd
DM
199 fieldLabel: Proxmox.Utils.render_network_iface_type('OVSBridge'),
200 allowBlank: false,
201 nodename: me.nodename,
202 bridgeType: 'OVSBridge',
01031528 203 name: 'ovs_bridge',
a58001dd
DM
204 });
205 column2.push({
206 xtype: 'pveVlanField',
b33f451f 207 deleteEmpty: !me.isCreate,
a58001dd 208 name: 'ovs_tag',
01031528 209 value: '',
a58001dd
DM
210 });
211 column2.push({
212 xtype: 'textfield',
213 fieldLabel: gettext('OVS options'),
01031528 214 name: 'ovs_options',
a58001dd
DM
215 });
216 }
217
218 column2.push({
219 xtype: 'textfield',
220 fieldLabel: gettext('Comment'),
221 allowBlank: true,
222 nodename: me.nodename,
01031528 223 name: 'comments',
a58001dd
DM
224 });
225
05a977a2
TL
226 let url;
227 let method;
a58001dd 228
b33f451f 229 if (me.isCreate) {
a58001dd
DM
230 url = "/api2/extjs/nodes/" + me.nodename + "/network";
231 method = 'POST';
232 } else {
233 url = "/api2/extjs/nodes/" + me.nodename + "/network/" + me.iface;
234 method = 'PUT';
235 }
236
5c833def 237 column1.push({
ea7da80c
TL
238 xtype: 'hiddenfield',
239 name: 'type',
01031528 240 value: me.iftype,
ea7da80c
TL
241 },
242 {
243 xtype: me.isCreate ? 'textfield' : 'displayfield',
244 fieldLabel: gettext('Name'),
245 name: 'iface',
246 value: me.iface,
247 vtype: iface_vtype,
248 allowBlank: false,
4ed84281
DJ
249 autoEl: {
250 tag: 'div',
251 'data-qtip': gettext('For example, vmbr0.100, vmbr0, vlan0.100, vlan0'),
252 },
ea7da80c
TL
253 listeners: {
254 change: function(f, value) {
255 if (me.isCreate && iface_vtype === 'VlanName') {
05a977a2
TL
256 let vlanidField = me.down('field[name=vlan-id]');
257 let vlanrawdeviceField = me.down('field[name=vlan-raw-device]');
ea7da80c
TL
258 if (Proxmox.Utils.VlanInterface_match.test(value)) {
259 vlanidField.setDisabled(true);
260 vlanrawdeviceField.setDisabled(true);
261 } else if (Proxmox.Utils.Vlan_match.test(value)) {
262 vlanidField.setDisabled(true);
263 vlanrawdeviceField.setDisabled(false);
264 } else {
265 vlanidField.setDisabled(false);
266 vlanrawdeviceField.setDisabled(false);
267 }
268 }
01031528
TL
269 },
270 },
5c833def 271 });
a58001dd
DM
272
273 if (me.iftype === 'OVSBond') {
274 column1.push(
275 {
276 xtype: 'bondModeSelector',
277 fieldLabel: gettext('Mode'),
278 name: 'bond_mode',
279 openvswitch: true,
b33f451f 280 value: me.isCreate ? 'active-backup' : undefined,
01031528 281 allowBlank: false,
a58001dd
DM
282 },
283 {
284 xtype: 'textfield',
285 fieldLabel: gettext('Slaves'),
01031528
TL
286 name: 'ovs_bonds',
287 },
a58001dd
DM
288 );
289 } else {
a58001dd
DM
290 column1.push(
291 {
a0ec1620 292 xtype: 'proxmoxtextfield',
b33f451f 293 deleteEmpty: !me.isCreate,
8e2d096c
DC
294 fieldLabel: 'IPv4/CIDR',
295 vtype: 'IPCIDRAddress',
01031528 296 name: 'cidr',
a58001dd
DM
297 },
298 {
a0ec1620 299 xtype: 'proxmoxtextfield',
b33f451f 300 deleteEmpty: !me.isCreate,
8e2d096c 301 fieldLabel: gettext('Gateway') + ' (IPv4)',
a58001dd 302 vtype: 'IPAddress',
01031528 303 name: 'gateway',
a58001dd
DM
304 },
305 {
a0ec1620 306 xtype: 'proxmoxtextfield',
b33f451f 307 deleteEmpty: !me.isCreate,
8e2d096c
DC
308 fieldLabel: 'IPv6/CIDR',
309 vtype: 'IP6CIDRAddress',
01031528 310 name: 'cidr6',
a58001dd
DM
311 },
312 {
a0ec1620 313 xtype: 'proxmoxtextfield',
b33f451f 314 deleteEmpty: !me.isCreate,
8e2d096c 315 fieldLabel: gettext('Gateway') + ' (IPv6)',
a58001dd 316 vtype: 'IP6Address',
01031528 317 name: 'gateway6',
aedaf2b6 318 },
5c833def 319 );
a58001dd 320 }
82327aca
TL
321 advancedColumn1.push(
322 {
323 xtype: 'proxmoxintegerfield',
324 minValue: 1280,
325 maxValue: 65520,
326 deleteEmpty: !me.isCreate,
327 emptyText: 1500,
328 fieldLabel: 'MTU',
329 name: 'mtu',
330 },
331 );
a58001dd
DM
332
333 Ext.applyIf(me, {
334 url: url,
335 method: method,
336 items: {
337 xtype: 'inputpanel',
338 column1: column1,
5c833def 339 column2: column2,
1aaba242 340 columnB: columnB,
5c833def
TL
341 advancedColumn1: advancedColumn1,
342 advancedColumn2: advancedColumn2,
01031528 343 },
a58001dd
DM
344 });
345
346 me.callParent();
347
b33f451f 348 if (me.isCreate) {
a58001dd
DM
349 me.down('field[name=iface]').setValue(me.iface_default);
350 } else {
351 me.load({
352 success: function(response, options) {
05a977a2 353 let data = response.result.data;
a58001dd 354 if (data.type !== me.iftype) {
05a977a2 355 let msg = "Got unexpected device type";
a58001dd
DM
356 Ext.Msg.alert(gettext('Error'), msg, function() {
357 me.close();
358 });
359 return;
360 }
361 me.setValues(data);
362 me.isValid(); // trigger validation
01031528 363 },
a58001dd
DM
364 });
365 }
01031528 366 },
a58001dd 367});