當您呼叫會變異資源的 Compute Engine API 時,Compute Engine 會在作業清單中新增項目。舉例來說,如果您對 VM 進行更新,而該更新會變異 (變更) 資料,或是發生 主機事件而變更 VM 狀態,系統就會建立作業。本頁說明如何使用 Google Cloud 控制台、Google Cloud CLI 或 REST 查看 Compute Engine 作業清單。
請注意,作業可能需要一段時間才能完成,因此您在查看時,可能會發現尚未完成的作業。如要查看未完成作業的最終狀態,建議您不要重複查看作業,而是等待作業完成。
事前準備
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 Google Cloud 服務和 API 的程序。如要在本機開發環境中執行程式碼或範例,您可以選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Google Cloud console to access Google Cloud services and APIs, you don't need to set up authentication.
gcloud
-
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
- Set a default region and zone.
REST
To use the REST API samples on this page in a local development environment, you use the credentials you provide to the gcloud CLI.
After installing the Google Cloud CLI, initialize it by running the following command:
gcloud init
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
For more information, see Authenticate for using REST in the Google Cloud authentication documentation.
-
作業保留期限
在查詢作業時,請注意,完成的作業會在特定時間後自動從資料庫中移除。
Compute Engine 會將已完成的作業保留至少 1 小時,最長則為 14 天。雖然完成的作業通常會保留超過 1 小時,但不建議依據額外的保留期限。
請注意,保留期間不適用於使用者透過 Operations.delete
方法刪除的作業。
查看作業
如要查看專案的作業清單,請執行下列步驟:
主控台
前往 Google Cloud 控制台的「Operations」頁面。
如要進一步瞭解作業,請按一下作業摘要。舉例來說,如要查看
my-instance
VM 的遷移詳細資料,請按一下「自動遷移執行個體」作業。
gcloud
如要使用 gcloud compute
查看專案的作業清單,請使用 operations list
子指令。
如要查看指定區域中的作業清單,請新增 --filter
旗標。
gcloud compute operations list --filter="zone:(ZONE)"
將 ZONE
替換為您要查看作業清單的區域。舉例來說,如要查看 us-cental1-c
中的作業清單,請執行下列指令:
gcloud compute operations list --filter="zone:(us-central1-c)"
輸出結果會與下列內容相似:
NAME TYPE TARGET HTTP_STATUS STATUS TIMESTAMP
systemevent-1543845145000... compute.instances.migrateOnHostMaintenance us-central1-c/instances/my-instance 200 DONE 2018-12-03T05:52:25.000-08:00
REST
您必須在全域、地區或區域層級指定作業的 API 要求。即時遷移、VM 停止和自動重新啟動都是區域層級作業。
如果是區域作業,請向 zoneOperations.list
方法發出 GET
要求。
GET https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/zones/ZONE/operations
更改下列內容:
PROJECT_ID
:這項要求的專案 IDZONE
:這項要求的可用區
將要求主體保留空白。
以下是區域作業要求的輸出範例。在此輸出中,會顯示主機遷移的詳細資料。
{ "kind": "compute#operation", "id": "3216798767364213712", "name": "systemevent-1543845145000-57c1e7574b840-a195b637-5ff74d9b", "zone": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c", "operationType": "compute.instances.migrateOnHostMaintenance", "targetLink": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c/instances/my-instance", "targetId": "3070988523247098025", "status": "DONE", "statusMessage": "Instance migrated during Compute Engine maintenance.", "user": "system", "progress": 100, "insertTime": "2018-12-03T05:52:25.000-08:00", "startTime": "2018-12-03T05:52:25.000-08:00", "endTime": "2018-12-03T05:52:25.000-08:00", "selfLink": "https://www.googleapis.com/compute/v1/projects/my-project/zones/us-central1-c/operations/systemevent-1543845145000-57c1e7574b840-a195b637-5ff74d9b" }