public async Task <Realm> CreateRealmAsync( string projectId, string regionId, string realmId) { // Create the client. RealmsServiceClient client = await RealmsServiceClient.CreateAsync(); Realm realm = new Realm { RealmName = RealmName.FromProjectLocationRealm(projectId, regionId, realmId), TimeZone = "America/Los_Angeles" }; CreateRealmRequest request = new CreateRealmRequest { ParentAsLocationName = LocationName.FromProjectLocation(projectId, regionId), RealmId = realmId, Realm = realm }; // Make the request. Operation <Realm, OperationMetadata> response = await client.CreateRealmAsync(request); // Poll until the returned long-running operation is complete. Operation <Realm, OperationMetadata> completedResponse = await response.PollUntilCompletedAsync(); // Retrieve the operation result. return(completedResponse.Result); }
/// <summary>Snippet for CreateRealm</summary> public void CreateRealmRequestObject() { // Snippet: CreateRealm(CreateRealmRequest, CallSettings) // Create client RealmsServiceClient realmsServiceClient = RealmsServiceClient.Create(); // Initialize request argument(s) CreateRealmRequest request = new CreateRealmRequest { ParentAsLocationName = LocationName.FromProjectLocation("[PROJECT]", "[LOCATION]"), RealmId = "", Realm = new Realm(), }; // Make the request Operation <Realm, OperationMetadata> response = realmsServiceClient.CreateRealm(request); // Poll until the returned long-running operation is complete Operation <Realm, OperationMetadata> completedResponse = response.PollUntilCompleted(); // Retrieve the operation result Realm 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 <Realm, OperationMetadata> retrievedResponse = realmsServiceClient.PollOnceCreateRealm(operationName); // Check if the retrieved long-running operation has completed if (retrievedResponse.IsCompleted) { // If it has completed, then access the result Realm retrievedResult = retrievedResponse.Result; } // End snippet }
/// <summary> /// Create a new realm /// </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 string CreateRealm( string projectId = "YOUR-PROJECT-ID", string regionId = "us-central1", string realmId = "YOUR-REALM-ID") { // Initialize the client var client = RealmsServiceClient.Create(); // Construct the request string parent = $"projects/{projectId}/locations/{regionId}"; string realmName = $"{parent}/realms/{realmId}"; var realm = new Realm { Name = realmName, TimeZone = "America/Los_Angeles" }; var request = new CreateRealmRequest { Parent = parent, RealmId = realmId, Realm = realm }; // Call the API try { var created = client.CreateRealm(request); // Inspect the result return($"Realm created for {realm.Name}. Operation Id {created.Name}"); } catch (Exception e) { Console.WriteLine($"CreateRealm error:"); Console.WriteLine($"{e.Message}"); throw; } }