f-89: fip: IP flottante refusée sur une interface public_ip #89

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-10-30 01:00:24 +01:00
commit 047d231556
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
6 changed files with 25 additions and 4 deletions

View file

@ -8,6 +8,7 @@ import (
configuration "git.g3e.fr/syonad/two/internal/config/agent"
"git.g3e.fr/syonad/two/internal/fip"
"git.g3e.fr/syonad/two/internal/state"
"git.g3e.fr/syonad/two/internal/subnet"
"git.g3e.fr/syonad/two/pkg/db/kv"
"github.com/dgraph-io/badger/v4"
)
@ -39,9 +40,13 @@ func (c CreateFloatingIPCommand) Prepare(db *badger.DB, _ *configuration.Config)
if vmState != state.Running {
return fmt.Errorf("vm %q is %s", c.VM, vmState)
}
if _, err := fip.Resolve(db, c.VM, c.Interface); err != nil {
target, err := fip.Resolve(db, c.VM, c.Interface)
if err != nil {
return err
}
if target.Mode == subnet.ModePublicIP {
return fmt.Errorf("interface %q of vm %q is on public_ip subnet %q: it carries its public ip itself", c.Interface, c.VM, target.Subnet)
}
others, err := floatingIPs(db)
if err != nil {
return err