f-28: api: implement new model usage
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
cef465da2e
commit
9a16cf011a
3 changed files with 18 additions and 1 deletions
|
|
@ -47,6 +47,8 @@ func (s *Server) getSubnet(w http.ResponseWriter, _ *http.Request, name string)
|
||||||
sub.State = value
|
sub.State = value
|
||||||
case "vpc":
|
case "vpc":
|
||||||
sub.VPC = value
|
sub.VPC = value
|
||||||
|
case "mode":
|
||||||
|
sub.Mode = value
|
||||||
case "vxlan_id":
|
case "vxlan_id":
|
||||||
sub.VxlanID, _ = strconv.Atoi(value)
|
sub.VxlanID, _ = strconv.Atoi(value)
|
||||||
case "local_iface":
|
case "local_iface":
|
||||||
|
|
|
||||||
|
|
@ -44,6 +44,8 @@ func (s *Server) listSubnets(w http.ResponseWriter, _ *http.Request) {
|
||||||
subnets[name].State = value
|
subnets[name].State = value
|
||||||
case "vpc":
|
case "vpc":
|
||||||
subnets[name].VPC = value
|
subnets[name].VPC = value
|
||||||
|
case "mode":
|
||||||
|
subnets[name].Mode = value
|
||||||
case "vxlan_id":
|
case "vxlan_id":
|
||||||
subnets[name].VxlanID, _ = strconv.Atoi(value)
|
subnets[name].VxlanID, _ = strconv.Atoi(value)
|
||||||
case "local_iface":
|
case "local_iface":
|
||||||
|
|
@ -77,6 +79,7 @@ func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) {
|
||||||
cmd := dispatcher.CreateSubnetCommand{
|
cmd := dispatcher.CreateSubnetCommand{
|
||||||
Name: req.Name,
|
Name: req.Name,
|
||||||
VPC: req.VPC,
|
VPC: req.VPC,
|
||||||
|
Mode: req.Mode,
|
||||||
VxlanID: req.VxlanID,
|
VxlanID: req.VxlanID,
|
||||||
IfaceType: req.IfaceType,
|
IfaceType: req.IfaceType,
|
||||||
GatewayIP: req.GatewayIP,
|
GatewayIP: req.GatewayIP,
|
||||||
|
|
@ -109,6 +112,8 @@ func (s *Server) postSubnet(w http.ResponseWriter, r *http.Request) {
|
||||||
sub.State = value
|
sub.State = value
|
||||||
case "vpc":
|
case "vpc":
|
||||||
sub.VPC = value
|
sub.VPC = value
|
||||||
|
case "mode":
|
||||||
|
sub.Mode = value
|
||||||
case "vxlan_id":
|
case "vxlan_id":
|
||||||
sub.VxlanID, _ = strconv.Atoi(value)
|
sub.VxlanID, _ = strconv.Atoi(value)
|
||||||
case "local_iface":
|
case "local_iface":
|
||||||
|
|
|
||||||
|
|
@ -14,6 +14,7 @@ import (
|
||||||
type CreateSubnetCommand struct {
|
type CreateSubnetCommand struct {
|
||||||
Name string
|
Name string
|
||||||
VPC string
|
VPC string
|
||||||
|
Mode string
|
||||||
VxlanID int
|
VxlanID int
|
||||||
IfaceType string
|
IfaceType string
|
||||||
GatewayIP string
|
GatewayIP string
|
||||||
|
|
@ -21,6 +22,12 @@ type CreateSubnetCommand struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c CreateSubnetCommand) Prepare(db *badger.DB, cfg *configuration.Config) error {
|
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 {
|
if _, err := kv.GetFromDB(db, "subnet/"+c.Name+"/state"); err == nil {
|
||||||
return fmt.Errorf("subnet %q already exists", c.Name)
|
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+"/state", "creating")
|
||||||
kv.AddInDB(db, "subnet/"+c.Name+"/vpc", c.VPC)
|
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+"/local_iface", localIface)
|
||||||
kv.AddInDB(db, "subnet/"+c.Name+"/gateway_ip", c.GatewayIP)
|
kv.AddInDB(db, "subnet/"+c.Name+"/gateway_ip", c.GatewayIP)
|
||||||
kv.AddInDB(db, "subnet/"+c.Name+"/cidr", c.CIDR)
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue