]>
Commit | Line | Data |
---|---|---|
01e02121 DC |
1 | Ext.define('PVE.qemu.IPConfigPanel', { |
2 | extend: 'Proxmox.panel.InputPanel', | |
3 | xtype: 'pveIPConfigPanel', | |
4 | ||
5 | insideWizard: false, | |
6 | ||
7 | vmconfig: {}, | |
8 | ||
9 | onGetValues: function(values) { | |
10 | var me = this; | |
11 | ||
12 | if (values.ipv4mode !== 'static') { | |
13 | values.ip = values.ipv4mode; | |
14 | } | |
15 | ||
16 | if (values.ipv6mode !== 'static') { | |
17 | values.ip6 = values.ipv6mode; | |
18 | } | |
19 | ||
20 | var params = {}; | |
21 | ||
22 | var cfg = PVE.Parser.printIPConfig(values); | |
23 | if (cfg === '') { | |
24 | params['delete'] = [me.confid]; | |
25 | } else { | |
26 | params[me.confid] = cfg; | |
27 | } | |
28 | return params; | |
29 | }, | |
30 | ||
31 | setVMConfig: function(config) { | |
32 | var me = this; | |
33 | me.vmconfig = config; | |
34 | }, | |
35 | ||
36 | setIPConfig: function(confid, data) { | |
37 | var me = this; | |
38 | ||
39 | me.confid = confid; | |
40 | ||
41 | if (data.ip === 'dhcp') { | |
42 | data.ipv4mode = data.ip; | |
43 | data.ip = ''; | |
44 | } else { | |
45 | data.ipv4mode = 'static'; | |
46 | } | |
47 | if (data.ip6 === 'dhcp' || data.ip6 === 'auto') { | |
48 | data.ipv6mode = data.ip6; | |
49 | data.ip6 = ''; | |
50 | } else { | |
51 | data.ipv6mode = 'static'; | |
52 | } | |
53 | ||
54 | me.ipconfig = data; | |
55 | me.setValues(me.ipconfig); | |
56 | }, | |
57 | ||
8058410f | 58 | initComponent: function() { |
01e02121 DC |
59 | var me = this; |
60 | ||
61 | me.ipconfig = {}; | |
62 | ||
63 | me.column1 = [ | |
64 | { | |
65 | xtype: 'displayfield', | |
66 | fieldLabel: gettext('Network Device'), | |
f6710aac | 67 | value: me.netid, |
01e02121 DC |
68 | }, |
69 | { | |
70 | layout: { | |
71 | type: 'hbox', | |
f6710aac | 72 | align: 'middle', |
01e02121 DC |
73 | }, |
74 | border: false, | |
75 | margin: '0 0 5 0', | |
76 | items: [ | |
77 | { | |
78 | xtype: 'label', | |
f6710aac | 79 | text: gettext('IPv4') + ':', |
01e02121 DC |
80 | }, |
81 | { | |
82 | xtype: 'radiofield', | |
83 | boxLabel: gettext('Static'), | |
84 | name: 'ipv4mode', | |
85 | inputValue: 'static', | |
86 | checked: false, | |
87 | margin: '0 0 0 10', | |
88 | listeners: { | |
89 | change: function(cb, value) { | |
90 | me.down('field[name=ip]').setDisabled(!value); | |
91 | me.down('field[name=gw]').setDisabled(!value); | |
f6710aac TL |
92 | }, |
93 | }, | |
01e02121 DC |
94 | }, |
95 | { | |
96 | xtype: 'radiofield', | |
97 | boxLabel: gettext('DHCP'), | |
98 | name: 'ipv4mode', | |
99 | inputValue: 'dhcp', | |
100 | checked: false, | |
f6710aac TL |
101 | margin: '0 0 0 10', |
102 | }, | |
103 | ], | |
01e02121 DC |
104 | }, |
105 | { | |
106 | xtype: 'textfield', | |
107 | name: 'ip', | |
108 | vtype: 'IPCIDRAddress', | |
109 | value: '', | |
110 | disabled: true, | |
f6710aac | 111 | fieldLabel: gettext('IPv4/CIDR'), |
01e02121 DC |
112 | }, |
113 | { | |
114 | xtype: 'textfield', | |
115 | name: 'gw', | |
116 | value: '', | |
117 | vtype: 'IPAddress', | |
118 | disabled: true, | |
f6710aac TL |
119 | fieldLabel: gettext('Gateway') + ' (' + gettext('IPv4') +')', |
120 | }, | |
01e02121 DC |
121 | ]; |
122 | ||
123 | me.column2 = [ | |
124 | { | |
f6710aac | 125 | xtype: 'displayfield', |
01e02121 DC |
126 | }, |
127 | { | |
128 | layout: { | |
129 | type: 'hbox', | |
f6710aac | 130 | align: 'middle', |
01e02121 DC |
131 | }, |
132 | border: false, | |
133 | margin: '0 0 5 0', | |
134 | items: [ | |
135 | { | |
136 | xtype: 'label', | |
f6710aac | 137 | text: gettext('IPv6') + ':', |
01e02121 DC |
138 | }, |
139 | { | |
140 | xtype: 'radiofield', | |
141 | boxLabel: gettext('Static'), | |
142 | name: 'ipv6mode', | |
143 | inputValue: 'static', | |
144 | checked: false, | |
145 | margin: '0 0 0 10', | |
146 | listeners: { | |
147 | change: function(cb, value) { | |
148 | me.down('field[name=ip6]').setDisabled(!value); | |
149 | me.down('field[name=gw6]').setDisabled(!value); | |
f6710aac TL |
150 | }, |
151 | }, | |
01e02121 DC |
152 | }, |
153 | { | |
154 | xtype: 'radiofield', | |
155 | boxLabel: gettext('DHCP'), | |
156 | name: 'ipv6mode', | |
157 | inputValue: 'dhcp', | |
158 | checked: false, | |
f6710aac TL |
159 | margin: '0 0 0 10', |
160 | }, | |
161 | ], | |
01e02121 DC |
162 | }, |
163 | { | |
164 | xtype: 'textfield', | |
165 | name: 'ip6', | |
166 | value: '', | |
167 | vtype: 'IP6CIDRAddress', | |
168 | disabled: true, | |
f6710aac | 169 | fieldLabel: gettext('IPv6/CIDR'), |
01e02121 DC |
170 | }, |
171 | { | |
172 | xtype: 'textfield', | |
173 | name: 'gw6', | |
174 | vtype: 'IP6Address', | |
175 | value: '', | |
176 | disabled: true, | |
f6710aac TL |
177 | fieldLabel: gettext('Gateway') + ' (' + gettext('IPv6') +')', |
178 | }, | |
01e02121 DC |
179 | ]; |
180 | ||
181 | me.callParent(); | |
f6710aac | 182 | }, |
01e02121 DC |
183 | }); |
184 | ||
185 | Ext.define('PVE.qemu.IPConfigEdit', { | |
186 | extend: 'Proxmox.window.Edit', | |
187 | ||
188 | isAdd: true, | |
189 | ||
8058410f | 190 | initComponent: function() { |
01e02121 DC |
191 | var me = this; |
192 | ||
193 | // convert confid from netX to ipconfigX | |
194 | var match = me.confid.match(/^net(\d+)$/); | |
195 | if (match) { | |
196 | me.netid = me.confid; | |
197 | me.confid = 'ipconfig' + match[1]; | |
198 | } | |
199 | ||
200 | var nodename = me.pveSelNode.data.node; | |
201 | if (!nodename) { | |
202 | throw "no node name specified"; | |
203 | } | |
204 | ||
205 | me.isCreate = me.confid ? false : true; | |
206 | ||
207 | var ipanel = Ext.create('PVE.qemu.IPConfigPanel', { | |
208 | confid: me.confid, | |
209 | netid: me.netid, | |
f6710aac | 210 | nodename: nodename, |
01e02121 DC |
211 | }); |
212 | ||
213 | Ext.applyIf(me, { | |
214 | subject: gettext('Network Config'), | |
f6710aac | 215 | items: ipanel, |
01e02121 DC |
216 | }); |
217 | ||
218 | me.callParent(); | |
219 | ||
220 | me.load({ | |
221 | success: function(response, options) { | |
222 | me.vmconfig = response.result.data; | |
223 | var ipconfig = {}; | |
224 | var value = me.vmconfig[me.confid]; | |
225 | if (value) { | |
226 | ipconfig = PVE.Parser.parseIPConfig(me.confid, value); | |
227 | if (!ipconfig) { | |
228 | Ext.Msg.alert(gettext('Error'), gettext('Unable to parse network configuration')); | |
229 | me.close(); | |
230 | return; | |
231 | } | |
232 | } | |
233 | ipanel.setIPConfig(me.confid, ipconfig); | |
234 | ipanel.setVMConfig(me.vmconfig); | |
f6710aac | 235 | }, |
01e02121 | 236 | }); |
f6710aac | 237 | }, |
01e02121 | 238 | }); |