diff --git a/cnm/plugin/main.go b/cnm/plugin/main.go index 995b957545..287113aee7 100644 --- a/cnm/plugin/main.go +++ b/cnm/plugin/main.go @@ -96,6 +96,13 @@ var args = common.ArgumentList{ Type: "bool", DefaultValue: false, }, + { + Name: common.OptStoreFileLocation, + Shorthand: common.OptStoreFileLocationAlias, + Description: "Set store file absolute path", + Type: "string", + DefaultValue: platform.CNMRuntimePath, + }, } // Prints description and version information. @@ -116,6 +123,7 @@ func main() { ipamQueryUrl, _ := common.GetArg(common.OptIpamQueryUrl).(string) ipamQueryInterval, _ := common.GetArg(common.OptIpamQueryInterval).(int) vers := common.GetArg(common.OptVersion).(bool) + storeFileLocation := common.GetArg(common.OptStoreFileLocation).(string) if vers { printVersion() @@ -143,16 +151,17 @@ func main() { return } - err = common.CreateDirectory(platform.CNMRuntimePath) + err = common.CreateDirectory(storeFileLocation) if err != nil { - fmt.Printf("Failed to create File Store directory Error:%v", err.Error()) + log.Errorf("Failed to create File Store directory %s, due to Error:%v", storeFileLocation, err.Error()) return } // Create the key value store. - config.Store, err = store.NewJsonFileStore(platform.CNMRuntimePath + name + ".json") + storeFileName := storeFileLocation + name + ".json" + config.Store, err = store.NewJsonFileStore(storeFileName) if err != nil { - fmt.Printf("Failed to create store: %v\n", err) + log.Errorf("Failed to create store file: %s, due to error %v\n", storeFileName, err) return } diff --git a/cns/service/main.go b/cns/service/main.go index 3609aba856..6c160f4d93 100644 --- a/cns/service/main.go +++ b/cns/service/main.go @@ -166,6 +166,13 @@ var args = acn.ArgumentList{ Type: "int", DefaultValue: "120", }, + { + Name: acn.OptStoreFileLocation, + Shorthand: acn.OptStoreFileLocationAlias, + Description: "Set store file absolute path", + Type: "string", + DefaultValue: platform.CNMRuntimePath, + }, } // Prints description and version information. @@ -195,6 +202,7 @@ func main() { telemetryEnabled := acn.GetArg(acn.OptTelemetry).(bool) httpConnectionTimeout := acn.GetArg(acn.OptHttpConnectionTimeout).(int) httpResponseHeaderTimeout := acn.GetArg(acn.OptHttpResponseHeaderTimeout).(int) + storeFileLocation := acn.GetArg(acn.OptStoreFileLocation).(string) if vers { printVersion() @@ -231,16 +239,17 @@ func main() { // Log platform information. log.Printf("Running on %v", platform.GetOSInfo()) - err = acn.CreateDirectory(platform.CNMRuntimePath) + err = acn.CreateDirectory(storeFileLocation) if err != nil { - log.Errorf("Failed to create File Store directory Error:%v", err.Error()) + log.Errorf("Failed to create File Store directory %s, due to Error:%v", storeFileLocation, err.Error()) return } // Create the key value store. - config.Store, err = store.NewJsonFileStore(platform.CNMRuntimePath + name + ".json") + storeFileName := storeFileLocation + name + ".json" + config.Store, err = store.NewJsonFileStore(storeFileName) if err != nil { - log.Errorf("Failed to create store: %v\n", err) + log.Errorf("Failed to create store file: %s, due to error %v\n", storeFileName, err) return } @@ -310,9 +319,10 @@ func main() { } // Create the key value store. - pluginConfig.Store, err = store.NewJsonFileStore(platform.CNMRuntimePath + pluginName + ".json") + pluginStoreFile := storeFileLocation + pluginName + ".json" + pluginConfig.Store, err = store.NewJsonFileStore(pluginStoreFile) if err != nil { - log.Errorf("Failed to create store: %v\n", err) + log.Errorf("Failed to create plugin store file %s, due to error : %v\n", pluginStoreFile, err) return } diff --git a/common/config.go b/common/config.go index 7a272dc73e..bf28971846 100644 --- a/common/config.go +++ b/common/config.go @@ -87,4 +87,8 @@ const ( // HTTP response header timeout OptHttpResponseHeaderTimeout = "http-response-header-timeout" OptHttpResponseHeaderTimeoutAlias = "httprespheadertimeout" + + // Store file location + OptStoreFileLocation = "store-file-path" + OptStoreFileLocationAlias = "storefilepath" )