@@ -250,8 +250,10 @@ func (a *App) startTransfer(t Task) {
250
250
}
251
251
252
252
func (a * App ) imageAccess (t Task ) {
253
+ operationName := "Disabling"
253
254
operation := "disable_image_access"
254
255
if t .Enable == true {
256
+ operationName = "Enabling"
255
257
operation = "image_access/latest/enable"
256
258
}
257
259
endpoint := fmt .Sprintf (
@@ -271,15 +273,36 @@ func (a *App) imageAccess(t Task) {
271
273
_ , statusCode := a .apiRequest ("PUT" , endpoint , bytes .NewBuffer (json ))
272
274
if statusCode != 204 {
273
275
log .Errorf ("Expected status code '204' and received: %d\n " , statusCode )
274
- log .Fatalf ("Error enabling Latest Image for Group %s Copy %s\n " , t .GroupName , t .CopyName )
276
+ log .Fatalf ("Error %s Latest Image for Group %s Copy %s\n " , operationName , t .GroupName , t .CopyName )
275
277
}
276
278
}
277
- fmt .Printf ("Enabling Latest Image for Group %s Copy %s\n " , t .GroupName , t .CopyName )
279
+ fmt .Printf ("%s Latest Image for Group %s Copy %s\n " , operationName , t .GroupName , t .CopyName )
280
+ }
281
+
282
+ func (a * App ) pollImageAccessEnabled (groupID int , stateDesired bool ) {
283
+ pollDelay := 3 // seconds
284
+ pollCount := 0 // iteration counter
285
+ pollMax := 60 // max times to poll before breaking the poll loop
286
+ fmt .Println ("waiting for image access to update.." )
287
+ groupCopiesSettings := a .getGroupCopiesSettings (groupID )
288
+ copySettings := a .getRequestedCopy (groupCopiesSettings )
289
+ for copySettings .ImageAccessInformation .ImageAccessEnabled != stateDesired {
290
+ time .Sleep (time .Duration (pollDelay ) * time .Second )
291
+ groupCopiesSettings = a .getGroupCopiesSettings (groupID )
292
+ copySettings = a .getRequestedCopy (groupCopiesSettings )
293
+ if pollCount > pollMax {
294
+ fmt .Println ("Maximum poll count reached while waiting for image access" )
295
+ break
296
+ }
297
+ pollCount ++
298
+ }
278
299
}
279
300
280
301
func (a * App ) directAccess (t Task ) {
302
+ operationName := "Disabling"
281
303
operation := "disable_direct_access"
282
304
if t .Enable == true {
305
+ operationName = "Enabling"
283
306
operation = "enable_direct_access"
284
307
}
285
308
endpoint := fmt .Sprintf (
@@ -292,7 +315,7 @@ func (a *App) directAccess(t Task) {
292
315
log .Fatalf ("Error enabling Direct Access for Group %s Copy %s\n " , t .GroupName , t .CopyName )
293
316
}
294
317
}
295
- fmt .Printf ("Enabling Direct Access for Group %s Copy %s\n " , t .GroupName , t .CopyName )
318
+ fmt .Printf ("%s Direct Access for Group %s Copy %s\n " , operationName , t .GroupName , t .CopyName )
296
319
}
297
320
298
321
// EnableAll wraper for enabling Direct Image Access for all CG
@@ -316,7 +339,7 @@ func (a *App) EnableAll() {
316
339
t .Enable = true // whether to enable or disable the following tasks
317
340
if ! a .Config .CheckMode {
318
341
a .imageAccess (t )
319
- time . Sleep ( 3 * time . Second ) // wait a few seconds for platform
342
+ a . pollImageAccessEnabled ( g . ID , true )
320
343
a .directAccess (t )
321
344
}
322
345
time .Sleep (time .Duration (a .Config .Delay ) * time .Second )
@@ -347,7 +370,7 @@ func (a *App) EnableOne() {
347
370
t .Enable = true // whether to enable or disable the following tasks
348
371
if ! a .Config .CheckMode {
349
372
a .imageAccess (t )
350
- time . Sleep ( 3 * time . Second ) // wait a few seconds for platform
373
+ a . pollImageAccessEnabled ( groupID , true )
351
374
a .directAccess (t )
352
375
}
353
376
}
@@ -368,7 +391,7 @@ func (a *App) FinishAll() {
368
391
t .Enable = false // whether to enable or disable the following tasks
369
392
if ! a .Config .CheckMode {
370
393
a .imageAccess (t )
371
- time . Sleep ( 3 * time . Second ) // wait a few seconds for platform
394
+ a . pollImageAccessEnabled ( g . ID , false )
372
395
a .startTransfer (t )
373
396
}
374
397
time .Sleep (time .Duration (a .Config .Delay ) * time .Second )
@@ -394,7 +417,7 @@ func (a *App) FinishOne() {
394
417
t .Enable = false // whether to enable or disable the following tasks
395
418
if ! a .Config .CheckMode {
396
419
a .imageAccess (t )
397
- time . Sleep ( 3 * time . Second ) // wait a few seconds for platform
420
+ a . pollImageAccessEnabled ( groupID , false )
398
421
a .startTransfer (t )
399
422
}
400
423
}
0 commit comments