共用方式為


使用 Azure CLI 追蹤異步操作

某些 Azure CLI 作業是異步的。 若要追蹤異步操作的狀態, operationStatuses 可以使用資源。 異步命令可以使用 --debug 已啟用旗標來執行。 指定 --debug 時,可以監視要求的進度。 檢查建立要求的 HTTP 回應上的 或 Location 標頭,即可找到Azure-AsyncOperation作業狀態 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"

此要求會傳回作業狀態結果,可使用相同的命令重新查詢,直到狀態達到 或Failed的最終狀態Succeeded為止。 此時,要求的作業已停止。

{
  "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"
}