From 97132550b0b000e53cee7801152c1f84d04099f2 Mon Sep 17 00:00:00 2001 From: GnomeZworc Date: Fri, 26 Dec 2025 23:46:18 +0100 Subject: [PATCH] f-8: code: move Load in DB to internal lib #8 Signed-off-by: GnomeZworc --- cmd/meta_cli/main.go | 35 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/cmd/meta_cli/main.go b/cmd/meta_cli/main.go index ce97286..971c370 100644 --- a/cmd/meta_cli/main.go +++ b/cmd/meta_cli/main.go @@ -3,26 +3,12 @@ package main import ( "flag" "fmt" - "os" - "strings" configuration "git.g3e.fr/syonad/two/internal/config/agent" + "git.g3e.fr/syonad/two/internal/load_db/nocloud" "git.g3e.fr/syonad/two/pkg/db/kv" - "github.com/dgraph-io/badger/v4" ) -var DB *badger.DB - -func AddInDB(dbName string, line string) error { - // ID = partie avant le premier ';' - id := strings.Split(line, ";")[0] + "/bash" - key := []byte(dbName + "/" + id) - - return DB.Update(func(txn *badger.Txn) error { - return txn.Set(key, []byte(line)) - }) -} - func main() { conf_file := flag.String("conf", "/etc/two/agent.yml", "configuration file") vm_name := flag.String("vm_name", "", "Nom de la vm") @@ -43,12 +29,21 @@ func main() { } fmt.Print(conf) - DB = kv.InitDB(kv.Config{ + db := kv.InitDB(kv.Config{ Path: conf.Database.Path, }) - defer DB.Close() + defer db.Close() - fmt.Printf("conf metadata for %s\n - this key %s\n - this password %s\n", *vm_name, *ssh_key, *password) - - os.Exit(0) + if *start { + nocloud.LoadNcCloudInDB(nocloud.Config{ + VpcName: *vpc, + Name: *vm_name, + BindIP: *bind_ip, + BindPort: *bind_port, + Password: *password, + SSHKEY: *ssh_key, + }, db) + } else if *stop { + nocloud.UnLoadNoCloudInDB(*vm_name, db) + } }