|
| 1 | + |
| 2 | +# ---------------------------------------------------------------------------------- |
| 3 | +# |
| 4 | +# Copyright Microsoft Corporation |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | +# ---------------------------------------------------------------------------------- |
| 15 | + |
| 16 | +<# |
| 17 | +.Synopsis |
| 18 | +Creates a new MySQL flexible server |
| 19 | +.Description |
| 20 | +Creates a new MySQL flexible server |
| 21 | +#> |
| 22 | +function New-AzMySqlFlexibleServer { |
| 23 | + [OutputType([Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20200701Preview.IServerAutoGenerated])] |
| 24 | + [CmdletBinding(DefaultParameterSetName='CreateExpanded', PositionalBinding=$false, SupportsShouldProcess, ConfirmImpact='Medium')] |
| 25 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Description('Creates a new server.')] |
| 26 | + param( |
| 27 | + [Parameter(Mandatory, HelpMessage = 'The name of the server.')] |
| 28 | + [Alias('ServerName')] |
| 29 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] |
| 30 | + [System.String] |
| 31 | + ${Name}, |
| 32 | + |
| 33 | + [Parameter(Mandatory, HelpMessage = 'The name of the resource group that contains the resource, You can obtain this value from the Azure Resource Manager API or the portal.')] |
| 34 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] |
| 35 | + [System.String] |
| 36 | + ${ResourceGroupName}, |
| 37 | + |
| 38 | + [Parameter(HelpMessage='The subscription ID that identifies an Azure subscription.')] |
| 39 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Path')] |
| 40 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.DefaultInfo(Script='(Get-AzContext).Subscription.Id')] |
| 41 | + [System.String] |
| 42 | + ${SubscriptionId}, |
| 43 | + |
| 44 | + [Parameter(HelpMessage = 'The location the resource resides in.')] |
| 45 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 46 | + [System.String] |
| 47 | + ${Location}, |
| 48 | + |
| 49 | + [Parameter(Mandatory, HelpMessage = 'Administrator username for the server. Once set, it cannot be changed.')] |
| 50 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 51 | + [System.String] |
| 52 | + ${AdministratorUserName}, |
| 53 | + |
| 54 | + [Parameter(Mandatory, HelpMessage = 'The password of the administrator. Minimum 8 characters and maximum 128 characters. Password must contain characters from three of the following categories: English uppercase letters, English lowercase letters, numbers, and non-alphanumeric characters.')] |
| 55 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 56 | + [System.Security.SecureString] |
| 57 | + [ValidateNotNullOrEmpty()] |
| 58 | + ${AdministratorLoginPassword}, |
| 59 | + |
| 60 | + [Parameter(HelpMessage = 'The name of the sku, typically, tier + family + cores, e.g. Standard_B1ms, Standard_D2ds_v4.')] |
| 61 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 62 | + [System.String] |
| 63 | + ${Sku}, |
| 64 | + |
| 65 | + [Parameter(HelpMessage = 'Compute tier of the server. Accepted values: Burstable, GeneralPurpose, Memory Optimized. Default: Burstable.')] |
| 66 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 67 | + [System.String] |
| 68 | + ${SkuTier}, |
| 69 | + |
| 70 | + [Parameter(HelpMessage = "Backup retention days for the server. Day count is between 7 and 35.")] |
| 71 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 72 | + [System.Int32] |
| 73 | + ${BackupRetentionDay}, |
| 74 | + |
| 75 | + [Parameter(HelpMessage = 'Max storage allowed for a server.')] |
| 76 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 77 | + [System.Int32] |
| 78 | + ${StorageInMb}, |
| 79 | + |
| 80 | + [Parameter(HelpMessage = 'Application-specific metadata in the form of key-value pairs.')] |
| 81 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 82 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.Info(PossibleTypes=([Microsoft.Azure.PowerShell.Cmdlets.MySql.Models.Api20171201.IServerForCreateTags]))] |
| 83 | + [System.Collections.Hashtable] |
| 84 | + ${Tag}, |
| 85 | + |
| 86 | + [Parameter(HelpMessage = 'Server version.')] |
| 87 | + [ArgumentCompleter([Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.ServerVersion])] |
| 88 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Body')] |
| 89 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.ServerVersion] |
| 90 | + ${Version}, |
| 91 | + |
| 92 | + [Parameter(HelpMessage = 'The credentials, account, tenant, and subscription used for communication with Azure.')] |
| 93 | + [Alias('AzureRMContext', 'AzureCredential')] |
| 94 | + [ValidateNotNull()] |
| 95 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Azure')] |
| 96 | + [System.Management.Automation.PSObject] |
| 97 | + ${DefaultProfile}, |
| 98 | + |
| 99 | + [Parameter(HelpMessage = 'Run the command as a job.')] |
| 100 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 101 | + [System.Management.Automation.SwitchParameter] |
| 102 | + ${AsJob}, |
| 103 | + |
| 104 | + [Parameter(DontShow, HelpMessage = 'Wait for .NET debugger to attach.')] |
| 105 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 106 | + [System.Management.Automation.SwitchParameter] |
| 107 | + ${Break}, |
| 108 | + |
| 109 | + [Parameter(DontShow)] |
| 110 | + [ValidateNotNull()] |
| 111 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 112 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] |
| 113 | + # SendAsync Pipeline Steps to be appended to the front of the pipeline. |
| 114 | + ${HttpPipelineAppend}, |
| 115 | + |
| 116 | + [Parameter(DontShow)] |
| 117 | + [ValidateNotNull()] |
| 118 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 119 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Runtime.SendAsyncStep[]] |
| 120 | + # SendAsync Pipeline Steps to be prepended to the front of the pipeline. |
| 121 | + ${HttpPipelinePrepend}, |
| 122 | + |
| 123 | + [Parameter(HelpMessage = 'Run the command asynchronously.')] |
| 124 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 125 | + [System.Management.Automation.SwitchParameter] |
| 126 | + ${NoWait}, |
| 127 | + |
| 128 | + [Parameter(DontShow)] |
| 129 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 130 | + [System.Uri] |
| 131 | + # The URI for the proxy server to use. |
| 132 | + ${Proxy}, |
| 133 | + |
| 134 | + [Parameter(DontShow)] |
| 135 | + [ValidateNotNull()] |
| 136 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 137 | + [System.Management.Automation.PSCredential] |
| 138 | + # Credentials for a proxy server to use for the remote call. |
| 139 | + ${ProxyCredential}, |
| 140 | + |
| 141 | + [Parameter(DontShow)] |
| 142 | + [Microsoft.Azure.PowerShell.Cmdlets.MySql.Category('Runtime')] |
| 143 | + [System.Management.Automation.SwitchParameter] |
| 144 | + # Use the default credentials for the proxy. |
| 145 | + ${ProxyUseDefaultCredentials} |
| 146 | + ) |
| 147 | + |
| 148 | + process { |
| 149 | + try { |
| 150 | + if ($PSBoundParameters.ContainsKey('Name')) { |
| 151 | + $PSBoundParameters.ServerName = $PSBoundParameters['Name'] |
| 152 | + $null = $PSBoundParameters.Remove('Name') |
| 153 | + } |
| 154 | + |
| 155 | + if ($PSBoundParameters.ContainsKey('Sku')) { |
| 156 | + $PSBoundParameters.SkuName = $PSBoundParameters['Sku'] |
| 157 | + $null = $PSBoundParameters.Remove('Sku') |
| 158 | + } |
| 159 | + else { |
| 160 | + $PSBoundParameters.SkuName = 'Standard_B1ms' |
| 161 | + } |
| 162 | + |
| 163 | + if ($PSBoundParameters.ContainsKey('BackupRetentionDay')) { |
| 164 | + $PSBoundParameters.StorageProfileBackupRetentionDay = $PSBoundParameters['BackupRetentionDay'] |
| 165 | + $null = $PSBoundParameters.Remove('BackupRetentionDay') |
| 166 | + } |
| 167 | + else { |
| 168 | + $PSBoundParameters.StorageProfileBackupRetentionDay = 7 |
| 169 | + } |
| 170 | + |
| 171 | + if ($PSBoundParameters.ContainsKey('StorageInMb')) { |
| 172 | + $PSBoundParameters.StorageProfileStorageMb = $PSBoundParameters['StorageInMb'] |
| 173 | + $null = $PSBoundParameters.Remove('StorageInMb') |
| 174 | + } |
| 175 | + else { |
| 176 | + $PSBoundParameters.StorageProfileStorageMb = 10240 |
| 177 | + } |
| 178 | + |
| 179 | + if (!$PSBoundParameters.ContainsKey('Version')) { |
| 180 | + $PSBoundParameters.Version = '5.7' |
| 181 | + } |
| 182 | + |
| 183 | + if (!$PSBoundParameters.ContainsKey('SkuTier')) { |
| 184 | + $PSBoundParameters.SkuTier = 'Burstable' |
| 185 | + } |
| 186 | + |
| 187 | + if (!$PSBoundParameters.ContainsKey('Location')) { |
| 188 | + $PSBoundParameters.Location = 'westus2' |
| 189 | + } |
| 190 | + |
| 191 | + if ($PSBoundParameters.ContainsKey('AdministratorUserName')) { |
| 192 | + $PSBoundParameters.AdministratorLogin = $PSBoundParameters['AdministratorUserName'] |
| 193 | + $null = $PSBoundParameters.Remove('AdministratorUserName') |
| 194 | + } |
| 195 | + |
| 196 | + $PSBoundParameters.CreateMode = [Microsoft.Azure.PowerShell.Cmdlets.MySql.Support.CreateMode]::Default |
| 197 | + $PSBoundParameters.AdministratorLoginPassword = . "$PSScriptRoot/../utils/Unprotect-SecureString.ps1" $PSBoundParameters['AdministratorLoginPassword'] |
| 198 | + |
| 199 | + Az.MySql.internal\New-AzMySqlFlexibleServer @PSBoundParameters |
| 200 | + } catch { |
| 201 | + throw |
| 202 | + } |
| 203 | + } |
| 204 | +} |
| 205 | + |
| 206 | + |
0 commit comments