Пример #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>
        /// 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);
        }