Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -116,6 +116,7 @@ CmdletsToExport =
'Remove-AzureRmRecoveryServicesAsrProtectionContainerMapping',
'Remove-AzureRmRecoveryServicesAsrRecoveryPlan',
'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItem',
'Remove-AzureRmRecoveryServicesAsrReplicationProtectedItemDisk',
'Remove-AzureRmRecoveryServicesAsrServicesProvider',
'Remove-AzureRmRecoveryServicesAsrStorageClassificationMapping',
'Remove-AzureRmRecoveryServicesAsrvCenter',
Expand Down Expand Up @@ -164,6 +165,7 @@ AliasesToExport = 'Add-ASRReplicationProtectedItemDisk', 'Edit-ASRRP', 'Edit-ASR
'Remove-ASRFabric', 'Remove-ASRNetworkMapping', 'Remove-ASRPolicy',
'Remove-ASRProtectionContainerMapping', 'Remove-ASRRP',
'Remove-ASRRecoveryPlan', 'Remove-ASRReplicationProtectedItem',
'Remove-ASRReplicationProtectedItemDisk',
'Remove-ASRServicesProvider',
'Remove-ASRStorageClassificationMapping', 'Remove-ASRvCenter',
'Restart-ASRJob', 'Resume-ASRJob', 'Set-ASRAlertSetting',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.4.2.1-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.dll</HintPath>
<Private>True</Private>
</Reference>
<Reference Include="Microsoft.Azure.Management.RecoveryServices.SiteRecovery, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.1.3.0-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.dll</HintPath>
<Reference Include="Microsoft.Azure.Management.RecoveryServices.SiteRecovery, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.2.0.0-preview\lib\net452\Microsoft.Azure.Management.RecoveryServices.SiteRecovery.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime, Version=2.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.18\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.2.3.19\lib\net452\Microsoft.Rest.ClientRuntime.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Rest.ClientRuntime.Azure, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.18\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
<HintPath>..\..\..\packages\Microsoft.Rest.ClientRuntime.Azure.3.3.19\lib\net452\Microsoft.Rest.ClientRuntime.Azure.dll</HintPath>
</Reference>
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\..\..\packages\Newtonsoft.Json.6.0.8\lib\net45\Newtonsoft.Json.dll</HintPath>
Expand Down Expand Up @@ -118,6 +118,7 @@
<Compile Include="RecoveryPlan\EditAzureRmRecoveryServicesAsrRecoveryPlan.cs" />
<Compile Include="RecoveryPlan\NewAzureRmRecoveryServicesAsrRecoveryPlan.cs" />
<Compile Include="RecoveryPoint\GetAzureRmRecoveryServicesAsrRecoveryPoint.cs" />
<Compile Include="ReplicationProtectedItem\RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs" />
<Compile Include="ReplicationProtectedItem\GetAzureRmRecoveryServicesAsrReplicationProtectedItem.cs" />
<Compile Include="ReplicationProtectedItem\AddAzureRmRecoveryServicesAsrReplicationProtectedItemDisk.cs" />
<Compile Include="ReplicationProtectedItem\NewAzureRmRecoveryServicesAsrReplicationProtectedItem.cs" />
Expand Down Expand Up @@ -196,4 +197,4 @@
</ItemGroup>
<Copy SourceFiles="@(MarkdownFiles)" DestinationFolder="$(OutputPath)\help\" ContinueOnError="false" />
</Target>
</Project>
</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,34 @@ public PSSiteRecoveryLongRunningOperation AddDisks(
return result;
}

/// <summary>
/// Remove disks from replicated protected item.
/// </summary>
/// <param name="fabricName">Fabric Name</param>
/// <param name="protectionContainerName">Protection Container ID</param>
/// <param name="replicationProtectedItemName">Virtual Machine ID or Replication group Id</param>
/// <param name="input">Remove disks input.</param>
/// <returns>Job response</returns>
public PSSiteRecoveryLongRunningOperation RemoveDisks(
string fabricName,
string protectionContainerName,
string replicationProtectedItemName,
RemoveDisksInput input)
{
var op = this.GetSiteRecoveryClient()
.ReplicationProtectedItems.BeginRemoveDisksWithHttpMessagesAsync(
fabricName,
protectionContainerName,
replicationProtectedItemName,
input,
this.GetRequestHeaders(true))
.GetAwaiter()
.GetResult();

var result = SiteRecoveryAutoMapperProfile.Mapper.Map<PSSiteRecoveryLongRunningOperation>(op);
return result;
}

