Game Server 클러스터에 대한 세부정보를 가져옵니다.
더 살펴보기
이 코드 샘플이 포함된 자세한 문서는 다음을 참조하세요.
코드 샘플
C#
Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.
using Google.Cloud.Gaming.V1;
public class GetClusterSample
{
public GameServerCluster GetCluster(
string projectId, string regionId, string realmId, string clusterId)
{
// Create the client.
GameServerClustersServiceClient client = GameServerClustersServiceClient.Create();
GetGameServerClusterRequest request = new GetGameServerClusterRequest
{
GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster(projectId, regionId, realmId, clusterId),
View = GameServerClusterView.Full
};
// Make the request.
GameServerCluster response = client.GetGameServerCluster(request);
// You could write response.Name and response.ClusterState to the console
// to see the installed versions of Agones and Kubernetes on the cluster.
return response;
}
}
Go
Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.
import (
"context"
"fmt"
"io"
gaming "cloud.google.com/go/gaming/apiv1"
gamingpb "google.golang.org/genproto/googleapis/cloud/gaming/v1"
)
// getGameServerCluster retrieves info on a game server cluster.
func getGameServerCluster(w io.Writer, projectID, location, realmID, clusterID string) error {
// projectID := "my-project"
// location := "global"
// realmID := "myrealm"
// clusterID := "mycluster"
ctx := context.Background()
client, err := gaming.NewGameServerClustersClient(ctx)
if err != nil {
return fmt.Errorf("NewGameServerClustersClient: %v", err)
}
defer client.Close()
req := &gamingpb.GetGameServerClusterRequest{
Name: fmt.Sprintf("projects/%s/locations/%s/realms/%s/gameServerClusters/%s", projectID, location, realmID, clusterID),
View: gamingpb.GameServerClusterView_FULL,
}
resp, err := client.GetGameServerCluster(ctx, req)
if err != nil {
return fmt.Errorf("GetGameServerCluster: %v", err)
}
fmt.Fprintf(w, "Cluster retrieved: %v\n", resp.Name)
fmt.Fprintf(w, "Cluster installed Agones version: %v\n", resp.ClusterState.AgonesVersionInstalled)
fmt.Fprintf(w, "Cluster installed Kubernetes version: %v\n", resp.ClusterState.KubernetesVersionInstalled)
fmt.Fprintf(w, "Cluster installation state: %v\n", resp.ClusterState.InstallationState)
return nil
}
자바
Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.
import com.google.cloud.gaming.v1.GameServerCluster;
import com.google.cloud.gaming.v1.GameServerClusterName;
import com.google.cloud.gaming.v1.GameServerClusterView;
import com.google.cloud.gaming.v1.GameServerClustersServiceClient;
import com.google.cloud.gaming.v1.GetGameServerClusterRequest;
import java.io.IOException;
public class GetCluster {
public static void getGameServerCluster(
String projectId, String regionId, String realmId, String clusterId) throws IOException {
// String projectId = "your-project-id";
// String regionId = "us-central1-f";
// String realmId = "your-realm-id";
// String clusterId = "your-game-server-cluster-id";
// Initialize client that will be used to send requests. This client only needs to be created
// once, and can be reused for multiple requests. After completing all of your requests, call
// the "close" method on the client to safely clean up any remaining background resources.
try (GameServerClustersServiceClient client = GameServerClustersServiceClient.create()) {
GetGameServerClusterRequest request =
GetGameServerClusterRequest.newBuilder()
.setName(GameServerClusterName.of(projectId, regionId, realmId, clusterId).toString())
.setView(GameServerClusterView.FULL)
.build();
GameServerCluster cluster = client.getGameServerCluster(request);
System.out.println("Game Server Cluster found: " + cluster.getName());
System.out.println(
"Cluster installed Agones version: "
+ cluster.getClusterState().getAgonesVersionInstalled());
System.out.println(
"Cluster installed Kubernetes version: "
+ cluster.getClusterState().getKubernetesVersionInstalled());
System.out.println(
"Cluster installation state: " + cluster.getClusterState().getInstallationState());
}
}
}
Node.js
Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.
const {
GameServerClustersServiceClient,
} = require('@google-cloud/game-servers');
const client = new GameServerClustersServiceClient();
async function getGameServerCluster() {
/**
* TODO(developer): Uncomment these variables before running the sample.
*/
// const projectId = 'Your Google Cloud Project ID';
// const location = 'A Compute Engine region, e.g. "us-central1"';
// const realmId = 'The ID of the realm to locate this cluster in';
// const gameClusterId = 'The unique ID for this Game Server Cluster';
const request = {
// Provide full resource name of a Game Server Realm
name: client.gameServerClusterPath(
projectId,
location,
realmId,
gameClusterId
),
view: 'FULL',
};
const [cluster] = await client.getGameServerCluster(request);
console.log('Game Server Cluster:');
console.log(`\tCluster name: ${cluster.name}`);
console.log(`\tCluster description: ${cluster.description}`);
console.log(
`\tCluster installed Agones version: ${cluster.clusterState.agonesVersionInstalled}`
);
console.log(
`\tCluster installed Kubernetes version: ${cluster.clusterState.kubernetesVersionInstalled}`
);
console.log(
`\tCluster installation state: ${cluster.clusterState.installationState}`
);
console.log(
`\tGKE cluster: ${cluster.connectionInfo.gkeClusterReference.cluster}`
);
}
getGameServerCluster();
Python
Game Servers용 클라이언트 라이브러리를 설치하고 사용하는 방법은 Game Servers 클라이언트 라이브러리를 참조하세요.
def get_cluster(project_id, location, realm_id, cluster_id):
"""Gets a game server cluster."""
client = gaming.GameServerClustersServiceClient()
request = game_server_clusters.GetGameServerClusterRequest(
name=f"projects/{project_id}/locations/{location}/realms/{realm_id}/gameServerClusters/{cluster_id}",
view=game_server_clusters.GameServerClusterView.FULL,
)
response = client.get_game_server_cluster(request)
print(f"Get cluster response:\n{response}")
return response
다음 단계
다른 Google Cloud 제품의 코드 샘플을 검색하고 필터링하려면 Google Cloud 샘플 브라우저를 참조하세요.