Ejemplo n.º 1
0
        /// <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>
        /// Get instance sku name based on edition
        ///    Edition              | SkuName
        ///    GeneralPurpose       | GP
        ///    BusinessCritical     | BC
        /// </summary>
        /// <param name="tier">Azure Sql database edition</param>
        /// <returns>The sku name</returns>
        public static string GetInstanceSkuPrefix(string tier)
        {
            if (string.IsNullOrWhiteSpace(tier))
            {
                return(null);
            }

            return(SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? "Unknown");
        }
        /// <summary>
        /// Get database sku name based on edition
        ///    Edition              | SkuName
        ///    GeneralPurpose       | GP
        ///    BusinessCritical     | BC
        ///    Hyperscale           | HS
        ///    Standard             | Standard
        ///    Basic                | Basic
        ///    Premium              | Premium
        ///
        /// Also adds _S in the end of SkuName in case if it is Serverless
        /// </summary>
        /// <param name="tier">Azure Sql database edition</param>
        /// <param name="isServerless">If sku should be serverless type</param>
        /// <returns>The sku name</returns>
        public static string GetDatabaseSkuName(string tier, bool isServerless = false)
        {
            if (string.IsNullOrWhiteSpace(tier))
            {
                return(null);
            }

            return((SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? tier) + (isServerless ? "_S" : ""));
        }
        /// <summary>
        /// Get elastic pool sku name based on tier
        ///    Edition              | SkuName
        ///    GeneralPurpose       | GP
        ///    BusinessCritical     | BC
        ///    Standard             | StandardPool
        ///    Basic                | BasicPool
        ///    Premium              | PremiumPool
        /// </summary>
        /// <param name="tier">Azure Sql elastic pool edition</param>
        /// <returns>The sku name</returns>
        public static string GetPoolSkuName(string tier)
        {
            if (string.IsNullOrWhiteSpace(tier))
            {
                return(null);
            }

            return(SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? string.Format("{0}Pool", tier));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Get database sku name based on edition
        ///    Edition              | SkuName
        ///    GeneralPurpose       | GP
        ///    BusinessCritical     | BC
        ///    Hyperscale           | HS
        ///    Standard             | Standard
        ///    Basic                | Basic
        ///    Premium              | Premium
        /// </summary>
        /// <param name="tier">Azure Sql database edition</param>
        /// <returns>The sku name</returns>
        public static string GetDatabaseSkuName(string tier)
        {
            if (string.IsNullOrWhiteSpace(tier))
            {
                return(null);
            }

            return(SqlSkuUtils.GetVcoreSkuPrefix(tier) ?? tier);
        }
        /// <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);
        }