/// <summary>
/// Retrieves Replicated Protected Item.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1183,6 +1183,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details)
this.RecoveryAzureCloudService = details.RecoveryCloudService;
this.RecoveryFabricLocation = details.RecoveryFabricLocation;
this.RecoveryAvailabilitySet = details.RecoveryAvailabilitySet;
this.RecoveryAvailabilityZone = details.RecoveryAvailabilityZone;
this.TestFailoverRecoveryFabricObjectId = details.TestFailoverRecoveryFabricObjectId;
this.MonitoringJobType = details.MonitoringJobType;
this.MonitoringPercentageCompletion = details.MonitoringPercentageCompletion;
Expand Down Expand Up @@ -1214,7 +1215,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details)
.ConvertAll(disk => new ASRAzureToAzureProtectedDiskDetails(disk)));
}

if (details.UnprotectedDisks != null && details.UnprotectedDisks.Count > 0)
/* if (details.UnprotectedDisks != null && details.UnprotectedDisks.Count > 0)
{
this.A2AUnprotectedDiskDetails = new List<A2AUnprotectedDiskDetails>();
foreach (var unprotectedDisk in details.UnprotectedDisks)
Expand All @@ -1226,6 +1227,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details)
});
}
}
*/

if (details.VmSyncedConfigDetails != null)
{
Expand Down Expand Up @@ -1281,6 +1283,11 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details)
/// </summary>
public string RecoveryAvailabilitySet { get; set; }

/// <summary>
/// Recovery availability zone.
/// </summary>
public string RecoveryAvailabilityZone { get; set; }

/// <summary>
/// Synced configuration details of the virtual machine.
/// </summary>
Expand Down Expand Up @@ -1311,7 +1318,7 @@ public ASRAzureToAzureSpecificRPIDetails(A2AReplicationDetails details)
/// <summary>
/// Gets or sets A2A unprotected disk details.
/// </summary>
public List<A2AUnprotectedDiskDetails> A2AUnprotectedDiskDetails { get; set; }
//public List<A2AUnprotectedDiskDetails> A2AUnprotectedDiskDetails { get; set; }

/// <summary>
/// Gets or sets the recovery fabric object Id.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2261,6 +2261,7 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedDiskDetails disk)
this.DiskName = disk.DiskName;
this.DiskType = disk.DiskType;
this.DiskState = disk.DiskState;
this.AllowedDiskLevelOperation = disk.AllowedDiskLevelOperation;
this.Managed = false;
}

Expand All @@ -2280,6 +2281,7 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedManagedDiskDetails disk)
this.DiskName = disk.DiskName;
this.DiskType = disk.DiskType;
this.DiskState = disk.DiskState;
this.AllowedDiskLevelOperation = disk.AllowedDiskLevelOperation;
this.RecoveryReplicaDiskAccountType = disk.RecoveryReplicaDiskAccountType;
this.RecoveryReplicaDiskId = disk.RecoveryReplicaDiskId;
this.RecoveryResourceGroupId = disk.RecoveryResourceGroupId;
Expand Down Expand Up @@ -2360,6 +2362,11 @@ public ASRAzureToAzureProtectedDiskDetails(A2AProtectedManagedDiskDetails disk)
/// </summary>
public string DiskState { get; set; }

/// <summary>
/// Gets or sets the Allowed Disk Level Operation.
/// </summary>
public IList<string> AllowedDiskLevelOperation { get; set; }

/// <summary>
/// Gets or sets recovery disk uri.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.VMwareToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)]
[ValidateNotNullOrEmpty]
public string RecoveryAzureNetworkId { get; set; }

