Skip to content

Commit b4f9840

Browse files
authored
Store file override (#452)
1 parent 61ccd6f commit b4f9840

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

cnm/plugin/main.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,13 @@ var args = common.ArgumentList{
9696
Type: "bool",
9797
DefaultValue: false,
9898
},
99+
{
100+
Name: common.OptStoreFileLocation,
101+
Shorthand: common.OptStoreFileLocationAlias,
102+
Description: "Set store file absolute path",
103+
Type: "string",
104+
DefaultValue: platform.CNMRuntimePath,
105+
},
99106
}
100107

101108
// Prints description and version information.
@@ -116,6 +123,7 @@ func main() {
116123
ipamQueryUrl, _ := common.GetArg(common.OptIpamQueryUrl).(string)
117124
ipamQueryInterval, _ := common.GetArg(common.OptIpamQueryInterval).(int)
118125
vers := common.GetArg(common.OptVersion).(bool)
126+
storeFileLocation := common.GetArg(common.OptStoreFileLocation).(string)
119127

120128
if vers {
121129
printVersion()
@@ -143,16 +151,17 @@ func main() {
143151
return
144152
}
145153

146-
err = common.CreateDirectory(platform.CNMRuntimePath)
154+
err = common.CreateDirectory(storeFileLocation)
147155
if err != nil {
148-
fmt.Printf("Failed to create File Store directory Error:%v", err.Error())
156+
log.Errorf("Failed to create File Store directory %s, due to Error:%v", storeFileLocation, err.Error())
149157
return
150158
}
151159

152160
// Create the key value store.
153-
config.Store, err = store.NewJsonFileStore(platform.CNMRuntimePath + name + ".json")
161+
storeFileName := storeFileLocation + name + ".json"
162+
config.Store, err = store.NewJsonFileStore(storeFileName)
154163
if err != nil {
155-
fmt.Printf("Failed to create store: %v\n", err)
164+
log.Errorf("Failed to create store file: %s, due to error %v\n", storeFileName, err)
156165
return
157166
}
158167

cns/service/main.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,13 @@ var args = acn.ArgumentList{
166166
Type: "int",
167167
DefaultValue: "120",
168168
},
169+
{
170+
Name: acn.OptStoreFileLocation,
171+
Shorthand: acn.OptStoreFileLocationAlias,
172+
Description: "Set store file absolute path",
173+
Type: "string",
174+
DefaultValue: platform.CNMRuntimePath,
175+
},
169176
}
170177

171178
// Prints description and version information.
@@ -195,6 +202,7 @@ func main() {
195202
telemetryEnabled := acn.GetArg(acn.OptTelemetry).(bool)
196203
httpConnectionTimeout := acn.GetArg(acn.OptHttpConnectionTimeout).(int)
197204
httpResponseHeaderTimeout := acn.GetArg(acn.OptHttpResponseHeaderTimeout).(int)
205+
storeFileLocation := acn.GetArg(acn.OptStoreFileLocation).(string)
198206

199207
if vers {
200208
printVersion()
@@ -231,16 +239,17 @@ func main() {
231239
// Log platform information.
232240
log.Printf("Running on %v", platform.GetOSInfo())
233241

234-
err = acn.CreateDirectory(platform.CNMRuntimePath)
242+
err = acn.CreateDirectory(storeFileLocation)
235243
if err != nil {
236-
log.Errorf("Failed to create File Store directory Error:%v", err.Error())
244+
log.Errorf("Failed to create File Store directory %s, due to Error:%v", storeFileLocation, err.Error())
237245
return
238246
}
239247

240248
// Create the key value store.
241-
config.Store, err = store.NewJsonFileStore(platform.CNMRuntimePath + name + ".json")
249+
storeFileName := storeFileLocation + name + ".json"
250+
config.Store, err = store.NewJsonFileStore(storeFileName)
242251
if err != nil {
243-
log.Errorf("Failed to create store: %v\n", err)
252+
log.Errorf("Failed to create store file: %s, due to error %v\n", storeFileName, err)
244253
return
245254
}
246255

@@ -310,9 +319,10 @@ func main() {
310319
}
311320

312321
// Create the key value store.
313-
pluginConfig.Store, err = store.NewJsonFileStore(platform.CNMRuntimePath + pluginName + ".json")
322+
pluginStoreFile := storeFileLocation + pluginName + ".json"
323+
pluginConfig.Store, err = store.NewJsonFileStore(pluginStoreFile)
314324
if err != nil {
315-
log.Errorf("Failed to create store: %v\n", err)
325+
log.Errorf("Failed to create plugin store file %s, due to error : %v\n", pluginStoreFile, err)
316326
return
317327
}
318328

common/config.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,8 @@ const (
8787
// HTTP response header timeout
8888
OptHttpResponseHeaderTimeout = "http-response-header-timeout"
8989
OptHttpResponseHeaderTimeoutAlias = "httprespheadertimeout"
90+
91+
// Store file location
92+
OptStoreFileLocation = "store-file-path"
93+
OptStoreFileLocationAlias = "storefilepath"
9094
)

0 commit comments

Comments
 (0)