/// <summary> /// Converts the response from the service to a powershell database object /// </summary> /// <param name="resourceGroupName">The resource group the server is in</param> /// <param name="serverName">The name of the Azure Sql Database Server</param> /// <param name="pool">The service response</param> /// <returns>The converted model</returns> private AzureSqlElasticPoolModel CreateElasticPoolModelFromResponse(string resourceGroup, string serverName, Management.Sql.Models.ElasticPool pool) { AzureSqlElasticPoolModel model = new AzureSqlElasticPoolModel { ResourceId = pool.Id, ResourceGroupName = resourceGroup, ServerName = serverName, ElasticPoolName = pool.Name, CreationDate = pool.CreationDate ?? DateTime.MinValue, State = pool.State, StorageMB = pool.StorageMB, MaxSizeBytes = pool.MaxSizeBytes, Tags = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(pool.Tags), false), Location = pool.Location, Edition = pool.Edition, ZoneRedundant = pool.ZoneRedundant, Capacity = pool.Sku.Capacity, SkuName = pool.Sku.Name, DatabaseCapacityMin = pool.PerDatabaseSettings.MinCapacity, DatabaseCapacityMax = pool.PerDatabaseSettings.MaxCapacity, Dtu = pool.Dtu, DatabaseDtuMin = pool.DatabaseDtuMin, DatabaseDtuMax = pool.DatabaseDtuMax, Family = pool.Sku.Family, LicenseType = pool.LicenseType }; return(model); }
/// <summary> /// Creates an Azure Sql Database ElasticPool. /// </summary> /// <param name="resourceGroup">The name of the resource group</param> /// <param name="serverName">The name of the Azure Sql Database Server</param> /// <param name="model">The input parameters for the create/update operation</param> /// <returns>The upserted Azure Sql Database ElasticPool</returns> internal AzureSqlElasticPoolModel CreateElasticPool(AzureSqlElasticPoolModel model) { var resp = Communicator.Create(model.ResourceGroupName, model.ServerName, model.ElasticPoolName, new Management.Sql.Models.ElasticPool { Location = model.Location, Tags = model.Tags, Sku = string.IsNullOrWhiteSpace(model.SkuName) ? null : new Sku() { Name = model.SkuName, Tier = model.Edition, Family = model.Family, Capacity = model.Capacity }, MaxSizeBytes = model.MaxSizeBytes, ZoneRedundant = model.ZoneRedundant, PerDatabaseSettings = new ElasticPoolPerDatabaseSettings() { MinCapacity = model.DatabaseCapacityMin, MaxCapacity = model.DatabaseCapacityMax }, LicenseType = model.LicenseType }); return(CreateElasticPoolModelFromResponse(model.ResourceGroupName, model.ServerName, resp)); }
/// <summary> /// Converts the response from the service to a powershell database object /// </summary> /// <param name="resourceGroupName">The resource group the server is in</param> /// <param name="serverName">The name of the Azure Sql Database Server</param> /// <param name="pool">The service response</param> /// <returns>The converted model</returns> private AzureSqlElasticPoolModel CreateElasticPoolModelFromResponse(string resourceGroup, string serverName, Management.Sql.Models.ElasticPool pool) { DatabaseEdition edition = DatabaseEdition.None; Enum.TryParse <DatabaseEdition>(pool.Edition, out edition); AzureSqlElasticPoolModel model = new AzureSqlElasticPoolModel { ResourceId = pool.Id, ResourceGroupName = resourceGroup, ServerName = serverName, ElasticPoolName = pool.Name, CreationDate = pool.CreationDate ?? DateTime.MinValue, DatabaseDtuMax = pool.DatabaseDtuMax.Value, DatabaseDtuMin = pool.DatabaseDtuMin.Value, Dtu = pool.Dtu, State = pool.State, StorageMB = pool.StorageMB, Tags = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(pool.Tags), false), Location = pool.Location, Edition = edition }; return(model); }
/// <summary> /// Updates an Azure Sql Database ElasticPool using Patch. /// </summary> /// <param name="resourceGroup">The name of the resource group</param> /// <param name="serverName">The name of the Azure Sql Database Server</param> /// <param name="model">The input parameters for the create/update operation</param> /// <returns>The upserted Azure Sql Database ElasticPool</returns> internal AzureSqlElasticPoolModel UpsertElasticPool(AzureSqlElasticPoolModel model) { var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, model.ElasticPoolName, new Management.Sql.Models.ElasticPoolUpdate { Location = model.Location, Tags = model.Tags, Sku = string.IsNullOrWhiteSpace(model.SkuName) ? null : new Sku() { Name = model.SkuName, Tier = model.Edition, Family = model.Family, Capacity = model.Capacity }, MaxSizeBytes = model.MaxSizeBytes, ZoneRedundant = model.ZoneRedundant, PerDatabaseSettings = new ElasticPoolPerDatabaseSettings() { MinCapacity = model.DatabaseCapacityMin, MaxCapacity = model.DatabaseCapacityMax }, LicenseType = model.LicenseType, MaintenanceConfigurationId = MaintenanceConfigurationHelper.ConvertMaintenanceConfigurationIdArgument(model.MaintenanceConfigurationId, Context.Subscription.Id), }); return(CreateElasticPoolModelFromResponse(model.ResourceGroupName, model.ServerName, resp)); }
/// <summary> /// Creates or updates an Azure Sql Database ElasticPool. /// </summary> /// <param name="resourceGroup">The name of the resource group</param> /// <param name="serverName">The name of the Azure Sql Database Server</param> /// <param name="model">The input parameters for the create/update operation</param> /// <returns>The upserted Azure Sql Database ElasticPool</returns> internal AzureSqlElasticPoolModel UpsertElasticPool(AzureSqlElasticPoolModel model) { var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, model.ElasticPoolName, Util.GenerateTracingId(), new Management.Sql.Models.ElasticPool { Location = model.Location, Tags = model.Tags, DatabaseDtuMax = model.DatabaseDtuMax, DatabaseDtuMin = model.DatabaseDtuMin, Edition = model.Edition.ToString(), Dtu = model.Dtu, StorageMB = model.StorageMB }); return(CreateElasticPoolModelFromResponse(model.ResourceGroupName, model.ServerName, resp)); }
/// <summary> /// Create the model from user input /// </summary> /// <param name="model">Model retrieved from service</param> /// <returns>The model that was passed in</returns> protected override IEnumerable <AzureSqlElasticPoolModel> ApplyUserInputToModel(IEnumerable <AzureSqlElasticPoolModel> model) { string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName); List <AzureSqlElasticPoolModel> newEntity = new List <AzureSqlElasticPoolModel>(); AzureSqlElasticPoolModel newModel = new AzureSqlElasticPoolModel() { ResourceGroupName = ResourceGroupName, ServerName = ServerName, ElasticPoolName = ElasticPoolName, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), Location = location, ZoneRedundant = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null, MaxSizeBytes = MyInvocation.BoundParameters.ContainsKey("StorageMB") ? (long?)(StorageMB * Megabytes) : null, LicenseType = LicenseType, MaintenanceConfigurationId = MaintenanceConfigurationId, }; if (ParameterSetName == DtuPoolParameterSet) { string edition = string.IsNullOrWhiteSpace(Edition) ? null : Edition; if (!string.IsNullOrWhiteSpace(edition)) { newModel.SkuName = AzureSqlElasticPoolAdapter.GetPoolSkuName(edition); newModel.Edition = edition; newModel.Capacity = MyInvocation.BoundParameters.ContainsKey("Dtu") ? (int?)Dtu : null; } newModel.DatabaseCapacityMin = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMin") ? (double?)DatabaseDtuMin : null; newModel.DatabaseCapacityMax = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMax") ? (double?)DatabaseDtuMax : null; } else { newModel.SkuName = AzureSqlElasticPoolAdapter.GetPoolSkuName(Edition); newModel.Edition = Edition; newModel.Capacity = VCore; newModel.Family = ComputeGeneration; newModel.DatabaseCapacityMin = MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMin") ? (double?)DatabaseVCoreMin : null; newModel.DatabaseCapacityMax = MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMax") ? (double?)DatabaseVCoreMax : null; newModel.HighAvailabilityReplicaCount = MyInvocation.BoundParameters.ContainsKey("HighAvailabilityReplicaCount") ? (int?)HighAvailabilityReplicaCount : null; } newEntity.Add(newModel); return(newEntity); }
/// <summary> /// Creates or updates an Azure Sql Database ElasticPool. /// </summary> /// <param name="resourceGroup">The name of the resource group</param> /// <param name="serverName">The name of the Azure Sql Database Server</param> /// <param name="model">The input parameters for the create/update operation</param> /// <returns>The upserted Azure Sql Database ElasticPool</returns> internal AzureSqlElasticPoolModel UpsertElasticPool(AzureSqlElasticPoolModel model) { var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.ServerName, model.ElasticPoolName, Util.GenerateTracingId(), new ElasticPoolCreateOrUpdateParameters() { Location = model.Location, Properties = new ElasticPoolCreateOrUpdateProperties() { DatabaseDtuMax = model.DatabaseDtuMax, DatabaseDtuMin = model.DatabaseDtuMin, Edition = model.Edition.ToString(), Dtu = model.Dtu, StorageMB = model.StorageMB } }); return(CreateElasticPoolModelFromResponse(model.ResourceGroupName, model.ServerName, resp)); }
/// <summary> /// Converts the response from the service to a powershell database object /// </summary> /// <param name="resourceGroupName">The resource group the server is in</param> /// <param name="serverName">The name of the Azure Sql Database Server</param> /// <param name="pool">The service response</param> /// <returns>The converted model</returns> private AzureSqlElasticPoolModel CreateElasticPoolModelFromResponse(string resourceGroup, string serverName, Management.Sql.Models.ElasticPool pool) { AzureSqlElasticPoolModel model = new AzureSqlElasticPoolModel(); model.ResourceId = pool.Id; model.ResourceGroupName = resourceGroup; model.ServerName = serverName; model.ElasticPoolName = pool.Name; model.CreationDate = pool.Properties.CreationDate ?? DateTime.MinValue; model.DatabaseDtuMax = (int)pool.Properties.DatabaseDtuMax; model.DatabaseDtuMin = (int)pool.Properties.DatabaseDtuMin; model.Dtu = (int)pool.Properties.Dtu; model.State = pool.Properties.State; model.StorageMB = pool.Properties.StorageMB; model.Tags = pool.Tags as Dictionary <string, string>; model.Location = pool.Location; DatabaseEdition edition = DatabaseEdition.None; Enum.TryParse <DatabaseEdition>(pool.Properties.Edition, out edition); model.Edition = edition; return(model); }
/// <summary> /// Create the model from user input /// </summary> /// <param name="model">Model retrieved from service</param> /// <returns>The model that was passed in</returns> protected override IEnumerable <AzureSqlElasticPoolModel> ApplyUserInputToModel(IEnumerable <AzureSqlElasticPoolModel> model) { string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName); List <AzureSqlElasticPoolModel> newEntity = new List <AzureSqlElasticPoolModel>(); AzureSqlElasticPoolModel newModel = new AzureSqlElasticPoolModel() { ResourceGroupName = ResourceGroupName, ServerName = ServerName, ElasticPoolName = ElasticPoolName, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), Location = location, ZoneRedundant = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null, MaxSizeBytes = MyInvocation.BoundParameters.ContainsKey("StorageMB") ? (long?)(StorageMB * Megabytes) : null, LicenseType = LicenseType ?? model.FirstOrDefault().LicenseType }; var elasticPool = ModelAdapter.GetElasticPool(ResourceGroupName, ServerName, ElasticPoolName); Management.Sql.Models.Sku poolCurrentSku = new Management.Sql.Models.Sku() { Name = elasticPool.SkuName, Tier = elasticPool.Edition, Family = elasticPool.Family, Capacity = elasticPool.Capacity }; Management.Sql.Models.ElasticPoolPerDatabaseSettings poolCurrentDbSetting = new Management.Sql.Models.ElasticPoolPerDatabaseSettings() { MinCapacity = elasticPool.DatabaseCapacityMin, MaxCapacity = elasticPool.DatabaseCapacityMax }; if (ParameterSetName == DtuPoolParameterSet) { if (!string.IsNullOrWhiteSpace(Edition) || MyInvocation.BoundParameters.ContainsKey("Dtu")) { string edition = string.IsNullOrWhiteSpace(Edition) ? poolCurrentSku.Tier : Edition; newModel.SkuName = AzureSqlElasticPoolAdapter.GetPoolSkuName(edition); newModel.Edition = edition; newModel.Capacity = MyInvocation.BoundParameters.ContainsKey("Dtu") ? (int?)Dtu : null; } if (MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMin") || MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMax")) { newModel.DatabaseCapacityMin = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMin") ? (double?)DatabaseDtuMin : null; newModel.DatabaseCapacityMax = MyInvocation.BoundParameters.ContainsKey("DatabaseDtuMax") ? (double?)DatabaseDtuMax : null; } } else { if (!string.IsNullOrWhiteSpace(Edition) || MyInvocation.BoundParameters.ContainsKey("VCore") || !string.IsNullOrWhiteSpace(ComputeGeneration)) { string skuTier = string.IsNullOrWhiteSpace(Edition) ? poolCurrentSku.Tier : Edition; newModel.SkuName = AzureSqlElasticPoolAdapter.GetPoolSkuName(skuTier); newModel.Edition = skuTier; newModel.Capacity = MyInvocation.BoundParameters.ContainsKey("VCore") ? VCore : poolCurrentSku.Capacity; newModel.Family = string.IsNullOrWhiteSpace(ComputeGeneration) ? poolCurrentSku.Family : ComputeGeneration; } if (MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMin") || MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMax")) { newModel.DatabaseCapacityMin = MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMin") ? (double?)DatabaseVCoreMin : null; newModel.DatabaseCapacityMax = MyInvocation.BoundParameters.ContainsKey("DatabaseVCoreMax") ? (double?)DatabaseVCoreMax : null; } } newEntity.Add(newModel); return(newEntity); }