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