Skip to content

Commit 940d05c

Browse files
authored
Merge pull request #10892 from v-nestan/nemanjas/mi_change_hw_generation
Nemanjas/mi change hw generation
2 parents f904d89 + 2c77f92 commit 940d05c

File tree

10 files changed

+40280
-2037
lines changed

10 files changed

+40280
-2037
lines changed

src/Sql/Sql.Test/ScenarioTests/ManagedInstanceCrudScenarioTests.ps1

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,36 @@ function Test-SetManagedInstance
189189
Assert-AreEqual $managedInstance4.PublicDataEndpointEnabled $publicDataEndpointEnabled
190190
Assert-AreEqual $managedInstance4.ProxyOverride $proxyOverride
191191
Assert-StartsWith ($managedInstance4.ManagedInstanceName + ".") $managedInstance4.FullyQualifiedDomainName
192+
193+
# Test hardware generation change using ComputeGeneration
194+
$credentials = Get-ServerCredential
195+
$computeGeneration = "Gen5"
196+
197+
$managedInstance5 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
198+
-ComputeGeneration $computeGeneration -Force
199+
200+
Assert-AreEqual $managedInstance5.ManagedInstanceName $managedInstance.ManagedInstanceName
201+
Assert-AreEqual $managedInstance5.AdministratorLogin $managedInstance.AdministratorLogin
202+
Assert-AreEqual $managedInstance5.VCores $managedInstance4.VCores
203+
Assert-AreEqual $managedInstance5.StorageSizeInGB $managedInstance4.StorageSizeInGB
204+
Assert-AreEqual $managedInstance5.Sku.Tier $managedInstance4.Sku.Tier
205+
Assert-AreEqual $managedInstance5.Sku.Family $computeGeneration
206+
Assert-StartsWith ($managedInstance5.ManagedInstanceName + ".") $managedInstance5.FullyQualifiedDomainName
207+
208+
# Test edition change using Edition
209+
$credentials = Get-ServerCredential
210+
$edition = "BusinessCritical"
211+
212+
$managedInstance6 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
213+
-Edition $edition -Force
214+
215+
Assert-AreEqual $managedInstance6.ManagedInstanceName $managedInstance5.ManagedInstanceName
216+
Assert-AreEqual $managedInstance6.AdministratorLogin $managedInstance5.AdministratorLogin
217+
Assert-AreEqual $managedInstance6.VCores $managedInstance5.VCores
218+
Assert-AreEqual $managedInstance6.StorageSizeInGB $managedInstance5.StorageSizeInGB
219+
Assert-AreEqual $managedInstance6.Sku.Tier $edition
220+
Assert-AreEqual $managedInstance6.Sku.Family $managedInstance5.Sku.Family
221+
Assert-StartsWith ($managedInstance6.ManagedInstanceName + ".") $managedInstance6.FullyQualifiedDomainName
192222
}
193223
finally
194224
{

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.InstancePoolCrudTests/TestDeleteManagedInstanceInInstancePool.json

Lines changed: 10486 additions & 649 deletions
Large diffs are not rendered by default.

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.InstancePoolCrudTests/TestUpdateManagedInstanceInInstancePool.json

Lines changed: 10676 additions & 599 deletions
Large diffs are not rendered by default.

src/Sql/Sql.Test/SessionRecords/Microsoft.Azure.Commands.Sql.Test.ScenarioTests.ManagedInstanceCrudScenarioTests/TestSetManagedInstance.json

Lines changed: 18939 additions & 768 deletions
Large diffs are not rendered by default.

src/Sql/Sql/ChangeLog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
-->
2020
## Upcoming Release
2121
* Added support for cross subscription point in time restore on Managed Instances.
22+
* Add support for changing existing Sql Managed Instance hardware generation
2223

2324
## Version 2.2.0
2425
Fix New-AzSqlDatabaseSecondary cmdlet to check for PartnerDatabaseName existence instead of DatabaseName existence.

src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
using Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter;
2626
using Microsoft.Azure.Commands.Sql.ManagedInstance.Model;
2727
using Microsoft.Azure.Management.Sql.Models;
28+
using System;
2829

2930
namespace Microsoft.Azure.Commands.Sql.ManagedInstance.Cmdlet
3031
{
@@ -178,6 +179,15 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
178179
[Parameter(HelpMessage = "Skip confirmation message for performing the action")]
179180
public SwitchParameter Force { get; set; }
180181

182+
/// <summary>
183+
/// Gets or sets the instance compute generation
184+
/// </summary>
185+
[Parameter(Mandatory = false,
186+
HelpMessage = "The compute generation for the instance.")]
187+
[ValidateNotNullOrEmpty]
188+
[PSArgumentCompleter(Constants.ComputeGenerationGen5)]
189+
public string ComputeGeneration { get; set; }
190+
181191
/// <summary>
182192
/// Get the instance to update
183193
/// </summary>
@@ -187,6 +197,31 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
187197
return new List<AzureSqlManagedInstanceModel>() { ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name) };
188198
}
189199

