Supprimer le remplacement d'un déploiement

Supprimez le remplacement d'un déploiement pour Game Servers.

Pages de documentation incluant cet exemple de code

Pour afficher l'exemple de code utilisé en contexte, consultez la documentation suivante :

Exemple de code

C#

Pour apprendre à installer et à utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes de Game Servers.


using Google.Cloud.Gaming.V1;
using Google.LongRunning;
using Google.Protobuf.WellKnownTypes;
using System.Threading.Tasks;

public class UpdateRolloutRemoveOverrideConfigSample
{
    public async Task<GameServerDeployment> UpdateRolloutRemoveOverrideConfigAsync(
        string projectId, string deploymentId)
    {
        // Create the client.
        GameServerDeploymentsServiceClient client = await GameServerDeploymentsServiceClient.CreateAsync();

        GameServerDeploymentRollout rollout = new GameServerDeploymentRollout
        {
            Name = GameServerDeploymentName.FormatProjectLocationDeployment(projectId, "global", deploymentId)
        };

        UpdateGameServerDeploymentRolloutRequest request = new UpdateGameServerDeploymentRolloutRequest
        {
            Rollout = rollout,
            UpdateMask = new FieldMask { Paths = { "game_server_config_overrides" } }
        };

        // Make the request.
        Operation<GameServerDeployment, OperationMetadata> response = await client.UpdateGameServerDeploymentRolloutAsync(request);
        Operation<GameServerDeployment, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result.
        return completedResponse.Result;
    }
}

Go

Pour apprendre à installer et à utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes de Game Servers.


import (
	"context"
	"fmt"
	"io"

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

// updateRolloutClearOverrideConfig removes any config overrides on a game
// server deployment.
func updateRolloutClearOverrideConfig(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.UpdateGameServerDeploymentRolloutRequest{
		Rollout: &gamingpb.GameServerDeploymentRollout{
			Name: fmt.Sprintf("projects/%s/locations/global/gameServerDeployments/%s", projectID, deploymentID),
		},
		UpdateMask: &fieldmaskpb.FieldMask{
			Paths: []string{
				"game_server_config_overrides",
			},
		},
	}

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

	fmt.Fprintf(w, "Deployment rollout updated: %v", resp.Name)
	return nil
}

Node.js

Pour apprendre à installer et à utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes de Game Servers.

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

const client = new GameServerDeploymentsServiceClient();

async function removeRolloutGameServerDeploymentOverride() {
  /**
   * 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 = {
    rollout: {
      name: client.gameServerDeploymentPath(
        projectId,
        'global',
        deploymentId
      ),
    },
    updateMask: {
      paths: ['game_server_config_overrides'],
    },
  };

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

  console.log(`Deployment updated: ${deployment.name}`);
}

removeRolloutGameServerDeploymentOverride();

Python

Pour apprendre à installer et à utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes de Game Servers.

def update_rollout_remove_override(project_id, deployment_id):
    """Update the rollout of a game server deployment to remove the override config."""

    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.UpdateGameServerDeploymentRolloutRequest()
    request.rollout.name = (
        f"projects/{project_id}/locations/global/gameServerDeployments/{deployment_id}"
    )
    request.rollout.game_server_config_overrides = []
    request.update_mask = field_mask.FieldMask(paths=["game_server_config_overrides"])

    operation = client.update_game_server_deployment_rollout(request)
    print(f"Update deployment rollout operation: {operation.operation.name}")
    operation.result(timeout=120)

Étape suivante

Pour rechercher et filtrer des exemples de code pour d'autres produits Google Cloud, consultez l'explorateur d'exemples Google Cloud.