Obtenir le déploiement

Affichez les détails d'un déploiement de 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

Go

Pour savoir comment installer et utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes Game Servers.


import (
	"context"
	"fmt"
	"io"

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

// getGameServerDeploymentRollout retrieves info on a game server deployment's rollout.
func getGameServerDeploymentRollout(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.GetGameServerDeploymentRolloutRequest{
		Name: fmt.Sprintf("projects/%s/locations/global/gameServerDeployments/%s", projectID, deploymentID),
	}

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

	fmt.Fprintf(w, "Rollout default: %v\n", resp.DefaultGameServerConfig)
	for _, override := range resp.GameServerConfigOverrides {
		switch override.Selector.(type) {
		case *gamingpb.GameServerConfigOverride_RealmsSelector:
			fmt.Fprint(w, "Override these realms ", override.GetRealmsSelector().Realms)
		default:
			fmt.Fprint(w, "Unknown override selector")
		}

		switch override.Change.(type) {
		case *gamingpb.GameServerConfigOverride_ConfigVersion:
			fmt.Fprint(w, "with this config: ", override.GetConfigVersion())
		default:
			fmt.Fprint(w, "with an unknown override")
		}
		fmt.Fprintln(w)
	}
	return nil
}

Node.js

Pour savoir comment installer et utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes Game Servers.

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

const client = new GameServerDeploymentsServiceClient();

async function getGameServerDeploymentRollout() {
  /**
   * 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 [rollout] = await client.getGameServerDeploymentRollout(request);
  console.log(`Rollout name: ${rollout.name}`);
  console.log(`Rollout default: ${rollout.defaultGameServerConfig}`);
  for (const override of rollout.gameServerConfigOverrides) {
    console.log(`Rollout config overrides: ${override.configVersion}`);
    console.log(
      `Rollout realm overrides: ${JSON.stringify(override.realmsSelector)}`
    );
  }

  const updateTime = rollout.updateTime;
  const updateDate = new Date(updateTime.seconds * 1000);
  console.log(`Rollout updated on: ${updateDate.toLocaleDateString()}\n`);
}

getGameServerDeploymentRollout();

Python

Pour savoir comment installer et utiliser la bibliothèque cliente pour Game Servers, consultez la page Bibliothèques clientes Game Servers.

def get_rollout(project_id, deployment_id):
    """Gets the rollout of 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.GetGameServerDeploymentRolloutRequest(
        name=f"projects/{project_id}/locations/global/gameServerDeployments/{deployment_id}",
    )

    response = client.get_game_server_deployment_rollout(request)
    print(f"Get deployment response:\n{response}")
    return response

Étape suivante

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