public async Task <GameServerCluster> CreateClusterAsync(
        string projectId, string regionId, string realmId, string clusterId, string gkeName)
    {
        // Create the client.
        GameServerClustersServiceClient client = await GameServerClustersServiceClient.CreateAsync();

        GameServerCluster cluster = new GameServerCluster()
        {
            GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster(projectId, regionId, realmId, clusterId),
            ConnectionInfo        = new GameServerClusterConnectionInfo
            {
                GkeClusterReference = new GkeClusterReference
                {
                    Cluster = gkeName
                },
                Namespace = "default"
            }
        };
        CreateGameServerClusterRequest request = new CreateGameServerClusterRequest
        {
            ParentAsRealmName   = RealmName.FromProjectLocationRealm(projectId, regionId, realmId),
            GameServerClusterId = clusterId,
            GameServerCluster   = cluster
        };

        // Make the request.
        Operation <GameServerCluster, OperationMetadata> response = await client.CreateGameServerClusterAsync(request);

        // Poll until the returned long-running operation is complete.
        Operation <GameServerCluster, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result.
        return(completedResponse.Result);
    }
Beispiel #2
0
        /// <summary>
        /// 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.
        /// </summary>
        /// <param name="projectId">Your Google Cloud Project Id</param>
        /// <param name="regionId">Region in which the cluster will be created</param>
        /// <param name="realmId"></param>
        /// <param name="clusterId">The id of the game server cluster</param>
        /// <param name="gkeName">The name of Google Kubernetes Engine cluster</param>
        public string CreateGameServerCluster(
            string projectId = "YOUR-PROJECT-ID",
            string regionId  = "us-central1",
            string realmId   = "YOUR-REALM-ID",
            string clusterId = "YOUR-GAME-SERVER-CLUSTER-ID",
            string gkeName   = "projects/YOUR-PROJECT-ID/locations/us-central1/clusters/test")
        {
            // Initialize the client
            var client = GameServerClustersServiceClient.Create();

            // Construct the request
            string parent            = $"projects/{projectId}/locations/{regionId}/realms/{realmId}";
            string clusterName       = $"{parent}/gameServerClusters/{clusterId}";
            var    gameServerCluster = new GameServerCluster
            {
                Name           = clusterName,
                ConnectionInfo = new GameServerClusterConnectionInfo
                {
                    GkeName   = gkeName,
                    Namespace = "default"
                }
            };
            var request = new CreateGameServerClusterRequest
            {
                Parent = parent,
                GameServerClusterId = clusterId,
                GameServerCluster   = gameServerCluster
            };

            // Call the API
            try
            {
                var created = client.CreateGameServerCluster(request);

                // Inspect the result
                return($"Game server cluster created: {created.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"CreateGameServerCluster error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }