/// <summary> /// Convert a Management.Sql.LegacySdk.Models.ManagedInstance to AzureSqlDatabaseManagedInstanceModel /// </summary> /// <param name="resourceGroupName">The resource group the managed instance is in</param> /// <param name="resp">The management client managed instance response to convert</param> /// <returns>The converted managed instance model</returns> private static AzureSqlManagedInstanceModel CreateManagedInstanceModelFromResponse(Management.Sql.Models.ManagedInstance resp) { AzureSqlManagedInstanceModel managedInstance = new AzureSqlManagedInstanceModel(); // Extract the resource group name from the ID. // ID is in the form: // /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rgName/providers/Microsoft.Sql/managedInstances/managedInstanceName string[] segments = resp.Id.Split('/'); managedInstance.ResourceGroupName = segments[4]; managedInstance.ManagedInstanceName = resp.Name; managedInstance.Id = resp.Id; managedInstance.FullyQualifiedDomainName = resp.FullyQualifiedDomainName; managedInstance.AdministratorLogin = resp.AdministratorLogin; managedInstance.Location = resp.Location; managedInstance.Tags = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(resp.Tags), false); managedInstance.Identity = resp.Identity; managedInstance.FullyQualifiedDomainName = resp.FullyQualifiedDomainName; managedInstance.SubnetId = resp.SubnetId; managedInstance.LicenseType = resp.LicenseType; managedInstance.VCores = resp.VCores; managedInstance.StorageSizeInGB = resp.StorageSizeInGB; managedInstance.Collation = resp.Collation; managedInstance.PublicDataEndpointEnabled = resp.PublicDataEndpointEnabled; managedInstance.ProxyOverride = resp.ProxyOverride; Management.Internal.Resources.Models.Sku sku = new Management.Internal.Resources.Models.Sku(); sku.Name = resp.Sku.Name; sku.Tier = resp.Sku.Tier; managedInstance.Sku = sku; return(managedInstance); }
/// <summary> /// Upserts a managed instance /// </summary> /// <param name="model">The managed instance to upsert</param> /// <returns>The updated managed instance model</returns> public AzureSqlManagedInstanceModel UpsertManagedInstance(AzureSqlManagedInstanceModel model) { var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.FullyQualifiedDomainName, new Management.Sql.Models.ManagedInstance() { Location = model.Location, Tags = model.Tags, AdministratorLogin = model.AdministratorLogin, AdministratorLoginPassword = model.AdministratorPassword != null ? ConversionUtilities.SecureStringToString(model.AdministratorPassword) : null, Sku = model.Sku != null ? new Management.Sql.Models.Sku(model.Sku.Name, model.Sku.Tier) : null, LicenseType = model.LicenseType, StorageSizeInGB = model.StorageSizeInGB, SubnetId = model.SubnetId, VCores = model.VCores, Identity = model.Identity, Collation = model.Collation, PublicDataEndpointEnabled = model.PublicDataEndpointEnabled, ProxyOverride = model.ProxyOverride, TimezoneId = model.TimezoneId, DnsZonePartner = model.DnsZonePartner, InstancePoolId = model.InstancePoolName != null ? string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/instancePools/{2}", Context.Subscription.Id, model.ResourceGroupName, model.InstancePoolName): null }); return(CreateManagedInstanceModelFromResponse(resp)); }
/// <summary> /// Upserts a managed instance /// </summary> /// <param name="model">The managed instance to upsert</param> /// <returns>The updated managed instance model</returns> public AzureSqlManagedInstanceModel UpsertManagedInstance(AzureSqlManagedInstanceModel model) { var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.FullyQualifiedDomainName, new Management.Sql.Models.ManagedInstance() { Location = model.Location, Tags = model.Tags, AdministratorLogin = model.AdministratorLogin, AdministratorLoginPassword = model.AdministratorPassword != null ? ConversionUtilities.SecureStringToString(model.AdministratorPassword) : null, Sku = model.Sku != null ? new Management.Sql.Models.Sku(model.Sku.Name, model.Sku.Tier) : null, LicenseType = model.LicenseType, StorageSizeInGB = model.StorageSizeInGB, SubnetId = model.SubnetId, VCores = model.VCores, Identity = model.Identity, Collation = model.Collation, PublicDataEndpointEnabled = model.PublicDataEndpointEnabled, ProxyOverride = model.ProxyOverride, TimezoneId = model.TimezoneId, DnsZonePartner = model.DnsZonePartner, InstancePoolId = model.InstancePoolName != null ? string.Format("/subscriptions/{0}/resourceGroups/{1}/providers/Microsoft.Sql/instancePools/{2}", Context.Subscription.Id, model.ResourceGroupName, model.InstancePoolName) : null, MinimalTlsVersion = model.MinimalTlsVersion, StorageAccountType = MapExternalBackupStorageRedundancyToInternal(model.BackupStorageRedundancy), MaintenanceConfigurationId = MaintenanceConfigurationHelper.ConvertMaintenanceConfigurationIdArgument(model.MaintenanceConfigurationId, Context.Subscription.Id), Administrators = GetActiveDirectoryInformation(model.Administrators), PrimaryUserAssignedIdentityId = model.PrimaryUserAssignedIdentityId, KeyId = model.KeyId }); return(CreateManagedInstanceModelFromResponse(resp)); }
/// <summary> /// Convert a Management.Sql.LegacySdk.Models.ManagedInstance to AzureSqlDatabaseManagedInstanceModel /// </summary> /// <param name="resourceGroupName">The resource group the managed instance is in</param> /// <param name="resp">The management client managed instance response to convert</param> /// <returns>The converted managed instance model</returns> private static AzureSqlManagedInstanceModel CreateManagedInstanceModelFromResponse(Management.Sql.Models.ManagedInstance resp) { AzureSqlManagedInstanceModel managedInstance = new AzureSqlManagedInstanceModel(); // Extract the resource group name from the ID. // ID is in the form: // /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rgName/providers/Microsoft.Sql/managedInstances/managedInstanceName string[] segments = resp.Id.Split('/'); managedInstance.ResourceGroupName = segments[4]; managedInstance.ManagedInstanceName = resp.Name; managedInstance.Id = resp.Id; managedInstance.FullyQualifiedDomainName = resp.FullyQualifiedDomainName; managedInstance.AdministratorLogin = resp.AdministratorLogin; managedInstance.Location = resp.Location; managedInstance.Tags = TagsConversionHelper.CreateTagDictionary(TagsConversionHelper.CreateTagHashtable(resp.Tags), false); managedInstance.Identity = resp.Identity; managedInstance.FullyQualifiedDomainName = resp.FullyQualifiedDomainName; managedInstance.SubnetId = resp.SubnetId; managedInstance.LicenseType = resp.LicenseType; managedInstance.VCores = resp.VCores; managedInstance.StorageSizeInGB = resp.StorageSizeInGB; managedInstance.Collation = resp.Collation; managedInstance.PublicDataEndpointEnabled = resp.PublicDataEndpointEnabled; managedInstance.ProxyOverride = resp.ProxyOverride; managedInstance.TimezoneId = resp.TimezoneId; managedInstance.DnsZone = resp.DnsZone; managedInstance.InstancePoolName = resp.InstancePoolId != null ? new ResourceIdentifier(resp.InstancePoolId).ResourceName : null; managedInstance.MinimalTlsVersion = resp.MinimalTlsVersion; managedInstance.BackupStorageRedundancy = resp.CurrentBackupStorageRedundancy; managedInstance.RequestedBackupStorageRedundancy = resp.RequestedBackupStorageRedundancy; managedInstance.CurrentBackupStorageRedundancy = resp.CurrentBackupStorageRedundancy; managedInstance.MaintenanceConfigurationId = resp.MaintenanceConfigurationId; managedInstance.ServicePrincipal = ResourceServicePrincipalHelper.WrapServicePrincipalObject(resp.ServicePrincipal); Management.Internal.Resources.Models.Sku sku = new Management.Internal.Resources.Models.Sku(); sku.Name = resp.Sku.Name; sku.Tier = resp.Sku.Tier; sku.Family = resp.Sku.Family; managedInstance.Sku = sku; managedInstance.Administrators = resp.Administrators; if (managedInstance.Administrators != null && managedInstance.Administrators.AdministratorType == null) { managedInstance.Administrators.AdministratorType = "ActiveDirectory"; } managedInstance.PrimaryUserAssignedIdentityId = resp.PrimaryUserAssignedIdentityId; managedInstance.KeyId = resp.KeyId; managedInstance.ZoneRedundant = resp.ZoneRedundant; return(managedInstance); }
/// <summary> /// Constructs the model to send to the update API /// </summary> /// <param name="model">The result of the get operation</param> /// <returns>The model to send to the update</returns> protected override IEnumerable <AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <AzureSqlManagedInstanceModel> model) { AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name, "administrators/activedirectory"); Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku(); // Get current edition and family string currentEdition = existingInstance.Sku.Tier; string currentComputeGeneration = existingInstance.Sku.Family; // If either edition or compute generation are set, get the new sku if (this.Edition != null || this.ComputeGeneration != null) { string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(!string.IsNullOrWhiteSpace(Edition) ? this.Edition : currentEdition); Sku.Name = editionShort + "_" + (!string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration); Sku.Tier = !string.IsNullOrWhiteSpace(this.Edition) ? this.Edition : null; Sku.Family = !string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration; } else { Sku = existingInstance.Sku; } // Construct a new entity so we only send the relevant data to the Managed instance List <AzureSqlManagedInstanceModel> updateData = new List <AzureSqlManagedInstanceModel>(); updateData.Add(model.FirstOrDefault()); updateData[0].ResourceGroupName = this.ResourceGroupName; updateData[0].ManagedInstanceName = this.Name; updateData[0].FullyQualifiedDomainName = this.Name; updateData[0].Location = model.FirstOrDefault().Location; updateData[0].Sku = Sku; updateData[0].AdministratorPassword = this.AdministratorPassword; updateData[0].LicenseType = this.LicenseType ?? updateData[0].LicenseType; updateData[0].StorageSizeInGB = this.StorageSizeInGB ?? model.FirstOrDefault().StorageSizeInGB; updateData[0].VCores = this.VCore ?? updateData[0].VCores; updateData[0].PublicDataEndpointEnabled = this.PublicDataEndpointEnabled ?? updateData[0].PublicDataEndpointEnabled; updateData[0].ProxyOverride = this.ProxyOverride ?? this.ProxyOverride; updateData[0].Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true); updateData[0].Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, model.FirstOrDefault().Identity); updateData[0].InstancePoolName = this.InstancePoolName ?? updateData[0].InstancePoolName; updateData[0].MinimalTlsVersion = this.MinimalTlsVersion ?? updateData[0].MinimalTlsVersion; updateData[0].MaintenanceConfigurationId = this.MaintenanceConfigurationId ?? updateData[0].MaintenanceConfigurationId; updateData[0].AdministratorLogin = model.FirstOrDefault().AdministratorLogin; updateData[0].PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId ?? model.FirstOrDefault().PrimaryUserAssignedIdentityId; updateData[0].KeyId = this.KeyId ?? updateData[0].KeyId; updateData[0].SubnetId = this.SubnetId ?? model.FirstOrDefault().SubnetId; updateData[0].ZoneRedundant = this.ZoneRedundant.IsPresent ? this.ZoneRedundant.ToBool() : (bool?)null; updateData[0].RequestedBackupStorageRedundancy = this.BackupStorageRedundancy ?? updateData[0].CurrentBackupStorageRedundancy; updateData[0].ServicePrincipal = ResourceServicePrincipalHelper.GetServicePrincipalObjectFromType(this.ServicePrincipalType ?? null); return(updateData); }
/// <summary> /// Constructs the model to send to the update API /// </summary> /// <param name="model">The result of the get operation</param> /// <returns>The model to send to the update</returns> protected override IEnumerable <AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <AzureSqlManagedInstanceModel> model) { AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name); Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku(); // Get current edition and family string currentEdition = existingInstance.Sku.Tier; string currentComputeGeneration = existingInstance.Sku.Family; // If either edition or compute generation are set, get the new sku if (this.Edition != null || this.ComputeGeneration != null) { string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(!string.IsNullOrWhiteSpace(Edition) ? this.Edition : currentEdition); Sku.Name = editionShort + "_" + (!string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration); Sku.Tier = !string.IsNullOrWhiteSpace(this.Edition) ? this.Edition : null; Sku.Family = !string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration; } else { Sku = existingInstance.Sku; } // Construct a new entity so we only send the relevant data to the Managed instance List <AzureSqlManagedInstanceModel> updateData = new List <AzureSqlManagedInstanceModel>(); updateData.Add(new AzureSqlManagedInstanceModel() { ResourceGroupName = this.ResourceGroupName, ManagedInstanceName = this.Name, FullyQualifiedDomainName = this.Name, Location = model.FirstOrDefault().Location, Sku = Sku, AdministratorPassword = this.AdministratorPassword, LicenseType = this.LicenseType, StorageSizeInGB = this.StorageSizeInGB ?? model.FirstOrDefault().StorageSizeInGB, VCores = this.VCore, PublicDataEndpointEnabled = this.PublicDataEndpointEnabled, ProxyOverride = this.ProxyOverride, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, model.FirstOrDefault().Identity), InstancePoolName = this.InstancePoolName, MinimalTlsVersion = this.MinimalTlsVersion, MaintenanceConfigurationId = this.MaintenanceConfigurationId, AdministratorLogin = model.FirstOrDefault().AdministratorLogin, PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId ?? model.FirstOrDefault().PrimaryUserAssignedIdentityId, KeyId = this.KeyId }); return(updateData); }
/// <summary> /// Upserts a managed instance /// </summary> /// <param name="model">The managed instance to upsert</param> /// <returns>The updated managed instance model</returns> public AzureSqlManagedInstanceModel UpdateManagedInstance(AzureSqlManagedInstanceModel model) { var resp = Communicator.Update(model.ResourceGroupName, model.FullyQualifiedDomainName, new Management.Sql.Models.ManagedInstanceUpdate() { Tags = model.Tags, AdministratorLogin = model.AdministratorLogin, AdministratorLoginPassword = model.AdministratorPassword != null ? ConversionUtilities.SecureStringToString(model.AdministratorPassword) : null, Sku = model.Sku != null ? new Management.Sql.Models.Sku(model.Sku.Name, model.Sku.Tier) : null, LicenseType = model.LicenseType, StorageSizeInGB = model.StorageSizeInGB, SubnetId = model.SubnetId, VCores = model.VCores }); return(CreateManagedInstanceModelFromResponse(resp)); }
/// <summary> /// Validate requested Hardware family. /// </summary> protected bool ShouldConfirmHardwareFamilyChange() { bool shouldConfirmHardwareFamilyChange = false; ModelAdapter = InitModelAdapter(); AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name); // Get current hardware family string currentHardwareFamily = existingInstance.Sku.Family; // Check whether the hardware family was changed bool isHardwareFamilyChanged = !currentHardwareFamily.Equals(this.ComputeGeneration, StringComparison.InvariantCultureIgnoreCase); // Check whether hardware family is being changed to a newer hardware family if (isHardwareFamilyChanged && currentHardwareFamily.Equals(Constants.ComputeGenerationGen4, StringComparison.InvariantCultureIgnoreCase)) { shouldConfirmHardwareFamilyChange = true; } return(shouldConfirmHardwareFamilyChange); }
/// <summary> /// Upserts a managed instance /// </summary> /// <param name="model">The managed instance to upsert</param> /// <returns>The updated managed instance model</returns> public AzureSqlManagedInstanceModel UpsertManagedInstance(AzureSqlManagedInstanceModel model) { var resp = Communicator.CreateOrUpdate(model.ResourceGroupName, model.FullyQualifiedDomainName, new Management.Sql.Models.ManagedInstance() { Location = model.Location, Tags = model.Tags, AdministratorLogin = model.AdministratorLogin, AdministratorLoginPassword = model.AdministratorPassword != null ? ConversionUtilities.SecureStringToString(model.AdministratorPassword) : null, Sku = model.Sku != null ? new Management.Sql.Models.Sku(model.Sku.Name, model.Sku.Tier) : null, LicenseType = model.LicenseType, StorageSizeInGB = model.StorageSizeInGB, SubnetId = model.SubnetId, VCores = model.VCores, Identity = model.Identity, Collation = model.Collation, PublicDataEndpointEnabled = model.PublicDataEndpointEnabled, ProxyOverride = model.ProxyOverride }); return(CreateManagedInstanceModelFromResponse(resp)); }
/// <summary> /// Constructs the model to send to the update API /// </summary> /// <param name="model">The result of the get operation</param> /// <returns>The model to send to the update</returns> protected override IEnumerable <AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <AzureSqlManagedInstanceModel> model) { AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name); Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku(); if (Edition != null) { string computeGeneration = existingInstance.Sku.Name.Contains(Constants.ComputeGenerationGen4) ? Constants.ComputeGenerationGen4 : Constants.ComputeGenerationGen5; string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition); Sku.Name = editionShort + "_" + computeGeneration; Sku.Tier = Edition; } else { Sku = null; } // Construct a new entity so we only send the relevant data to the Managed instance List <AzureSqlManagedInstanceModel> updateData = new List <AzureSqlManagedInstanceModel>(); updateData.Add(new AzureSqlManagedInstanceModel() { ResourceGroupName = this.ResourceGroupName, ManagedInstanceName = this.Name, FullyQualifiedDomainName = this.Name, Location = model.FirstOrDefault().Location, Sku = Sku, AdministratorPassword = this.AdministratorPassword, LicenseType = this.LicenseType, StorageSizeInGB = this.StorageSizeInGB ?? model.FirstOrDefault().StorageSizeInGB, VCores = this.VCore, PublicDataEndpointEnabled = this.PublicDataEndpointEnabled, ProxyOverride = this.ProxyOverride, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), Identity = model.FirstOrDefault().Identity ?? ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent), InstancePoolName = this.InstancePoolName }); return(updateData); }