]>
Commit | Line | Data |
---|---|---|
1 | Ext.define('PVE.qemu.NetworkInputPanel', { | |
2 | extend: 'Proxmox.panel.InputPanel', | |
3 | alias: 'widget.pveQemuNetworkInputPanel', | |
4 | onlineHelp: 'qm_network_device', | |
5 | ||
6 | insideWizard: false, | |
7 | ||
8 | onGetValues: function(values) { | |
9 | var me = this; | |
10 | ||
11 | me.network.model = values.model; | |
12 | if (values.nonetwork) { | |
13 | return {}; | |
14 | } else { | |
15 | me.network.bridge = values.bridge; | |
16 | me.network.tag = values.tag; | |
17 | me.network.firewall = values.firewall; | |
18 | } | |
19 | me.network.macaddr = values.macaddr; | |
20 | me.network.disconnect = values.disconnect; | |
21 | me.network.queues = values.queues; | |
22 | ||
23 | if (values.rate) { | |
24 | me.network.rate = values.rate; | |
25 | } else { | |
26 | delete me.network.rate; | |
27 | } | |
28 | ||
29 | var params = {}; | |
30 | ||
31 | params[me.confid] = PVE.Parser.printQemuNetwork(me.network); | |
32 | ||
33 | return params; | |
34 | }, | |
35 | ||
36 | setNetwork: function(confid, data) { | |
37 | var me = this; | |
38 | ||
39 | me.confid = confid; | |
40 | ||
41 | if (data) { | |
42 | data.networkmode = data.bridge ? 'bridge' : 'nat'; | |
43 | } else { | |
44 | data = {}; | |
45 | data.networkmode = 'bridge'; | |
46 | } | |
47 | me.network = data; | |
48 | ||
49 | me.setValues(me.network); | |
50 | }, | |
51 | ||
52 | setNodename: function(nodename) { | |
53 | var me = this; | |
54 | ||
55 | me.bridgesel.setNodename(nodename); | |
56 | }, | |
57 | ||
58 | initComponent: function() { | |
59 | var me = this; | |
60 | ||
61 | me.network = {}; | |
62 | me.confid = 'net0'; | |
63 | ||
64 | me.column1 = []; | |
65 | me.column2 = []; | |
66 | ||
67 | me.bridgesel = Ext.create('PVE.form.BridgeSelector', { | |
68 | name: 'bridge', | |
69 | fieldLabel: gettext('Bridge'), | |
70 | nodename: me.nodename, | |
71 | autoSelect: true, | |
72 | allowBlank: false, | |
73 | }); | |
74 | ||
75 | me.column1 = [ | |
76 | me.bridgesel, | |
77 | { | |
78 | xtype: 'pveVlanField', | |
79 | name: 'tag', | |
80 | value: '', | |
81 | }, | |
82 | { | |
83 | xtype: 'proxmoxcheckbox', | |
84 | fieldLabel: gettext('Firewall'), | |
85 | name: 'firewall', | |
86 | checked: me.insideWizard || me.isCreate, | |
87 | }, | |
88 | ]; | |
89 | ||
90 | me.advancedColumn1 = [ | |
91 | { | |
92 | xtype: 'proxmoxcheckbox', | |
93 | fieldLabel: gettext('Disconnect'), | |
94 | name: 'disconnect', | |
95 | }, | |
96 | ]; | |
97 | ||
98 | if (me.insideWizard) { | |
99 | me.column1.unshift({ | |
100 | xtype: 'checkbox', | |
101 | name: 'nonetwork', | |
102 | inputValue: 'none', | |
103 | boxLabel: gettext('No network device'), | |
104 | listeners: { | |
105 | change: function(cb, value) { | |
106 | var fields = [ | |
107 | 'disconnect', | |
108 | 'bridge', | |
109 | 'tag', | |
110 | 'firewall', | |
111 | 'model', | |
112 | 'macaddr', | |
113 | 'rate', | |
114 | 'queues', | |
115 | ]; | |
116 | fields.forEach(function(fieldname) { | |
117 | me.down('field[name='+fieldname+']').setDisabled(value); | |
118 | }); | |
119 | me.down('field[name=bridge]').validate(); | |
120 | }, | |
121 | }, | |
122 | }); | |
123 | me.column2.unshift({ | |
124 | xtype: 'displayfield', | |
125 | }); | |
126 | } | |
127 | ||
128 | me.column2.push( | |
129 | { | |
130 | xtype: 'pveNetworkCardSelector', | |
131 | name: 'model', | |
132 | fieldLabel: gettext('Model'), | |
133 | value: PVE.qemu.OSDefaults.generic.networkCard, | |
134 | allowBlank: false, | |
135 | }, | |
136 | { | |
137 | xtype: 'textfield', | |
138 | name: 'macaddr', | |
139 | fieldLabel: gettext('MAC address'), | |
140 | vtype: 'MacAddress', | |
141 | allowBlank: true, | |
142 | emptyText: 'auto', | |
143 | }); | |
144 | me.advancedColumn2 = [ | |
145 | { | |
146 | xtype: 'numberfield', | |
147 | name: 'rate', | |
148 | fieldLabel: gettext('Rate limit') + ' (MB/s)', | |
149 | minValue: 0, | |
150 | maxValue: 10*1024, | |
151 | value: '', | |
152 | emptyText: 'unlimited', | |
153 | allowBlank: true, | |
154 | }, | |
155 | { | |
156 | xtype: 'proxmoxintegerfield', | |
157 | name: 'queues', | |
158 | fieldLabel: 'Multiqueue', | |
159 | minValue: 1, | |
160 | maxValue: 8, | |
161 | value: '', | |
162 | allowBlank: true, | |
163 | }, | |
164 | ]; | |
165 | ||
166 | me.callParent(); | |
167 | }, | |
168 | }); | |
169 | ||
170 | Ext.define('PVE.qemu.NetworkEdit', { | |
171 | extend: 'Proxmox.window.Edit', | |
172 | ||
173 | isAdd: true, | |
174 | ||
175 | initComponent: function() { | |
176 | var me = this; | |
177 | ||
178 | var nodename = me.pveSelNode.data.node; | |
179 | if (!nodename) { | |
180 | throw "no node name specified"; | |
181 | } | |
182 | ||
183 | me.isCreate = !me.confid; | |
184 | ||
185 | var ipanel = Ext.create('PVE.qemu.NetworkInputPanel', { | |
186 | confid: me.confid, | |
187 | nodename: nodename, | |
188 | isCreate: me.isCreate, | |
189 | }); | |
190 | ||
191 | Ext.applyIf(me, { | |
192 | subject: gettext('Network Device'), | |
193 | items: ipanel, | |
194 | }); | |
195 | ||
196 | me.callParent(); | |
197 | ||
198 | me.load({ | |
199 | success: function(response, options) { | |
200 | var i, confid; | |
201 | me.vmconfig = response.result.data; | |
202 | if (!me.isCreate) { | |
203 | var value = me.vmconfig[me.confid]; | |
204 | var network = PVE.Parser.parseQemuNetwork(me.confid, value); | |
205 | if (!network) { | |
206 | Ext.Msg.alert(gettext('Error'), 'Unable to parse network options'); | |
207 | me.close(); | |
208 | return; | |
209 | } | |
210 | ipanel.setNetwork(me.confid, network); | |
211 | } else { | |
212 | for (i = 0; i < 100; i++) { | |
213 | confid = 'net' + i.toString(); | |
214 | if (!Ext.isDefined(me.vmconfig[confid])) { | |
215 | me.confid = confid; | |
216 | break; | |
217 | } | |
218 | } | |
219 | ||
220 | let ostype = me.vmconfig.ostype; | |
221 | let defaults = PVE.qemu.OSDefaults.getDefaults(ostype); | |
222 | let data = { | |
223 | model: defaults.networkCard, | |
224 | }; | |
225 | ||
226 | ipanel.setNetwork(me.confid, data); | |
227 | } | |
228 | }, | |
229 | }); | |
230 | }, | |
231 | }); |