You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// CreateVolumeWaitHandler will wait for volume creation
@@ -165,3 +177,117 @@ func DeleteServerWaitHandler(ctx context.Context, a APIClientInterface, projectI
165
177
handler.SetTimeout(20*time.Minute)
166
178
returnhandler
167
179
}
180
+
181
+
// ProjectRequestWaitHandler will wait for a request to succeed.
182
+
//
183
+
// It receives a request ID that can be obtained from the "X-Request-Id" header in the HTTP response of any operation in the IaaS API.
184
+
// To get this response header, use the "runtime.WithCaptureHTTPResponse" method from the "core" packaghe to get the raw HTTP response of an SDK operation.
185
+
// Then, the value of the request ID can be obtained by accessing the header key which is defined in the constant "XRequestIDHeader" of this package.
returnfalse, request, fmt.Errorf("request failed for request with id %s, the response is not valid: the id, the request action or the status are missing", requestId)
209
+
}
210
+
211
+
if*request.RequestId!=requestId {
212
+
returnfalse, request, fmt.Errorf("request failed for request with id %s: the response id doesn't match the request id", requestId)
213
+
}
214
+
215
+
switch*request.RequestAction {
216
+
caseRequestCreateAction:
217
+
if*request.Status==RequestCreatedStatus {
218
+
returntrue, request, nil
219
+
}
220
+
caseRequestUpdateAction:
221
+
if*request.Status==RequestUpdatedStatus {
222
+
returntrue, request, nil
223
+
}
224
+
caseRequestDeleteAction:
225
+
if*request.Status==RequestDeletedStatus {
226
+
returntrue, request, nil
227
+
}
228
+
default:
229
+
returnfalse, request, fmt.Errorf("request failed for request with id %s, the request action %s is not supported", requestId, *request.RequestAction)
230
+
}
231
+
232
+
if*request.Status==RequestFailedStatus {
233
+
returntrue, request, fmt.Errorf("request failed for request with id %s", requestId)
234
+
}
235
+
236
+
returnfalse, request, nil
237
+
})
238
+
handler.SetTimeout(20*time.Minute)
239
+
returnhandler
240
+
}
241
+
242
+
// AddVolumeToServerWaitHandler will wait for a volume to be attached to a server
returnfalse, volumeAttachment, fmt.Errorf("attachment failed for server with id %s and volume with id %s, the response is not valid: the volume id is missing", serverId, volumeId)
250
+
}
251
+
if*volumeAttachment.VolumeId==volumeId {
252
+
returntrue, volumeAttachment, nil
253
+
}
254
+
}
255
+
returnfalse, nil, nil
256
+
}
257
+
oapiErr, ok:=err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
258
+
if!ok {
259
+
returnfalse, volumeAttachment, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError: %w", err)
260
+
}
261
+
ifoapiErr.StatusCode!=http.StatusNotFound {
262
+
returnfalse, volumeAttachment, err
263
+
}
264
+
returnfalse, nil, nil
265
+
})
266
+
handler.SetTimeout(10*time.Minute)
267
+
returnhandler
268
+
}
269
+
270
+
// RemoveVolumeFromServerWaitHandler will wait for a volume to be attached to a server
returnfalse, volumeAttachment, fmt.Errorf("remove volume failed for server with id %s and volume with id %s, the response is not valid: the volume id is missing", serverId, volumeId)
278
+
}
279
+
}
280
+
returnfalse, nil, nil
281
+
}
282
+
oapiErr, ok:=err.(*oapierror.GenericOpenAPIError) //nolint:errorlint //complaining that error.As should be used to catch wrapped errors, but this error should not be wrapped
283
+
if!ok {
284
+
returnfalse, volumeAttachment, fmt.Errorf("could not convert error to oapierror.GenericOpenAPIError: %w", err)
0 commit comments