Compute Engine 可让您在映像上设置弃用状态,以便弃用您所拥有的自定义映像。每个弃用状态都会引起服务器的不同响应,从而帮助您以一种可管理的方式将用户从不受支持的映像转移出去。可以使用 Google Cloud 控制台、Google Cloud CLI 或 Compute Engine API 方法来弃用映像。
弃用状态
支持以下弃用状态:
ACTIVE
:映像处于活跃状态,并且可以正常使用。映像系列指向一个系列中最新、最活跃的映像。DEPRECATED
:映像被标记为“已弃用”,但仍可用于创建虚拟机。您可以为此映像创建新的链接。即使此映像是某个系列中最新的映像,映像系列也不会再指向此映像。如果您使用 Google Cloud CLI 创建具有已弃用映像的虚拟机,则请求会成功并显示一条警告。
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 身份验证文档中的使用 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" }
请替换以下内容:
如未另行说明,那么本页面中的内容已根据知识共享署名 4.0 许可获得了许可,并且代码示例已根据 Apache 2.0 许可获得了许可。有关详情,请参阅 Google 开发者网站政策。Java 是 Oracle 和/或其关联公司的注册商标。
最后更新时间 (UTC):2025-07-08。
-