Expand All @@ -225,6 +227,8 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.VMwareToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.HyperVSiteToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)]
[ValidateNotNullOrEmpty]
public string RecoveryAzureSubnetName { get; set; }

Expand Down Expand Up @@ -261,6 +265,14 @@ public class NewAzureRmRecoveryServicesAsrReplicationProtectedItem : SiteRecover
[ValidateNotNullOrEmpty]
public string RecoveryAvailabilitySetId { get; set; }

/// <summary>
/// Gets or sets ID of the AvailabilityZone to recover the machine to in the event of a failover.
Copy link
Member

Choose a reason for hiding this comment

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

Zone is just a number and not an ID.

/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure)]
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureWithoutDiskDetails)]
[ValidateNotNullOrEmpty]
public string RecoveryAvailabilityZone { get; set; }

/// <summary>
/// Gets or sets BootDiagnosticStorageAccountId.
/// </summary>
Expand Down Expand Up @@ -604,14 +616,23 @@ private void AzureToAzureReplication(EnableProtectionInput input)
RecoveryResourceGroupId = this.RecoveryResourceGroupId,
RecoveryCloudServiceId = this.RecoveryCloudServiceId,
RecoveryAvailabilitySetId = this.RecoveryAvailabilitySetId,
RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId
RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId,
RecoveryAvailabilityZone = this.RecoveryAvailabilityZone,
RecoveryAzureNetworkId = this.RecoveryAzureNetworkId,
RecoverySubnetName = this.RecoveryAzureSubnetName
};

if (!string.IsNullOrEmpty(this.RecoveryCloudServiceId))
{
providerSettings.RecoveryResourceGroupId = null;
}

if (!string.IsNullOrEmpty(this.RecoveryAvailabilityZone) &&
!string.IsNullOrEmpty(this.RecoveryAvailabilitySetId))
{
Copy link

Choose a reason for hiding this comment

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

use different parameter set instead of having this check.

throw new Exception("RecoveryAvailabilityZone and RecoveryAvailabilitySetId cannot be set together for a VM");
}

