Skip to content

Nemanjas/mi change hw generation #10892

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,36 @@ function Test-SetManagedInstance
Assert-AreEqual $managedInstance4.PublicDataEndpointEnabled $publicDataEndpointEnabled
Assert-AreEqual $managedInstance4.ProxyOverride $proxyOverride
Assert-StartsWith ($managedInstance4.ManagedInstanceName + ".") $managedInstance4.FullyQualifiedDomainName

# Test hardware generation change using ComputeGeneration
$credentials = Get-ServerCredential
$computeGeneration = "Gen5"

$managedInstance5 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
-ComputeGeneration $computeGeneration -Force

Assert-AreEqual $managedInstance5.ManagedInstanceName $managedInstance.ManagedInstanceName
Assert-AreEqual $managedInstance5.AdministratorLogin $managedInstance.AdministratorLogin
Assert-AreEqual $managedInstance5.VCores $managedInstance4.VCores
Assert-AreEqual $managedInstance5.StorageSizeInGB $managedInstance4.StorageSizeInGB
Assert-AreEqual $managedInstance5.Sku.Tier $managedInstance4.Sku.Tier
Assert-AreEqual $managedInstance5.Sku.Family $computeGeneration
Assert-StartsWith ($managedInstance5.ManagedInstanceName + ".") $managedInstance5.FullyQualifiedDomainName

# Test edition change using Edition
$credentials = Get-ServerCredential
$edition = "BusinessCritical"

