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.
IMAGE_NAME
:要淘汰的映像檔名稱STATE
:廢止狀態REPLACEMENT
:要用來取代淘汰映像檔的映像檔PROJECT_ID
:映像檔所屬的專案。RESOURCE_ID
:要淘汰的映像檔名稱。STATE
:這項資源的淘汰狀態。REPLACEMENT
:要用來取代淘汰映像檔的映像檔。
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 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.
詳情請參閱 Google Cloud 驗證說明文件中的「Authenticate for using REST」。
淘汰自訂映像檔
主控台
gcloud
使用
gcloud compute images deprecate
指令設定映像檔的淘汰狀態。gcloud compute images deprecate IMAGE_NAME \ --state STATE \ --replacement 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" }
更改下列內容:
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-07-11 (世界標準時間)。
-