@@ -41,6 +41,7 @@ type GCECompute interface {
41
41
DetachDisk (ctx context.Context , volumeZone , instanceName , volumeName string ) (* compute.Operation , error )
42
42
GetDiskSourceURI (disk * compute.Disk , zone string ) string
43
43
GetDiskTypeURI (zone , diskType string ) string
44
+ WaitForAttach (ctx context.Context , zone , diskName , instanceName string ) error
44
45
// Instance Methods
45
46
GetInstanceOrError (ctx context.Context , instanceZone , instanceName string ) (* compute.Instance , error )
46
47
// Operation Methods
@@ -158,6 +159,27 @@ func (cloud *CloudProvider) WaitForOp(ctx context.Context, op *compute.Operation
158
159
})
159
160
}
160
161
162
+ func (cloud * CloudProvider ) WaitForAttach (ctx context.Context , zone , diskName , instanceName string ) error {
163
+ return wait .Poll (5 * time .Second , 2 * time .Minute , func () (bool , error ) {
164
+ disk , err := cloud .GetDiskOrError (ctx , zone , diskName )
165
+ if err != nil {
166
+ glog .Errorf ("GetDiskOrError failed to get disk: %v" , err )
167
+ return false , err
168
+ }
169
+
170
+ if disk == nil {
171
+ return false , fmt .Errorf ("Disk %v could not be found in zone %v" , diskName , zone )
172
+ }
173
+
174
+ for _ , user := range disk .Users {
175
+ if strings .Contains (user , instanceName ) && strings .Contains (user , zone ) {
176
+ return true , nil
177
+ }
178
+ }
179
+ return false , nil
180
+ })
181
+ }
182
+
161
183
func opIsDone (op * compute.Operation ) bool {
162
184
return op != nil && op .Status == "DONE"
163
185
}
0 commit comments