Compute Engine 可讓您在映像檔上設定淘汰狀態,以淘汰您擁有的自訂映像檔。每一種淘汰狀態會引起不同的伺服器反應,協助您採用易管理的方法,為使用者淘汰不再支援的映像檔。您可以使用 Google Cloud 主控台、Google Cloud CLI 或 Compute Engine API 方法來淘汰映像檔。
淘汰狀態
系統支援下列淘汰狀態:
ACTIVE
:圖片處於活動狀態,可正常使用。映像檔系列會指向系列中最新的映像檔。DEPRECATED
:映像檔已標示為已淘汰,但仍可用於建立 VM。您可以建立此圖片的新連結。即使它是系列中最新的映像檔,映像檔系列也不再指向此映像檔。如果您使用 Google Cloud CLI 建立含有已淘汰映像檔的 VM,要求會成功,並顯示警告。
OBSOLETE
:圖片已標示為過時,無法再使用。如果您嘗試在要求中使用此圖片,系統會傳回錯誤訊息。仍然允許對於此映像檔的現有連結。DELETED
:這個圖片已刪除。如果您嘗試使用已刪除的圖片,系統會傳回錯誤訊息。
您可以將淘汰狀態變更為 ACTIVE
,藉此還原淘汰狀態 (讓圖片再次啟用)。
事前準備
- 參閱「圖片」說明文件。
-
如果尚未設定,請先設定驗證機制。驗證是指驗證身分,以便存取 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.
-
淘汰自訂映像檔
主控台
gcloud
使用 gcloud compute images deprecate
指令設定映像檔的淘汰狀態。
gcloud compute images deprecate IMAGE_NAME \ --state STATE \ --replacement REPLACEMENT
更改下列內容:
IMAGE_NAME
:要淘汰的映像檔名稱STATE
:廢止狀態REPLACEMENT
:要用來取代淘汰圖片的圖片
Go
Java
Python
REST
對 images().deprecate
方法提出 POST
要求。指定要淘汰的映像檔名稱。
POST https://compute.googleapis.com/compute/v1/projects/PROJECT_ID/global/images/RESOURCE_ID/deprecate { "state": "STATE", "replacement": "REPLACEMENT" }
更改下列內容:
PROJECT_ID
:映像檔所屬的專案。RESOURCE_ID
:您要淘汰的圖片名稱。STATE
:此資源的淘汰狀態。REPLACEMENT
:用來取代淘汰圖片的圖片。