From 9a16cf011a2f3aa269deab7dc0df6318f5c707c8 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Mon, 18 May 2026 20:15:16 +0200 Subject: [PATCH] f-28: api: implement new model usage Signed-off-by: GnomeZworc --- internal/api/agent/subnet.go | 2 ++ internal/api/agent/subnets.go | 5 +++++ internal/dispatcher/agent/subnet_commands.go | 12 +++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/internal/api/agent/subnet.go b/internal/api/agent/subnet.go index 31eddc8..21bebf8 100644 --- a/internal/api/agent/subnet.go +++ b/internal/api/agent/subnet.go @@ -47,6 +47,8 @@ func (s *Server) getSubnet(w http.ResponseWriter, _ *http.Request, name string) sub.State = value case "vpc": sub.VPC = value + case "mode": + sub.Mode = value case "vxlan_id": sub.VxlanID, _ = strconv.Atoi(value) case "local_iface": diff --git a/internal/api/agent/subnets.go b/internal/api/agent/subnets.go index 60467aa..61082f1 100644 --- a/internal/api/agent/subnets.go +++ b/internal/api/agent/subnets.go @@ -44,6 +44,8 @@ func (s *Server) listSubnets(w http.ResponseWriter, _ *http.Request) { subnets[name].State = value case "vpc": subnets[name].VPC = value + case "mode": + subnets[name].Mode = value case "vxlan_id": subnets[name].VxlanID, _ = strconv.Atoi(value) case "local_iface": @@ -77,6 +79,7 @@ func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) { cmd := dispatcher.CreateSubnetCommand{ Name: req.Name, VPC: req.VPC, + Mode: req.Mode, VxlanID: req.VxlanID, IfaceType: req.IfaceType, GatewayIP: req.GatewayIP, @@ -109,6 +112,8 @@ func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) { sub.State = value case "vpc": sub.VPC = value + case "mode": + sub.Mode = value case "vxlan_id": sub.VxlanID, _ = strconv.Atoi(value) case "local_iface": diff --git a/internal/dispatcher/agent/subnet_commands.go b/internal/dispatcher/agent/subnet_commands.go index 18f2cd3..b454974 100644 --- a/internal/dispatcher/agent/subnet_commands.go +++ b/internal/dispatcher/agent/subnet_commands.go @@ -14,6 +14,7 @@ import ( type CreateSubnetCommand struct { Name string VPC string + Mode string VxlanID int IfaceType string GatewayIP string @@ -21,6 +22,12 @@ type CreateSubnetCommand struct { } func (c CreateSubnetCommand) Prepare(db *badger.DB, cfg *configuration.Config) error { + if c.Mode == "" { + c.Mode = "vxlan" + } + if c.Mode != "vxlan" && c.Mode != "bridge" { + return fmt.Errorf("unknown subnet mode %q", c.Mode) + } if _, err := kv.GetFromDB(db, "subnet/"+c.Name+"/state"); err == nil { return fmt.Errorf("subnet %q already exists", c.Name) } @@ -37,10 +44,13 @@ func (c CreateSubnetCommand) Prepare(db *badger.DB, cfg *configuration.Config) e } kv.AddInDB(db, "subnet/"+c.Name+"/state", "creating") kv.AddInDB(db, "subnet/"+c.Name+"/vpc", c.VPC) - kv.AddInDB(db, "subnet/"+c.Name+"/vxlan_id", strconv.Itoa(c.VxlanID)) + kv.AddInDB(db, "subnet/"+c.Name+"/mode", c.Mode) kv.AddInDB(db, "subnet/"+c.Name+"/local_iface", localIface) kv.AddInDB(db, "subnet/"+c.Name+"/gateway_ip", c.GatewayIP) kv.AddInDB(db, "subnet/"+c.Name+"/cidr", c.CIDR) + if c.Mode == "vxlan" { + kv.AddInDB(db, "subnet/"+c.Name+"/vxlan_id", strconv.Itoa(c.VxlanID)) + } return nil }