f-11: code: move start and stop metadata #11
Signed-off-by: GnomeZworc <nicolas.boufidjeline@g3e.fr>
This commit is contained in:
parent
9780947805
commit
a8ffeebb72
9 changed files with 46 additions and 30 deletions
|
|
@ -5,9 +5,8 @@ import (
|
|||
"fmt"
|
||||
|
||||
configuration "git.g3e.fr/syonad/two/internal/config/agent"
|
||||
"git.g3e.fr/syonad/two/internal/load_db/nocloud"
|
||||
"git.g3e.fr/syonad/two/internal/metadata"
|
||||
"git.g3e.fr/syonad/two/pkg/db/kv"
|
||||
"git.g3e.fr/syonad/two/pkg/systemd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
@ -24,8 +23,6 @@ func main() {
|
|||
|
||||
flag.Parse()
|
||||
|
||||
service, _ := systemd.New()
|
||||
|
||||
conf, err := configuration.LoadConfig(*conf_file)
|
||||
if err != nil {
|
||||
fmt.Println(err)
|
||||
|
|
@ -38,21 +35,15 @@ func main() {
|
|||
defer db.Close()
|
||||
|
||||
if *start {
|
||||
nocloud.LoadNcCloudInDB(nocloud.Config{
|
||||
metadata.StartMetadata(metadata.NoCloudConfig{
|
||||
VpcName: *vpc,
|
||||
Name: *vm_name,
|
||||
BindIP: *bind_ip,
|
||||
BindPort: *bind_port,
|
||||
Password: *password,
|
||||
SSHKEY: *ssh_key,
|
||||
}, db)
|
||||
if !*dryrun {
|
||||
service.Start("metadata@" + *vm_name)
|
||||
}
|
||||
}, db, *dryrun)
|
||||
} else if *stop {
|
||||
nocloud.UnLoadNoCloudInDB(*vm_name, db)
|
||||
if !*dryrun {
|
||||
service.Stop("metadata@" + *vm_name)
|
||||
}
|
||||
metadata.StopMetadata(*vm_name, db, *dryrun)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +0,0 @@
|
|||
package nocloud
|
||||
|
||||
type Config struct {
|
||||
VpcName string
|
||||
BindIP string
|
||||
BindPort string
|
||||
Name string
|
||||
Password string
|
||||
SSHKEY string
|
||||
}
|
||||
26
internal/metadata/handle.go
Normal file
26
internal/metadata/handle.go
Normal 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)
|
||||
}
|
||||
}
|
||||
|
|
@ -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)
|
||||
|
|
@ -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
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue