f-11: code: move start and stop metadata #11

Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
GnomeZworc 2026-01-07 23:16:58 +01:00
commit a8ffeebb72
Signed by: nicolas.boufideline
GPG key ID: 4406BBBF8845D632
9 changed files with 46 additions and 30 deletions

View file

@ -1,10 +0,0 @@
package nocloud
type Config struct {
VpcName string
BindIP string
BindPort string
Name string
Password string
SSHKEY string
}

View file

@ -0,0 +1,26 @@
package metadata
import (
"git.g3e.fr/syonad/two/pkg/systemd"
"github.com/dgraph-io/badger/v4"
)
func StartMetadata(config NoCloudConfig, db *badger.DB, dryrun bool) {
service, _ := systemd.New()
defer service.Close()
LoadNcCloudInDB(config, db)
if !dryrun {
service.Start("metadata@" + config.Name)
}
}
func StopMetadata(vm_name string, db *badger.DB, dryrun bool) {
service, _ := systemd.New()
defer service.Close()
UnLoadNoCloudInDB(vm_name, db)
if !dryrun {
service.Stop("metadata@" + vm_name)
}
}

View file

@ -1,4 +1,4 @@
package nocloud
package metadata
import (
"bytes"
@ -12,7 +12,7 @@ import (
//go:embed templates/*.tmpl
var templateFS embed.FS
func renderConfig(path string, cfg Config) (string, error) {
func RenderConfig(path string, cfg NoCloudConfig) (string, error) {
tpl, err := template.ParseFS(templateFS, path)
if err != nil {
return "", err
@ -26,11 +26,11 @@ func renderConfig(path string, cfg Config) (string, error) {
return buf.String(), nil
}
func LoadNcCloudInDB(config Config, db *badger.DB) {
meta_data, _ := renderConfig("templates/meta-data.tmpl", config)
user_data, _ := renderConfig("templates/user-data.tmpl", config)
network_config, _ := renderConfig("templates/network-config.tmpl", config)
vendor_data, _ := renderConfig("templates/vendor-data.tmpl", config)
func LoadNcCloudInDB(config NoCloudConfig, db *badger.DB) {
meta_data, _ := RenderConfig("templates/meta-data.tmpl", config)
user_data, _ := RenderConfig("templates/user-data.tmpl", config)
network_config, _ := RenderConfig("templates/network-config.tmpl", config)
vendor_data, _ := RenderConfig("templates/vendor-data.tmpl", config)
kv.AddInDB(db, "metadata/"+config.Name+"/meta-data", meta_data)
kv.AddInDB(db, "metadata/"+config.Name+"/user-data", user_data)

View file

@ -18,3 +18,12 @@ type ServerConfig struct {
ConfFile string
VmName string
}
type NoCloudConfig struct {
VpcName string
BindIP string
BindPort string
Name string
Password string
SSHKEY string
}