private async Task CreateInstanceWithMultiRegionAsync() { InstanceAdminClient instanceAdminClient = InstanceAdminClient.Create(); var projectName = ProjectName.FromProject(ProjectId); Instance instance = new Instance { DisplayName = "Multi-region samples test", ConfigAsInstanceConfigName = InstanceConfigName.FromProjectInstanceConfig(ProjectId, InstanceConfigId), InstanceName = InstanceName.FromProjectInstance(ProjectId, InstanceIdWithMultiRegion), NodeCount = 1, }; var response = await instanceAdminClient.CreateInstanceAsync(projectName, InstanceIdWithMultiRegion, instance); // Poll until the returned long-running operation is complete await response.PollUntilCompletedAsync(); }
/// <summary>Snippet for CreateInstanceAsync</summary> public async Task CreateInstanceAsync_RequestObject() { // Snippet: CreateInstanceAsync(CreateInstanceRequest,CallSettings) // Create client InstanceAdminClient instanceAdminClient = await InstanceAdminClient.CreateAsync(); // Initialize request argument(s) CreateInstanceRequest request = new CreateInstanceRequest { ParentAsProjectName = new ProjectName("[PROJECT]"), InstanceIdAsInstanceName = new InstanceName("[PROJECT]", "[INSTANCE]"), Instance = new Instance(), }; // Make the request Operation <Instance, CreateInstanceMetadata> response = await instanceAdminClient.CreateInstanceAsync(request); // Poll until the returned long-running operation is complete Operation <Instance, CreateInstanceMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result Instance result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <Instance, CreateInstanceMetadata> retrievedResponse = await instanceAdminClient.PollOnceCreateInstanceAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Instance retrievedResult = retrievedResponse.Result; } // End snippet }
public async Task CreateInstanceAsync() { // Snippet: CreateInstanceAsync(string,string,Instance,CallSettings) // Additional: CreateInstanceAsync(string,string,Instance,CancellationToken) // Create client InstanceAdminClient instanceAdminClient = await InstanceAdminClient.CreateAsync(); // Initialize request argument(s) string formattedParent = new ProjectName("[PROJECT]").ToString(); string instanceId = ""; Instance instance = new Instance(); // Make the request Operation <Instance> response = await instanceAdminClient.CreateInstanceAsync(formattedParent, instanceId, instance); // Poll until the returned long-running operation is complete Operation <Instance> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result Instance result = completedResponse.Result; // Or get the name of the operation string operationName = response.Name; // This name can be stored, then the long-running operation retrieved later by name Operation <Instance> retrievedResponse = await instanceAdminClient.PollOnceCreateInstanceAsync(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Instance retrievedResult = retrievedResponse.Result; } // End snippet }