删除部署

本页面介绍了如何删除 Game Servers 部署。

准备工作

开始之前,我们建议您先了解 Game Servers 概览中的关键概念。请确保您已执行以下任务:

  • 确保您已启用 Game Services API。
  • 启用 Game Services API
  • 选择安装了 Cloud SDK 的 shell,或使用 API 客户端:
  • Cloud Shell

    如需启动 Cloud Shell,请执行以下步骤:

    1. 转到 Google Cloud Console。

      Google Cloud Console

    2. 在控制台的右上角,点击激活 Cloud Shell 按钮:

    控制台下方的框架内会打开一个 Cloud Shell 会话。您可以使用此 shell 运行 gcloud 命令。

    本地 shell

    如需安装 gcloud,请安装 Cloud SDK,其中包含 gcloud 命令行工具。

    确认您已为 gcloud 命令行工具设置所需的默认项目(否则,您需要以后为每个命令明确指定标志 --project):

    gcloud config list project
    

    如果无法运行以下命令来设置默认项目,请将 project-id 替换为所需的项目 ID:

    gcloud config set project project-id
    

    运行以下命令以验证 Google Cloud SDK 的版本。Game Servers 需要 306.0.0 或更高版本的 SDK。

    gcloud version
    

    如需更新安装,请运行以下命令:

    gcloud components update
    

    客户端库

    您可以使用客户端库以编程方式控制 Google Cloud Game Servers。如需了解库和身份验证的使用说明,请参阅客户端库概览

删除部署

在删除 Game Servers 部署之前,请务必删除该部署下的所有配置

gcloud 命令

您可以使用 gcloud 命令行工具删除部署。

如需删除部署,请运行以下命令,并将 deploymentID 替换为您之前创建的部署的标识符:

gcloud game servers deployments delete deploymentID

Go


import (
	"context"
	"fmt"
	"io"

	gaming "cloud.google.com/go/gaming/apiv1"
	gamingpb "google.golang.org/genproto/googleapis/cloud/gaming/v1"
)

// deleteGameServerDeployment deletes a game server deployment.
func deleteGameServerDeployment(w io.Writer, projectID, deploymentID string) error {
	// projectID := "my-project"
	// deploymentID := "mydeployment"
	ctx := context.Background()
	client, err := gaming.NewGameServerDeploymentsClient(ctx)
	if err != nil {
		return fmt.Errorf("NewGameServerDeploymentsClient: %v", err)
	}
	defer client.Close()

	req := &gamingpb.DeleteGameServerDeploymentRequest{
		Name: fmt.Sprintf("projects/%s/locations/global/gameServerDeployments/%s", projectID, deploymentID),
	}

	op, err := client.DeleteGameServerDeployment(ctx, req)
	if err != nil {
		return fmt.Errorf("DeleteGameServerDeployment: %v", err)
	}
	err = op.Wait(ctx)
	if err != nil {
		return fmt.Errorf("Wait: %v", err)
	}

	fmt.Fprintf(w, "Deployment deleted.")
	return nil
}

Node.js

const {
  GameServerDeploymentsServiceClient,
} = require('@google-cloud/game-servers');

const client = new GameServerDeploymentsServiceClient();

async function deleteGameServerDeployment() {
  /**
   * TODO(developer): Uncomment these variables before running the sample.
   */
  // const projectId = 'Your Google Cloud Project ID';
  // const deploymentId = 'A unique ID for the Game Server Deployment';
  const request = {
    // The full resource name
    name: client.gameServerDeploymentPath(projectId, 'global', deploymentId),
  };

  const [operation] = await client.deleteGameServerDeployment(request);
  await operation.promise();

  console.log(`Deployment with name ${request.name} deleted.`);
}

deleteGameServerDeployment();

Python

def delete_deployment(project_id, deployment_id):
    """Deletes a game server deployment."""

    client = gaming.GameServerDeploymentsServiceClient()

    # Location is hard coded as global, as game server deployments can
    # only be created in global.  This is done for all operations on
    # game server deployments, as well as for its child resource types.
    request = game_server_deployments.DeleteGameServerDeploymentRequest(
        name=f"projects/{project_id}/locations/global/gameServerDeployments/{deployment_id}",
    )

    operation = client.delete_game_server_deployment(request)
    print(f"Delete deployment operation: {operation.operation.name}")
    operation.result(timeout=120)

验证部署是否已删除

如需验证是否已成功删除部署,请使用 gcloud 命令行工具列出部署。

如需列出所有部署,请运行以下命令:

gcloud game servers deployments list

已删除的部署不会出现在命令的输出中。

后续步骤

了解如何查看游戏服务器审核日志记录信息