Skip to content
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

Added support for -QueryString parameters to cmdlets hitting /validate API and Fixed issues with dynamic parameters #14132

Merged
merged 6 commits into from
Feb 5, 2021
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 @@ -204,5 +204,22 @@ public void TestUpdateRPIWithAvZone()
this.VaultSettingsFilePath +
"\"");
}

[Fact]
[Trait(
Category.AcceptanceType,
Category.CheckIn)]
public void TestCreateRPIWithManagedDisk()
{
this.VaultSettingsFilePath = System.IO.Path.Combine(
System.AppDomain.CurrentDomain.BaseDirectory,
"ScenarioTests", "B2A", "B2AInput", "B2A.VaultCredentials");
this.RunPowerShellTest(
_logger,
Constants.NewModel,
"Test-CreateRPIWithManagedDisk -vaultSettingsFilePath \"" +
this.VaultSettingsFilePath +
"\"");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -890,4 +890,24 @@ function Test-UpdateRPIWithAvailabilityZone
Set-AsrReplicationProtectedItem -InputObject $rpi -RecoveryAvailabilityZone $avZoneSet
$rpi = Get-AsrReplicationProtectedItem -ProtectionContainer $pc -FriendlyName $VMFriendlyName
Assert-NotNull($rpi.ProviderSpecificDetails.RecoveryAvailabilityZone)
}

function Test-CreateRPIWithManagedDisk
{
param([string] $vaultSettingsFilePath)

# Import Azure RecoveryServices Vault Settings File
Import-AzRecoveryServicesAsrVaultSettingsFile -Path $vaultSettingsFilePath
$PrimaryFabricName = "H2ASite"
$fabric = Get-AsrFabric -FriendlyName $PrimaryFabricName
$pc = Get-ASRProtectionContainer -Fabric $fabric
$pcm = Get-ASRProtectionContainerMapping -ProtectionContainer $pc
$policyName ="b2apolicy"
$policy = Get-AzRecoveryServicesAsrPolicy -Name $policyName
$VMFriendlyName ="NestedDum1"
$VM= Get-AsrProtectableItem -ProtectionContainer $pc -FriendlyName $VMFriendlyName
$ResourceGroupId ="/subscriptions/b364ed8d-4279-4bf8-8fd1-56f8fa0ae05c/resourceGroups/h2arg"
$LogStorageAccountId = "/subscriptions/b364ed8d-4279-4bf8-8fd1-56f8fa0ae05c/resourceGroups/h2arg/providers/Microsoft.Storage/storageAccounts/hrasa"
$ppg = "/subscriptions/b364ed8d-4279-4bf8-8fd1-56f8fa0ae05c/resourceGroups/h2arg/providers/Microsoft.Compute/proximityPlacementGroups/ppgh2a"
$EnableDRjob = New-AsrReplicationProtectedItem -ProtectableItem $VM -Name $VM.Name -ProtectionContainerMapping $pcm -RecoveryAzureStorageAccountId $LogStorageAccountId -OSDiskName $($VMFriendlyName+"disk") -OS Windows -RecoveryResourceGroupId $ResourceGroupId -RecoveryProximityPlacementGroupId $ppg -UseManagedDisk true
}

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,17 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover
[ValidateNotNullOrEmpty]
public string RecoveryAvailabilitySetId { get; set; }

/// <summary>
/// Gets or sets if the Azure virtual machine that is created on failover should use managed disks.
/// </summary>
[Parameter]
[ValidateNotNullOrEmpty]
[ValidateSet(
Constants.True,
Constants.False)]
[Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure)]
public string UseManagedDisk { get; set; }

/// <summary>
/// Gets or sets BootDiagnosticStorageAccountId.
/// </summary>
Expand Down Expand Up @@ -592,6 +603,7 @@ private void EnterpriseAndHyperVToAzure(EnableProtectionInput input)
: this.RecoveryVmName;
providerSettings.TargetProximityPlacementGroupId = this.RecoveryProximityPlacementGroupId;
providerSettings.TargetAvailabilityZone = this.RecoveryAvailabilityZone;
providerSettings.UseManagedDisks = this.UseManagedDisk;