$managedInstance6 = Set-AzSqlInstance -ResourceGroupName $rg.ResourceGroupName -Name $managedInstance.ManagedInstanceName `
-Edition $edition -Force

Assert-AreEqual $managedInstance6.ManagedInstanceName $managedInstance5.ManagedInstanceName
Assert-AreEqual $managedInstance6.AdministratorLogin $managedInstance5.AdministratorLogin
Assert-AreEqual $managedInstance6.VCores $managedInstance5.VCores
Assert-AreEqual $managedInstance6.StorageSizeInGB $managedInstance5.StorageSizeInGB
Assert-AreEqual $managedInstance6.Sku.Tier $edition
Assert-AreEqual $managedInstance6.Sku.Family $managedInstance5.Sku.Family
Assert-StartsWith ($managedInstance6.ManagedInstanceName + ".") $managedInstance6.FullyQualifiedDomainName
}
finally
{
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/Sql/Sql/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->
## Upcoming Release
* Added support for cross subscription point in time restore on Managed Instances.
* Add support for changing existing Sql Managed Instance hardware generation

## Version 2.2.0
Fix New-AzSqlDatabaseSecondary cmdlet to check for PartnerDatabaseName existence instead of DatabaseName existence.
Expand Down
67 changes: 61 additions & 6 deletions src/Sql/Sql/ManagedInstance/Cmdlet/SetAzureSqlManagedInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
using Microsoft.Azure.Commands.Sql.ManagedInstance.Adapter;
using Microsoft.Azure.Commands.Sql.ManagedInstance.Model;
using Microsoft.Azure.Management.Sql.Models;
using System;

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

/// <summary>
/// Gets or sets the instance compute generation
/// </summary>
[Parameter(Mandatory = false,
HelpMessage = "The compute generation for the instance.")]
[ValidateNotNullOrEmpty]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to add custom validators as attributes above fields?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked SQL DB, instance pools and managed instance new and set cmdlets and couldn't find the example of that so I decided to go this way. If it is possible, it is not common.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AFAIK there is a completer for resource group name, if that exists then it must just be an ARM call so you could also call capabilities to find edition, sku name, compute gen, etc. So probably possible. But let's not block release on it :)

[PSArgumentCompleter(Constants.ComputeGenerationGen5)]
public string ComputeGeneration { get; set; }

/// <summary>
/// Get the instance to update
/// </summary>
Expand All @@ -187,6 +197,31 @@ public class SetAzureSqlManagedInstance : ManagedInstanceCmdletBase
return new List<AzureSqlManagedInstanceModel>() { ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name) };
}

/// <summary>
/// Validate requested Hardware family.
/// </summary>
protected bool ShouldConfirmHardwareFamilyChange()
{
bool shouldConfirmHardwareFamilyChange = false;

ModelAdapter = InitModelAdapter();
AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name);

// Get current hardware family
string currentHardwareFamily = existingInstance.Sku.Family;

// Check whether the hardware family was changed
bool isHardwareFamilyChanged = !currentHardwareFamily.Equals(this.ComputeGeneration, StringComparison.InvariantCultureIgnoreCase);

// Check whether hardware family is being changed to a newer hardware family
if (isHardwareFamilyChanged && currentHardwareFamily.Equals(Constants.ComputeGenerationGen4, StringComparison.InvariantCultureIgnoreCase))
{
shouldConfirmHardwareFamilyChange = true;
}

return shouldConfirmHardwareFamilyChange;
}

/// <summary>
/// Constructs the model to send to the update API
/// </summary>
Expand All @@ -197,16 +232,21 @@ protected override IEnumerable<AzureSqlManagedInstanceModel> ApplyUserInputToMod
AzureSqlManagedInstanceModel existingInstance = ModelAdapter.GetManagedInstance(this.ResourceGroupName, this.Name);
Management.Internal.Resources.Models.Sku Sku = new Management.Internal.Resources.Models.Sku();

if (Edition != null)
// 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 computeGeneration = existingInstance.Sku.Name.Contains(Constants.ComputeGenerationGen4) ? Constants.ComputeGenerationGen4 : Constants.ComputeGenerationGen5;
string editionShort = AzureSqlManagedInstanceAdapter.GetInstanceSkuPrefix(Edition);
Sku.Name = editionShort + "_" + computeGeneration;
Sku.Tier = Edition;
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 = null;
Sku = existingInstance.Sku;
}

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

// Validate requested hardware family
if (!string.IsNullOrWhiteSpace(this.ComputeGeneration))
{
// Hardware family is being changed to a newer hardware family and it is not possible to scale back - Give confirmation message
if (this.ShouldConfirmHardwareFamilyChange())
{
if (!Force.IsPresent && !ShouldContinue(
string.Format(CultureInfo.InvariantCulture, Properties.Resources.DoYouWantToProceed, this.Name),
string.Format(CultureInfo.InvariantCulture, string.Format(Properties.Resources.ChangingHardwareFamilyIsIrreversable, this.ComputeGeneration), this.Name)))
{
return;
}
}
}

base.ExecuteCmdlet();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ private static AzureSqlManagedInstanceModel CreateManagedInstanceModelFromRespon
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;

Expand Down
29 changes: 28 additions & 1 deletion src/Sql/Sql/Properties/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions src/Sql/Sql/Properties/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -580,4 +580,13 @@
<data name="VulnerabilityAssessmentOperationIsNotAvailableOnMasterDatabase" xml:space="preserve">
<value>Vulnerability Assessment operation is not available on master database. Skipping...</value>
</data>
<data name="DoYouWantToProceed" xml:space="preserve">
<value>Do you want to proceed?</value>
</data>
<data name="ChangingHardwareFamilyIsIrreversable" xml:space="preserve">
<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>
</data>
<data name="CannotChangeHardwareFamily" xml:space="preserve">
<value>You cannot change hardware family.</value>
</data>
</root>
63 changes: 49 additions & 14 deletions src/Sql/Sql/help/Set-AzSqlInstance.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,39 +15,59 @@ Sets properties for an Azure SQL Database Managed Instance.
### SetInstanceFromInputParameters (Default)
```
Set-AzSqlInstance [-Name] <String> [-ResourceGroupName] <String> [-AdministratorPassword <SecureString>]
[-Edition <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>] [-VCore <Int32>]
[-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>] [-AssignIdentity]
[-InstancePoolName <String>] [-Force] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-Edition <String>] [-ComputeGeneration <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>]
[-VCore <Int32>] [-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>]
[-AssignIdentity] [-InstancePoolName <String>] [-Force]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### SetInstanceFromAzureSqlManagedInstanceModelInstanceDefinition
```
Set-AzSqlInstance [-InputObject] <AzureSqlManagedInstanceModel> [-AdministratorPassword <SecureString>]
[-Edition <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>] [-VCore <Int32>]
[-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>] [-AssignIdentity]
[-InstancePoolName <String>] [-Force] [-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm]
[<CommonParameters>]
[-Edition <String>] [-ComputeGeneration <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>]
[-VCore <Int32>] [-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>]
[-AssignIdentity] [-InstancePoolName <String>] [-Force]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### SetInstanceFromAzureResourceId
```
Set-AzSqlInstance [-ResourceId] <String> [-AdministratorPassword <SecureString>] [-Edition <String>]
[-LicenseType <String>] [-StorageSizeInGB <Int32>] [-VCore <Int32>] [-PublicDataEndpointEnabled <Boolean>]
[-ProxyOverride <String>] [-Tag <Hashtable>] [-AssignIdentity] [-InstancePoolName <String>] [-Force]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
[-ComputeGeneration <String>] [-LicenseType <String>] [-StorageSizeInGB <Int32>] [-VCore <Int32>]
[-PublicDataEndpointEnabled <Boolean>] [-ProxyOverride <String>] [-Tag <Hashtable>] [-AssignIdentity]
[-InstancePoolName <String>] [-Force] [-DefaultProfile <IAzureContextContainer>] [-WhatIf]
[-Confirm] [<CommonParameters>]
```

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

## EXAMPLES

### Example 1: Set existing instance using new values for -AdministratorPassword, -LicenseType, -StorageSizeInGB and -VCore
### Example 1: Set existing instance using new values for -AdministratorPassword, -LicenseType, -StorageSizeInGB, -VCore and -Edition
```powershell
PS C:\>$InstancePassword = "Newpassword1234"
PS C:\> $SecureString = ConvertTo-SecureString $InstancePassword -AsPlainText -Force
PS C:\> Set-AzSqlInstance -Name "managedinstance1" -ResourceGroupName "ResourceGroup01" -AdministratorPassword $SecureString -LicenseType LicenseIncluded -StorageSizeInGB 1024 -VCore 16
PS C:\> Set-AzSqlInstance -Name "managedinstance1" -ResourceGroupName "ResourceGroup01" -AdministratorPassword $SecureString -LicenseType LicenseIncluded -StorageSizeInGB 1024 -VCore 16 -Edition BusinessCritical
Location : westcentralus
Id : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourcegroup01/providers/Microsoft.Sql/managedInstances/managedInstance1
ResourceGroupName : resourcegroup01
ManagedInstanceName : managedInstance1
Tags :
Identity : Microsoft.Azure.Management.Sql.Models.ResourceIdentity
Sku : Microsoft.Azure.Management.Internal.Resources.Models.Sku
FullyQualifiedDomainName : managedInstance1.wcusxxxxxxxxxxxxx.database.windows.net
AdministratorLogin : adminLogin1
AdministratorPassword :
SubnetId : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourcegroup01/providers/Microsoft.Network/virtualNetworks/vnet_name/subnets/subnet_name
LicenseType : LicenseIncluded
VCores : 16
StorageSizeInGB : 1024
InstancePoolName :
```
### Example 2: Change existing instance hardware generation using new value for -ComputeGeneration
```powershell
PS C:\> Set-AzSqlInstance -Name "managedinstance1" -ResourceGroupName "ResourceGroup01" -ComputeGeneration Gen5
Location : westcentralus
Id : /subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/resourcegroup01/providers/Microsoft.Sql/managedInstances/managedInstance1
ResourceGroupName : resourcegroup01
Expand All @@ -67,7 +87,7 @@ InstancePoolName :

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

### Example 2: Set existing instance using new values for -AdministratorPassword, -LicenseType, -StorageSizeInGB and -VCore for an instance within an instance pool
### Example 3: Set existing instance using new values for -AdministratorPassword, -LicenseType, -StorageSizeInGB and -VCore for an instance within an instance pool
```powershell
PS C:\>$InstancePassword = "Newpassword1234"
PS C:\> $SecureString = ConvertTo-SecureString $InstancePassword -AsPlainText -Force
Expand Down Expand Up @@ -123,6 +143,21 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -ComputeGeneration
The compute generation for the instance.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:

Required: False
Position: Named
Default value: None
Accept pipeline input: False
Accept wildcard characters: False
```

### -DefaultProfile
The credentials, account, tenant, and subscription used for communication with Azure.

Expand Down