你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
使用 Azure CLI 跟踪异步操作
某些 Azure CLI 操作是异步的。 若要跟踪异步操作的状态,可以使用 operationStatuses
资源。 可以在启用 --debug
标志的情况下运行异步命令。 指定 --debug
后,可以监视请求的进度。 可以通过检查对创建请求的 HTTP 响应上的 Azure-AsyncOperation
或 Location
标头来找到操作状态 URL。
... many lines of logged information ...
urllib3.connectionpool: https://management.azure.com:443 "PUT /subscriptions/.../resourceGroups/.../providers/Microsoft.NetworkCloud/clusters/.../metricsConfigurations/default?api-version=2022-12-12-preview HTTP/1.1" 201 926
cli.azure.cli.core.util: Response status: 201
cli.azure.cli.core.util: Response headers:
... several lines of http headers of the response ...
cli.azure.cli.core.util: 'Azure-AsyncOperation': 'https://management.azure.com/subscriptions/.../providers/Microsoft.NetworkCloud/locations/EASTUS/operationStatuses/12312312-1231-1231-1231-123123123123*99399E995...?api-version=2022-12-12-preview'
... remaining http headers of the response and more lines of logging ...
使用前面的值:https://management.azure.com/subscriptions/.../providers/Microsoft.NetworkCloud/locations/EASTUS/operationStatuses/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e*99399E995...?api-version=2022-12-12-preview
,可以发出 Azure CLI az rest
调用来检索操作状态。
az rest -m get -u "https://management.azure.com/subscriptions/.../providers/Microsoft.NetworkCloud/locations/EASTUS/operationStatuses/12312312-1231-1231-1231-123123123123*99399E995...?api-version=2022-12-12-preview"
此请求将返回使用同一命令重复查询的操作状态结果,直到状态达到最终状态 Succeeded
或 Failed
。 此时,所请求的操作已停止。
{
"endTime": "2023-02-08T17:38:31.2042934Z",
"error": {},
"id": "subscriptions/.../providers/Microsoft.NetworkCloud/locations/EASTUS/operationStatuses/aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e*99399E995...?api-version=2022-12-12-preview",
"name": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e*99399E995...",
"properties": null,
"resourceId": "subscriptions/.../resourceGroups/.../providers/Microsoft.NetworkCloud/clusters/.../metricsConfigurations/default?api-version=2022-12-12-preview",
"startTime": "2023-02-08T17:38:24.7576911Z",
"status": "Succeeded"
}