使用 Azure CLI 追蹤非同步作業
某些 Azure CLI 作業是非同步。 若要追蹤非同步作業的狀態, operationStatuses
可以使用資源。 非同步命令可以使用 --debug
已啟用旗標來執行。 指定 時 --debug
,可以監視要求的進度。 藉由檢查 Azure-AsyncOperation
建立要求的 HTTP 回應上的 或 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/12312312-1231-1231-1231-123123123123*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"
此要求會傳回可使用相同命令重新查詢的作業狀態結果,直到狀態達到 或 Failed
的最終狀態 Succeeded
為止。 此時,要求的作業已停止。
{
"endTime": "2023-02-08T17:38:31.2042934Z",
"error": {},
"id": "subscriptions/.../providers/Microsoft.NetworkCloud/locations/EASTUS/operationStatuses/12312312-1231-1231-1231-123123123123*99399E995...?api-version=2022-12-12-preview",
"name": "12312312-1231-1231-1231-123123123123*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"
}