]> git.proxmox.com Git - pve-manager.git/blob - www/manager6/qemu/PCIEdit.js
change .pve-hint to .pmx-hint css-class
[pve-manager.git] / www / manager6 / qemu / PCIEdit.js
1 Ext.define('PVE.qemu.PCIInputPanel', {
2 extend: 'Proxmox.panel.InputPanel',
3
4 onlineHelp: 'qm_pci_passthrough',
5
6 setVMConfig: function(vmconfig) {
7 var me = this;
8 me.vmconfig = vmconfig;
9
10 var hostpci = me.vmconfig[me.confid] || '';
11
12 var values = PVE.Parser.parsePropertyString(hostpci, 'host');
13 if (values.host && values.host.length < 6) { // 00:00 format not 00:00.0
14 values.host += ".0";
15 values.multifunction = true;
16 }
17 values['x-vga'] = PVE.Parser.parseBoolean(values['x-vga'], 0);
18 values.pcie = PVE.Parser.parseBoolean(values.pcie, 0);
19 values.rombar = PVE.Parser.parseBoolean(values.rombar, 1);
20
21 me.setValues(values);
22 if (!me.vmconfig.machine || me.vmconfig.machine.indexOf('q35') === -1) {
23 // machine is not set to some variant of q35, so we disable pcie
24 var pcie = me.down('field[name=pcie]');
25 pcie.setDisabled(true);
26 pcie.setBoxLabel(gettext('Q35 only'));
27 }
28
29 if (values.romfile) {
30 me.down('field[name=romfile]').setVisible(true);
31 }
32 },
33
34 onGetValues: function(values) {
35 var me = this;
36 var ret = {};
37 if(!me.confid) {
38 var i;
39 for (i = 0; i < 5; i++) {
40 if (!me.vmconfig['hostpci' + i.toString()]) {
41 me.confid = 'hostpci' + i.toString();
42 break;
43 }
44 }
45 }
46 if (values.multifunction) {
47 // modify host to skip the '.X'
48 values.host = values.host.substring(0,5);
49 delete values.multifunction;
50 }
51
52 if (values.rombar) {
53 delete values.rombar;
54 } else {
55 values.rombar = 0;
56 }
57
58 if (!values.romfile) {
59 delete values.romfile;
60 }
61
62 ret[me.confid] = PVE.Parser.printPropertyString(values, 'host');
63 return ret;
64 },
65
66 initComponent: function() {
67 var me = this;
68
69 me.nodename = me.pveSelNode.data.node;
70 if (!me.nodename) {
71 throw "no node name specified";
72 }
73
74 me.column1 = [
75 {
76 xtype: 'pvePCISelector',
77 fieldLabel: gettext('Device'),
78 name: 'host',
79 nodename: me.nodename,
80 allowBlank: false,
81 onLoadCallBack: function(store, records, success) {
82 if (!success || !records.length) {
83 return;
84 }
85
86 var first = records[0];
87 if (first.data.iommugroup === -1) {
88 // no iommu groups
89 var warning = Ext.create('Ext.form.field.Display', {
90 columnWidth: 1,
91 padding: '0 0 10 0',
92 value: 'No IOMMU detected, please activate it.' +
93 'See Documentation for further information.',
94 userCls: 'pmx-hint'
95 });
96 me.items.insert(0, warning);
97 me.updateLayout(); // insert does not trigger that
98 }
99 },
100 listeners: {
101 change: function(pcisel, value) {
102 if (!value) {
103 return;
104 }
105 var pcidev = pcisel.getStore().getById(value);
106 var mdevfield = me.down('field[name=mdev]');
107 mdevfield.setDisabled(!pcidev || !pcidev.data.mdev);
108 if (!pcidev) {
109 return;
110 }
111 var id = pcidev.data.id.substring(0,5); // 00:00
112 var iommu = pcidev.data.iommugroup;
113 // try to find out if there are more devices
114 // in that iommu group
115 if (iommu !== -1) {
116 var count = 0;
117 pcisel.getStore().each(function(record) {
118 if (record.data.iommugroup === iommu &&
119 record.data.id.substring(0,5) !== id)
120 {
121 count++;
122 return false;
123 }
124 });
125 var warning = me.down('#iommuwarning');
126 if (count && !warning) {
127 warning = Ext.create('Ext.form.field.Display', {
128 columnWidth: 1,
129 padding: '0 0 10 0',
130 itemId: 'iommuwarning',
131 value: 'The selected Device is not in a seperate' +
132 'IOMMU group, make sure this is intended.',
133 userCls: 'pmx-hint'
134 });
135 me.items.insert(0, warning);
136 me.updateLayout(); // insert does not trigger that
137 } else if (!count && warning) {
138 me.remove(warning);
139 }
140 }
141 if (pcidev.data.mdev) {
142 mdevfield.setPciID(value);
143 }
144 }
145 }
146 },
147 {
148 xtype: 'proxmoxcheckbox',
149 fieldLabel: gettext('All Functions'),
150 name: 'multifunction'
151 }
152 ];
153
154 me.column2 = [
155 {
156 xtype: 'pveMDevSelector',
157 name: 'mdev',
158 disabled: true,
159 fieldLabel: gettext('MDev Type'),
160 nodename: me.nodename,
161 listeners: {
162 change: function(field, value) {
163 var mf = me.down('field[name=multifunction]');
164 if (!!value) {
165 mf.setValue(false);
166 }
167 mf.setDisabled(!!value);
168 }
169 }
170 },
171 {
172 xtype: 'proxmoxcheckbox',
173 fieldLabel: gettext('Primary GPU'),
174 name: 'x-vga'
175 }
176 ];
177
178 me.advancedColumn1 = [
179 {
180 xtype: 'proxmoxcheckbox',
181 fieldLabel: 'ROM-Bar',
182 name: 'rombar'
183 },
184 {
185 xtype: 'displayfield',
186 submitValue: true,
187 hidden: true,
188 fieldLabel: 'ROM-File',
189 name: 'romfile'
190 }
191 ];
192
193 me.advancedColumn2 = [
194 {
195 xtype: 'proxmoxcheckbox',
196 fieldLabel: 'PCI-Express',
197 name: 'pcie'
198 }
199 ];
200
201 me.callParent();
202 }
203 });
204
205 Ext.define('PVE.qemu.PCIEdit', {
206 extend: 'Proxmox.window.Edit',
207
208 vmconfig: undefined,
209
210 isAdd: true,
211
212 subject: gettext('PCI Device'),
213
214
215 initComponent : function() {
216 var me = this;
217
218 me.isCreate = !me.confid;
219
220 var ipanel = Ext.create('PVE.qemu.PCIInputPanel', {
221 confid: me.confid,
222 pveSelNode: me.pveSelNode
223 });
224
225 Ext.apply(me, {
226 items: [ ipanel ]
227 });
228
229 me.callParent();
230
231 me.load({
232 success: function(response) {
233 ipanel.setVMConfig(response.result.data);
234 }
235 });
236 }
237 });