Use interface name instead of cluster name
The cluster name option is not required anymore and removed, the interface name is used to name the cluster directly. For backward compatibility, the old path for storing cluster state is tried as a fallback when loading.
This commit is contained in:
@ -17,10 +17,12 @@ type state struct {
|
||||
Nodes []common.Node
|
||||
}
|
||||
|
||||
var defaultStatePath = "/var/lib/wesher/%s.json"
|
||||
var statePathTemplate = "/var/lib/wesher/%s.json"
|
||||
|
||||
const deprecatedStatePath = "/var/lib/wesher/state.json"
|
||||
|
||||
func (s *state) save(clusterName string) error {
|
||||
statePath := fmt.Sprintf(defaultStatePath, clusterName)
|
||||
statePath := fmt.Sprintf(statePathTemplate, clusterName)
|
||||
if err := os.MkdirAll(path.Dir(statePath), 0700); err != nil {
|
||||
return err
|
||||
}
|
||||
@ -34,13 +36,21 @@ func (s *state) save(clusterName string) error {
|
||||
}
|
||||
|
||||
func loadState(cs *state, clusterName string) {
|
||||
statePath := fmt.Sprintf(defaultStatePath, clusterName)
|
||||
statePath := fmt.Sprintf(statePathTemplate, clusterName)
|
||||
content, err := ioutil.ReadFile(statePath)
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
logrus.Warnf("could not open state in %s: %s", statePath, err)
|
||||
// try the deprecated pre 0.3 state path, it will later
|
||||
// be saved to the proper path
|
||||
if os.IsNotExist(err) {
|
||||
content, err = ioutil.ReadFile(deprecatedStatePath)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
if !os.IsNotExist(err) {
|
||||
logrus.Warnf("could not open state in %s: %s", statePath, err)
|
||||
}
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
// avoid partially unmarshalled content by using a temp var
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
)
|
||||
|
||||
func Test_state_save_soad(t *testing.T) {
|
||||
defaultStatePath = "/tmp/%s.json"
|
||||
statePathTemplate = "/tmp/%s.json"
|
||||
key := "abcdefghijklmnopqrstuvwxyzABCDEF"
|
||||
node := common.Node{
|
||||
Name: "node",
|
||||
|
Reference in New Issue
Block a user