/// <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 <AzureSqlDatabaseModel> ApplyUserInputToModel(IEnumerable <AzureSqlDatabaseModel> model) { List <Model.AzureSqlDatabaseModel> newEntity = new List <AzureSqlDatabaseModel>(); AzureSqlDatabaseModel newDbModel = new AzureSqlDatabaseModel() { ResourceGroupName = ResourceGroupName, ServerName = ServerName, DatabaseName = DatabaseName, MaxSizeBytes = MaxSizeBytes, Tags = TagsConversionHelper.ReadOrFetchTags(this, model.FirstOrDefault().Tags), ElasticPoolName = ElasticPoolName, Location = model.FirstOrDefault().Location, ReadScale = ReadScale, ZoneRedundant = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null, LicenseType = LicenseType ?? model.FirstOrDefault().LicenseType, // set to original license type AutoPauseDelayInMinutes = this.IsParameterBound(p => p.AutoPauseDelayInMinutes) ? AutoPauseDelayInMinutes : (int?)null, MinimumCapacity = this.IsParameterBound(p => p.MinimumCapacity) ? MinimumCapacity : (double?)null, ReadReplicaCount = this.IsParameterBound(p => p.ReadReplicaCount) ? ReadReplicaCount : (int?)null, BackupStorageRedundancy = BackupStorageRedundancy, }; var database = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName); Management.Sql.Models.Sku databaseCurrentSku = new Management.Sql.Models.Sku() { Name = database.SkuName, Tier = database.Edition, Family = database.Family, Capacity = database.Capacity }; // check if current db is serverless string databaseCurrentComputeModel = database.CurrentServiceObjectiveName.Contains("_S_") ? DatabaseComputeModel.Serverless : DatabaseComputeModel.Provisioned; if (this.ParameterSetName == UpdateParameterSetName) { newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName; newDbModel.Edition = Edition; newEntity.Add(newDbModel); } else if (this.ParameterSetName == VcoreDatabaseParameterSet) { if (!string.IsNullOrWhiteSpace(Edition) || !string.IsNullOrWhiteSpace(ComputeGeneration) || this.IsParameterBound(p => p.VCore)) { string skuTier = string.IsNullOrWhiteSpace(Edition) ? databaseCurrentSku.Tier : Edition; string requestedComputeModel = string.IsNullOrWhiteSpace(ComputeModel) ? databaseCurrentComputeModel : ComputeModel; newDbModel.SkuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(skuTier, requestedComputeModel == DatabaseComputeModel.Serverless); newDbModel.Edition = skuTier; newDbModel.Family = string.IsNullOrWhiteSpace(ComputeGeneration) ? databaseCurrentSku.Family : ComputeGeneration; newDbModel.Capacity = this.IsParameterBound(p => p.VCore) ? VCore : databaseCurrentSku.Capacity; } newEntity.Add(newDbModel); } return(newEntity); }
public void GetDatabaseSkuName() { Assert.Equal( "Basic", AzureSqlDatabaseAdapter.GetDatabaseSkuName("Basic")); Assert.Equal( "Standard", AzureSqlDatabaseAdapter.GetDatabaseSkuName("Standard")); Assert.Equal( "Premium", AzureSqlDatabaseAdapter.GetDatabaseSkuName("Premium")); Assert.Equal( "DataWarehouse", AzureSqlDatabaseAdapter.GetDatabaseSkuName("DataWarehouse")); Assert.Equal( "Stretch", AzureSqlDatabaseAdapter.GetDatabaseSkuName("Stretch")); Assert.Equal( "GP", AzureSqlDatabaseAdapter.GetDatabaseSkuName("GeneralPurpose")); Assert.Equal( "BC", AzureSqlDatabaseAdapter.GetDatabaseSkuName("BusinessCritical")); Assert.Equal( "HS", AzureSqlDatabaseAdapter.GetDatabaseSkuName("Hyperscale")); }
/// <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 <AzureSqlDatabaseModel> ApplyUserInputToModel(IEnumerable <AzureSqlDatabaseModel> model) { List <Model.AzureSqlDatabaseModel> newEntity = new List <AzureSqlDatabaseModel>(); AzureSqlDatabaseModel newDbModel = new AzureSqlDatabaseModel() { ResourceGroupName = ResourceGroupName, ServerName = ServerName, DatabaseName = DatabaseName, MaxSizeBytes = MaxSizeBytes, Tags = TagsConversionHelper.ReadOrFetchTags(this, model.FirstOrDefault().Tags), ElasticPoolName = ElasticPoolName, Location = model.FirstOrDefault().Location, ReadScale = ReadScale, ZoneRedundant = ZoneRedundant != null ? (bool?)ZoneRedundant.ToBool() : null, LicenseType = LicenseType ?? model.FirstOrDefault().LicenseType // set to original license type }; var database = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName); Management.Sql.Models.Sku databaseCurrentSku = new Management.Sql.Models.Sku() { Name = database.SkuName, Tier = database.Edition, Family = database.Family, Capacity = database.Capacity }; if (this.ParameterSetName == UpdateParameterSetName) { newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName; newDbModel.Edition = Edition; newEntity.Add(newDbModel); } else if (this.ParameterSetName == VcoreDatabaseParameterSet) { if (!string.IsNullOrWhiteSpace(Edition) || !string.IsNullOrWhiteSpace(ComputeGeneration) || MyInvocation.BoundParameters.ContainsKey("VCore")) { string skuTier = string.IsNullOrWhiteSpace(Edition) ? databaseCurrentSku.Tier : Edition; newDbModel.SkuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(skuTier); newDbModel.Edition = skuTier; newDbModel.Family = string.IsNullOrWhiteSpace(ComputeGeneration) ? databaseCurrentSku.Family : ComputeGeneration; newDbModel.Capacity = MyInvocation.BoundParameters.ContainsKey("VCore") ? VCore : databaseCurrentSku.Capacity; } newEntity.Add(newDbModel); } return(newEntity); }
/// <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 <AzureSqlDatabaseCopyModel> ApplyUserInputToModel(IEnumerable <AzureSqlDatabaseCopyModel> model) { string copyResourceGroup = string.IsNullOrWhiteSpace(CopyResourceGroupName) ? ResourceGroupName : CopyResourceGroupName; string copyServer = string.IsNullOrWhiteSpace(CopyServerName) ? ServerName : CopyServerName; string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName); string copyLocation = copyServer.Equals(ServerName) ? location : ModelAdapter.GetServerLocation(copyResourceGroup, copyServer); Database.Model.AzureSqlDatabaseModel sourceDb = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName); List <Model.AzureSqlDatabaseCopyModel> newEntity = new List <AzureSqlDatabaseCopyModel>(); AzureSqlDatabaseCopyModel copyModel = new AzureSqlDatabaseCopyModel() { Location = location, ResourceGroupName = ResourceGroupName, ServerName = ServerName, DatabaseName = DatabaseName, CopyResourceGroupName = copyResourceGroup, CopyServerName = copyServer, CopyDatabaseName = CopyDatabaseName, CopyLocation = copyLocation, ServiceObjectiveName = ServiceObjectiveName, ElasticPoolName = ElasticPoolName, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), LicenseType = LicenseType, // note: default license type is LicenseIncluded RequestedBackupStorageRedundancy = BackupStorageRedundancy, ZoneRedundant = this.IsParameterBound(p => p.ZoneRedundant) ? ZoneRedundant.ToBool() : (bool?)null, }; if (ParameterSetName == DtuDatabaseParameterSet) { if (!string.IsNullOrWhiteSpace(ServiceObjectiveName)) { copyModel.SkuName = ServiceObjectiveName; } else if (string.IsNullOrWhiteSpace(ElasticPoolName)) { copyModel.SkuName = sourceDb.CurrentServiceObjectiveName; copyModel.Edition = sourceDb.Edition; copyModel.Capacity = sourceDb.Capacity; copyModel.Family = sourceDb.Family; } } else { copyModel.SkuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(sourceDb.Edition); copyModel.Edition = sourceDb.Edition; copyModel.Capacity = VCore; copyModel.Family = ComputeGeneration; } newEntity.Add(copyModel); return(newEntity); }
/// <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 <AzureSqlDatabaseCopyModel> ApplyUserInputToModel(IEnumerable <AzureSqlDatabaseCopyModel> model) { string copyResourceGroup = string.IsNullOrWhiteSpace(CopyResourceGroupName) ? ResourceGroupName : CopyResourceGroupName; string copyServer = string.IsNullOrWhiteSpace(CopyServerName) ? ServerName : CopyServerName; string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName); string copyLocation = copyServer.Equals(ServerName) ? location : ModelAdapter.GetServerLocation(copyResourceGroup, copyServer); Database.Model.AzureSqlDatabaseModel sourceDb = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName); List <Model.AzureSqlDatabaseCopyModel> newEntity = new List <AzureSqlDatabaseCopyModel>(); AzureSqlDatabaseCopyModel copyModel = new AzureSqlDatabaseCopyModel() { Location = location, ResourceGroupName = ResourceGroupName, ServerName = ServerName, DatabaseName = DatabaseName, CopyResourceGroupName = copyResourceGroup, CopyServerName = copyServer, CopyDatabaseName = CopyDatabaseName, CopyLocation = copyLocation, ServiceObjectiveName = ServiceObjectiveName, ElasticPoolName = ElasticPoolName, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true) }; if (ParameterSetName == DtuDatabaseParameterSet) { if (!string.IsNullOrWhiteSpace(ServiceObjectiveName)) { copyModel.SkuName = ServiceObjectiveName; } else if (string.IsNullOrWhiteSpace(ElasticPoolName)) { copyModel.SkuName = sourceDb.CurrentServiceObjectiveName; copyModel.Edition = sourceDb.Edition; copyModel.Capacity = sourceDb.Capacity; copyModel.Family = sourceDb.Family; } } else { copyModel.SkuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(sourceDb.Edition); copyModel.Edition = sourceDb.Edition; copyModel.Capacity = VCore; copyModel.Family = ComputeGeneration; } newEntity.Add(copyModel); return(newEntity); }
/// <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 <AzureReplicationLinkModel> ApplyUserInputToModel(IEnumerable <AzureReplicationLinkModel> model) { string location = ModelAdapter.GetServerLocation(this.PartnerResourceGroupName, this.PartnerServerName); List <Model.AzureReplicationLinkModel> newEntity = new List <AzureReplicationLinkModel>(); Database.Model.AzureSqlDatabaseModel primaryDb = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName); AzureReplicationLinkModel linkModel = new AzureReplicationLinkModel() { PartnerLocation = location, ResourceGroupName = this.ResourceGroupName, ServerName = this.ServerName, DatabaseName = this.DatabaseName, PartnerResourceGroupName = this.PartnerResourceGroupName, PartnerServerName = this.PartnerServerName, PartnerDatabaseName = GetEffectivePartnerDatabaseName(this.DatabaseName, this.PartnerDatabaseName), SecondaryElasticPoolName = this.SecondaryElasticPoolName, AllowConnections = this.AllowConnections, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), LicenseType = LicenseType, RequestedBackupStorageRedundancy = this.BackupStorageRedundancy, SecondaryType = SecondaryType, HighAvailabilityReplicaCount = this.IsParameterBound(p => p.HighAvailabilityReplicaCount) ? HighAvailabilityReplicaCount : (int?)null, ZoneRedundant = this.IsParameterBound(p => p.ZoneRedundant) ? ZoneRedundant.ToBool() : (bool?)null, }; if (ParameterSetName == DtuDatabaseParameterSet) { if (!string.IsNullOrWhiteSpace(SecondaryServiceObjectiveName)) { linkModel.SkuName = SecondaryServiceObjectiveName; } else if (string.IsNullOrWhiteSpace(SecondaryElasticPoolName)) { linkModel.SkuName = primaryDb.CurrentServiceObjectiveName; linkModel.Edition = primaryDb.Edition; linkModel.Capacity = primaryDb.Capacity; linkModel.Family = primaryDb.Family; } } else { linkModel.SkuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(primaryDb.Edition); linkModel.Edition = primaryDb.Edition; linkModel.Capacity = SecondaryVCore; linkModel.Family = SecondaryComputeGeneration; } newEntity.Add(linkModel); return(newEntity); }
/// <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 <AzureReplicationLinkModel> ApplyUserInputToModel(IEnumerable <AzureReplicationLinkModel> model) { string location = ModelAdapter.GetServerLocation(this.PartnerResourceGroupName, this.PartnerServerName); List <Model.AzureReplicationLinkModel> newEntity = new List <AzureReplicationLinkModel>(); Database.Model.AzureSqlDatabaseModel primaryDb = ModelAdapter.GetDatabase(ResourceGroupName, ServerName, DatabaseName); AzureReplicationLinkModel linkModel = new AzureReplicationLinkModel() { PartnerLocation = location, ResourceGroupName = this.ResourceGroupName, ServerName = this.ServerName, DatabaseName = this.DatabaseName, PartnerResourceGroupName = this.PartnerResourceGroupName, PartnerServerName = this.PartnerServerName, PartnerDatabaseName = string.IsNullOrWhiteSpace(this.PartnerDatabaseName) ? this.DatabaseName : this.PartnerDatabaseName, SecondaryElasticPoolName = this.SecondaryElasticPoolName, AllowConnections = this.AllowConnections, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), LicenseType = LicenseType }; if (ParameterSetName == DtuDatabaseParameterSet) { if (!string.IsNullOrWhiteSpace(SecondaryServiceObjectiveName)) { linkModel.SkuName = SecondaryServiceObjectiveName; } else if (string.IsNullOrWhiteSpace(SecondaryElasticPoolName)) { linkModel.SkuName = primaryDb.CurrentServiceObjectiveName; linkModel.Edition = primaryDb.Edition; linkModel.Capacity = primaryDb.Capacity; linkModel.Family = primaryDb.Family; } } else { linkModel.SkuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(primaryDb.Edition); linkModel.Edition = primaryDb.Edition; linkModel.Capacity = SecondaryVCore; linkModel.Family = SecondaryComputeGeneration; } newEntity.Add(linkModel); return(newEntity); }
/// <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 AzureSqlDatabaseCreateOrUpdateModel ApplyUserInputToModel(AzureSqlDatabaseCreateOrUpdateModel model) { string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName); AzureSqlDatabaseCreateOrUpdateModel dbCreateUpdateModel = new AzureSqlDatabaseCreateOrUpdateModel(); AzureSqlDatabaseModel newDbModel = new AzureSqlDatabaseModel() { Location = location, ResourceGroupName = ResourceGroupName, ServerName = ServerName, CatalogCollation = CatalogCollation, CollationName = CollationName, DatabaseName = DatabaseName, MaxSizeBytes = MaxSizeBytes, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), ElasticPoolName = ElasticPoolName, ReadScale = this.IsParameterBound(p => p.ReadScale) ? ReadScale : (DatabaseReadScale?)null, ZoneRedundant = this.IsParameterBound(p => p.ZoneRedundant) ? ZoneRedundant.ToBool() : (bool?)null, LicenseType = LicenseType, // note: default license type will be LicenseIncluded in SQL RP if not specified AutoPauseDelayInMinutes = this.IsParameterBound(p => p.AutoPauseDelayInMinutes) ? AutoPauseDelayInMinutes : (int?)null, MinimumCapacity = this.IsParameterBound(p => p.MinimumCapacity) ? MinimumCapacity : (double?)null, HighAvailabilityReplicaCount = this.IsParameterBound(p => p.HighAvailabilityReplicaCount) ? HighAvailabilityReplicaCount : (int?)null, RequestedBackupStorageRedundancy = BackupStorageRedundancy, SecondaryType = SecondaryType, MaintenanceConfigurationId = MaintenanceConfigurationId, EnableLedger = this.IsParameterBound(p => p.EnableLedger) ? EnableLedger.ToBool() : (bool?)null, }; if (ParameterSetName == DtuDatabaseParameterSet) { newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName; newDbModel.Edition = Edition; } else { newDbModel.SkuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition, ComputeModel == DatabaseComputeModel.Serverless); newDbModel.Edition = Edition; newDbModel.Capacity = VCore; newDbModel.Family = ComputeGeneration; } dbCreateUpdateModel.Database = newDbModel; dbCreateUpdateModel.SampleName = SampleName; return(dbCreateUpdateModel); }
/// <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 AzureSqlDatabaseCreateOrUpdateModel ApplyUserInputToModel(AzureSqlDatabaseCreateOrUpdateModel model) { string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName); AzureSqlDatabaseCreateOrUpdateModel dbCreateUpdateModel = new AzureSqlDatabaseCreateOrUpdateModel(); AzureSqlDatabaseModel newDbModel = new AzureSqlDatabaseModel() { Location = location, ResourceGroupName = ResourceGroupName, ServerName = ServerName, CatalogCollation = CatalogCollation, CollationName = CollationName, DatabaseName = DatabaseName, MaxSizeBytes = MaxSizeBytes, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), ElasticPoolName = ElasticPoolName, ReadScale = ReadScale, ZoneRedundant = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null, LicenseType = LicenseType, // note: default license type will be LicenseIncluded in SQL RP if not specified AutoPauseDelayInMinutes = MyInvocation.BoundParameters.ContainsKey("AutoPauseDelayInMinutes") ? AutoPauseDelayInMinutes : (int?)null, MinimumCapacity = MyInvocation.BoundParameters.ContainsKey("AutoPauseDelayInMinutes") ? MinimumCapacity : (double?)null, }; if (ParameterSetName == DtuDatabaseParameterSet) { newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName; newDbModel.Edition = Edition; } else { newDbModel.SkuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition, ComputeModel == DatabaseComputeModel.Serverless); newDbModel.Edition = Edition; newDbModel.Capacity = VCore; newDbModel.Family = ComputeGeneration; } dbCreateUpdateModel.Database = newDbModel; dbCreateUpdateModel.SampleName = SampleName; return(dbCreateUpdateModel); }
/// <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 AzureSqlDatabaseCreateOrUpdateModel ApplyUserInputToModel(AzureSqlDatabaseCreateOrUpdateModel model) { string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName); AzureSqlDatabaseCreateOrUpdateModel dbCreateUpdateModel = new AzureSqlDatabaseCreateOrUpdateModel(); AzureSqlDatabaseModel newDbModel = new AzureSqlDatabaseModel() { Location = location, ResourceGroupName = ResourceGroupName, ServerName = ServerName, CatalogCollation = CatalogCollation, CollationName = CollationName, DatabaseName = DatabaseName, MaxSizeBytes = MaxSizeBytes, Tags = TagsConversionHelper.CreateTagDictionary(Tags, validate: true), ElasticPoolName = ElasticPoolName, ReadScale = ReadScale, ZoneRedundant = MyInvocation.BoundParameters.ContainsKey("ZoneRedundant") ? (bool?)ZoneRedundant.ToBool() : null }; if (ParameterSetName == DtuDatabaseParameterSet) { newDbModel.SkuName = string.IsNullOrWhiteSpace(RequestedServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : RequestedServiceObjectiveName; newDbModel.Edition = Edition; } else { newDbModel.SkuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition); newDbModel.Edition = Edition; newDbModel.Capacity = VCore; newDbModel.Family = ComputeGeneration; } dbCreateUpdateModel.Database = newDbModel; dbCreateUpdateModel.SampleName = SampleName; return(dbCreateUpdateModel); }
/// <summary> /// Send the restore request /// </summary> /// <returns>The list of entities</returns> protected override AzureSqlDatabaseModel GetEntity() { AzureSqlDatabaseModel model; DateTime restorePointInTime = DateTime.MinValue; string createMode; string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName); switch (ParameterSetName) { case FromPointInTimeBackupSetName: case FromPointInTimeBackupWithVcoreSetName: createMode = "PointInTimeRestore"; restorePointInTime = PointInTime; break; case FromDeletedDatabaseBackupSetName: case FromDeletedDatabaseBackupWithVcoreSetName: createMode = "Restore"; restorePointInTime = PointInTime == DateTime.MinValue ? DeletionDate : PointInTime; break; case FromGeoBackupSetName: case FromGeoBackupWithVcoreSetName: createMode = "Recovery"; break; case FromLongTermRetentionBackupSetName: case FromLongTermRetentionBackupWithVcoreSetName: createMode = "RestoreLongTermRetentionBackup"; break; default: throw new ArgumentException("No ParameterSet name"); } model = new AzureSqlDatabaseModel() { Location = location, ResourceGroupName = ResourceGroupName, ServerName = ServerName, DatabaseName = TargetDatabaseName, ElasticPoolName = ElasticPoolName, RequestedServiceObjectiveName = ServiceObjectiveName, Edition = Edition, CreateMode = createMode, LicenseType = LicenseType, RequestedBackupStorageRedundancy = BackupStorageRedundancy, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), ZoneRedundant = this.IsParameterBound(p => p.ZoneRedundant) ? ZoneRedundant.ToBool() : (bool?)null, }; if (ParameterSetName == FromPointInTimeBackupWithVcoreSetName || ParameterSetName == FromDeletedDatabaseBackupWithVcoreSetName || ParameterSetName == FromGeoBackupWithVcoreSetName || ParameterSetName == FromLongTermRetentionBackupWithVcoreSetName) { string skuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition); model.SkuName = skuName; model.Edition = Edition; model.Capacity = VCore; model.Family = ComputeGeneration; } else { model.SkuName = string.IsNullOrWhiteSpace(ServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : ServiceObjectiveName; model.Edition = Edition; } /// get auth headers for cross-sub and cross-tenant restore operations string targetSubscriptionId = ModelAdapter.Context?.Subscription.Id; string sourceSubscriptionId = ParseSourceSubscriptionIdFromResourceId(ResourceId); Dictionary <string, List <string> > auxAuthHeader = null; if (!string.IsNullOrEmpty(ResourceId) && targetSubscriptionId != sourceSubscriptionId) { List <string> resourceIds = new List <string>(); resourceIds.Add(ResourceId); var auxHeaderDictionary = GetAuxilaryAuthHeaderFromResourceIds(resourceIds); if (auxHeaderDictionary != null && auxHeaderDictionary.Count > 0) { auxAuthHeader = new Dictionary <string, List <string> >(auxHeaderDictionary); } } return(ModelAdapter.RestoreDatabase(this.ResourceGroupName, restorePointInTime, ResourceId, model, sourceSubscriptionId, auxAuthHeader)); }
/// <summary> /// Send the restore request /// </summary> /// <returns>The list of entities</returns> protected override AzureSqlDatabaseModel GetEntity() { AzureSqlDatabaseModel model; DateTime restorePointInTime = DateTime.MinValue; string createMode; string location = ModelAdapter.GetServerLocation(ResourceGroupName, ServerName); switch (ParameterSetName) { case FromPointInTimeBackupSetName: case FromPointInTimeBackupWithVcoreSetName: createMode = "PointInTimeRestore"; restorePointInTime = PointInTime; break; case FromDeletedDatabaseBackupSetName: case FromDeletedDatabaseBackupWithVcoreSetName: createMode = "Restore"; restorePointInTime = PointInTime == DateTime.MinValue ? DeletionDate : PointInTime; break; case FromGeoBackupSetName: case FromGeoBackupWithVcoreSetName: createMode = "Recovery"; break; case FromLongTermRetentionBackupSetName: case FromLongTermRetentionBackupWithVcoreSetName: createMode = "RestoreLongTermRetentionBackup"; break; default: throw new ArgumentException("No ParameterSet name"); } model = new AzureSqlDatabaseModel() { Location = location, ResourceGroupName = ResourceGroupName, ServerName = ServerName, DatabaseName = TargetDatabaseName, ElasticPoolName = ElasticPoolName, RequestedServiceObjectiveName = ServiceObjectiveName, Edition = Edition, CreateMode = createMode, LicenseType = LicenseType }; if (ParameterSetName == FromPointInTimeBackupWithVcoreSetName || ParameterSetName == FromDeletedDatabaseBackupWithVcoreSetName || ParameterSetName == FromGeoBackupWithVcoreSetName || ParameterSetName == FromLongTermRetentionBackupWithVcoreSetName) { string skuName = AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition); model.SkuName = skuName; model.Edition = Edition; model.Capacity = VCore; model.Family = ComputeGeneration; } else { model.SkuName = string.IsNullOrWhiteSpace(ServiceObjectiveName) ? AzureSqlDatabaseAdapter.GetDatabaseSkuName(Edition) : ServiceObjectiveName; model.Edition = Edition; } return(ModelAdapter.RestoreDatabase(this.ResourceGroupName, restorePointInTime, ResourceId, model)); }