コード例 #1
0
        /// <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;
            }
        }
コード例 #2
0
    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();
    }
コード例 #3
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;
            }
        }
コード例 #4
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;
            }
        }
コード例 #5
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);
    }
コード例 #6
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());
    }
コード例 #7
0
        /// <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;
            }
        }