Skip to content

Commit

Permalink
Store file override (#452)
Browse files Browse the repository at this point in the history
  • Loading branch information
ninzavivek authored Dec 5, 2019
1 parent 61ccd6f commit b4f9840
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
17 changes: 13 additions & 4 deletions cnm/plugin/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 16 additions & 6 deletions cns/service/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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
}

Expand Down
4 changes: 4 additions & 0 deletions common/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

0 comments on commit b4f9840

Please sign in to comment.