@@ -171,12 +171,17 @@ func (o *ZapiRunner) GetOntapApiVersion() string {
171171
172172// SendZapi sends the provided ZAPIRequest to the Ontap system
173173func (o * ZapiRunner ) SendZapi (r ZAPIRequest ) (* http.Response , error ) {
174+ return o .SendZapiWithContext (context .Background (), r )
175+ }
176+
177+ // SendZapiWithContext sends the provided ZAPIRequest to the Ontap system using the provided context
178+ func (o * ZapiRunner ) SendZapiWithContext (ctx context.Context , r ZAPIRequest ) (* http.Response , error ) {
174179 startTime := time .Now ()
175180
176181 if o .DebugTraceFlags ["method" ] {
177- fields := log.Fields {"Method" : "SendZapi " , "Type" : "ZapiRunner" }
178- log .WithFields (fields ).Debug (">>>> SendZapi " )
179- defer log .WithFields (fields ).Debug ("<<<< SendZapi " )
182+ fields := log.Fields {"Method" : "SendZapiWithContext " , "Type" : "ZapiRunner" }
183+ log .WithFields (fields ).Debug (">>>> SendZapiWithContext " )
184+ defer log .WithFields (fields ).Debug ("<<<< SendZapiWithContext " )
180185 }
181186
182187 zapiCommand , err := r .ToXML ()
@@ -226,8 +231,12 @@ func (o *ZapiRunner) SendZapi(r ZAPIRequest) (*http.Response, error) {
226231 }
227232
228233 b := []byte (s )
229- ctx , cancel := context .WithTimeout (context .Background (), tridentconfig .StorageAPITimeout )
234+
235+ // Add default timeout
236+ var cancel context.CancelFunc
237+ ctx , cancel = context .WithTimeout (ctx , tridentconfig .StorageAPITimeout )
230238 defer cancel ()
239+
231240 req , err := http .NewRequestWithContext (ctx , "POST" , url , bytes .NewBuffer (b ))
232241 if err != nil {
233242 return nil , err
@@ -254,6 +263,11 @@ func (o *ZapiRunner) SendZapi(r ZAPIRequest) (*http.Response, error) {
254263
255264// ExecuteUsing converts this object to a ZAPI XML representation and uses the supplied ZapiRunner to send to a filer
256265func (o * ZapiRunner ) ExecuteUsing (z ZAPIRequest , requestType string , v interface {}) (interface {}, error ) {
266+ return o .ExecuteUsingWithContext (context .Background (), z , requestType , v )
267+ }
268+
269+ // ExecuteUsingWithContext converts this object to a ZAPI XML representation and uses the supplied ZapiRunner to send to a filer with context support
270+ func (o * ZapiRunner ) ExecuteUsingWithContext (ctx context.Context , z ZAPIRequest , requestType string , v interface {}) (interface {}, error ) {
257271 // Copy the v interface, in case we need a clean version for a retry
258272 o .m .RLock ()
259273 var vCopy interface {}
@@ -266,7 +280,7 @@ func (o *ZapiRunner) ExecuteUsing(z ZAPIRequest, requestType string, v interface
266280 svm := o .svm
267281
268282 // Try API call as-is first
269- response , err := o .executeWithoutIteration ( z , requestType , v )
283+ response , err := o .executeWithoutIterationWithContext ( ctx , z , requestType , v )
270284 o .m .RUnlock ()
271285 if err != nil {
272286 // Always return an error if the call itself failed
@@ -289,18 +303,23 @@ func (o *ZapiRunner) ExecuteUsing(z ZAPIRequest, requestType string, v interface
289303 o .svm = fmt .Sprintf ("%s-mc" , svm )
290304 }
291305
292- return o .executeWithoutIteration ( z , requestType , vCopy )
306+ return o .executeWithoutIterationWithContext ( ctx , z , requestType , vCopy )
293307}
294308
295309// executeWithoutIteration does not attempt to perform any nextTag style iteration
296310func (o * ZapiRunner ) executeWithoutIteration (z ZAPIRequest , requestType string , v interface {}) (interface {}, error ) {
311+ return o .executeWithoutIterationWithContext (context .Background (), z , requestType , v )
312+ }
313+
314+ // executeWithoutIterationWithContext does not attempt to perform any nextTag style iteration, with context support
315+ func (o * ZapiRunner ) executeWithoutIterationWithContext (ctx context.Context , z ZAPIRequest , requestType string , v interface {}) (interface {}, error ) {
297316 if o .DebugTraceFlags ["method" ] {
298- fields := log.Fields {"Method" : "ExecuteUsing " , "Type" : requestType }
299- log .WithFields (fields ).Debug (">>>> ExecuteUsing " )
300- defer log .WithFields (fields ).Debug ("<<<< ExecuteUsing " )
317+ fields := log.Fields {"Method" : "executeWithoutIterationWithContext " , "Type" : requestType }
318+ log .WithFields (fields ).Debug (">>>> executeWithoutIterationWithContext " )
319+ defer log .WithFields (fields ).Debug ("<<<< executeWithoutIterationWithContext " )
301320 }
302321
303- resp , err := o .SendZapi ( z )
322+ resp , err := o .SendZapiWithContext ( ctx , z )
304323 if err != nil {
305324 log .Errorf ("API invocation failed. %v" , err .Error ())
306325 return nil , err
0 commit comments