]> git.proxmox.com Git - pve-manager.git/blame - www/manager6/qemu/NetworkEdit.js
update shipped appliance info index
[pve-manager.git] / www / manager6 / qemu / NetworkEdit.js
CommitLineData
8487aa12 1Ext.define('PVE.qemu.NetworkInputPanel', {
ef4ef788 2 extend: 'Proxmox.panel.InputPanel',
85806e47 3 alias: 'widget.pveQemuNetworkInputPanel',
c8802a60 4 onlineHelp: 'qm_network_device',
8487aa12
DM
5
6 insideWizard: false,
7
8 onGetValues: function(values) {
9 var me = this;
10
11 me.network.model = values.model;
57f034f6 12 if (values.nonetwork) {
8487aa12 13 return {};
57f034f6 14 } else {
8487aa12
DM
15 me.network.bridge = values.bridge;
16 me.network.tag = values.tag;
17 me.network.firewall = values.firewall;
8487aa12
DM
18 }
19 me.network.macaddr = values.macaddr;
20 me.network.disconnect = values.disconnect;
21 me.network.queues = values.queues;
c8f2cf4c 22 me.network.mtu = values.mtu;
8487aa12
DM
23
24 if (values.rate) {
25 me.network.rate = values.rate;
26 } else {
27 delete me.network.rate;
28 }
29
30 var params = {};
31
32 params[me.confid] = PVE.Parser.printQemuNetwork(me.network);
33
34 return params;
35 },
36
c8f2cf4c
OB
37 viewModel: {
38 data: {
8c366792 39 networkModel: undefined,
c8f2cf4c
OB
40 mtu: '',
41 },
42 formulas: {
43 isVirtio: get => get('networkModel') === 'virtio',
44 showMtuHint: get => get('mtu') === 1,
45 },
46 },
47
8487aa12
DM
48 setNetwork: function(confid, data) {
49 var me = this;
50
51 me.confid = confid;
52
53 if (data) {
54 data.networkmode = data.bridge ? 'bridge' : 'nat';
55 } else {
56 data = {};
57 data.networkmode = 'bridge';
58 }
59 me.network = data;
2a4971d8 60
8487aa12
DM
61 me.setValues(me.network);
62 },
63
64 setNodename: function(nodename) {
65 var me = this;
66
67 me.bridgesel.setNodename(nodename);
68 },
69
8058410f 70 initComponent: function() {
8487aa12
DM
71 var me = this;
72
73 me.network = {};
74 me.confid = 'net0';
75
57f034f6
DC
76 me.column1 = [];
77 me.column2 = [];
78
8487aa12
DM
79 me.bridgesel = Ext.create('PVE.form.BridgeSelector', {
80 name: 'bridge',
81 fieldLabel: gettext('Bridge'),
82 nodename: me.nodename,
8487aa12 83 autoSelect: true,
f6710aac 84 allowBlank: false,
8487aa12
DM
85 });
86
87 me.column1 = [
8487aa12
DM
88 me.bridgesel,
89 {
90 xtype: 'pveVlanField',
91 name: 'tag',
f6710aac 92 value: '',
8487aa12 93 },
8487aa12 94 {
896c0d50 95 xtype: 'proxmoxcheckbox',
8487aa12 96 fieldLabel: gettext('Firewall'),
b2991833 97 name: 'firewall',
53e3ea84 98 checked: me.insideWizard || me.isCreate,
f6710aac 99 },
57f034f6
DC
100 ];
101
102 me.advancedColumn1 = [
8487aa12 103 {
57f034f6
DC
104 xtype: 'proxmoxcheckbox',
105 fieldLabel: gettext('Disconnect'),
f6710aac
TL
106 name: 'disconnect',
107 },
c8f2cf4c
OB
108 {
109 xtype: 'proxmoxintegerfield',
110 name: 'mtu',
111 fieldLabel: 'MTU',
112 bind: {
113 disabled: '{!isVirtio}',
114 value: '{mtu}',
115 },
9ea839b3 116 emptyText: '1500 (1 = bridge MTU)',
c8f2cf4c
OB
117 minValue: 1,
118 maxValue: 65520,
119 allowBlank: true,
ea7f41ed
TL
120 validator: val => val === '' || val >= 576 || val === '1'
121 ? true
122 : gettext('MTU needs to be >= 576 or 1 to inherit the MTU from the underlying bridge.'),
c8f2cf4c 123 },
8487aa12
DM
124 ];
125
126 if (me.insideWizard) {
57f034f6
DC
127 me.column1.unshift({
128 xtype: 'checkbox',
129 name: 'nonetwork',
8487aa12 130 inputValue: 'none',
57f034f6
DC
131 boxLabel: gettext('No network device'),
132 listeners: {
133 change: function(cb, value) {
134 var fields = [
135 'disconnect',
136 'bridge',
137 'tag',
138 'firewall',
139 'model',
140 'macaddr',
141 'rate',
f6710aac 142 'queues',
c8f2cf4c 143 'mtu',
57f034f6
DC
144 ];
145 fields.forEach(function(fieldname) {
146 me.down('field[name='+fieldname+']').setDisabled(value);
147 });
148 me.down('field[name=bridge]').validate();
f6710aac
TL
149 },
150 },
57f034f6
DC
151 });
152 me.column2.unshift({
f6710aac 153 xtype: 'displayfield',
8487aa12
DM
154 });
155 }
156
57f034f6 157 me.column2.push(
8487aa12 158 {
42902182 159 xtype: 'pveNetworkCardSelector',
8487aa12
DM
160 name: 'model',
161 fieldLabel: gettext('Model'),
c8f2cf4c 162 bind: '{networkModel}',
39c06c69 163 value: PVE.qemu.OSDefaults.generic.networkCard,
f6710aac 164 allowBlank: false,
8487aa12
DM
165 },
166 {
167 xtype: 'textfield',
168 name: 'macaddr',
169 fieldLabel: gettext('MAC address'),
170 vtype: 'MacAddress',
171 allowBlank: true,
f6710aac 172 emptyText: 'auto',
57f034f6
DC
173 });
174 me.advancedColumn2 = [
8487aa12
DM
175 {
176 xtype: 'numberfield',
177 name: 'rate',
178 fieldLabel: gettext('Rate limit') + ' (MB/s)',
179 minValue: 0,
180 maxValue: 10*1024,
181 value: '',
182 emptyText: 'unlimited',
f6710aac 183 allowBlank: true,
8487aa12
DM
184 },
185 {
bf96f60d 186 xtype: 'proxmoxintegerfield',
8487aa12 187 name: 'queues',
a1af3e38 188 fieldLabel: 'Multiqueue',
8487aa12 189 minValue: 1,
68941058 190 maxValue: 64,
8487aa12 191 value: '',
f6710aac
TL
192 allowBlank: true,
193 },
8487aa12 194 ];
c8f2cf4c
OB
195 me.advancedColumnB = [
196 {
197 xtype: 'displayfield',
198 userCls: 'pmx-hint',
199 value: gettext("Use the special value '1' to inherit the MTU value from the underlying bridge"),
200 bind: {
201 hidden: '{!showMtuHint}',
202 },
203 },
204 ];
8487aa12
DM
205
206 me.callParent();
f6710aac 207 },
8487aa12
DM
208});
209
210Ext.define('PVE.qemu.NetworkEdit', {
9fccc702 211 extend: 'Proxmox.window.Edit',
8487aa12
DM
212
213 isAdd: true,
214
8058410f 215 initComponent: function() {
8487aa12
DM
216 var me = this;
217
218 var nodename = me.pveSelNode.data.node;
2a4971d8
TL
219 if (!nodename) {
220 throw "no node name specified";
8487aa12
DM
221 }
222
ef725143 223 me.isCreate = !me.confid;
8487aa12
DM
224
225 var ipanel = Ext.create('PVE.qemu.NetworkInputPanel', {
226 confid: me.confid,
b2991833 227 nodename: nodename,
f6710aac 228 isCreate: me.isCreate,
8487aa12
DM
229 });
230
231 Ext.applyIf(me, {
232 subject: gettext('Network Device'),
f6710aac 233 items: ipanel,
8487aa12
DM
234 });
235
236 me.callParent();
237
238 me.load({
239 success: function(response, options) {
240 var i, confid;
241 me.vmconfig = response.result.data;
d5e771ce 242 if (!me.isCreate) {
8487aa12
DM
243 var value = me.vmconfig[me.confid];
244 var network = PVE.Parser.parseQemuNetwork(me.confid, value);
245 if (!network) {
185a77e5 246 Ext.Msg.alert(gettext('Error'), 'Unable to parse network options');
8487aa12
DM
247 me.close();
248 return;
249 }
250 ipanel.setNetwork(me.confid, network);
251 } else {
252 for (i = 0; i < 100; i++) {
253 confid = 'net' + i.toString();
254 if (!Ext.isDefined(me.vmconfig[confid])) {
255 me.confid = confid;
256 break;
257 }
258 }
410198ac
DJ
259
260 let ostype = me.vmconfig.ostype;
261 let defaults = PVE.qemu.OSDefaults.getDefaults(ostype);
262 let data = {
263 model: defaults.networkCard,
264 };
265
266 ipanel.setNetwork(me.confid, data);
8487aa12 267 }
f6710aac 268 },
8487aa12 269 });
f6710aac 270 },
8487aa12 271});