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

        GameServerCluster cluster = new GameServerCluster()
        {
            GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster(projectId, regionId, realmId, clusterId)
        };

        cluster.Labels.Add("label-key-1", "label-value-1");
        cluster.Labels.Add("label-key-2", "label-value-2");

        UpdateGameServerClusterRequest request = new UpdateGameServerClusterRequest
        {
            GameServerCluster = cluster,
            UpdateMask        = new FieldMask {
                Paths = { "labels" }
            }
        };

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

        Operation <GameServerCluster, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync();

        // Retrieve the operation result. This result will NOT contain the updated labels.
        // If you want to get the updated resource, use a GET request on the resource.
        return(completedResponse.Result);
    }
        /// <summary>
        /// Deletes a game server cluster
        /// </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>
        public string DeleteGameServerCluster(
            string projectId = "YOUR-PROJECT-ID",
            string regionId  = "us-central1-f",
            string realmId   = "YOUR-REALM-ID",
            string clusterId = "YOUR-GAME-SERVER-CLUSTER-ID")
        {
            // Initialize the client
            var client = GameServerClustersServiceClient.Create();

            // Construct the request
            string parent      = $"projects/{projectId}/locations/{regionId}/realms/{realmId}";
            string clusterName = $"{parent}/gameServerClusters/{clusterId}";

            // Call the API
            try
            {
                var deleted = client.DeleteGameServerCluster(clusterName);

                // Inspect the result
                return($"Game server cluster deleted: {deleted.Name}");
            }
            catch (Exception e)
            {
                Console.WriteLine($"DeleteGameServerCluster error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
    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);
    }
    public void DeleteCluster(
        string projectId, string regionId, string realmId, string clusterId)
    {
        // Create the client.
        GameServerClustersServiceClient client = GameServerClustersServiceClient.Create();

        DeleteGameServerClusterRequest request = new DeleteGameServerClusterRequest
        {
            GameServerClusterName = GameServerClusterName.FromProjectLocationRealmCluster(projectId, regionId, realmId, clusterId)
        };

        // Make the request.
        Operation <Empty, OperationMetadata> response = client.DeleteGameServerCluster(request);

        // Poll until the returned long-running operation is complete.
        response.PollUntilCompleted();
    }
Exemplo n.º 5
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;
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// List game server clusters
        /// </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>
        public List <string> ListGameServerClusters(
            string projectId = "YOUR-PROJECT-ID",
            string regionId  = "us-central1-f",
            string realmId   = "YOUR-REALM-ID",
            string clusterId = "YOUR-GAME-SERVER-CLUSTER-ID")
        {
            // Initialize the client
            var client = GameServerClustersServiceClient.Create();

            // Construct the request
            string parent = $"projects/{projectId}/locations/{regionId}/realms/{realmId}";

            // Call the API
            try
            {
                var response = client.ListGameServerClusters(parent);

                // Inspect the result
                List <string>            result  = new List <string>();
                bool                     hasMore = true;
                Page <GameServerCluster> currentPage;
                while (hasMore)
                {
                    currentPage = response.ReadPage(pageSize: 10);

                    // Read the result in a given page
                    foreach (var cluster in currentPage)
                    {
                        Console.WriteLine($"Game server cluster returned: {cluster.Name}");
                        result.Add(cluster.Name);
                    }
                    hasMore = currentPage != null;
                }
                ;

                return(result);
            }
            catch (Exception e)
            {
                Console.WriteLine($"ListGameServerClusters error:");
                Console.WriteLine($"{e.Message}");
                throw;
            }
        }
Exemplo n.º 7
0
    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);
    }
Exemplo n.º 8
0
    public IList <GameServerCluster> ListClusters(
        string projectId, string regionId, string realmId)
    {
        // Create the client.
        GameServerClustersServiceClient client = GameServerClustersServiceClient.Create();

        ListGameServerClustersRequest request = new ListGameServerClustersRequest
        {
            ParentAsRealmName = RealmName.FromProjectLocationRealm(projectId, regionId, realmId),
            View = GameServerClusterView.Full
        };

        // Make the request.
        PagedEnumerable <ListGameServerClustersResponse, GameServerCluster> response = client.ListGameServerClusters(request);

        // You could iterate through response and write the cluster.Name and
        // cluster.ClusterState to the console to see the installed versions of Agones
        // and Kubernetes on each cluster.

        // The returned sequence will lazily perform RPCs as it's being iterated over.
        return(response.ToList());
    }
        /// <summary>
        /// Deletes a game server cluster
        /// </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>
        public string UpdateGameServerCluster(
            string projectId = "YOUR-PROJECT-ID",
            string regionId  = "us-central1-f",
            string realmId   = "YOUR-REALM-ID",
            string clusterId = "YOUR-GAME-SERVER-CLUSTER-ID")
        {
            // Initialize the client
            var client = GameServerClustersServiceClient.Create();

            // Construct the request
            string parent      = $"projects/{projectId}/locations/{regionId}/realms/{realmId}";
            string clusterName = $"{parent}/gameServerClusters/{clusterId}";
            var    cluster     = new GameServerCluster
            {
                Name   = clusterName,
                Labels = { { "key", "value" } }
            };
            var fieldMask = new FieldMask();

            fieldMask.Paths.Add("labels");

            // Call the API
            try
            {
                var updatedOperationId = client.UpdateGameServerCluster(cluster, fieldMask);

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