-
Notifications
You must be signed in to change notification settings - Fork 2
adding remove disk api, introducing zone, network fields in enable protection #9
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
base: asr_a2a_bug_fixes_hotadd
Are you sure you want to change the base?
Changes from 1 commit
529c7bb
537ad52
db854ed
7982833
5c282cb
814cb41
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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; } | ||
|
|
||
|
|
@@ -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; } | ||
|
|
||
|
|
@@ -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. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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> | ||
|
|
@@ -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)) | ||
| { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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())) | ||
|
|
||
| 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. | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)] | ||
|
||
| [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; } | ||
ayfathim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// <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, | ||
|
||
| Mandatory = true)] | ||
| [ValidateNotNullOrEmpty] | ||
| public string[] DiskId { get; set; } | ||
|
|
||
| [Parameter] | ||
| public SwitchParameter WaitForCompletion { get; set; } | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 . |
||
|
|
||
| /// <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); | ||
ayfathim marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| 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> | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.