f-21: code: add dispatch command for subnet
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
3127c05216
commit
6a5a646eaa
1 changed files with 27 additions and 4 deletions
|
|
@ -1,6 +1,14 @@
|
|||
package dispatcher
|
||||
|
||||
import "github.com/dgraph-io/badger/v4"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"strconv"
|
||||
|
||||
"git.g3e.fr/syonad/two/internal/subnet"
|
||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||
"github.com/dgraph-io/badger/v4"
|
||||
)
|
||||
|
||||
type CreateSubnetCommand struct {
|
||||
Name string
|
||||
|
|
@ -12,8 +20,13 @@ type CreateSubnetCommand struct {
|
|||
}
|
||||
|
||||
func (c CreateSubnetCommand) Execute(db *badger.DB) error {
|
||||
// TODO: brancher internal/subnet/create.go
|
||||
return nil
|
||||
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+"/local_ip", c.LocalIP)
|
||||
kv.AddInDB(db, "subnet/"+c.Name+"/gateway_ip", c.GatewayIP)
|
||||
kv.AddInDB(db, "subnet/"+c.Name+"/cidr", c.CIDR)
|
||||
return subnet.CreateSubnet(db, c.Name)
|
||||
}
|
||||
|
||||
type DeleteSubnetCommand struct {
|
||||
|
|
@ -21,6 +34,16 @@ type DeleteSubnetCommand struct {
|
|||
}
|
||||
|
||||
func (c DeleteSubnetCommand) Execute(db *badger.DB) error {
|
||||
// TODO: brancher internal/subnet/delete.go
|
||||
kv.AddInDB(db, "subnet/"+c.Name+"/state", "deleting")
|
||||
if err := subnet.DeleteSubnet(db, c.Name); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
}
|
||||
if state, err := kv.GetFromDB(db, "subnet/"+c.Name+"/state"); err != nil {
|
||||
fmt.Println(err)
|
||||
os.Exit(1)
|
||||
} else if state == "deleted" {
|
||||
kv.DeleteInDB(db, "subnet/"+c.Name)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue