From 647670494aee28f6d5a2bb82b0a3b19fe15b2b3e Mon Sep 17 00:00:00 2001 From: Kazuki Shimizu Date: Sun, 30 Jun 2024 19:49:55 +0900 Subject: [PATCH] implemented preconf --- command_func.go | 7 +++++++ configs/spec_template.yaml | 3 +++ internal/pkg/shell/shell.go | 14 ++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/command_func.go b/command_func.go index c9e3dac..a227667 100644 --- a/command_func.go +++ b/command_func.go @@ -244,6 +244,13 @@ func CmdConf(c *cli.Context) error { nodeinfo[node.Name] = node.Type } + if len(tnconfig.PreConf) != 0 { + for _, preConf := range tnconfig.PreConf { + preConfCmds := shell.ExecCmd(preConf.Cmds) + utils.PrintCmds(os.Stdout, preConfCmds, verbose) + } + } + for _, nodeConfig := range tnconfig.NodeConfigs { execConfCmds := nodeConfig.ExecConf(nodeinfo[nodeConfig.Name]) for _, execConfCmd := range execConfCmds { diff --git a/configs/spec_template.yaml b/configs/spec_template.yaml index f956420..42a5c07 100644 --- a/configs/spec_template.yaml +++ b/configs/spec_template.yaml @@ -2,6 +2,9 @@ precmd: - cmds: - cmd: "" preinit: +- cmds: + - cmd: "" +preconf: - cmds: - cmd: "" postinit: diff --git a/internal/pkg/shell/shell.go b/internal/pkg/shell/shell.go index 6ff60c4..e0ba1c5 100644 --- a/internal/pkg/shell/shell.go +++ b/internal/pkg/shell/shell.go @@ -19,6 +19,7 @@ var log = l.New() type Tn struct { PreCmd []PreCmd `yaml:"precmd"` PreInit []PreInit `yaml:"preinit"` + PreConf []PreConf `yaml:"preconf"` PostInit []PostInit `yaml:"postinit"` PostFini []PostFini `yaml:"postfini"` Nodes []Node `yaml:"nodes" mapstructure:"nodes"` @@ -38,6 +39,11 @@ type PreInit struct { Cmds []Cmd `yaml:"cmds" mapstructure:"cmds"` } +// PreConf +type PreConf struct { + Cmds []Cmd `yaml:"cmds" mapstructure:"cmds"` +} + // PostInit type PostInit struct { Cmds []Cmd `yaml:"cmds" mapstructure:"cmds"` @@ -232,6 +238,13 @@ func GenerateFile() (genContent string, err error) { }, }, } + preconf := PreConf{ + Cmds: []Cmd{ + Cmd{ + Cmd: "", + }, + }, + } postinit := PostInit{ Cmds: []Cmd{ Cmd{ @@ -341,6 +354,7 @@ func GenerateFile() (genContent string, err error) { tnconfig := &Tn{ PreCmd: []PreCmd{precmd}, PreInit: []PreInit{preinit}, + PreConf: []PreConf{preconf}, PostInit: []PostInit{postinit}, PostFini: []PostFini{postfini}, Nodes: []Node{nodes},