if (!string.IsNullOrEmpty(this.RecoveryAzureNetworkId))
{
Expand Down
1 change: 1 addition & 0 deletions src/RecoveryServices/RecoveryServices/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Added Zone Redundancy for Recovery Service Vaults.
* Azure Site Recovery support for Proximity placement group for VMware to Azure and HyperV to Azure providers.
* Azure Site Recovery support for Availability zone for VMware to Azure and HyperV to Azure providers.
* Azure Site Recovery support for UseManagedDisk for HyperV to Azure provider

## Version 3.3.0
* Added Cross Region Restore feature.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ New-AzRecoveryServicesAsrReplicationProtectedItem [-HyperVToAzure] -ProtectableI
-RecoveryAzureStorageAccountId <String> -OSDiskName <String> -OS <String> [-LogStorageAccountId <String>]
[-IncludeDiskId <String[]>] [-RecoveryAzureNetworkId <String>] [-RecoveryAzureSubnetName <String>]
-RecoveryResourceGroupId <String> [-RecoveryAvailabilityZone <String>]
[-RecoveryProximityPlacementGroupId <String>] [-WaitForCompletion] [-DefaultProfile <IAzureContextContainer>]
[-WhatIf] [-Confirm] [<CommonParameters>]
[-RecoveryProximityPlacementGroupId <String>] [-UseManagedDisk <String>] [-WaitForCompletion]
[-DefaultProfile <IAzureContextContainer>] [-WhatIf] [-Confirm] [<CommonParameters>]
```

### AzureToAzure
Expand Down Expand Up @@ -685,6 +685,22 @@ Accept pipeline input: False
Accept wildcard characters: False
```

### -UseManagedDisk
Specifies if the Azure virtual machine that is created on failover should use managed disks. It Accepts either True or False.

```yaml
Type: System.String
Parameter Sets: (All)
Aliases:
Accepted values: True, False

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

### -VmmToVmm
Switch parameter to specify the replicated item is a Hyper-V virtual machine that is being replicated between VMM managed Hyper-V sites.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.Cmdlet

public abstract class DeploymentCreateCmdlet: DeploymentWhatIfCmdlet
{
[Parameter(Mandatory = false, HelpMessage = "The query string (for example, a SAS token) to be used with the TemplateUri parameter. Would be used in case of linked templates")]
public string QueryString { get; set; }

protected abstract ConfirmImpact ConfirmImpact { get; }

protected abstract PSDeploymentCmdletParameters DeploymentParameters { get; }
Expand Down Expand Up @@ -110,5 +113,14 @@ private bool ShouldProcessGivenCurrentConfirmFlagAndPreference()

return this.ConfirmImpact >= confirmPreference;
}

public override object GetDynamicParameters()
{
if (!string.IsNullOrEmpty(QueryString))
{
protectedTemplateUri = TemplateUri + "?" + QueryString;
}
return base.GetDynamicParameters();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ public abstract class ResourceWithParameterCmdletBase : ResourceManagerCmdletBas

private string templateSpecId;

protected string protectedTemplateUri;

private ITemplateSpecsClient templateSpecsClient;

protected ResourceWithParameterCmdletBase()
Expand Down Expand Up @@ -166,7 +168,7 @@ public ITemplateSpecsClient TemplateSpecsClient
set { this.templateSpecsClient = value; }
}

public object GetDynamicParameters()
public virtual object GetDynamicParameters()
{
if (!this.IsParameterBound(c => c.SkipTemplateParameterPrompt))
{
Expand Down Expand Up @@ -217,19 +219,26 @@ public object GetDynamicParameters()
else if (!string.IsNullOrEmpty(TemplateUri) &&
!TemplateUri.Equals(templateUri, StringComparison.OrdinalIgnoreCase))
{
templateUri = TemplateUri;
if (string.IsNullOrEmpty(protectedTemplateUri))
{
templateUri = TemplateUri;
}
else
{
templateUri = protectedTemplateUri;
}
if (string.IsNullOrEmpty(TemplateParameterUri))
{
dynamicParameters = TemplateUtility.GetTemplateParametersFromFile(
TemplateUri,
templateUri,
TemplateParameterObject,
this.ResolvePath(TemplateParameterFile),
staticParameterNames);
}
else
{
dynamicParameters = TemplateUtility.GetTemplateParametersFromFile(
TemplateUri,
templateUri,
TemplateParameterObject,
TemplateParameterUri,
staticParameterNames);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Management.Automation;
using Microsoft.Azure.Commands.Common.Strategies;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Formatters;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Properties;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;

namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.CmdletBase
{
public abstract class TestDeploymentCmdletBase : ResourceWithParameterCmdletBase, IDynamicParameters
{

[Parameter(Mandatory = false, HelpMessage = "The query string (for example, a SAS token) to be used with the TemplateUri parameter. Would be used in case of linked templates")]
public string QueryString { get; set; }

public override object GetDynamicParameters()
{
if (!string.IsNullOrEmpty(QueryString))
{
protectedTemplateUri = TemplateUri + "?" + QueryString;
}
return base.GetDynamicParameters();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ public class NewAzureManagementGroupDeploymentCmdlet : DeploymentCreateCmdlet
[ValidateChangeTypes]
public string[] WhatIfExcludeChangeType { get; set; }

[Parameter(Mandatory = false, HelpMessage = "The query string (for example, a SAS token) to be used with the TemplateUri parameter. Would be used in case of linked templates")]
public string QueryString { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,6 @@ public class NewAzureSubscriptionDeploymentCmdlet : DeploymentCreateCmdlet
[ValidateChangeTypes]
public string[] WhatIfExcludeChangeType { get; set; }

[Parameter(Mandatory = false, HelpMessage = "The query string (for example, a SAS token) to be used with the TemplateUri parameter. Would be used in case of linked templates")]
public string QueryString { get; set; }

[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,6 @@ public class NewAzureTenantDeploymentCmdlet: DeploymentCreateCmdlet
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

[Parameter(Mandatory = false, HelpMessage = "The query string (for example, a SAS token) to be used with the TemplateUri parameter. Would be used in case of linked templates")]
public string QueryString { get; set; }

protected override ConfirmImpact ConfirmImpact => ((CmdletAttribute)Attribute.GetCustomAttribute(
typeof(NewAzureTenantDeploymentCmdlet),
typeof(CmdletAttribute))).ConfirmImpact;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.CmdletBase;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
using Microsoft.Azure.Commands.ResourceManager.Common;
Expand All @@ -25,7 +26,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Validate a template to see whether it's using the right syntax, resource providers, resource types, etc.
/// </summary>
[Cmdlet(VerbsDiagnostic.Test, AzureRMConstants.AzureRMPrefix + "ManagementGroupDeployment", DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSResourceManagerError))]
public class TestAzureManagementGroupDeploymentCmdlet : ResourceWithParameterCmdletBase, IDynamicParameters
public class TestAzureManagementGroupDeploymentCmdlet : TestDeploymentCmdletBase
{
[Parameter(Mandatory = true, HelpMessage = "The management group id.")]
[ValidateNotNullOrEmpty]
Expand All @@ -43,6 +44,7 @@ protected override void OnProcessRecord()
ScopeType = DeploymentScopeType.ManagementGroup,
ManagementGroupId = this.ManagementGroupId,
Location = this.Location,
QueryString = QueryString,
TemplateFile = this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
TemplateObject = this.TemplateObject,
TemplateParameterObject = this.GetTemplateParameterObject(this.TemplateParameterObject),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.CmdletBase;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
using Microsoft.Azure.Commands.ResourceManager.Common;
Expand All @@ -26,7 +27,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// </summary>
[Cmdlet(VerbsDiagnostic.Test, AzureRMConstants.AzureRMPrefix + "Deployment", DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSResourceManagerError))]
[Alias("Test-AzSubscriptionDeployment")]
public class TestAzureSubscriptionDeploymentCmdlet : ResourceWithParameterCmdletBase, IDynamicParameters
public class TestAzureSubscriptionDeploymentCmdlet : TestDeploymentCmdletBase
{
[Parameter(Mandatory = true, HelpMessage = "The location to store deployment data.")]
[LocationCompleter("Microsoft.Resources/resourceGroups")]
Expand All @@ -41,6 +42,7 @@ protected override void OnProcessRecord()
Location = Location,
TemplateFile = TemplateUri ?? this.TryResolvePath(TemplateFile),
TemplateObject = TemplateObject,
QueryString = QueryString,
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
ParameterUri = TemplateParameterUri
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// ----------------------------------------------------------------------------------

using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.CmdletBase;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
using Microsoft.Azure.Commands.ResourceManager.Common;
Expand All @@ -26,7 +27,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// </summary>
[Cmdlet(VerbsDiagnostic.Test, AzureRMConstants.AzureRMPrefix + "TenantDeployment",
DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSResourceManagerError))]
public class TestAzureTenantDeploymentCmdlet : ResourceWithParameterCmdletBase, IDynamicParameters
public class TestAzureTenantDeploymentCmdlet : TestDeploymentCmdletBase
{
[Parameter(Mandatory = true, HelpMessage = "The location to store deployment data.")]
[LocationCompleter("Microsoft.Resources/resourceGroups")]
Expand All @@ -41,6 +42,7 @@ protected override void OnProcessRecord()
Location = this.Location,
TemplateFile = this.TemplateUri ?? this.TryResolvePath(this.TemplateFile),
TemplateObject = this.TemplateObject,
QueryString = QueryString,
TemplateParameterObject = this.GetTemplateParameterObject(this.TemplateParameterObject),
ParameterUri = this.TemplateParameterUri
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,6 @@ public class NewAzureResourceGroupDeploymentCmdlet : DeploymentCreateCmdlet
[Parameter(Mandatory = false, HelpMessage = "Run cmdlet in the background")]
public SwitchParameter AsJob { get; set; }

[Parameter(Mandatory = false, HelpMessage = "The query string (for example, a SAS token) to be used with the TemplateUri parameter. Would be used in case of linked templates")]
public string QueryString { get; set; }

protected override ConfirmImpact ConfirmImpact => ((CmdletAttribute)Attribute.GetCustomAttribute(
typeof(NewAzureResourceGroupDeploymentCmdlet),
typeof(CmdletAttribute))).ConfirmImpact;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

using System;
using System.Management.Automation;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.CmdletBase;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels;
using Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkModels.Deployments;
using Microsoft.Azure.Commands.ResourceManager.Common;
Expand All @@ -28,7 +29,7 @@ namespace Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation
/// Validate a template to see whether it's using the right syntax, resource providers, resource types, etc.
/// </summary>
[Cmdlet("Test", AzureRMConstants.AzureRMPrefix + "ResourceGroupDeployment", DefaultParameterSetName = ParameterlessTemplateFileParameterSetName), OutputType(typeof(PSResourceManagerError))]
public class TestAzureResourceGroupDeploymentCmdlet : ResourceWithParameterCmdletBase, IDynamicParameters
public class TestAzureResourceGroupDeploymentCmdlet : TestDeploymentCmdletBase
{
[Parameter(Mandatory = true, ValueFromPipelineByPropertyName = true, HelpMessage = "The resource group name.")]
[ResourceGroupCompleter]
Expand Down Expand Up @@ -66,6 +67,7 @@ protected override void OnProcessRecord()
DeploymentMode = Mode,
TemplateFile = TemplateUri ?? this.ResolvePath(TemplateFile),
TemplateObject = TemplateObject,
QueryString = QueryString,
TemplateParameterObject = GetTemplateParameterObject(TemplateParameterObject),
ParameterUri = TemplateParameterUri,
OnErrorDeployment = RollbackToLastDeployment || !string.IsNullOrEmpty(RollBackDeploymentName)
Expand Down
2 changes: 2 additions & 0 deletions src/Resources/Resources/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
-->

## Upcoming Release
* Added support for -QueryString parameter in Test-Az*Deployments cmdlets
* Fixed issue with dynamic parameters when New-Az*Deployments is used with -QueryString

## Version 3.2.0
* Added support for -QueryString parameter in New-Az*Deployments cmdlets
Expand Down
Loading