200+
/// <summary>
201+
/// Validate requested Hardware family.
202+
/// </summary>
203+
protected bool ShouldConfirmHardwareFamilyChange()
204+
{
205+
bool shouldConfirmHardwareFamilyChange = false;
206+
207+
ModelAdapter = InitModelAdapter();
208+
AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name);
209+
210+
// Get current hardware family
211+
string currentHardwareFamily = existingInstance.Sku.Family;
212+
213+
// Check whether the hardware family was changed
214+
bool isHardwareFamilyChanged = !currentHardwareFamily.Equals(this.ComputeGeneration, StringComparison.InvariantCultureIgnoreCase);
215+
216+
// Check whether hardware family is being changed to a newer hardware family
217+
if (isHardwareFamilyChanged && currentHardwareFamily.Equals(Constants.ComputeGenerationGen4, StringComparison.InvariantCultureIgnoreCase))
218+
{
219+
shouldConfirmHardwareFamilyChange = true;
220+
}
221+
222+
return shouldConfirmHardwareFamilyChange;
223+
}
224+
190225
/// <summary>
191226
/// Constructs the model to send to the update API
192227
/// </summary>
@@ -197,16 +232,21 @@ protected override IEnumerable<AzureSqlManagedInstanceModel> ApplyUserInputToMod
197232
AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name);
198233
Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku();
199234

200-
if (Edition != null)
235+
// Get current edition and family
236+
string currentEdition = existingInstance.Sku.Tier;
237+
string currentComputeGeneration = existingInstance.Sku.Family;
238+
239+
// If either edition or compute generation are set, get the new sku
240+
if (this.Edition != null || this.ComputeGeneration != null)
201241
{
202-
string computeGeneration = existingInstance.Sku.Name.Contains(Constants.ComputeGenerationGen4) ? Constants.ComputeGenerationGen4 : Constants.ComputeGenerationGen5;
203-
string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
204-
Sku.Name = editionShort + "_" + computeGeneration;
205-
Sku.Tier = Edition;
242+
string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(!string.IsNullOrWhiteSpace(Edition) ? this.Edition : currentEdition);
243+
Sku.Name = editionShort + "_" + (!string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration);
244+
Sku.Tier = !string.IsNullOrWhiteSpace(this.Edition) ? this.Edition : null;
245+
Sku.Family = !string.IsNullOrWhiteSpace(this.ComputeGeneration) ? this.ComputeGeneration : currentComputeGeneration;
206246
}
207247
else
208248
{
209-
Sku = null;
249+
Sku = existingInstance.Sku;
210250
}
211251

212252
// Construct a new entity so we only send the relevant data to the Managed instance
@@ -266,6 +306,21 @@ public override void ExecuteCmdlet()
266306
Name = resourceInfo.ResourceName;
267307
}
268308

