Compute Engine 可讓您在映像檔上設定淘汰狀態,以淘汰您擁有的自訂映像檔。每一種淘汰狀態會引起不同的伺服器反應,協助您採用易管理的方法,為使用者淘汰不再支援的映像檔。您可以使用 Trusted Cloud 控制台、Google Cloud CLI 或 Compute Engine API 方法來淘汰映像檔。
淘汰狀態
支援的淘汰狀態如下:
ACTIVE
:圖片有效,可正常使用。映像檔系列會指向系列中最新且有效的映像檔。DEPRECATED
:映像檔標示為已淘汰,但仍可用於建立 VM。 您仍然可以建立此圖片的新連結。即使它是系列中最新的映像檔,映像檔系列也不再指向此映像檔。如果您使用 Google Cloud CLI 透過已淘汰的映像檔建立 VM,要求會成功執行,但會顯示警告。
OBSOLETE
:圖片已標示為過時,無法再使用。 如果您嘗試在要求中使用此映像檔,系統會傳回錯誤訊息。仍然允許對於此映像檔的現有連結。DELETED
:這張圖片已刪除。如果您嘗試使用已刪除的圖片,系統會傳回錯誤訊息。
如要還原淘汰狀態 (再次啟用圖片),請將淘汰狀態變更為 ACTIVE
。
事前準備
- 參閱映像檔文件。
-
如果尚未設定驗證,請先完成設定。
「驗證」是指驗證身分的程序,確認您有權存取 Trusted Cloud by S3NS 服務和 API。如要從本機開發環境執行程式碼或範例,請選取下列任一選項,向 Compute Engine 進行驗證:
Select the tab for how you plan to use the samples on this page:
Console
When you use the Trusted Cloud console to access Trusted Cloud by S3NS services and APIs, you don't need to set up authentication.
gcloud
-
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
- Set a default region and zone.
REST
如要在本機開發環境中使用本頁的 REST API 範例,請使用您提供給 gcloud CLI 的憑證。
安裝 Google Cloud CLI,然後 使用同盟身分登入 gcloud CLI。 登入後,執行下列指令初始化 Google Cloud CLI:
gcloud init
詳情請參閱 Trusted Cloud 驗證說明文件中的「Authenticate for using REST」。
淘汰自訂映像檔
主控台
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
:要用來取代淘汰映像檔的映像檔。
除非另有註明,否則本頁面中的內容是採用創用 CC 姓名標示 4.0 授權,程式碼範例則為阿帕契 2.0 授權。詳情請參閱《Google Developers 網站政策》。Java 是 Oracle 和/或其關聯企業的註冊商標。
上次更新時間:2025-08-19 (世界標準時間)。
[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["缺少我需要的資訊","missingTheInformationINeed","thumb-down"],["過於複雜/步驟過多","tooComplicatedTooManySteps","thumb-down"],["過時","outOfDate","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["示例/程式碼問題","samplesCodeIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-08-19 (世界標準時間)。"],[[["Compute Engine allows users to deprecate custom images, transitioning users away from unsupported images using different deprecation states."],["There are four deprecation states for images: `ACTIVE`, `DEPRECATED`, `OBSOLETE`, and `DELETED`, each with different effects on image availability and usage."],["Deprecated images can still be used to create VMs, but image families no longer point to them, and using them with the gcloud CLI will trigger a warning."],["Obsolete images are no longer available for use, while deleted images are permanently removed, and both will return an error message upon any attempt to be used."],["Users can change the deprecation state of an image back to `ACTIVE` to make it usable again, which can be done through the Google Cloud Console, gcloud CLI, or the Compute Engine API."]]],[]] -