[英]Images not getting deleted in Azure even after getting success status code using REST API in C#
I am using the API: https://management.azure.com/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Compute/images/{imageName}?api-version=2019-03-01
to delete the Images.我正在使用 API:
https://management.azure.com/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Compute/images/{imageName}?api-version=2019-03-01
: https://management.azure.com/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Compute/images/{imageName}?api-version=2019-03-01
resourceGroups/ https://management.azure.com/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Compute/images/{imageName}?api-version=2019-03-01
api- https://management.azure.com/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Compute/images/{imageName}?api-version=2019-03-01
删除图像。 Here's the code (the code is executed in a loop of list of Images):这是代码(代码在图像列表的循环中执行):
using (var client = new HttpClient())
{
client.DefaultRequestHeaders.Add("Authorization", "Bearer " + accessToken); //obtained from https://management.azure.com/
client.BaseAddress = new Uri(BaseManagementUri); //https://management.azure.com/
using (var responseGet = client.DeleteAsync(api).Result)
{
if (responseGet.IsSuccessStatusCode) //returns true and status code is 202
{
log.LogInformation($"Deleted {resourceUri}");
}
else
{
log.LogWarning($"Failed to deleted {resourceUri}\n{responseGet.Content.ReadAsByteArrayAsync().Result}");
}
}
}
The responseGet contains: StatusCode: 202, ReasonPhrase: 'Accepted', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent
, StatusCode: Accepted
. responseGet 包含:
StatusCode: 202, ReasonPhrase: 'Accepted', Version: 1.1, Content: System.Net.Http.HttpConnection+HttpConnectionResponseContent
, StatusCode: Accepted
。
When I check the Azure Portal or GET
list of images using REST API , I can see the Image is still present.当我 使用 REST API检查 Azure 门户或
GET
图像列表时,我可以看到图像仍然存在。 But when I run the same code for deleting the snapshot it gets deleted successfully.但是当我运行相同的代码删除快照时,它会被成功删除。 I use the same API for snapshot and looks like this:
https://management.azure.com/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Compute/snapshots/{snapshotName}?api-version=2019-03-01
.我对快照使用相同的 API,如下所示:
https://management.azure.com/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Compute/snapshots/{snapshotName}?api-version=2019-03-01
: https://management.azure.com/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Compute/snapshots/{snapshotName}?api-version=2019-03-01
snapshotName}?api-version https://management.azure.com/subscriptions/{subId}/resourceGroups/{rgName}/providers/Microsoft.Compute/snapshots/{snapshotName}?api-version=2019-03-01
。
What should I do for deleting the Image?删除图像应该怎么做?
Different REST APIs will return different results, when you get the 202 (Accepted)
, the operation will not be completed immediately, you need to call another API like below to check the progress.不同的 REST API 会返回不同的结果,当你得到
202 (Accepted)
,操作不会立即完成,你需要调用另一个类似下面的 API 来检查进度。
GET https://management.azure.com/subscriptions/{subscription-id}/providers/Microsoft.Compute/locations/{region}/operations/{operation-id}?api-version=2016-03-30
Please check this doc - Track asynchronous Azure operations
and this sample , also a similar issue here .请检查此文档 -
Track asynchronous Azure operations
和此示例, 此处也有类似问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.