/// <summary> /// Generates the model from user input. /// </summary> /// <param name="model">This is null since the instance doesn't exist yet</param> /// <returns>The generated model from user input</returns> protected override IEnumerable <Model.AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <Model.AzureSqlManagedInstanceModel> model) { List <Model.AzureSqlManagedInstanceModel> newEntity = new List <Model.AzureSqlManagedInstanceModel>(); Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku(); if (string.Equals(this.ParameterSetName, NewBySkuNameParameterSet, System.StringComparison.OrdinalIgnoreCase)) { Sku.Name = SkuName; } else if (string.Equals(this.ParameterSetName, NewByEditionAndComputeGenerationParameterSet, System.StringComparison.OrdinalIgnoreCase)) { string editionShort = Edition.Equals(Constants.GeneralPurposeEdition) ? "GP" : Edition.Equals(Constants.BusinessCriticalEdition) ? "BC" : "Unknown"; Sku.Name = editionShort + "_" + ComputeGeneration; } newEntity.Add(new Model.AzureSqlManagedInstanceModel() { Location = this.Location, ResourceGroupName = this.ResourceGroupName, FullyQualifiedDomainName = this.Name, AdministratorLogin = this.AdministratorCredential.UserName, AdministratorPassword = this.AdministratorCredential.Password, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent), LicenseType = this.LicenseType, StorageSizeInGB = this.StorageSizeInGB, SubnetId = this.SubnetId, VCores = this.VCore, Sku = Sku, Collation = this.Collation }); return(newEntity); }
/// <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> /// Generates the model from user input. /// </summary> /// <param name="model">This is null since the instance doesn't exist yet</param> /// <returns>The generated model from user input</returns> protected override IEnumerable <Model.AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <Model.AzureSqlManagedInstanceModel> model) { List <Model.AzureSqlManagedInstanceModel> newEntity = new List <Model.AzureSqlManagedInstanceModel>(); Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku(); if (string.Equals(this.ParameterSetName, NewBySkuNameParameterSet, System.StringComparison.OrdinalIgnoreCase)) { Sku.Name = SkuName; } else if (string.Equals(this.ParameterSetName, NewByEditionAndComputeGenerationParameterSet, System.StringComparison.OrdinalIgnoreCase) || string.Equals(this.ParameterSetName, NewByInstancePoolParentObjectParameterSet, System.StringComparison.OrdinalIgnoreCase) || string.Equals(this.ParameterSetName, NewByInstancePoolResourceIdParameterSet, System.StringComparison.OrdinalIgnoreCase)) { string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition); Sku.Name = editionShort + "_" + ComputeGeneration; } newEntity.Add(new AzureSqlManagedInstanceModel() { Location = this.Location, ResourceGroupName = this.ResourceGroupName, FullyQualifiedDomainName = this.Name, AdministratorPassword = (this.AdministratorCredential != null) ? this.AdministratorCredential.Password : null, AdministratorLogin = (this.AdministratorCredential != null) ? this.AdministratorCredential.UserName : null, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent, this.IdentityType ?? null, UserAssignedIdentityId, null), LicenseType = this.LicenseType, // `-StorageSizeInGB 0` as a parameter to this cmdlet means "use default". // For non-MI database, we can just pass in 0 and the server will treat 0 as default. // However this is (currently) not the case for MI. We need to convert the 0 to null // here in client before sending to the server. StorageSizeInGB = SqlSkuUtils.ValueIfNonZero(this.StorageSizeInGB), SubnetId = this.SubnetId, VCores = this.VCore, Sku = Sku, Collation = this.Collation, PublicDataEndpointEnabled = this.PublicDataEndpointEnabled, ProxyOverride = this.ProxyOverride, TimezoneId = this.TimezoneId, DnsZonePartner = this.DnsZonePartner, InstancePoolName = this.InstancePoolName, MinimalTlsVersion = this.MinimalTlsVersion, RequestedBackupStorageRedundancy = this.BackupStorageRedundancy, MaintenanceConfigurationId = this.MaintenanceConfigurationId, PrimaryUserAssignedIdentityId = this.PrimaryUserAssignedIdentityId, KeyId = this.KeyId, Administrators = new Management.Sql.Models.ManagedInstanceExternalAdministrator() { AzureADOnlyAuthentication = (this.EnableActiveDirectoryOnlyAuthentication.IsPresent) ? (bool?)true : null, Login = this.ExternalAdminName, Sid = this.ExternalAdminSID }, ZoneRedundant = this.ZoneRedundant.IsPresent ? this.ZoneRedundant.ToBool() : (bool?)null, ServicePrincipal = ResourceServicePrincipalHelper.GetServicePrincipalObjectFromType(this.ServicePrincipalType ?? null) });; return(newEntity); }
/// <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> /// Generates the model from user input. /// </summary> /// <param name="model">This is null since the instance doesn't exist yet</param> /// <returns>The generated model from user input</returns> protected override IEnumerable <Model.AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <Model.AzureSqlManagedInstanceModel> model) { List <Model.AzureSqlManagedInstanceModel> newEntity = new List <Model.AzureSqlManagedInstanceModel>(); Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku(); if (string.Equals(this.ParameterSetName, NewBySkuNameParameterSet, System.StringComparison.OrdinalIgnoreCase)) { Sku.Name = SkuName; } else if (string.Equals(this.ParameterSetName, NewByEditionAndComputeGenerationParameterSet, System.StringComparison.OrdinalIgnoreCase) || string.Equals(this.ParameterSetName, NewByInstancePoolParentObjectParameterSet, System.StringComparison.OrdinalIgnoreCase) || string.Equals(this.ParameterSetName, NewByInstancePoolResourceIdParameterSet, System.StringComparison.OrdinalIgnoreCase)) { string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition); Sku.Name = editionShort + "_" + ComputeGeneration; } newEntity.Add(new AzureSqlManagedInstanceModel() { Location = this.Location, ResourceGroupName = this.ResourceGroupName, FullyQualifiedDomainName = this.Name, AdministratorLogin = this.AdministratorCredential.UserName, AdministratorPassword = this.AdministratorCredential.Password, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent), LicenseType = this.LicenseType, // `-StorageSizeInGB 0` as a parameter to this cmdlet means "use default". // For non-MI database, we can just pass in 0 and the server will treat 0 as default. // However this is (currently) not the case for MI. We need to convert the 0 to null // here in client before sending to the server. StorageSizeInGB = SqlSkuUtils.ValueIfNonZero(this.StorageSizeInGB), SubnetId = this.SubnetId, VCores = this.VCore, Sku = Sku, Collation = this.Collation, PublicDataEndpointEnabled = this.PublicDataEndpointEnabled, ProxyOverride = this.ProxyOverride, TimezoneId = this.TimezoneId, DnsZonePartner = this.DnsZonePartner, InstancePoolName = this.InstancePoolName }); return(newEntity); }
/// <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); }
/// <summary> /// Generates the model from user input. /// </summary> /// <param name="model">This is null since the instance doesn't exist yet</param> /// <returns>The generated model from user input</returns> protected override IEnumerable <Model.AzureSqlManagedInstanceModel> ApplyUserInputToModel(IEnumerable <Model.AzureSqlManagedInstanceModel> model) { List <Model.AzureSqlManagedInstanceModel> newEntity = new List <Model.AzureSqlManagedInstanceModel>(); Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku(); if (string.Equals(this.ParameterSetName, NewBySkuNameParameterSet, System.StringComparison.OrdinalIgnoreCase)) { Sku.Name = SkuName; } else if (string.Equals(this.ParameterSetName, NewByEditionAndComputeGenerationParameterSet, System.StringComparison.OrdinalIgnoreCase)) { string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition); Sku.Name = editionShort + "_" + ComputeGeneration; } newEntity.Add(new Model.AzureSqlManagedInstanceModel() { Location = this.Location, ResourceGroupName = this.ResourceGroupName, FullyQualifiedDomainName = this.Name, AdministratorLogin = this.AdministratorCredential.UserName, AdministratorPassword = this.AdministratorCredential.Password, Tags = TagsConversionHelper.CreateTagDictionary(Tag, validate: true), Identity = ResourceIdentityHelper.GetIdentityObjectFromType(this.AssignIdentity.IsPresent), LicenseType = this.LicenseType, StorageSizeInGB = this.StorageSizeInGB, SubnetId = this.SubnetId, VCores = this.VCore, Sku = Sku, Collation = this.Collation, PublicDataEndpointEnabled = this.PublicDataEndpointEnabled, ProxyOverride = this.ProxyOverride, TimezoneId = this.TimezoneId, DnsZonePartner = this.DnsZonePartner }); return(newEntity); }