205 lines
6.0 KiB
Markdown
205 lines
6.0 KiB
Markdown
# Correction du pré-remplissage du PCI Slot
|
|
|
|
## Problème identifié
|
|
|
|
Lors de l'import de périphériques PCI, le slot (ex: `08:00.0`) n'était pas pré-rempli dans le formulaire.
|
|
|
|
### Diagnostic
|
|
|
|
Le code tentait de pré-remplir un champ `device_id` qui n'existe pas dans le modèle:
|
|
|
|
**Backend** (`peripherals.py` ligne 1507):
|
|
```python
|
|
"device_id": device_info.get("slot"), # ❌ Ce champ n'existe pas
|
|
```
|
|
|
|
**Frontend** (`peripherals.js` lignes 1839-1842):
|
|
```javascript
|
|
if (suggested.device_id) {
|
|
const deviceIdField = document.getElementById('device_id'); // ❌ Ce champ n'existe pas
|
|
if (deviceIdField) deviceIdField.value = suggested.device_id;
|
|
}
|
|
```
|
|
|
|
### Analyse du modèle
|
|
|
|
Le modèle `Peripheral` possédait:
|
|
- `device_id` (INTEGER) - Lien vers la table devices (assignation actuelle)
|
|
- `linked_device_id` (INTEGER) - Lien vers data.db pour benchmarks
|
|
- `usb_device_id` (TEXT) - Format `idVendor:idProduct` (ex: `1d6b:0003`)
|
|
- `pci_device_id` (VARCHAR) - Format `vendor:device` (ex: `10de:2504`)
|
|
|
|
**Mais pas de champ pour stocker le slot PCI** (`08:00.0`).
|
|
|
|
## Solution implémentée
|
|
|
|
### 1. Nouveau champ `pci_slot`
|
|
|
|
Ajout d'un champ dédié pour stocker le slot PCI (Bus:Device.Function).
|
|
|
|
#### Migration 014
|
|
|
|
**Fichier**: `migrations/014_add_pci_slot.sql`
|
|
|
|
```sql
|
|
ALTER TABLE peripherals ADD COLUMN pci_slot VARCHAR(20);
|
|
CREATE INDEX idx_peripherals_pci_slot ON peripherals(pci_slot);
|
|
```
|
|
|
|
**Application**:
|
|
```bash
|
|
python3 backend/apply_migration_014.py
|
|
```
|
|
|
|
**Résultat**:
|
|
```
|
|
✅ Migration 014 applied successfully
|
|
✅ Column 'pci_slot' added: (68, 'pci_slot', 'VARCHAR(20)', 0, None, 0)
|
|
```
|
|
|
|
### 2. Modèle mis à jour
|
|
|
|
**Fichier**: `backend/app/models/peripheral.py` (ligne 72)
|
|
|
|
```python
|
|
usb_device_id = Column(String(20)) # idVendor:idProduct (e.g. 1d6b:0003)
|
|
pci_device_id = Column(String(20)) # vendor:device for PCI (e.g. 10ec:8168)
|
|
pci_slot = Column(String(20)) # PCI slot identifier (e.g. 08:00.0) ← NOUVEAU
|
|
```
|
|
|
|
### 3. Schéma mis à jour
|
|
|
|
**Fichier**: `backend/app/schemas/peripheral.py` (ligne 63)
|
|
|
|
```python
|
|
usb_device_id: Optional[str] = Field(None, max_length=20)
|
|
pci_device_id: Optional[str] = Field(None, max_length=20)
|
|
pci_slot: Optional[str] = Field(None, max_length=20) # ← NOUVEAU
|
|
```
|
|
|
|
### 4. Backend corrigé
|
|
|
|
**Fichier**: `backend/app/api/endpoints/peripherals.py` (ligne 1507)
|
|
|
|
```python
|
|
suggested = {
|
|
"nom": nom,
|
|
"type_principal": type_principal,
|
|
"sous_type": sous_type,
|
|
"marque": brand or device_info.get("vendor_name"),
|
|
"modele": model or device_info.get("device_name"),
|
|
"pci_slot": device_info.get("slot"), # ✅ Utilise pci_slot
|
|
"pci_device_id": device_info.get("pci_device_id"),
|
|
"cli_raw": device_section,
|
|
"caracteristiques_specifiques": caracteristiques_specifiques
|
|
}
|
|
```
|
|
|
|
### 5. Frontend corrigé
|
|
|
|
**Fichier**: `frontend/js/peripherals.js` (lignes 1838-1842)
|
|
|
|
```javascript
|
|
// Fill PCI slot (like 08:00.0)
|
|
if (suggested.pci_slot) {
|
|
const pciSlotField = document.getElementById('pci_slot');
|
|
if (pciSlotField) pciSlotField.value = suggested.pci_slot;
|
|
}
|
|
```
|
|
|
|
### 6. Formulaire HTML mis à jour
|
|
|
|
**Fichier**: `frontend/peripherals.html` (lignes 183-196)
|
|
|
|
```html
|
|
<div class="form-group">
|
|
<label for="usb_device_id">
|
|
Device ID USB
|
|
<span class="help-text-inline">(idVendor:idProduct)</span>
|
|
</label>
|
|
<input type="text" id="usb_device_id" name="usb_device_id" placeholder="1d6b:0003">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="pci_slot">
|
|
PCI Slot
|
|
<span class="help-text-inline">(Bus:Device.Function)</span>
|
|
</label>
|
|
<input type="text" id="pci_slot" name="pci_slot" placeholder="08:00.0">
|
|
</div>
|
|
|
|
<div class="form-group">
|
|
<label for="pci_device_id">
|
|
PCI Device ID
|
|
<span class="help-text-inline">(vendor:device)</span>
|
|
</label>
|
|
<input type="text" id="pci_device_id" name="pci_device_id" placeholder="10de:2504">
|
|
</div>
|
|
```
|
|
|
|
## Résumé des identifiants PCI
|
|
|
|
Chaque périphérique PCI possède maintenant **deux identifiants**:
|
|
|
|
| Champ | Description | Exemple | Source |
|
|
|-------|-------------|---------|--------|
|
|
| **`pci_slot`** | Emplacement physique sur le bus PCI | `08:00.0` | `lspci -v` (colonne 1) |
|
|
| **`pci_device_id`** | Identifiant vendor:device | `10de:2504` | `lspci -n` (colonnes 3-4) |
|
|
|
|
### Exemple
|
|
|
|
Pour une **NVIDIA GeForce RTX 3060** sur le slot `08:00.0`:
|
|
|
|
```
|
|
08:00.0 VGA compatible controller: NVIDIA Corporation GA106 [GeForce RTX 3060 Lite Hash Rate] (rev a1)
|
|
```
|
|
|
|
Avec `lspci -n`:
|
|
```
|
|
08:00.0 0300: 10de:2504 (rev a1)
|
|
```
|
|
|
|
**Données importées**:
|
|
- `pci_slot`: `08:00.0`
|
|
- `pci_device_id`: `10de:2504`
|
|
- `marque`: `NVIDIA`
|
|
- `modele`: `GeForce RTX 3060 Lite Hash Rate`
|
|
- `type_principal`: `PCI`
|
|
- `sous_type`: `Carte graphique`
|
|
|
|
## Bénéfices
|
|
|
|
✅ **PCI Slot pré-rempli**: Le slot physique (08:00.0) est maintenant visible et stocké
|
|
✅ **PCI Device ID pré-rempli**: L'identifiant vendor:device (10de:2504) est stocké
|
|
✅ **Distinction USB/PCI**: Champs séparés pour USB et PCI
|
|
✅ **Indexation**: Index ajouté pour requêtes rapides par slot
|
|
✅ **Cohérence**: Même pattern que usb_device_id
|
|
|
|
## Fichiers modifiés
|
|
|
|
1. **migrations/014_add_pci_slot.sql** - Migration SQL
|
|
2. **backend/apply_migration_014.py** - Script d'application
|
|
3. **backend/app/models/peripheral.py** - Ajout du champ pci_slot
|
|
4. **backend/app/schemas/peripheral.py** - Ajout au schéma
|
|
5. **backend/app/api/endpoints/peripherals.py** - Utilisation de pci_slot
|
|
6. **frontend/js/peripherals.js** - Pré-remplissage du champ
|
|
7. **frontend/peripherals.html** - Ajout du champ au formulaire
|
|
|
|
## Test
|
|
|
|
Pour tester le pré-remplissage:
|
|
|
|
1. Importer un périphérique PCI (ex: carte graphique)
|
|
2. Vérifier que le formulaire affiche:
|
|
- **PCI Slot**: `08:00.0` ✅
|
|
- **PCI Device ID**: `10de:2504` ✅
|
|
- **Type principal**: `PCI` ✅
|
|
- **Sous-type**: `Carte graphique` ✅
|
|
|
|
## Conclusion
|
|
|
|
Le slot PCI est maintenant correctement stocké dans un champ dédié `pci_slot`, permettant:
|
|
- Un pré-remplissage automatique lors de l'import
|
|
- Une identification précise de l'emplacement physique du périphérique
|
|
- Une distinction claire entre slot (08:00.0) et device ID (10de:2504)
|