f-62: vm: MAC fournie à la création par interface, fin de la table préchargée, migration #62

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-19 21:25:18 +02:00
commit 077141443e
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
20 changed files with 338 additions and 171 deletions

View file

@ -23,6 +23,7 @@ type VMDisk struct {
type VMNIC struct {
Subnet string
IP string
MAC string
Primary bool
}
@ -60,6 +61,9 @@ func (c StartVMCommand) Prepare(db *badger.DB, _ *configuration.Config) error {
if err := kv.AddInDB(db, prefix+"ip", n.IP); err != nil {
return fmt.Errorf("store nic %d ip: %w", i, err)
}
if err := kv.AddInDB(db, prefix+"mac", n.MAC); err != nil {
return fmt.Errorf("store nic %d mac: %w", i, err)
}
if n.Primary {
if err := kv.AddInDB(db, prefix+"primary", "true"); err != nil {
return fmt.Errorf("store nic %d primary: %w", i, err)

View file

@ -17,7 +17,7 @@ func TestStartVMCommand_Prepare_SingleDisk(t *testing.T) {
cmd := StartVMCommand{
Name: "vm-1",
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.5", Primary: true}},
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.5", MAC: "52:54:00:00:00:05", Primary: true}},
Disks: []VMDisk{{Path: "/data/root.qcow2", Dev: "sda"}},
}
if err := cmd.Prepare(db, nil); err != nil {
@ -41,7 +41,7 @@ func TestStartVMCommand_Prepare_MultiDisk(t *testing.T) {
cmd := StartVMCommand{
Name: "vm-2",
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.6", Primary: true}},
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.6", MAC: "52:54:00:00:00:05", Primary: true}},
Disks: []VMDisk{
{Path: "/data/root.qcow2", Dev: "sda"},
{Path: "/data/data.qcow2", Dev: "sdb"},
@ -74,7 +74,7 @@ func TestStartVMCommand_Prepare_SlotGap(t *testing.T) {
// sdb absent au boot — slot réservé pour hotplug
cmd := StartVMCommand{
Name: "vm-3",
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.7", Primary: true}},
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.7", MAC: "52:54:00:00:00:05", Primary: true}},
Disks: []VMDisk{
{Path: "/data/root.qcow2", Dev: "sda"},
{Path: "/data/extra.qcow2", Dev: "sdc"},
@ -103,7 +103,7 @@ func TestStartVMCommand_Prepare_NoVolumePath(t *testing.T) {
cmd := StartVMCommand{
Name: "vm-4",
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.8", Primary: true}},
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.8", MAC: "52:54:00:00:00:05", Primary: true}},
Disks: []VMDisk{{Path: "/data/root.qcow2", Dev: "sda"}},
}
if err := cmd.Prepare(db, nil); err != nil {
@ -166,7 +166,7 @@ func TestStartVMCommand_Prepare_Duplicate(t *testing.T) {
cmd := StartVMCommand{
Name: "vm-exist",
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.9", Primary: true}},
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.9", MAC: "52:54:00:00:00:05", Primary: true}},
Disks: []VMDisk{{Path: "/data/root.qcow2", Dev: "sda"}},
}
if err := cmd.Prepare(db, nil); err == nil {
@ -185,7 +185,7 @@ func prepareWithDocuments(t *testing.T, docs map[string]string) *badger.DB {
cmd := StartVMCommand{
Name: "vm-doc",
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.5", Primary: true}},
NICs: []VMNIC{{Subnet: "sn-1", IP: "10.0.0.5", MAC: "52:54:00:00:00:05", Primary: true}},
Disks: []VMDisk{{Path: "/data/root.qcow2", Dev: "vda"}},
Documents: docs,
}