309+
// Validate requested hardware family
310+
if (!string.IsNullOrWhiteSpace(this.ComputeGeneration))
311+
{
312+
// Hardware family is being changed to a newer hardware family and it is not possible to scale back - Give confirmation message
313+
if (this.ShouldConfirmHardwareFamilyChange())
314+
{
315+
if (!Force.IsPresent && !ShouldContinue(
316+
string.Format(CultureInfo.InvariantCulture, Properties.Resources.DoYouWantToProceed, this.Name),
317+
string.Format(CultureInfo.InvariantCulture, string.Format(Properties.Resources.ChangingHardwareFamilyIsIrreversable, this.ComputeGeneration), this.Name)))
318+
{
319+
return;
320+
}
321+
}
322+
}
323+
269324
base.ExecuteCmdlet();
270325
}
271326
}

src/Sql/Sql/ManagedInstance/Services/AzureSqlManagedInstanceAdapter.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -205,6 +205,7 @@ private static AzureSqlManagedInstanceModel CreateManagedInstanceModelFromRespon
205205
Management.Internal.Resources.Models.Sku sku = new Management.Internal.Resources.Models.Sku();
206206
sku.Name = resp.Sku.Name;
207207
sku.Tier = resp.Sku.Tier;
208+
sku.Family = resp.Sku.Family;
208209

209210
managedInstance.Sku = sku;
210211

src/Sql/Sql/Properties/Resources.Designer.cs

Lines changed: 28 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Sql/Sql/Properties/Resources.resx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,4 +580,13 @@
580580
<data name="VulnerabilityAssessmentOperationIsNotAvailableOnMasterDatabase" xml:space="preserve">
581581
<value>Vulnerability Assessment operation is not available on master database. Skipping...</value>
582582
</data>
583+
<data name="DoYouWantToProceed" xml:space="preserve">
584+
<value>Do you want to proceed?</value>
585+
</data>
586+
<data name="ChangingHardwareFamilyIsIrreversable" xml:space="preserve">
587+
<value>For this update operation provided compute generation parameter is '{0}'. Once the hardware generation is upgraded, it is not possible to switch back to Gen4 compute generation as this hardware is being deprecated.</value>
588+
</data>
589+
<data name="CannotChangeHardwareFamily" xml:space="preserve">
590+
<value>You cannot change hardware family.</value>
591+
</data>
583592
</root>

src/Sql/Sql/help/Set-AzSqlInstance.md

Lines changed: 49 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,39 +15,59 @@ Sets properties for an Azure SQL Database Managed Instance.
1515
### SetInstanceFromInputParameters (Default)
1616
```
1717
Set-AzSqlInstance [-Name] <String> [-ResourceGroupName] <String> [-AdministratorPassword <SecureString>]
18-
[-Edition <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>] [-VCore <Int32>]
19-
[-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>] [-AssignIdentity]
20-
[-InstancePoolName <String>] [-Force] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
21-
[<CommonParameters>]
18+
[-Edition <String>] [-ComputeGeneration <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>]
19+
[-VCore <Int32>] [-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>]
20+
[-AssignIdentity] [-InstancePoolName <String>] [-Force]
21+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
2222
```
2323

2424
### SetInstanceFromAzureSqlManagedInstanceModelInstanceDefinition
2525
```
2626
Set-AzSqlInstance [-InputObject] <AzureSqlManagedInstanceModel> [-AdministratorPassword <SecureString>]
27-
[-Edition <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>] [-VCore <Int32>]
28-
[-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>] [-AssignIdentity]
29-
[-InstancePoolName <String>] [-Force] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
30-
[<CommonParameters>]
27+
[-Edition <String>] [-ComputeGeneration <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>]
28+
[-VCore <Int32>] [-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>]
29+
[-AssignIdentity] [-InstancePoolName <String>] [-Force]
30+
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
3131
```
3232

3333
### SetInstanceFromAzureResourceId
3434
```
3535
Set-AzSqlInstance [-ResourceId] <String> [-AdministratorPassword <SecureString>] [-Edition <String>]
36-
[-LicenseType <String>] [-StorageSizeInGB <Int32>] [-VCore <Int32>] [-PublicDataEndpointEnabled <Boolean>]
37-
[-ProxyOverride <String>] [-Tag <Hashtable>] [-AssignIdentity] [-InstancePoolName <String>] [-Force]
38-
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
36+
[-ComputeGeneration <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>] [-VCore <Int32>]
37+
[-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>] [-AssignIdentity]
38+
[-InstancePoolName <String>] [-Force] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
39+
[-Confirm] [<CommonParameters>]
3940
```
4041

