]>
Commit | Line | Data |
---|---|---|
8487aa12 | 1 | Ext.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: { | |
39 | networkModel: '', | |
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 | }, | |
116 | minValue: 1, | |
117 | maxValue: 65520, | |
118 | allowBlank: true, | |
119 | }, | |
8487aa12 DM |
120 | ]; |
121 | ||
122 | if (me.insideWizard) { | |
57f034f6 DC |
123 | me.column1.unshift({ |
124 | xtype: 'checkbox', | |
125 | name: 'nonetwork', | |
8487aa12 | 126 | inputValue: 'none', |
57f034f6 DC |
127 | boxLabel: gettext('No network device'), |
128 | listeners: { | |
129 | change: function(cb, value) { | |
130 | var fields = [ | |
131 | 'disconnect', | |
132 | 'bridge', | |
133 | 'tag', | |
134 | 'firewall', | |
135 | 'model', | |
136 | 'macaddr', | |
137 | 'rate', | |
f6710aac | 138 | 'queues', |
c8f2cf4c | 139 | 'mtu', |
57f034f6 DC |
140 | ]; |
141 | fields.forEach(function(fieldname) { | |
142 | me.down('field[name='+fieldname+']').setDisabled(value); | |
143 | }); | |
144 | me.down('field[name=bridge]').validate(); | |
f6710aac TL |
145 | }, |
146 | }, | |
57f034f6 DC |
147 | }); |
148 | me.column2.unshift({ | |
f6710aac | 149 | xtype: 'displayfield', |
8487aa12 DM |
150 | }); |
151 | } | |
152 | ||
57f034f6 | 153 | me.column2.push( |
8487aa12 | 154 | { |
42902182 | 155 | xtype: 'pveNetworkCardSelector', |
8487aa12 DM |
156 | name: 'model', |
157 | fieldLabel: gettext('Model'), | |
c8f2cf4c | 158 | bind: '{networkModel}', |
39c06c69 | 159 | value: PVE.qemu.OSDefaults.generic.networkCard, |
f6710aac | 160 | allowBlank: false, |
8487aa12 DM |
161 | }, |
162 | { | |
163 | xtype: 'textfield', | |
164 | name: 'macaddr', | |
165 | fieldLabel: gettext('MAC address'), | |
166 | vtype: 'MacAddress', | |
167 | allowBlank: true, | |
f6710aac | 168 | emptyText: 'auto', |
57f034f6 DC |
169 | }); |
170 | me.advancedColumn2 = [ | |
8487aa12 DM |
171 | { |
172 | xtype: 'numberfield', | |
173 | name: 'rate', | |
174 | fieldLabel: gettext('Rate limit') + ' (MB/s)', | |
175 | minValue: 0, | |
176 | maxValue: 10*1024, | |
177 | value: '', | |
178 | emptyText: 'unlimited', | |
f6710aac | 179 | allowBlank: true, |
8487aa12 DM |
180 | }, |
181 | { | |
bf96f60d | 182 | xtype: 'proxmoxintegerfield', |
8487aa12 | 183 | name: 'queues', |
a1af3e38 | 184 | fieldLabel: 'Multiqueue', |
8487aa12 DM |
185 | minValue: 1, |
186 | maxValue: 8, | |
187 | value: '', | |
f6710aac TL |
188 | allowBlank: true, |
189 | }, | |
8487aa12 | 190 | ]; |
c8f2cf4c OB |
191 | me.advancedColumnB = [ |
192 | { | |
193 | xtype: 'displayfield', | |
194 | userCls: 'pmx-hint', | |
195 | value: gettext("Use the special value '1' to inherit the MTU value from the underlying bridge"), | |
196 | bind: { | |
197 | hidden: '{!showMtuHint}', | |
198 | }, | |
199 | }, | |
200 | ]; | |
8487aa12 DM |
201 | |
202 | me.callParent(); | |
f6710aac | 203 | }, |
8487aa12 DM |
204 | }); |
205 | ||
206 | Ext.define('PVE.qemu.NetworkEdit', { | |
9fccc702 | 207 | extend: 'Proxmox.window.Edit', |
8487aa12 DM |
208 | |
209 | isAdd: true, | |
210 | ||
8058410f | 211 | initComponent: function() { |
8487aa12 DM |
212 | var me = this; |
213 | ||
214 | var nodename = me.pveSelNode.data.node; | |
2a4971d8 TL |
215 | if (!nodename) { |
216 | throw "no node name specified"; | |
8487aa12 DM |
217 | } |
218 | ||
ef725143 | 219 | me.isCreate = !me.confid; |
8487aa12 DM |
220 | |
221 | var ipanel = Ext.create('PVE.qemu.NetworkInputPanel', { | |
222 | confid: me.confid, | |
b2991833 | 223 | nodename: nodename, |
f6710aac | 224 | isCreate: me.isCreate, |
8487aa12 DM |
225 | }); |
226 | ||
227 | Ext.applyIf(me, { | |
228 | subject: gettext('Network Device'), | |
f6710aac | 229 | items: ipanel, |
8487aa12 DM |
230 | }); |
231 | ||
232 | me.callParent(); | |
233 | ||
234 | me.load({ | |
235 | success: function(response, options) { | |
236 | var i, confid; | |
237 | me.vmconfig = response.result.data; | |
d5e771ce | 238 | if (!me.isCreate) { |
8487aa12 DM |
239 | var value = me.vmconfig[me.confid]; |
240 | var network = PVE.Parser.parseQemuNetwork(me.confid, value); | |
241 | if (!network) { | |
185a77e5 | 242 | Ext.Msg.alert(gettext('Error'), 'Unable to parse network options'); |
8487aa12 DM |
243 | me.close(); |
244 | return; | |
245 | } | |
246 | ipanel.setNetwork(me.confid, network); | |
247 | } else { | |
248 | for (i = 0; i < 100; i++) { | |
249 | confid = 'net' + i.toString(); | |
250 | if (!Ext.isDefined(me.vmconfig[confid])) { | |
251 | me.confid = confid; | |
252 | break; | |
253 | } | |
254 | } | |
410198ac DJ |
255 | |
256 | let ostype = me.vmconfig.ostype; | |
257 | let defaults = PVE.qemu.OSDefaults.getDefaults(ostype); | |
258 | let data = { | |
259 | model: defaults.networkCard, | |
260 | }; | |
261 | ||
262 | ipanel.setNetwork(me.confid, data); | |
8487aa12 | 263 | } |
f6710aac | 264 | }, |
8487aa12 | 265 | }); |
f6710aac | 266 | }, |
8487aa12 | 267 | }); |