f-14: code: add db usage in vpc creation #14

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-01-26 20:10:56 +01:00
commit f9c1cd7d32
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
2 changed files with 62 additions and 37 deletions

View file

@ -5,21 +5,39 @@ import (
"fmt"
"os"
configuration "git.g3e.fr/syonad/two/internal/config/agent"
"git.g3e.fr/syonad/two/internal/vpc"
"git.g3e.fr/syonad/two/pkg/db/kv"
"github.com/dgraph-io/badger/v4"
)
var (
netns = flag.String("netns", "", "Network namespace à faire")
name = flag.String("name", "", "interface name")
action = flag.String("action", "", "Action a faire")
netns = flag.String("netns", "", "Network namespace à faire")
name = flag.String("name", "", "interface name")
action = flag.String("action", "", "Action a faire")
conf_file = flag.String("conf", "/etc/two/agent.yml", "configuration file")
)
var DB *badger.DB
func main() {
flag.Parse()
conf, err := configuration.LoadConfig(*conf_file)
if err != nil {
fmt.Println(err)
return
}
DB = kv.InitDB(kv.Config{
Path: conf.Database.Path,
}, false)
defer DB.Close()
switch *action {
case "create":
if err := vpc.CreateVPC(*name); err != nil {
kv.AddInDB(DB, "vpc/"+*name+"/state", "creating")
if err := vpc.CreateVPC(DB, *name); err != nil {
fmt.Println(err)
}
case "delete":