if (this.AzureToAzureDiskReplicationConfiguration == null)
{
if (this.AzureVmId.ToLower().Contains(ARMResourceTypeConstants.Compute.ToLower()))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
// ----------------------------------------------------------------------------------
//
// Copyright Microsoft Corporation
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ----------------------------------------------------------------------------------

using System.Management.Automation;
using System.Collections.Generic;
using Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models;
using Job = Microsoft.Azure.Management.RecoveryServices.SiteRecovery.Models.Job;

namespace Microsoft.Azure.Commands.RecoveryServices.SiteRecovery
{
/// <summary>
/// Removes disks to replication protected item.
Copy link

Choose a reason for hiding this comment

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

$nit; from

/// </summary>
[Cmdlet("Remove", ResourceManager.Common.AzureRMConstants.AzureRMPrefix + "RecoveryServicesAsrReplicationProtectedItemDisk", DefaultParameterSetName = ASRParameterSets.EnterpriseToEnterprise, SupportsShouldProcess = true)]
Copy link

Choose a reason for hiding this comment

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

[Alias("Remove-ASRReplicationProtectedItemDisk")]
[OutputType(typeof(ASRJob))]
public class RemoveAzureRmRecoveryServicesAsrReplicationProtectedItemDisk : SiteRecoveryCmdletBase
{
[ValidateNotNullOrEmpty]
[Parameter(Mandatory = true)]
public ASRReplicationProtectedItem ReplicationProtectedItem { get; set; }

/// <summary>
/// Switch parameter specifying that the disk replication config created for managed disk.
/// </summary>
[Parameter(
ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk,
Mandatory = true)]
public SwitchParameter ManagedDisk { get; set; }

/// <summary>
/// Gets or sets the disk uri.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzure,
Mandatory = true)]
[ValidateNotNullOrEmpty]
public string[] VhdUri { get; set; }

/// <summary>
/// Gets or sets the disk Id.
/// </summary>
[Parameter(ParameterSetName = ASRParameterSets.AzureToAzureManagedDisk,
Copy link
Member

Choose a reason for hiding this comment

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

did not see any requirement of parameter sets - please remove.

Copy link

Choose a reason for hiding this comment

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

looks fine to me there will be two parameter set one for mananged disk other for non Managed disk.

Or we can call field some common identifier and take diskId or VhdUri in that .In that the approach Sriram you are suggesting ?

Mandatory = true)]
[ValidateNotNullOrEmpty]
public string[] DiskId { get; set; }

[Parameter]
public SwitchParameter WaitForCompletion { get; set; }
Copy link

Choose a reason for hiding this comment

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

This is not required any more. Powershell team has AsJob new flag to handle that .
We have to move all longrunning cmdlet to that pattern.


/// <summary>
/// ProcessRecord of the command.
/// </summary>
public override void ExecuteSiteRecoveryCmdlet()
{
base.ExecuteSiteRecoveryCmdlet();

// check for A2A protected item - if providerSpecificDetails is A2AReplicationDetails.

var removeDisksProviderSpecificInput = new RemoveDisksProviderSpecificInput();
var inputProperties = new RemoveDisksInputProperties
{
ProviderSpecificDetails = removeDisksProviderSpecificInput
};
var input = new RemoveDisksInput { Properties = inputProperties };
AzureToAzureReplication(input);

this.response = this.RecoveryServicesClient.RemoveDisks(
Utilities.GetValueFromArmId(
this.ReplicationProtectedItem.ID,
ARMResourceTypeConstants.ReplicationFabrics),
Utilities.GetValueFromArmId(
this.ReplicationProtectedItem.ID,
ARMResourceTypeConstants.ReplicationProtectionContainers),
this.ReplicationProtectedItem.Name,
input);

this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
PSRecoveryServicesClient.GetJobIdFromReponseLocation(this.response.Location));

this.WriteObject(new ASRJob(this.jobResponse));

if (this.WaitForCompletion.IsPresent)
{
this.WaitForJobCompletion(this.jobResponse.Name);

this.jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
PSRecoveryServicesClient
.GetJobIdFromReponseLocation(this.response.Location));

this.WriteObject(new ASRJob(this.jobResponse));
}
}

/// <summary>
/// Helper method to fill in input details.
/// </summary>
private void AzureToAzureReplication(RemoveDisksInput input)
{
var providerSettings = new A2ARemoveDisksInput()
{
VmDisksUris = new List<string>(),
VmManagedDisksIds = new List<string>()
};

if (this.ManagedDisk.IsPresent)
{
providerSettings.VmManagedDisksIds = this.DiskId;
}
else
{
providerSettings.VmDisksUris = this.VhdUri;
}

input.Properties.ProviderSpecificDetails = providerSettings;
}

/// <summary>
/// Writes Job.
/// </summary>
Copy link

Choose a reason for hiding this comment

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

no need for these method and private variables ,move the code to ExecuteSiteRecoveryCmdlet method

/// <param name="job">Job object.</param>
private void WriteJob(
Job job)
{
this.WriteObject(new ASRJob(job));
}

private Job jobResponse;

/// <summary>
/// Job response.
/// </summary>
private PSSiteRecoveryLongRunningOperation response;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@
<packages>
<package id="AutoMapper" version="6.0.2" targetFramework="net452" />
<package id="Microsoft.Azure.Management.RecoveryServices" version="4.2.0-preview" targetFramework="net45" />
<package id="Microsoft.Azure.Management.RecoveryServices.SiteRecovery" version="1.3.0-preview" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.18" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.18" targetFramework="net452" />
<package id="Microsoft.Azure.Management.RecoveryServices.SiteRecovery" version="2.0.0-preview" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime" version="2.3.19" targetFramework="net452" />
<package id="Microsoft.Rest.ClientRuntime.Azure" version="3.3.19" targetFramework="net452" />
<package id="Newtonsoft.Json" version="6.0.8" targetFramework="net452" />
</packages>
<package id="System.Net.Http" version="4.3.0" targetFramework="net452" />
</packages>