4142
## DESCRIPTION
4243
The **Set-AzSqlInstance** cmdlet modifies properties of an Azure SQL Database Managed instance.
4344

4445
## EXAMPLES
4546

46-
### Example 1: Set existing instance using new values for -AdministratorPassword, -LicenseType, -StorageSizeInGB and -VCore
47+
### Example 1: Set existing instance using new values for -AdministratorPassword, -LicenseType, -StorageSizeInGB, -VCore and -Edition
4748
```powershell
4849
PS C:\>$InstancePassword = "Newpassword1234"
4950
PS C:\> $SecureString = ConvertTo-SecureString $InstancePassword -AsPlainText -Force
50-
PS C:\> Set-AzSqlInstance -Name "managedinstance1" -ResourceGroupName "ResourceGroup01" -AdministratorPassword $SecureString -LicenseType LicenseIncluded -StorageSizeInGB 1024 -VCore 16
51+
PS C:\> Set-AzSqlInstance -Name "managedinstance1" -ResourceGroupName "ResourceGroup01" -AdministratorPassword $SecureString -LicenseType LicenseIncluded -StorageSizeInGB 1024 -VCore 16 -Edition BusinessCritical
52+
Location : westcentralus
53+
Id : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourcegroup01/providers/Microsoft.Sql/managedInstances/managedInstance1
54+
ResourceGroupName : resourcegroup01
55+
ManagedInstanceName : managedInstance1
56+
Tags :
57+
Identity : Microsoft.Azure.Management.Sql.Models.ResourceIdentity
58+
Sku : Microsoft.Azure.Management.Internal.Resources.Models.Sku
59+
FullyQualifiedDomainName : managedInstance1.wcusxxxxxxxxxxxxx.database.windows.net
60+
AdministratorLogin : adminLogin1
61+
AdministratorPassword :
62+
SubnetId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourcegroup01/providers/Microsoft.Network/virtualNetworks/vnet_name/subnets/subnet_name
63+
LicenseType : LicenseIncluded
64+
VCores : 16
65+
StorageSizeInGB : 1024
66+
InstancePoolName :
67+
```
68+
### Example 2: Change existing instance hardware generation using new value for -ComputeGeneration
69+
```powershell
70+
PS C:\> Set-AzSqlInstance -Name "managedinstance1" -ResourceGroupName "ResourceGroup01" -ComputeGeneration Gen5
5171
Location : westcentralus
5272
Id : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourcegroup01/providers/Microsoft.Sql/managedInstances/managedInstance1
5373
ResourceGroupName : resourcegroup01
@@ -67,7 +87,7 @@ InstancePoolName :
6787

6888
This command sets existing instance using new values for -AdministratorPassword, -LicenseType, -StorageSizeInGB and -VCore
6989

70-
### Example 2: Set existing instance using new values for -AdministratorPassword, -LicenseType, -StorageSizeInGB and -VCore for an instance within an instance pool
90+
### Example 3: Set existing instance using new values for -AdministratorPassword, -LicenseType, -StorageSizeInGB and -VCore for an instance within an instance pool
7191
```powershell
7292
PS C:\>$InstancePassword = "Newpassword1234"
7393
PS C:\> $SecureString = ConvertTo-SecureString $InstancePassword -AsPlainText -Force
@@ -123,6 +143,21 @@ Accept pipeline input: False
123143
Accept wildcard characters: False
124144
```
125145
146+
### -ComputeGeneration
147+
The compute generation for the instance.
148+
149+
```yaml
150+
Type: System.String
151+
Parameter Sets: (All)
152+
Aliases:
153+
154+
Required: False
155+
Position: Named
156+
Default value: None
157+
Accept pipeline input: False
158+
Accept wildcard characters: False
159+
```
160+
126161
### -DefaultProfile
127162
The credentials, account, tenant, and subscription used for communication with Azure.
128163

0 commit comments

Comments
 (0)