f-34: route: add default gateway full gestion
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
d15454d35b
commit
46596f8142
13 changed files with 396 additions and 51 deletions
|
|
@ -21,15 +21,16 @@ type CreateSubnetCommand struct {
|
|||
InterfaceIP string
|
||||
CIDR string
|
||||
DefaultRoute bool
|
||||
Gateway string
|
||||
}
|
||||
|
||||
func (c CreateSubnetCommand) Key() string { return "subnet/" + c.Name }
|
||||
|
||||
func (c CreateSubnetCommand) Prepare(db *badger.DB, cfg *configuration.Config) error {
|
||||
if c.Mode == "" {
|
||||
c.Mode = "vxlan"
|
||||
c.Mode = subnet.ModeVxlan
|
||||
}
|
||||
if c.Mode != "vxlan" && c.Mode != "bridge" {
|
||||
if !subnet.ValidMode(c.Mode) {
|
||||
return fmt.Errorf("unknown subnet mode %q", c.Mode)
|
||||
}
|
||||
if _, err := kv.GetFromDB(db, "subnet/"+c.Name+"/state"); err == nil {
|
||||
|
|
@ -53,9 +54,14 @@ func (c CreateSubnetCommand) Prepare(db *badger.DB, cfg *configuration.Config) e
|
|||
kv.AddInDB(db, "subnet/"+c.Name+"/interface_ip", c.InterfaceIP)
|
||||
kv.AddInDB(db, "subnet/"+c.Name+"/cidr", c.CIDR)
|
||||
kv.AddInDB(db, "subnet/"+c.Name+"/default_route", strconv.FormatBool(c.DefaultRoute))
|
||||
if c.Mode == "vxlan" {
|
||||
if c.Mode == subnet.ModeVxlan {
|
||||
kv.AddInDB(db, "subnet/"+c.Name+"/vxlan_id", strconv.Itoa(c.VxlanID))
|
||||
}
|
||||
if c.Gateway != "" {
|
||||
if err := kv.AddInDB(db, "subnet/"+c.Name+"/gateway", c.Gateway); err != nil {
|
||||
return fmt.Errorf("store gateway: %w", err)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue