/// <summary> /// Creates an InMageRcm policy. /// </summary> private void CreateInMageRcmPolicy() { if (string.Compare( this.ReplicationProvider, Constants.InMageRcm, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.ReplicationProvider)); } this.MultiVmSyncStatus = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.MultiVmSyncStatus)) ? this.MultiVmSyncStatus : Constants.Enable; var crashConsistentFrequencyInMinutes = 5; var createPolicyInput = new CreatePolicyInput() { Properties = new CreatePolicyInputProperties() { ProviderSpecificInput = new InMageRcmPolicyCreationInput() { RecoveryPointHistoryInMinutes = this.RecoveryPointRetentionInHours * 60, CrashConsistentFrequencyInMinutes = crashConsistentFrequencyInMinutes, AppConsistentFrequencyInMinutes = this.ApplicationConsistentSnapshotFrequencyInHours * 60, EnableMultiVmSync = this.MultiVmSyncStatus.Equals(Constants.Enable) ? Constants.True : Constants.False } } }; var response = RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput); string jobId = PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location); var jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(jobId); WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Creates an A2A Policy. /// </summary> private void CreateA2APolicy() { this.MultiVmSyncStatus = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.MultiVmSyncStatus)) ? this.MultiVmSyncStatus : Constants.Enable; var crashConsistentFrequencyInMinutes = 5; var a2aPolicyCreationInput = new A2APolicyCreationInput() { AppConsistentFrequencyInMinutes = this.ApplicationConsistentSnapshotFrequencyInHours * 60, CrashConsistentFrequencyInMinutes = crashConsistentFrequencyInMinutes, MultiVmSyncStatus = (SetMultiVmSyncStatus)Enum.Parse( typeof(SetMultiVmSyncStatus), this.MultiVmSyncStatus), RecoveryPointHistory = this.RecoveryPointRetentionInHours * 60 }; var createPolicyInputProperties = new CreatePolicyInputProperties() { ProviderSpecificInput = a2aPolicyCreationInput }; var createPolicyInput = new CreatePolicyInput() { Properties = createPolicyInputProperties }; var response = RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput); string jobId = PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location); var jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(jobId); WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Updates an InMage Policy Object. /// </summary> private void UpdateV2VPolicyObject() { if (string.Compare( this.InputObject.ReplicationProvider, Constants.InMage, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.InputObject.ReplicationProvider)); } // Get the InMage Provider specific details from the Policy. var replicationProviderSettings = this.InputObject.ReplicationProviderSettings as ASRInMagePolicyDetails; // Set the Paremeters to be updated. this.applicationConsistentSnapshotFrequencyInMinutes = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.ApplicationConsistentSnapshotFrequencyInHours)) ? this.ApplicationConsistentSnapshotFrequencyInHours * 60 : replicationProviderSettings.AppConsistentFrequencyInMinutes; this.RecoveryPointRetentionInHours = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.RecoveryPointRetentionInHours)) ? this.RecoveryPointRetentionInHours : replicationProviderSettings.RecoveryPointHistory / 60; this.rpoWarningThresholdInMinutes = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.RPOWarningThresholdInMinutes)) ? this.RPOWarningThresholdInMinutes : replicationProviderSettings.RecoveryPointThresholdInMinutes; this.multiVmSyncStatus = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.MultiVmSyncStatus)) ? this.MultiVmSyncStatus : (replicationProviderSettings.MultiVmSyncStatus.Equals("Enabled") ? Constants.Enable : Constants.Disable); // Set the Provider Specific Input for InMage. var inmagePolicyInput = new InMagePolicyInput { AppConsistentFrequencyInMinutes = this.applicationConsistentSnapshotFrequencyInMinutes, RecoveryPointHistory = this.RecoveryPointRetentionInHours * 60, // Convert from hours to minutes. RecoveryPointThresholdInMinutes = this.rpoWarningThresholdInMinutes, MultiVmSyncStatus = (SetMultiVmSyncStatus)Enum.Parse( typeof(SetMultiVmSyncStatus), this.multiVmSyncStatus) }; var updatePolicyProperties = new UpdatePolicyInputProperties { ReplicationProviderSettings = inmagePolicyInput }; // Create the Update Policy Input. var updatePolicyInput = new UpdatePolicyInput { Properties = updatePolicyProperties }; var response = this.RecoveryServicesClient.UpdatePolicy( this.InputObject.Name, updatePolicyInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Creates an E2E Policy object /// </summary> private void EnterpriseToEnterprisePolicyObject() { if ((string.Compare( this.ReplicationProvider, Constants.HyperVReplica2012, StringComparison.OrdinalIgnoreCase) != 0) && (string.Compare( this.ReplicationProvider, Constants.HyperVReplica2012R2, StringComparison.OrdinalIgnoreCase) != 0)) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.ReplicationProvider)); } PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime); var replicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort( this.ReplicationFrequencyInSeconds); var createPolicyInputProperties = new CreatePolicyInputProperties(); if (string.Compare( this.ReplicationProvider, Constants.HyperVReplica2012, StringComparison.OrdinalIgnoreCase) == 0) { createPolicyInputProperties.ProviderSpecificInput = new HyperVReplicaPolicyInput { AllowedAuthenticationType = (ushort)(string.Compare( this.Authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0 ? 1 : 2), ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours, Compression = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.Compression)) ? this.Compression : Constants.Disable, InitialReplicationMethod = string.Compare( this.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0 ? "OverNetwork" : "Offline", OnlineReplicationStartTime = this.ReplicationStartTime.ToString(), RecoveryPoints = this.NumberOfRecoveryPointsToRetain, ReplicaDeletion = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicaDeletion)) ? this.ReplicaDeletion : Constants.NotRequired, ReplicationPort = this.ReplicationPort }; } else { createPolicyInputProperties.ProviderSpecificInput = new HyperVReplicaBluePolicyInput { AllowedAuthenticationType = (ushort)(string.Compare( this.Authentication, Constants .AuthenticationTypeKerberos, StringComparison .OrdinalIgnoreCase) == 0 ? 1 : 2), ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours, Compression = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.Compression)) ? this.Compression : Constants.Disable, InitialReplicationMethod = string.Compare( this.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0 ? "OverNetwork" : "Offline", OnlineReplicationStartTime = this.ReplicationStartTime.ToString(), RecoveryPoints = this.NumberOfRecoveryPointsToRetain, ReplicaDeletion = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicaDeletion)) ? this.ReplicaDeletion : Constants.NotRequired, ReplicationFrequencyInSeconds = replicationFrequencyInSeconds, ReplicationPort = this.ReplicationPort }; } var createPolicyInput = new CreatePolicyInput { Properties = createPolicyInputProperties }; var responseBlue = this.RecoveryServicesClient.CreatePolicy( this.Name, createPolicyInput); var jobResponseBlue = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(responseBlue.Location)); this.WriteObject(new ASRJob(jobResponseBlue)); }
/// <summary> /// Creates an E2A Policy Object /// </summary> private void HyperVToAzurePolicyObject() { if (string.Compare( this.InputObject.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.InputObject.ReplicationProvider)); } var replicationProviderSettings = this.InputObject.ReplicationProviderSettings as ASRHyperVReplicaAzurePolicyDetails; this.replicationFrequencyInSeconds = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicationFrequencyInSeconds)) ? PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort( this.ReplicationFrequencyInSeconds) : (ushort)replicationProviderSettings .ReplicationFrequencyInSeconds; this.recoveryPoints = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.NumberOfRecoveryPointsToRetain)) ? this.NumberOfRecoveryPointsToRetain : replicationProviderSettings.RecoveryPoints; this.applicationConsistentSnapshotFrequencyInHours = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.ApplicationConsistentSnapshotFrequencyInHours)) ? this.ApplicationConsistentSnapshotFrequencyInHours : replicationProviderSettings.ApplicationConsistentSnapshotFrequencyInHours; this.replicationStartTime = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicationStartTime)) ? this.replicationStartTime : replicationProviderSettings.OnlineReplicationStartTime; this.recoveryAzureStorageAccountId = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryAzureStorageAccountId)) ? this.RecoveryAzureStorageAccountId : replicationProviderSettings.ActiveStorageAccountId; this.encryption = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.Encryption)) ? this.Encryption : (string.Compare( replicationProviderSettings.Encryption, "Disabled", StringComparison.OrdinalIgnoreCase) == 0 ? Constants.Disable : Constants.Enable); var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput { ApplicationConsistentSnapshotFrequencyInHours = this.applicationConsistentSnapshotFrequencyInHours, Encryption = this.encryption, OnlineReplicationStartTime = this.replicationStartTime.ToString(), RecoveryPointHistoryDuration = this.recoveryPoints, ReplicationInterval = this.replicationFrequencyInSeconds }; hyperVReplicaAzurePolicyInput.StorageAccounts = new List <string>(); if (this.RecoveryAzureStorageAccountId != null) { var storageAccount = this.recoveryAzureStorageAccountId; hyperVReplicaAzurePolicyInput.StorageAccounts.Add(storageAccount); } var updatePolicyProperties = new UpdatePolicyInputProperties { ReplicationProviderSettings = hyperVReplicaAzurePolicyInput }; var updatePolicyInput = new UpdatePolicyInput { Properties = updatePolicyProperties }; var response = this.RecoveryServicesClient.UpdatePolicy( this.InputObject.Name, updatePolicyInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Creates an E2E Policy object /// </summary> private void EnterpriseToEnterprisePolicyObject() { if ((string.Compare( this.InputObject.ReplicationProvider, Constants.HyperVReplica2012, StringComparison.OrdinalIgnoreCase) != 0) && (string.Compare( this.InputObject.ReplicationProvider, Constants.HyperVReplica2012R2, StringComparison.OrdinalIgnoreCase) != 0)) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.InputObject.ReplicationProvider)); } var replicationProviderSettings = this.InputObject.ReplicationProviderSettings as ASRHyperVReplicaPolicyDetails; this.replicationMethod = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicationMethod)) ? (string.Compare( this .ReplicationMethod, Constants .OnlineReplicationMethod, StringComparison .OrdinalIgnoreCase) == 0 ? "OverNetwork" : "Offline") : (string.Compare( replicationProviderSettings.InitialReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0 ? "OverNetwork" : "Offline"); this.replicationFrequencyInSeconds = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicationFrequencyInSeconds)) ? PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort( this.ReplicationFrequencyInSeconds) : replicationProviderSettings .ReplicationFrequencyInSeconds; this.recoveryPoints = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.NumberOfRecoveryPointsToRetain)) ? this.NumberOfRecoveryPointsToRetain : replicationProviderSettings.RecoveryPoints; this.applicationConsistentSnapshotFrequencyInHours = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.ApplicationConsistentSnapshotFrequencyInHours)) ? this.ApplicationConsistentSnapshotFrequencyInHours : replicationProviderSettings.ApplicationConsistentSnapshotFrequencyInHours; this.compression = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.Compression)) ? this.Compression : replicationProviderSettings.Compression; this.replicationPort = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicationPort)) ? this.ReplicationPort : replicationProviderSettings.ReplicationPort; this.authentication = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.Authentication)) ? (ushort)(string.Compare( this .Authentication, Constants .AuthenticationTypeKerberos, StringComparison .OrdinalIgnoreCase) == 0 ? 1 : 2) : (ushort)(string.Compare( replicationProviderSettings.AllowedAuthenticationType, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0 ? 1 : 2); this.replicationStartTime = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicationStartTime)) ? this.replicationStartTime : replicationProviderSettings.OnlineReplicationStartTime; this.replicaDeletion = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.ReplicaDeletion)) ? this.ReplicaDeletion : replicationProviderSettings.ReplicaDeletionOption; var updatePolicyProperties = new UpdatePolicyInputProperties(); if (string.Compare( this.InputObject.ReplicationProvider, Constants.HyperVReplica2012, StringComparison.OrdinalIgnoreCase) == 0) { updatePolicyProperties.ReplicationProviderSettings = new HyperVReplicaPolicyInput { AllowedAuthenticationType = this.authentication, ApplicationConsistentSnapshotFrequencyInHours = this.applicationConsistentSnapshotFrequencyInHours, Compression = this.compression, InitialReplicationMethod = this.replicationMethod, OnlineReplicationStartTime = this.replicationStartTime.ToString(), RecoveryPoints = this.recoveryPoints, ReplicaDeletion = this.replicaDeletion, ReplicationPort = this.replicationPort }; } else { updatePolicyProperties.ReplicationProviderSettings = new HyperVReplicaBluePolicyInput { AllowedAuthenticationType = this.authentication, ApplicationConsistentSnapshotFrequencyInHours = this.applicationConsistentSnapshotFrequencyInHours, Compression = this.compression, InitialReplicationMethod = this.replicationMethod, OnlineReplicationStartTime = this.replicationStartTime.ToString(), RecoveryPoints = this.recoveryPoints, ReplicaDeletion = this.replicaDeletion, ReplicationPort = this.replicationPort, ReplicationFrequencyInSeconds = this.replicationFrequencyInSeconds }; } var updatePolicyInput = new UpdatePolicyInput { Properties = updatePolicyProperties }; var responseBlue = this.RecoveryServicesClient.UpdatePolicy( this.InputObject.Name, updatePolicyInput); var jobResponseBlue = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(responseBlue.Location)); this.WriteObject(new ASRJob(jobResponseBlue)); }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteSiteRecoveryCmdlet() { base.ExecuteSiteRecoveryCmdlet(); if (this.ShouldProcess( this.InputObject.FriendlyName, VerbsCommon.Set)) { var replicationProtectedItemResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryReplicationProtectedItem( Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics), Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), this.InputObject.Name); var provider = replicationProtectedItemResponse.Properties.ProviderSpecificDetails; // Check for Replication Provider type HyperVReplicaAzure/InMageAzureV2 if (!(provider is HyperVReplicaAzureReplicationDetails) && !(provider is InMageAzureV2ReplicationDetails) && !(provider is A2AReplicationDetails)) { this.WriteWarning( Resources.UnsupportedReplicationProvidedForUpdateVmProperties); return; } // Check for at least one option if (string.IsNullOrEmpty(this.Name) && string.IsNullOrEmpty(this.Size) && string.IsNullOrEmpty(this.PrimaryNic) && string.IsNullOrEmpty(this.RecoveryNetworkId) && this.UseManagedDisk == null && string.IsNullOrEmpty(this.RecoveryAvailabilitySet) && string.IsNullOrEmpty(this.RecoveryCloudServiceId) && string.IsNullOrEmpty(this.RecoveryResourceGroupId) && string.IsNullOrEmpty(this.LicenseType)) { this.WriteWarning(Resources.ArgumentsMissingForUpdateVmProperties); return; } // Both primary & recovery inputs should be present if (string.IsNullOrEmpty(this.PrimaryNic) ^ string.IsNullOrEmpty(this.RecoveryNetworkId)) { this.WriteWarning(Resources.NetworkArgumentsMissingForUpdateVmProperties); return; } var vmName = this.Name; var vmSize = this.Size; var vmRecoveryNetworkId = this.RecoveryNetworkId; var licenseType = this.LicenseType; var recoveryResourceGroupId = this.RecoveryResourceGroupId; var recoveryCloudServiceId = this.RecoveryCloudServiceId; var useManagedDisk = this.UseManagedDisk; var availabilitySetId = this.RecoveryAvailabilitySet; var vMNicInputDetailsList = new List <VMNicInputDetails>(); var providerSpecificInput = new UpdateReplicationProtectedItemProviderInput(); if (provider is HyperVReplicaAzureReplicationDetails) { var providerSpecificDetails = (HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails; if (string.IsNullOrEmpty(this.Name)) { vmName = providerSpecificDetails.RecoveryAzureVMName; } if (string.IsNullOrEmpty(this.Size)) { vmSize = providerSpecificDetails.RecoveryAzureVMSize; } if (string.IsNullOrEmpty(this.RecoveryNetworkId)) { vmRecoveryNetworkId = providerSpecificDetails .SelectedRecoveryAzureNetworkId; } if (string.IsNullOrEmpty(this.LicenseType)) { licenseType = providerSpecificDetails.LicenseType; } if (string.IsNullOrEmpty(this.RecoveryAvailabilitySet)) { availabilitySetId = providerSpecificDetails.RecoveryAvailabilitySetId; } if (string.IsNullOrEmpty(this.UseManagedDisk)) { useManagedDisk = providerSpecificDetails.UseManagedDisks; } if (string.IsNullOrEmpty(this.RecoveryResourceGroupId)) { recoveryResourceGroupId = providerSpecificDetails.RecoveryAzureResourceGroupId; } var deploymentType = Utilities.GetValueFromArmId( providerSpecificDetails.RecoveryAzureStorageAccount, ARMResourceTypeConstants.Providers); if (deploymentType.ToLower() .Contains(Constants.Classic.ToLower())) { providerSpecificInput = new HyperVReplicaAzureUpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = recoveryResourceGroupId, RecoveryAzureV2ResourceGroupId = null }; } else { providerSpecificInput = new HyperVReplicaAzureUpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = null, RecoveryAzureV2ResourceGroupId = recoveryResourceGroupId, UseManagedDisks = useManagedDisk }; } vMNicInputDetailsList = getNicListToUpdate(providerSpecificDetails.VmNics); } else if (provider is InMageAzureV2ReplicationDetails) { var providerSpecificDetails = (InMageAzureV2ReplicationDetails)replicationProtectedItemResponse.Properties .ProviderSpecificDetails; if (string.IsNullOrEmpty(this.Name)) { vmName = providerSpecificDetails.RecoveryAzureVMName; } if (string.IsNullOrEmpty(this.Size)) { vmSize = providerSpecificDetails.RecoveryAzureVMSize; } if (string.IsNullOrEmpty(this.RecoveryNetworkId)) { vmRecoveryNetworkId = providerSpecificDetails .SelectedRecoveryAzureNetworkId; } if (string.IsNullOrEmpty(this.LicenseType)) { licenseType = providerSpecificDetails.LicenseType; } if (string.IsNullOrEmpty(this.RecoveryAvailabilitySet)) { availabilitySetId = providerSpecificDetails.RecoveryAvailabilitySetId; } if (string.IsNullOrEmpty(this.UseManagedDisk)) { useManagedDisk = providerSpecificDetails.UseManagedDisks; } if (string.IsNullOrEmpty(this.RecoveryResourceGroupId)) { recoveryResourceGroupId = providerSpecificDetails.RecoveryAzureResourceGroupId; } var deploymentType = Utilities.GetValueFromArmId( providerSpecificDetails.RecoveryAzureStorageAccount, ARMResourceTypeConstants.Providers); if (deploymentType.ToLower() .Contains(Constants.Classic.ToLower())) { providerSpecificInput = new InMageAzureV2UpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = recoveryResourceGroupId, RecoveryAzureV2ResourceGroupId = null }; } else { providerSpecificInput = new InMageAzureV2UpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = null, RecoveryAzureV2ResourceGroupId = recoveryResourceGroupId, UseManagedDisks = useManagedDisk }; } vMNicInputDetailsList = getNicListToUpdate(providerSpecificDetails.VmNics); } else if (provider is A2AReplicationDetails) { A2AReplicationDetails providerSpecificDetails = (A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails; if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryResourceGroupId))) { recoveryResourceGroupId = providerSpecificDetails.RecoveryAzureResourceGroupId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryCloudServiceId))) { recoveryCloudServiceId = providerSpecificDetails.RecoveryCloudService; } providerSpecificInput = new A2AUpdateReplicationProtectedItemInput() { RecoveryCloudServiceId = this.RecoveryCloudServiceId, RecoveryResourceGroupId = this.RecoveryResourceGroupId }; if (string.IsNullOrEmpty(this.RecoveryNetworkId)) { vmRecoveryNetworkId = providerSpecificDetails.SelectedRecoveryAzureNetworkId; } vMNicInputDetailsList = getNicListToUpdate(providerSpecificDetails.VmNics); } var updateReplicationProtectedItemInputProperties = new UpdateReplicationProtectedItemInputProperties { RecoveryAzureVMName = vmName, RecoveryAzureVMSize = vmSize, SelectedRecoveryAzureNetworkId = vmRecoveryNetworkId, VmNics = vMNicInputDetailsList, LicenseType = licenseType == Management.RecoveryServices.SiteRecovery.Models.LicenseType .NoLicenseType.ToString() ? Management.RecoveryServices.SiteRecovery.Models.LicenseType .NoLicenseType : Management.RecoveryServices.SiteRecovery.Models.LicenseType .WindowsServer, RecoveryAvailabilitySetId = availabilitySetId, ProviderSpecificDetails = providerSpecificInput }; var input = new UpdateReplicationProtectedItemInput { Properties = updateReplicationProtectedItemInputProperties }; var response = this.RecoveryServicesClient.UpdateVmProperties( Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics), Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), this.InputObject.Name, input); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); } }
/// <summary> /// Starts RP Planned failover. /// </summary> private void StartRpPlannedFailover() { // Refresh RP Object var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan( this.RecoveryPlan.Name); var recoveryPlanPlannedFailoverInputProperties = new RecoveryPlanPlannedFailoverInputProperties { FailoverDirection = this.Direction == PossibleOperationsDirections.PrimaryToRecovery.ToString() ? PossibleOperationsDirections.PrimaryToRecovery : PossibleOperationsDirections.RecoveryToPrimary, ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>() }; foreach (var replicationProvider in rp.Properties.ReplicationProviders) { if (0 == string.Compare( replicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { if (this.Direction == Constants.PrimaryToRecovery) { var recoveryPlanHyperVReplicaAzureFailoverInput = new RecoveryPlanHyperVReplicaAzureFailoverInput { PrimaryKekCertificatePfx = this.primaryKekCertpfx, SecondaryKekCertificatePfx = this.secondaryKekCertpfx }; recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanHyperVReplicaAzureFailoverInput); } else { var recoveryPlanHyperVReplicaAzureFailbackInput = new RecoveryPlanHyperVReplicaAzureFailbackInput { DataSyncOption = this.Optimize == Constants.ForDownTime ? DataSyncStatus.ForDownTime : DataSyncStatus.ForSynchronization, RecoveryVmCreationOption = string.Compare( this.CreateVmIfNotFound, Constants.Yes, StringComparison .OrdinalIgnoreCase) == 0 ? AlternateLocationRecoveryOption .CreateVmIfNotFound : AlternateLocationRecoveryOption.NoAction }; recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanHyperVReplicaAzureFailbackInput); } } else if (0 == string.Compare( replicationProvider, Constants.InMageRcmFailback, StringComparison.OrdinalIgnoreCase)) { this.MultiVmSyncPoint = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.MultiVmSyncPoint)) ? this.MultiVmSyncPoint : Constants.Enable; var recoveryPointType = this.RecoveryTag == Constants.RecoveryTagApplicationConsistent ? InMageRcmFailbackRecoveryPointType.ApplicationConsistent : InMageRcmFailbackRecoveryPointType.CrashConsistent; // Validate the direction as RecoveryToPrimary. if (this.Direction == Constants.RecoveryToPrimary) { var recoveryPlanFailoverInput = new RecoveryPlanInMageRcmFailbackFailoverInput { RecoveryPointType = recoveryPointType, UseMultiVmSyncPoint = this.MultiVmSyncPoint == Constants.Enable ? Constants.True : Constants.False }; recoveryPlanPlannedFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanFailoverInput); } else { // PrimaryToRecovery direction is invalid for InMageRcmFailback. new ArgumentException(Resources.InvalidDirectionForAzureToVMWare); } } else if (string.Compare( replicationProvider, Constants.InMageAzureV2, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare( replicationProvider, Constants.InMage, StringComparison.OrdinalIgnoreCase) == 0 || string.Compare( replicationProvider, Constants.InMageRcm, StringComparison.OrdinalIgnoreCase) == 0) { throw new InvalidOperationException( string.Format( Resources.UnsupportedReplicationProviderForPlannedFailover, replicationProvider)); } } var recoveryPlanPlannedFailoverInput = new RecoveryPlanPlannedFailoverInput { Properties = recoveryPlanPlannedFailoverInputProperties }; var response = this.RecoveryServicesClient.StartAzureSiteRecoveryPlannedFailover( this.RecoveryPlan.Name, recoveryPlanPlannedFailoverInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Updates an InMageRcm policy. /// </summary> private void UpdateInMageRcmPolicy() { if (string.Compare( this.InputObject.ReplicationProvider, Constants.InMageRcm, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.InputObject.ReplicationProvider)); } // Get the InMageRcm provider specific details from the policy. var replicationProviderSettings = this.InputObject.ReplicationProviderSettings as ASRInMageRcmPolicyDetails; // Set the paremeters to be updated. this.applicationConsistentSnapshotFrequencyInMinutes = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.applicationConsistentSnapshotFrequencyInHours)) ? this.ApplicationConsistentSnapshotFrequencyInHours * 60 : replicationProviderSettings.AppConsistentFrequencyInMinutes; this.RecoveryPointRetentionInHours = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.RecoveryPointRetentionInHours)) ? this.RecoveryPointRetentionInHours : replicationProviderSettings.RecoveryPointHistoryInMinutes / 60; this.multiVmSyncStatus = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName( () => this.MultiVmSyncStatus)) ? this.MultiVmSyncStatus : replicationProviderSettings.MultiVmSyncStatus; this.crashConsistentFrequencyInMinutes = replicationProviderSettings.CrashConsistentFrequencyInMinutes; // Create the update policy input. var updatePolicyInput = new UpdatePolicyInput { Properties = new UpdatePolicyInputProperties { ReplicationProviderSettings = new InMageRcmPolicyCreationInput { RecoveryPointHistoryInMinutes = this.RecoveryPointRetentionInHours * 60, CrashConsistentFrequencyInMinutes = crashConsistentFrequencyInMinutes, AppConsistentFrequencyInMinutes = this.applicationConsistentSnapshotFrequencyInMinutes, EnableMultiVmSync = this.multiVmSyncStatus.Equals(Constants.Enable) ? Constants.True : Constants.False } } }; var response = this.RecoveryServicesClient.UpdatePolicy( this.InputObject.Name, updatePolicyInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Creates an E2A Policy Object /// </summary> private void EnterpriseToAzurePolicyObject() { if (string.Compare( this.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.ReplicationProvider)); } PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime); var replicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort( this.ReplicationFrequencyInSeconds); var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput { ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours, Encryption = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.Encryption)) ? this.Encryption : Constants.Disable, OnlineReplicationStartTime = this.ReplicationStartTime == null ? null : this.ReplicationStartTime.ToString(), RecoveryPointHistoryDuration = this.NumberOfRecoveryPointsToRetain, ReplicationInterval = replicationFrequencyInSeconds }; hyperVReplicaAzurePolicyInput.StorageAccounts = new List <string>(); if (this.RecoveryAzureStorageAccountId != null) { var storageAccount = this.RecoveryAzureStorageAccountId; hyperVReplicaAzurePolicyInput.StorageAccounts.Add(storageAccount); } var createPolicyInputProperties = new CreatePolicyInputProperties { ProviderSpecificInput = hyperVReplicaAzurePolicyInput }; var createPolicyInput = new CreatePolicyInput { Properties = createPolicyInputProperties }; var response = this.RecoveryServicesClient.CreatePolicy( this.Name, createPolicyInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteSiteRecoveryCmdlet() { base.ExecuteSiteRecoveryCmdlet(); ASRVMNicConfig nicConfig = null; if (string.IsNullOrEmpty(this.RecoveryVMNetworkId) && !string.IsNullOrEmpty(this.RecoveryVMSubnetName)) { this.WriteWarning(Resources.RecoveryNetworkInformationMissing); return; } if (string.IsNullOrEmpty(this.TfoVMNetworkId) && !string.IsNullOrEmpty(this.TfoVMSubnetName)) { this.WriteWarning(Resources.TfoNetworkInformationMissing); return; } if (string.IsNullOrEmpty(this.RecoveryVMSubnetName) && !string.IsNullOrEmpty(this.RecoveryNicStaticIPAddress)) { this.WriteWarning(Resources.RecoverySubnetInformationMissing); return; } if (string.IsNullOrEmpty(this.TfoVMSubnetName) && !string.IsNullOrEmpty(this.TfoNicStaticIPAddress)) { this.WriteWarning(Resources.TfoSubnetInformationMissing); return; } switch (this.ParameterSetName) { case ASRParameterSets.AzureToAzure: var providerSpecificDetails = this.ReplicationProtectedItem.ProviderSpecificDetails; if (!(providerSpecificDetails is ASRAzureToAzureSpecificRPIDetails)) { this.WriteWarning( Resources.UnsupportedReplicationProvidedForASRVMNicConfig); return; } var vmNicDetailsList = this.ReplicationProtectedItem.NicDetailsList ?? new List <ASRVMNicDetails>(); var vmNic = vmNicDetailsList.FirstOrDefault( nic => nic.NicId.Equals( this.NicId, StringComparison.OrdinalIgnoreCase)); if (vmNic == null) { this.WriteWarning(string.Format(Resources.NicNotFoundInVM, this.NicId)); return; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryVMNetworkId))) { this.RecoveryVMNetworkId = this.ReplicationProtectedItem.SelectedRecoveryAzureNetworkId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryVMSubnetName))) { this.RecoveryVMSubnetName = vmNic.RecoveryVMSubnetName; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryNicStaticIPAddress))) { this.RecoveryNicStaticIPAddress = vmNic.ReplicaNicStaticIPAddress; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryNetworkSecurityGroupId))) { this.RecoveryNetworkSecurityGroupId = vmNic.RecoveryNetworkSecurityGroupId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.EnableAcceleratedNetworkingOnRecovery))) { this.EnableAcceleratedNetworkingOnRecovery = vmNic.EnableAcceleratedNetworkingOnRecovery ?? false; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryPublicIPAddressId))) { this.RecoveryPublicIPAddressId = vmNic.RecoveryPublicIPAddressId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryLBBackendAddressPoolId))) { this.RecoveryLBBackendAddressPoolId = vmNic.RecoveryLBBackendAddressPoolId?.ToArray(); } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.TfoVMNetworkId))) { this.TfoVMNetworkId = this.ReplicationProtectedItem.SelectedTfoAzureNetworkId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.TfoVMSubnetName))) { this.TfoVMSubnetName = vmNic.TfoVMSubnetName; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.TfoNicStaticIPAddress))) { this.TfoNicStaticIPAddress = vmNic.TfoIPConfigs?.FirstOrDefault()?.StaticIPAddress ?? string.Empty; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.TfoNetworkSecurityGroupId))) { this.TfoNetworkSecurityGroupId = vmNic.TfoNetworkSecurityGroupId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.EnableAcceleratedNetworkingOnTfo))) { this.EnableAcceleratedNetworkingOnTfo = vmNic.EnableAcceleratedNetworkingOnTfo ?? false; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.TfoPublicIPAddressId))) { this.TfoPublicIPAddressId = vmNic.TfoIPConfigs?.FirstOrDefault()?.PublicIpAddressId ?? string.Empty; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.TfoLBBackendAddressPoolId))) { this.TfoLBBackendAddressPoolId = vmNic.TfoIPConfigs?.FirstOrDefault()?.LBBackendAddressPoolIds?.ToArray(); } nicConfig = new ASRVMNicConfig { NicId = this.NicId, RecoveryVMNetworkId = this.RecoveryVMNetworkId, RecoveryVMSubnetName = this.RecoveryVMSubnetName, RecoveryNetworkSecurityGroupId = this.RecoveryNetworkSecurityGroupId, EnableAcceleratedNetworkingOnRecovery = this.EnableAcceleratedNetworkingOnRecovery, RecoveryIPConfigs = new List <IPConfig> { new IPConfig { StaticIPAddress = this.RecoveryNicStaticIPAddress, PublicIpAddressId = this.RecoveryPublicIPAddressId, LBBackendAddressPoolIds = this.RecoveryLBBackendAddressPoolId?.ToList() ?? new List <string>() } }, TfoVMNetworkId = this.TfoVMNetworkId, TfoVMSubnetName = this.TfoVMSubnetName, TfoNetworkSecurityGroupId = this.TfoNetworkSecurityGroupId, EnableAcceleratedNetworkingOnTfo = this.EnableAcceleratedNetworkingOnTfo, TfoIPConfigs = new List <IPConfig> { new IPConfig { StaticIPAddress = this.TfoNicStaticIPAddress, PublicIpAddressId = this.TfoPublicIPAddressId, LBBackendAddressPoolIds = this.TfoLBBackendAddressPoolId?.ToList() ?? new List <string>() } } }; break; } this.WriteObject(nicConfig); }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteSiteRecoveryCmdlet() { base.ExecuteSiteRecoveryCmdlet(); if (this.ShouldProcess( this.InputObject.FriendlyName, VerbsCommon.Set)) { var replicationProtectedItemResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryReplicationProtectedItem( Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics), Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), this.InputObject.Name); var provider = replicationProtectedItemResponse.Properties.ProviderSpecificDetails; // Check for Replication Provider type HyperVReplicaAzure/InMageAzureV2/A2A if (!(provider is HyperVReplicaAzureReplicationDetails) && !(provider is InMageAzureV2ReplicationDetails) && !(provider is A2AReplicationDetails)) { this.WriteWarning( Resources.UnsupportedReplicationProvidedForUpdateVmProperties); return; } // Check for at least one option if (string.IsNullOrEmpty(this.Name) && string.IsNullOrEmpty(this.Size) && string.IsNullOrEmpty(this.UpdateNic) && string.IsNullOrEmpty(this.RecoveryNetworkId) && string.IsNullOrEmpty(this.PrimaryNic) && this.UseManagedDisk == null && this.IsParameterBound(c => c.RecoveryAvailabilitySet) && this.IsParameterBound(c => c.RecoveryAvailabilityZone) && this.IsParameterBound(c => c.RecoveryProximityPlacementGroupId) && string.IsNullOrEmpty(this.RecoveryCloudServiceId) && string.IsNullOrEmpty(this.RecoveryResourceGroupId) && string.IsNullOrEmpty(this.LicenseType) && string.IsNullOrEmpty(this.RecoveryBootDiagStorageAccountId) && this.AzureToAzureUpdateReplicationConfiguration == null) { this.WriteWarning(Resources.ArgumentsMissingForUpdateVmProperties); return; } // Both primary & recovery inputs should be present if (this.ASRVMNicConfiguration == null && (string.IsNullOrEmpty(this.UpdateNic) ^ string.IsNullOrEmpty(this.RecoveryNetworkId))) { this.WriteWarning(Resources.NetworkArgumentsMissingForUpdateVmProperties); return; } // NSG, LB and PIP only for A2A provider. if ((!string.IsNullOrEmpty(RecoveryNetworkSecurityGroupId) || !string.IsNullOrEmpty(RecoveryPublicIPAddressId) || RecoveryLBBackendAddressPoolId != null && RecoveryLBBackendAddressPoolId.Length > 0) && !(provider is A2AReplicationDetails)) { this.WriteWarning( Resources.UnsupportedReplicationProvidedForNetworkingResources); return; } if (this.ASRVMNicConfiguration != null && !(provider is A2AReplicationDetails)) { this.WriteWarning(Resources.UnsupportedReplicationProvidedForASRVMNicConfig); return; } if (this.ASRVMNicConfiguration != null && !string.IsNullOrEmpty(this.UpdateNic)) { this.WriteWarning(Resources.ASRVMNicsAndUpdateNicNotAllowed); return; } var vmName = this.Name; var vmSize = this.Size; var vmRecoveryNetworkId = this.RecoveryNetworkId; var licenseType = this.LicenseType; var recoveryResourceGroupId = this.RecoveryResourceGroupId; var recoveryCloudServiceId = this.RecoveryCloudServiceId; var useManagedDisk = this.UseManagedDisk; var availabilitySetId = this.RecoveryAvailabilitySet; var proximityPlacementGroupId = this.RecoveryProximityPlacementGroupId; var availabilityZone = this.RecoveryAvailabilityZone; var primaryNic = this.PrimaryNic; var diskIdToDiskEncryptionMap = this.DiskIdToDiskEncryptionSetMap; var tfoNetworkId = string.Empty; var vMNicInputDetailsList = new List <VMNicInputDetails>(); var providerSpecificInput = new UpdateReplicationProtectedItemProviderInput(); if (provider is HyperVReplicaAzureReplicationDetails) { var providerSpecificDetails = (HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails; if (string.IsNullOrEmpty(this.Name)) { vmName = providerSpecificDetails.RecoveryAzureVmName; } if (string.IsNullOrEmpty(this.Size)) { vmSize = providerSpecificDetails.RecoveryAzureVMSize; } if (string.IsNullOrEmpty(this.RecoveryNetworkId)) { vmRecoveryNetworkId = providerSpecificDetails .SelectedRecoveryAzureNetworkId; } if (string.IsNullOrEmpty(this.LicenseType)) { licenseType = providerSpecificDetails.LicenseType; } availabilitySetId = this.IsParameterBound(c => c.RecoveryAvailabilitySet) ? this.RecoveryAvailabilitySet : providerSpecificDetails.RecoveryAvailabilitySetId; availabilityZone = this.IsParameterBound(c => c.RecoveryAvailabilityZone) ? this.RecoveryAvailabilityZone : providerSpecificDetails.TargetAvailabilityZone; proximityPlacementGroupId = this.IsParameterBound(c => c.RecoveryProximityPlacementGroupId) ? this.RecoveryProximityPlacementGroupId : providerSpecificDetails.TargetProximityPlacementGroupId; if (string.IsNullOrEmpty(this.UseManagedDisk)) { useManagedDisk = providerSpecificDetails.UseManagedDisks; } if (string.IsNullOrEmpty(this.RecoveryResourceGroupId)) { recoveryResourceGroupId = providerSpecificDetails.RecoveryAzureResourceGroupId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.PrimaryNic))) { primaryNic = providerSpecificDetails.SelectedSourceNicId; } if (this.DiskIdToDiskEncryptionSetMap == null || this.DiskIdToDiskEncryptionSetMap.Count == 0) { diskIdToDiskEncryptionMap = providerSpecificDetails.AzureVmDiskDetails. ToDictionary(x => x.DiskId, x => x.DiskEncryptionSetId); } var deploymentType = Utilities.GetValueFromArmId( providerSpecificDetails.RecoveryAzureStorageAccount, ARMResourceTypeConstants.Providers); if (deploymentType.ToLower() .Contains(Constants.Classic.ToLower())) { providerSpecificInput = new HyperVReplicaAzureUpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = recoveryResourceGroupId, RecoveryAzureV2ResourceGroupId = null }; } else { providerSpecificInput = new HyperVReplicaAzureUpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = null, RecoveryAzureV2ResourceGroupId = recoveryResourceGroupId, UseManagedDisks = useManagedDisk, DiskIdToDiskEncryptionMap = this.DiskIdToDiskEncryptionSetMap, TargetAvailabilityZone = availabilityZone, TargetProximityPlacementGroupId = proximityPlacementGroupId }; } vMNicInputDetailsList = getNicListToUpdate(providerSpecificDetails.VmNics); } else if (provider is InMageAzureV2ReplicationDetails) { var providerSpecificDetails = (InMageAzureV2ReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails; if (string.IsNullOrEmpty(this.Name)) { vmName = providerSpecificDetails.RecoveryAzureVMName; } if (string.IsNullOrEmpty(this.Size)) { vmSize = providerSpecificDetails.RecoveryAzureVMSize; } if (string.IsNullOrEmpty(this.RecoveryNetworkId)) { vmRecoveryNetworkId = providerSpecificDetails.SelectedRecoveryAzureNetworkId; } if (string.IsNullOrEmpty(this.LicenseType)) { licenseType = providerSpecificDetails.LicenseType; } availabilitySetId = this.IsParameterBound(c => c.RecoveryAvailabilitySet) ? this.RecoveryAvailabilitySet : providerSpecificDetails.RecoveryAvailabilitySetId; availabilityZone = this.IsParameterBound(c => c.RecoveryAvailabilityZone) ? this.RecoveryAvailabilityZone : providerSpecificDetails.TargetAvailabilityZone; proximityPlacementGroupId = this.IsParameterBound(c => c.RecoveryProximityPlacementGroupId) ? this.RecoveryProximityPlacementGroupId : providerSpecificDetails.TargetProximityPlacementGroupId; if (string.IsNullOrEmpty(this.UseManagedDisk)) { useManagedDisk = providerSpecificDetails.UseManagedDisks; } if (string.IsNullOrEmpty(this.RecoveryResourceGroupId)) { recoveryResourceGroupId = providerSpecificDetails.RecoveryAzureResourceGroupId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.PrimaryNic))) { primaryNic = providerSpecificDetails.SelectedSourceNicId; } var deploymentType = Utilities.GetValueFromArmId( providerSpecificDetails.TargetVmId, ARMResourceTypeConstants.Providers); if (deploymentType.ToLower() .Contains(Constants.ClassicCompute.ToLower())) { providerSpecificInput = new InMageAzureV2UpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = recoveryResourceGroupId, RecoveryAzureV2ResourceGroupId = null }; } else { providerSpecificInput = new InMageAzureV2UpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = null, RecoveryAzureV2ResourceGroupId = recoveryResourceGroupId, UseManagedDisks = useManagedDisk, TargetAvailabilityZone = availabilityZone, TargetProximityPlacementGroupId = proximityPlacementGroupId }; } vMNicInputDetailsList = getNicListToUpdate(providerSpecificDetails.VmNics); } else if (provider is A2AReplicationDetails) { A2AReplicationDetails providerSpecificDetails = (A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails; if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryResourceGroupId))) { recoveryResourceGroupId = providerSpecificDetails.RecoveryAzureResourceGroupId; } availabilitySetId = this.IsParameterBound(c => c.RecoveryAvailabilitySet) ? this.RecoveryAvailabilitySet : providerSpecificDetails.RecoveryAvailabilitySet; if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryNetworkId))) { vmRecoveryNetworkId = providerSpecificDetails.SelectedRecoveryAzureNetworkId; } proximityPlacementGroupId = this.IsParameterBound(c => c.RecoveryProximityPlacementGroupId) ? this.RecoveryProximityPlacementGroupId : providerSpecificDetails.RecoveryProximityPlacementGroupId; if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryCloudServiceId))) { recoveryCloudServiceId = providerSpecificDetails.RecoveryCloudService; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryBootDiagStorageAccountId))) { this.RecoveryBootDiagStorageAccountId = providerSpecificDetails.RecoveryBootDiagStorageAccountId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.TfoAzureVMName))) { this.TfoAzureVMName = providerSpecificDetails.TfoAzureVMName; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.Name))) { vmName = providerSpecificDetails.RecoveryAzureVMName; } List <A2AVmManagedDiskUpdateDetails> managedDiskUpdateDetails = null; // ManagedDisk case if (this.AzureToAzureUpdateReplicationConfiguration == null && providerSpecificDetails.ProtectedManagedDisks != null) { managedDiskUpdateDetails = new List <A2AVmManagedDiskUpdateDetails>(); foreach (var managedDisk in providerSpecificDetails.ProtectedManagedDisks) { managedDiskUpdateDetails.Add( new A2AVmManagedDiskUpdateDetails( managedDisk.DiskId, managedDisk.RecoveryTargetDiskAccountType, managedDisk.RecoveryReplicaDiskAccountType, failoverDiskName: managedDisk.FailoverDiskName, tfoDiskName: managedDisk.TfoDiskName)); } } else if (this.AzureToAzureUpdateReplicationConfiguration != null && this.AzureToAzureUpdateReplicationConfiguration[0].IsManagedDisk) { managedDiskUpdateDetails = new List <A2AVmManagedDiskUpdateDetails>(); foreach (var managedDisk in this.AzureToAzureUpdateReplicationConfiguration) { managedDiskUpdateDetails.Add( new A2AVmManagedDiskUpdateDetails( managedDisk.DiskId, managedDisk.RecoveryTargetDiskAccountType, managedDisk.RecoveryReplicaDiskAccountType, failoverDiskName: managedDisk.FailoverDiskName, tfoDiskName: managedDisk.TfoDiskName, diskEncryptionInfo: Utilities.A2AEncryptionDetails( managedDisk.DiskEncryptionSecretUrl, managedDisk.DiskEncryptionVaultId, managedDisk.KeyEncryptionKeyUrl, managedDisk.KeyEncryptionVaultId))); } } providerSpecificInput = new A2AUpdateReplicationProtectedItemInput() { RecoveryCloudServiceId = this.RecoveryCloudServiceId, RecoveryResourceGroupId = this.RecoveryResourceGroupId, RecoveryProximityPlacementGroupId = this.RecoveryProximityPlacementGroupId, RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId, ManagedDiskUpdateDetails = managedDiskUpdateDetails, TfoAzureVMName = this.TfoAzureVMName, DiskEncryptionInfo = Utilities.A2AEncryptionDetails( this.DiskEncryptionSecretUrl, this.DiskEncryptionVaultId, this.KeyEncryptionKeyUrl, this.KeyEncryptionVaultId) }; if (this.ASRVMNicConfiguration != null && this.ASRVMNicConfiguration.Count() > 0) { var recoveryNetworkIds = new HashSet <string>(); var tfoNetworkIds = new HashSet <string>(); this.ASRVMNicConfiguration.ForEach( nic => { if (!string.IsNullOrEmpty(nic.RecoveryVMNetworkId)) { recoveryNetworkIds.Add(nic.RecoveryVMNetworkId); } }); this.ASRVMNicConfiguration.ForEach( nic => { if (!string.IsNullOrEmpty(nic.TfoVMNetworkId)) { tfoNetworkIds.Add(nic.TfoVMNetworkId); } }); if (recoveryNetworkIds.Count() > 1) { this.WriteWarning(Resources.RecoveryNetworkIdConflictInASRVMNics); return; } if (tfoNetworkIds.Count() > 1) { this.WriteWarning(Resources.TfoNetworkIdConflictInASRVMNics); return; } if (!string.IsNullOrEmpty(this.RecoveryNetworkId) && !string.IsNullOrEmpty(recoveryNetworkIds.FirstOrDefault()) && !this.RecoveryNetworkId.Equals( recoveryNetworkIds.First(), StringComparison.OrdinalIgnoreCase)) { this.WriteWarning(Resources.RecoveryNetworkInformationMismatch); return; } if (!string.IsNullOrEmpty(recoveryNetworkIds.FirstOrDefault())) { vmRecoveryNetworkId = recoveryNetworkIds.First(); } tfoNetworkId = tfoNetworkIds.FirstOrDefault(); } if (string.IsNullOrEmpty(tfoNetworkId)) { tfoNetworkId = providerSpecificDetails.SelectedTfoAzureNetworkId; } vMNicInputDetailsList = getNicListToUpdate(providerSpecificDetails.VmNics); } var updateReplicationProtectedItemInputProperties = new UpdateReplicationProtectedItemInputProperties { RecoveryAzureVMName = vmName, RecoveryAzureVMSize = vmSize, SelectedRecoveryAzureNetworkId = vmRecoveryNetworkId, SelectedTfoAzureNetworkId = tfoNetworkId, SelectedSourceNicId = primaryNic, VmNics = vMNicInputDetailsList, LicenseType = licenseType == Management.RecoveryServices.SiteRecovery.Models.LicenseType .NoLicenseType.ToString() ? Management.RecoveryServices.SiteRecovery.Models.LicenseType .NoLicenseType : Management.RecoveryServices.SiteRecovery.Models.LicenseType .WindowsServer, RecoveryAvailabilitySetId = availabilitySetId, ProviderSpecificDetails = providerSpecificInput }; if (provider is HyperVReplicaAzureReplicationDetails || provider is InMageAzureV2ReplicationDetails) { updateReplicationProtectedItemInputProperties.SelectedSourceNicId = primaryNic; } var input = new UpdateReplicationProtectedItemInput { Properties = updateReplicationProtectedItemInputProperties }; var response = this.RecoveryServicesClient.UpdateVmProperties( Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics), Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), this.InputObject.Name, input); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); } }
private List <VMNicInputDetails> getNicListToUpdate(IList <VMNicDetails> vmNicList) { var vMNicInputDetailsList = new List <VMNicInputDetails>(); // Weather to track NIC found to be updated. IF primary NIC is not or empty no need to update. var nicFoundToBeUpdated = string.IsNullOrEmpty(this.UpdateNic); if (vmNicList != null) { foreach (var nDetails in vmNicList) { var vMNicInputDetails = new VMNicInputDetails(); if (!string.IsNullOrEmpty(this.UpdateNic) && string.Compare(nDetails.NicId, this.UpdateNic, StringComparison.OrdinalIgnoreCase) == 0) { vMNicInputDetails.NicId = this.UpdateNic; vMNicInputDetails.RecoveryVMSubnetName = this.RecoveryNicSubnetName; vMNicInputDetails.ReplicaNicStaticIPAddress = this.RecoveryNicStaticIPAddress; vMNicInputDetails.SelectionType = string.IsNullOrEmpty(this.NicSelectionType) ? Constants.SelectedByUser : this.NicSelectionType; vMNicInputDetails.RecoveryLBBackendAddressPoolIds = this.RecoveryLBBackendAddressPoolId?.ToList(); vMNicInputDetails.RecoveryPublicIpAddressId = this.RecoveryPublicIPAddressId; vMNicInputDetails.RecoveryNetworkSecurityGroupId = this.RecoveryNetworkSecurityGroupId; vMNicInputDetailsList.Add(vMNicInputDetails); // NicId matched for update nicFoundToBeUpdated = true; if (this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.EnableAcceleratedNetworkingOnRecovery))) { vMNicInputDetails.EnableAcceleratedNetworkingOnRecovery = true; } else { vMNicInputDetails.EnableAcceleratedNetworkingOnRecovery = false; } } else { vMNicInputDetails.NicId = nDetails.NicId; vMNicInputDetails.RecoveryVMSubnetName = nDetails.RecoveryVMSubnetName; vMNicInputDetails.ReplicaNicStaticIPAddress = nDetails.ReplicaNicStaticIPAddress; vMNicInputDetails.SelectionType = nDetails.SelectionType; vMNicInputDetailsList.Add(vMNicInputDetails); vMNicInputDetails.EnableAcceleratedNetworkingOnRecovery = nDetails.EnableAcceleratedNetworkingOnRecovery; vMNicInputDetails.RecoveryLBBackendAddressPoolIds = nDetails.RecoveryLBBackendAddressPoolIds; vMNicInputDetails.RecoveryPublicIpAddressId = nDetails.RecoveryPublicIpAddressId; vMNicInputDetails.RecoveryNetworkSecurityGroupId = nDetails.RecoveryNetworkSecurityGroupId; } } } if (!nicFoundToBeUpdated) { throw new PSInvalidOperationException(Resources.NicNotFoundInVMForUpdateVmProperties); } return(vMNicInputDetailsList); }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteSiteRecoveryCmdlet() { base.ExecuteSiteRecoveryCmdlet(); if (this.ShouldProcess( this.InputObject.FriendlyName, VerbsCommon.Set)) { var replicationProtectedItemResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryReplicationProtectedItem( Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics), Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), this.InputObject.Name); var provider = replicationProtectedItemResponse.Properties.ProviderSpecificDetails; // Check for Replication Provider type HyperVReplicaAzure/InMageAzureV2/A2A if (!(provider is HyperVReplicaAzureReplicationDetails) && !(provider is InMageAzureV2ReplicationDetails) && !(provider is A2AReplicationDetails)) { this.WriteWarning( Resources.UnsupportedReplicationProvidedForUpdateVmProperties); return; } // Check for at least one option if (string.IsNullOrEmpty(this.Name) && string.IsNullOrEmpty(this.Size) && string.IsNullOrEmpty(this.UpdateNic) && string.IsNullOrEmpty(this.RecoveryNetworkId) && string.IsNullOrEmpty(this.PrimaryNic) && this.UseManagedDisk == null && this.IsParameterBound(c => c.RecoveryAvailabilitySet) && string.IsNullOrEmpty(this.RecoveryCloudServiceId) && string.IsNullOrEmpty(this.RecoveryResourceGroupId) && string.IsNullOrEmpty(this.LicenseType) && string.IsNullOrEmpty(this.RecoveryBootDiagStorageAccountId) && this.AzureToAzureUpdateReplicationConfiguration == null) { this.WriteWarning(Resources.ArgumentsMissingForUpdateVmProperties); return; } // Both primary & recovery inputs should be present if (string.IsNullOrEmpty(this.UpdateNic) ^ string.IsNullOrEmpty(this.RecoveryNetworkId)) { this.WriteWarning(Resources.NetworkArgumentsMissingForUpdateVmProperties); return; } // NSG, LB and PIP only for A2A provider. if ((!string.IsNullOrEmpty(RecoveryNetworkSecurityGroupId) || !string.IsNullOrEmpty(RecoveryPublicIPAddressId) || RecoveryLBBackendAddressPoolId != null && RecoveryLBBackendAddressPoolId.Length > 0) && !(provider is A2AReplicationDetails)) { this.WriteWarning(Resources.NetworkingResourcesInDRNotSupportedForClassicVms); return; } var vmName = this.Name; var vmSize = this.Size; var vmRecoveryNetworkId = this.RecoveryNetworkId; var licenseType = this.LicenseType; var recoveryResourceGroupId = this.RecoveryResourceGroupId; var recoveryCloudServiceId = this.RecoveryCloudServiceId; var useManagedDisk = this.UseManagedDisk; var availabilitySetId = this.RecoveryAvailabilitySet; var primaryNic = this.PrimaryNic; var vMNicInputDetailsList = new List <VMNicInputDetails>(); var providerSpecificInput = new UpdateReplicationProtectedItemProviderInput(); if (provider is HyperVReplicaAzureReplicationDetails) { var providerSpecificDetails = (HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails; if (string.IsNullOrEmpty(this.Name)) { vmName = providerSpecificDetails.RecoveryAzureVmName; } if (string.IsNullOrEmpty(this.Size)) { vmSize = providerSpecificDetails.RecoveryAzureVMSize; } if (string.IsNullOrEmpty(this.RecoveryNetworkId)) { vmRecoveryNetworkId = providerSpecificDetails .SelectedRecoveryAzureNetworkId; } if (string.IsNullOrEmpty(this.LicenseType)) { licenseType = providerSpecificDetails.LicenseType; } availabilitySetId = this.IsParameterBound(c => c.RecoveryAvailabilitySet) ? this.RecoveryAvailabilitySet : providerSpecificDetails.RecoveryAvailabilitySetId; if (string.IsNullOrEmpty(this.UseManagedDisk)) { useManagedDisk = providerSpecificDetails.UseManagedDisks; } if (string.IsNullOrEmpty(this.RecoveryResourceGroupId)) { recoveryResourceGroupId = providerSpecificDetails.RecoveryAzureResourceGroupId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.PrimaryNic))) { primaryNic = providerSpecificDetails.SelectedSourceNicId; } var deploymentType = Utilities.GetValueFromArmId( providerSpecificDetails.RecoveryAzureStorageAccount, ARMResourceTypeConstants.Providers); if (deploymentType.ToLower() .Contains(Constants.Classic.ToLower())) { providerSpecificInput = new HyperVReplicaAzureUpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = recoveryResourceGroupId, RecoveryAzureV2ResourceGroupId = null }; } else { providerSpecificInput = new HyperVReplicaAzureUpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = null, RecoveryAzureV2ResourceGroupId = recoveryResourceGroupId, UseManagedDisks = useManagedDisk }; } vMNicInputDetailsList = getNicListToUpdate(providerSpecificDetails.VmNics); } else if (provider is InMageAzureV2ReplicationDetails) { var providerSpecificDetails = (InMageAzureV2ReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails; if (string.IsNullOrEmpty(this.Name)) { vmName = providerSpecificDetails.RecoveryAzureVMName; } if (string.IsNullOrEmpty(this.Size)) { vmSize = providerSpecificDetails.RecoveryAzureVMSize; } if (string.IsNullOrEmpty(this.RecoveryNetworkId)) { vmRecoveryNetworkId = providerSpecificDetails.SelectedRecoveryAzureNetworkId; } if (string.IsNullOrEmpty(this.LicenseType)) { licenseType = providerSpecificDetails.LicenseType; } availabilitySetId = this.IsParameterBound(c => c.RecoveryAvailabilitySet) ? this.RecoveryAvailabilitySet : providerSpecificDetails.RecoveryAvailabilitySetId; if (string.IsNullOrEmpty(this.UseManagedDisk)) { useManagedDisk = providerSpecificDetails.UseManagedDisks; } if (string.IsNullOrEmpty(this.RecoveryResourceGroupId)) { recoveryResourceGroupId = providerSpecificDetails.RecoveryAzureResourceGroupId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.PrimaryNic))) { primaryNic = providerSpecificDetails.SelectedSourceNicId; } var deploymentType = Utilities.GetValueFromArmId( providerSpecificDetails.TargetVmId, ARMResourceTypeConstants.Providers); if (deploymentType.ToLower() .Contains(Constants.ClassicCompute.ToLower())) { providerSpecificInput = new InMageAzureV2UpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = recoveryResourceGroupId, RecoveryAzureV2ResourceGroupId = null }; } else { providerSpecificInput = new InMageAzureV2UpdateReplicationProtectedItemInput { RecoveryAzureV1ResourceGroupId = null, RecoveryAzureV2ResourceGroupId = recoveryResourceGroupId, UseManagedDisks = useManagedDisk }; } vMNicInputDetailsList = getNicListToUpdate(providerSpecificDetails.VmNics); } else if (provider is A2AReplicationDetails) { A2AReplicationDetails providerSpecificDetails = (A2AReplicationDetails)replicationProtectedItemResponse.Properties.ProviderSpecificDetails; if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryResourceGroupId))) { recoveryResourceGroupId = providerSpecificDetails.RecoveryAzureResourceGroupId; } availabilitySetId = this.IsParameterBound(c => c.RecoveryAvailabilitySet) ? this.RecoveryAvailabilitySet : providerSpecificDetails.RecoveryAvailabilitySet; if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryNetworkId))) { vmRecoveryNetworkId = providerSpecificDetails.SelectedRecoveryAzureNetworkId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryCloudServiceId))) { recoveryCloudServiceId = providerSpecificDetails.RecoveryCloudService; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryBootDiagStorageAccountId))) { this.RecoveryBootDiagStorageAccountId = providerSpecificDetails.RecoveryBootDiagStorageAccountId; } List <A2AVmManagedDiskUpdateDetails> managedDiskUpdateDetails = null; // ManagedDisk case if (this.AzureToAzureUpdateReplicationConfiguration == null && providerSpecificDetails.ProtectedManagedDisks != null) { managedDiskUpdateDetails = new List <A2AVmManagedDiskUpdateDetails>(); foreach (var managedDisk in providerSpecificDetails.ProtectedManagedDisks) { managedDiskUpdateDetails.Add( new A2AVmManagedDiskUpdateDetails( managedDisk.DiskId, managedDisk.RecoveryTargetDiskAccountType, managedDisk.RecoveryReplicaDiskAccountType)); } } else if (this.AzureToAzureUpdateReplicationConfiguration != null && this.AzureToAzureUpdateReplicationConfiguration[0].IsManagedDisk) { managedDiskUpdateDetails = new List <A2AVmManagedDiskUpdateDetails>(); foreach (var managedDisk in this.AzureToAzureUpdateReplicationConfiguration) { managedDiskUpdateDetails.Add( new A2AVmManagedDiskUpdateDetails( managedDisk.DiskId, managedDisk.RecoveryTargetDiskAccountType, managedDisk.RecoveryReplicaDiskAccountType)); } } providerSpecificInput = new A2AUpdateReplicationProtectedItemInput() { RecoveryCloudServiceId = this.RecoveryCloudServiceId, RecoveryResourceGroupId = this.RecoveryResourceGroupId, RecoveryBootDiagStorageAccountId = this.RecoveryBootDiagStorageAccountId, ManagedDiskUpdateDetails = managedDiskUpdateDetails, DiskEncryptionInfo = this.A2AEncryptionDetails(provider) }; vMNicInputDetailsList = getNicListToUpdate(providerSpecificDetails.VmNics); } var updateReplicationProtectedItemInputProperties = new UpdateReplicationProtectedItemInputProperties { RecoveryAzureVMName = vmName, RecoveryAzureVMSize = vmSize, SelectedRecoveryAzureNetworkId = vmRecoveryNetworkId, SelectedSourceNicId = primaryNic, VmNics = vMNicInputDetailsList, LicenseType = licenseType == Management.RecoveryServices.SiteRecovery.Models.LicenseType .NoLicenseType.ToString() ? Management.RecoveryServices.SiteRecovery.Models.LicenseType .NoLicenseType : Management.RecoveryServices.SiteRecovery.Models.LicenseType .WindowsServer, RecoveryAvailabilitySetId = availabilitySetId, ProviderSpecificDetails = providerSpecificInput }; if (provider is HyperVReplicaAzureReplicationDetails || provider is InMageAzureV2ReplicationDetails) { updateReplicationProtectedItemInputProperties.SelectedSourceNicId = primaryNic; } var input = new UpdateReplicationProtectedItemInput { Properties = updateReplicationProtectedItemInputProperties }; var response = this.RecoveryServicesClient.UpdateVmProperties( Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics), Utilities.GetValueFromArmId( this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), this.InputObject.Name, input); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); } }
/// <summary> /// Starts RP Test failover. /// </summary> private void StartRpTestFailover() { // Refresh RP Object var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan( this.RecoveryPlan.Name); var recoveryPlanTestFailoverInputProperties = new RecoveryPlanTestFailoverInputProperties { FailoverDirection = this.Direction == PossibleOperationsDirections.PrimaryToRecovery.ToString() ? PossibleOperationsDirections.PrimaryToRecovery : PossibleOperationsDirections.RecoveryToPrimary, NetworkId = this.networkId, NetworkType = this.networkType, ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>() }; foreach (var replicationProvider in rp.Properties.ReplicationProviders) { if (0 == string.Compare( replicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { if (this.Direction == Constants.PrimaryToRecovery) { var recoveryPlanHyperVReplicaAzureFailoverInput = new RecoveryPlanHyperVReplicaAzureFailoverInput { PrimaryKekCertificatePfx = this.primaryKekCertpfx, SecondaryKekCertificatePfx = this.secondaryKekCertpfx }; recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanHyperVReplicaAzureFailoverInput); } else { throw new ArgumentException( Resources .UnsupportedDirectionForTFO); // Throw Unsupported Direction Exception } } else if (string.Compare( replicationProvider, Constants.InMageAzureV2, StringComparison.OrdinalIgnoreCase) == 0) { // Check if the Direction is PrimaryToRecovery. if (this.Direction == Constants.PrimaryToRecovery) { // Set the Recovery Point Types for InMage. var recoveryPointType = this.RecoveryTag == Constants.RecoveryTagLatestAvailableApplicationConsistent ? InMageV2RpRecoveryPointType.LatestApplicationConsistent : this.RecoveryTag == Constants.RecoveryTagLatest ? InMageV2RpRecoveryPointType.Latest : InMageV2RpRecoveryPointType.LatestProcessed; // Create the InMageAzureV2 Provider specific input. var recoveryPlanInMageAzureV2FailoverInput = new RecoveryPlanInMageAzureV2FailoverInput { RecoveryPointType = recoveryPointType }; // Add the InMageAzureV2 Provider specific input in the Test Failover Input. recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanInMageAzureV2FailoverInput); } } else if (string.Compare( replicationProvider, Constants.InMage, StringComparison.OrdinalIgnoreCase) == 0) { throw new InvalidOperationException( string.Format( Resources.UnsupportedReplicationProviderForTestFailover, this.ReplicationProtectedItem.ReplicationProvider)); } else if (string.Compare( replicationProvider, Constants.A2A, StringComparison.OrdinalIgnoreCase) == 0) { // Set the Recovery Point Types for InMage. var recoveryPointType = this.RecoveryTag == Constants.RecoveryTagLatestAvailableApplicationConsistent ? A2ARpRecoveryPointType.LatestApplicationConsistent : this.RecoveryTag == Constants.RecoveryTagLatest ? A2ARpRecoveryPointType.Latest : this.RecoveryTag == Constants.RecoveryTagLatestAvailableCrashConsistent ? A2ARpRecoveryPointType.LatestCrashConsistent : A2ARpRecoveryPointType.LatestProcessed; // Create the InMageAzureV2 Provider specific input. var recoveryPlanInMageAzureV2FailoverInput = new RecoveryPlanA2AFailoverInput { RecoveryPointType = recoveryPointType, CloudServiceCreationOption = this.CloudServiceCreationOption }; // Add the InMageAzureV2 Provider specific input in the Test Failover Input. recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanInMageAzureV2FailoverInput); } else if (string.Compare( replicationProvider, Constants.InMageRcm, StringComparison.OrdinalIgnoreCase) == 0) { this.MultiVmSyncPoint = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.MultiVmSyncPoint)) ? this.MultiVmSyncPoint : Constants.Disable; var recoveryPointType = this.RecoveryTag == Constants.RecoveryTagLatestAvailableApplicationConsistent ? RecoveryPlanPointType.LatestApplicationConsistent : this.RecoveryTag == Constants.RecoveryTagLatest ? RecoveryPlanPointType.Latest : this.RecoveryTag == Constants.RecoveryTagLatestAvailableCrashConsistent ? RecoveryPlanPointType.LatestCrashConsistent : RecoveryPlanPointType.LatestProcessed; // Check if the direction is PrimaryToRecovery. if (this.Direction == Constants.PrimaryToRecovery) { // Create the InMageRcm provider specific input. var recoveryPlanInMageRcmFailoverInput = new RecoveryPlanInMageRcmFailoverInput { RecoveryPointType = recoveryPointType, UseMultiVmSyncPoint = this.MultiVmSyncPoint == Constants.Enable ? Constants.True : Constants.False }; // Add the InMageRcm provider specific input in the test failover input. recoveryPlanTestFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanInMageRcmFailoverInput); } } else if (string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.InMageRcmFailback, StringComparison.OrdinalIgnoreCase) == 0) { throw new InvalidOperationException( string.Format( Resources.UnsupportedReplicationProviderForTestFailover, this.ReplicationProtectedItem.ReplicationProvider)); } } var recoveryPlanTestFailoverInput = new RecoveryPlanTestFailoverInput { Properties = recoveryPlanTestFailoverInputProperties }; var response = this.RecoveryServicesClient.StartAzureSiteRecoveryTestFailover( this.RecoveryPlan.Name, recoveryPlanTestFailoverInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Creates an InMageAzureV2 / InMage Policy Object. /// </summary> private void V2AandV2VPolicyObject() { // Validate the Replication Provider. if (string.Compare( this.ReplicationProvider, Constants.InMageAzureV2, StringComparison.OrdinalIgnoreCase) != 0 && string.Compare( this.ReplicationProvider, Constants.InMage, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Resources.IncorrectReplicationProvider, this.ReplicationProvider)); } // Set the Default Parameters. this.ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours; this.RecoveryPointRetentionInHours = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryPointRetentionInHours)) ? this.RecoveryPointRetentionInHours : 24; this.RPOWarningThresholdInMinutes = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RPOWarningThresholdInMinutes)) ? this.RPOWarningThresholdInMinutes : 15; this.MultiVmSyncStatus = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.MultiVmSyncStatus)) ? this.MultiVmSyncStatus : Constants.Enable; var crashConsistentFrequencyInMinutes = 5; // Create the Create Policy Input. var createPolicyInput = new CreatePolicyInput { Properties = new CreatePolicyInputProperties() }; // Check the Replication Provider Type. if (string.Compare( this.ReplicationProvider, Constants.InMageAzureV2, StringComparison.OrdinalIgnoreCase) == 0) { // Set the Provider Specific Input for InMageAzureV2. createPolicyInput.Properties.ProviderSpecificInput = new InMageAzureV2PolicyInput { AppConsistentFrequencyInMinutes = this.ApplicationConsistentSnapshotFrequencyInHours * 60, RecoveryPointHistory = this.RecoveryPointRetentionInHours * 60, // Convert from hours to minutes. RecoveryPointThresholdInMinutes = this.RPOWarningThresholdInMinutes, MultiVmSyncStatus = this.MultiVmSyncStatus, CrashConsistentFrequencyInMinutes = crashConsistentFrequencyInMinutes }; } else { // Set the Provider Specific Input for InMage. createPolicyInput.Properties.ProviderSpecificInput = new InMagePolicyInput { AppConsistentFrequencyInMinutes = this.ApplicationConsistentSnapshotFrequencyInHours * 60, RecoveryPointHistory = this.RecoveryPointRetentionInHours * 60, // Convert from hours to minutes. RecoveryPointThresholdInMinutes = this.RPOWarningThresholdInMinutes, MultiVmSyncStatus = this.MultiVmSyncStatus }; } var response = this.RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput); var jobId = PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location); var jobResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(jobId); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Starts recovery plan unplanned failover. /// </summary> private void StartRpUnplannedFailover() { // Refresh RP Object var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan( this.RecoveryPlan.Name); var recoveryPlanUnplannedFailoverInputProperties = new RecoveryPlanUnplannedFailoverInputProperties { FailoverDirection = this.Direction == PossibleOperationsDirections.PrimaryToRecovery.ToString() ? PossibleOperationsDirections.PrimaryToRecovery : PossibleOperationsDirections.RecoveryToPrimary, SourceSiteOperations = this.PerformSourceSideAction ? SourceSiteOperations.Required : SourceSiteOperations.NotRequired, //Required|NotRequired ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>() }; foreach (var replicationProvider in rp.Properties.ReplicationProviders) { if (0 == string.Compare( replicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { if (this.Direction == Constants.PrimaryToRecovery) { var recoveryPlanHyperVReplicaAzureFailoverInput = new RecoveryPlanHyperVReplicaAzureFailoverInput { PrimaryKekCertificatePfx = this.primaryKekCertpfx, SecondaryKekCertificatePfx = this.secondaryKekCertpfx }; if (this.RecoveryTag != null) { var recoveryPointType = this.RecoveryTag == Constants.RecoveryTagLatestAvailableApplicationConsistent ? HyperVReplicaAzureRpRecoveryPointType.LatestApplicationConsistent : this.RecoveryTag == Constants.RecoveryTagLatestAvailable ? HyperVReplicaAzureRpRecoveryPointType.LatestProcessed : HyperVReplicaAzureRpRecoveryPointType.Latest; recoveryPlanHyperVReplicaAzureFailoverInput.RecoveryPointType = recoveryPointType; } recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanHyperVReplicaAzureFailoverInput); } } else if (string.Compare( replicationProvider, Constants.InMageAzureV2, StringComparison.OrdinalIgnoreCase) == 0) { // Check if the Direction is PrimaryToRecovery. if (this.Direction == Constants.PrimaryToRecovery) { // Set the Recovery Point Types for InMage. var recoveryPointType = this.RecoveryTag == Constants.RecoveryTagLatestAvailableApplicationConsistent ? InMageV2RpRecoveryPointType.LatestApplicationConsistent : this.RecoveryTag == Constants.RecoveryTagLatestAvailable ? InMageV2RpRecoveryPointType.LatestProcessed : this.RecoveryTag == Constants.RecoveryTagLatestAvailableCrashConsistent ? InMageV2RpRecoveryPointType.LatestCrashConsistent : InMageV2RpRecoveryPointType.Latest; // Create the InMageAzureV2 Provider specific input. var recoveryPlanInMageAzureV2FailoverInput = new RecoveryPlanInMageAzureV2FailoverInput { RecoveryPointType = recoveryPointType }; // Add the InMageAzureV2 Provider specific input in the Planned Failover Input. recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanInMageAzureV2FailoverInput); } } else if (string.Compare( replicationProvider, Constants.InMage, StringComparison.OrdinalIgnoreCase) == 0) { // Check if the Direction is RecoveryToPrimary. if (this.Direction == Constants.RecoveryToPrimary) { // Set the Recovery Point Types for InMage. var recoveryPointType = this.RecoveryTag == Constants.RecoveryTagLatestAvailableApplicationConsistent ? RpInMageRecoveryPointType.LatestTag : RpInMageRecoveryPointType.LatestTime; // Create the InMage Provider specific input. var recoveryPlanInMageFailoverInput = new RecoveryPlanInMageFailoverInput { RecoveryPointType = recoveryPointType }; // Add the InMage Provider specific input in the Planned Failover Input. recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanInMageFailoverInput); } } else if (0 == string.Compare( replicationProvider, Constants.A2A, StringComparison.OrdinalIgnoreCase)) { string recoveryPointType = A2ARpRecoveryPointType.Latest; switch (this.RecoveryTag) { case Constants.RecoveryTagLatestAvailableCrashConsistent: recoveryPointType = A2ARpRecoveryPointType.LatestCrashConsistent; break; case Constants.RecoveryTagLatestAvailableApplicationConsistent: recoveryPointType = A2ARpRecoveryPointType.LatestApplicationConsistent; break; case Constants.RecoveryTagLatestAvailable: recoveryPointType = A2ARpRecoveryPointType.LatestProcessed; break; case Constants.RecoveryTagLatest: recoveryPointType = A2ARpRecoveryPointType.Latest; break; } var recoveryPlanA2AFailoverInput = new RecoveryPlanA2AFailoverInput() { RecoveryPointType = recoveryPointType }; recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add(recoveryPlanA2AFailoverInput); } else if (string.Compare( replicationProvider, Constants.InMageRcm, StringComparison.OrdinalIgnoreCase) == 0) { var recoveryPointType = this.RecoveryTag == Constants.RecoveryTagLatestAvailableApplicationConsistent ? RecoveryPlanPointType.LatestApplicationConsistent : this.RecoveryTag == Constants.RecoveryTagLatest ? RecoveryPlanPointType.Latest : this.RecoveryTag == Constants.RecoveryTagLatestAvailableCrashConsistent ? RecoveryPlanPointType.LatestCrashConsistent : RecoveryPlanPointType.LatestProcessed; this.MultiVmSyncPoint = this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.MultiVmSyncPoint)) ? this.MultiVmSyncPoint : Constants.Disable; // Check if the direction is PrimaryToRecovery. if (this.Direction == Constants.PrimaryToRecovery) { // Create the InMageRcm provider specific input. var recoveryPlanInMageRcmFailoverInput = new RecoveryPlanInMageRcmFailoverInput { RecoveryPointType = recoveryPointType, UseMultiVmSyncPoint = this.MultiVmSyncPoint == Constants.Enable ? Constants.True : Constants.False }; // Add the InMagRcm provider specific input in the unplanned failover input. recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add( recoveryPlanInMageRcmFailoverInput); } } else if (string.Compare( this.ReplicationProtectedItem.ReplicationProvider, Constants.InMageRcmFailback, StringComparison.OrdinalIgnoreCase) == 0) { throw new InvalidOperationException( string.Format( Resources.UnsupportedReplicationProviderForUnplannedFailover, this.ReplicationProtectedItem.ReplicationProvider)); } } var recoveryPlanUnplannedFailoverInput = new RecoveryPlanUnplannedFailoverInput { Properties = recoveryPlanUnplannedFailoverInputProperties }; var response = this.RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover( this.RecoveryPlan.Name, recoveryPlanUnplannedFailoverInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
private List <VMNicInputDetails> getNicListToUpdate(IList <VMNicDetails> vmNicList) { var vMNicInputDetailsList = new List <VMNicInputDetails>(); // Weather to track NIC found to be updated. IF primary NIC is not or empty no need to update. var nicFoundToBeUpdated = string.IsNullOrEmpty(this.UpdateNic); if (vmNicList != null) { // If VM NICs list provided along with UpdateNic then only the NICs list is // honored. if (this.ASRVMNicConfiguration != null && this.ASRVMNicConfiguration.Count() > 0) { var vmNicIds = vmNicList.Select(nic => nic.NicId); foreach (var nic in this.ASRVMNicConfiguration) { if (!vmNicIds.Contains(nic.NicId, StringComparer.OrdinalIgnoreCase)) { throw new PSInvalidOperationException( Resources.NicNotFoundInVMForUpdateVmProperties); } var vMNicInputDetails = new VMNicInputDetails(); vMNicInputDetails.NicId = nic.NicId; vMNicInputDetails.RecoveryNicName = nic.RecoveryNicName; vMNicInputDetails.RecoveryNicResourceGroupName = nic.RecoveryNicResourceGroupName; vMNicInputDetails.ReuseExistingNic = nic.ReuseExistingNic; vMNicInputDetails.RecoveryVMSubnetName = nic.RecoveryVMSubnetName; vMNicInputDetails.EnableAcceleratedNetworkingOnRecovery = nic.EnableAcceleratedNetworkingOnRecovery; vMNicInputDetails.RecoveryNetworkSecurityGroupId = nic.RecoveryNetworkSecurityGroupId; vMNicInputDetails.ReplicaNicStaticIPAddress = nic.RecoveryIPConfigs?.FirstOrDefault()?.StaticIPAddress; vMNicInputDetails.RecoveryPublicIpAddressId = nic.RecoveryIPConfigs?.FirstOrDefault()?.PublicIpAddressId; vMNicInputDetails.RecoveryLBBackendAddressPoolIds = nic.RecoveryIPConfigs?.FirstOrDefault()?.LBBackendAddressPoolIds; vMNicInputDetails.TfoNicName = nic.TfoNicName; vMNicInputDetails.TfoNicResourceGroupName = nic.TfoNicResourceGroupName; vMNicInputDetails.TfoReuseExistingNic = nic.TfoReuseExistingNic; vMNicInputDetails.TfoVMSubnetName = nic.TfoVMSubnetName; vMNicInputDetails.EnableAcceleratedNetworkingOnTfo = nic.EnableAcceleratedNetworkingOnTfo; vMNicInputDetails.TfoNetworkSecurityGroupId = nic.TfoNetworkSecurityGroupId; vMNicInputDetails.TfoIPConfigs = nic.TfoIPConfigs; vMNicInputDetails.SelectionType = string.IsNullOrEmpty(this.NicSelectionType) ? Constants.SelectedByUser : this.NicSelectionType; vMNicInputDetailsList.Add(vMNicInputDetails); } return(vMNicInputDetailsList); } foreach (var nDetails in vmNicList) { var vMNicInputDetails = new VMNicInputDetails(); if (!string.IsNullOrEmpty(this.UpdateNic) && string.Compare(nDetails.NicId, this.UpdateNic, StringComparison.OrdinalIgnoreCase) == 0) { vMNicInputDetails.NicId = this.UpdateNic; vMNicInputDetails.RecoveryVMSubnetName = this.RecoveryNicSubnetName; vMNicInputDetails.ReplicaNicStaticIPAddress = this.RecoveryNicStaticIPAddress; vMNicInputDetails.SelectionType = string.IsNullOrEmpty(this.NicSelectionType) ? Constants.SelectedByUser : this.NicSelectionType; vMNicInputDetails.RecoveryLBBackendAddressPoolIds = this.RecoveryLBBackendAddressPoolId?.ToList(); vMNicInputDetails.RecoveryPublicIpAddressId = this.RecoveryPublicIPAddressId; vMNicInputDetails.RecoveryNetworkSecurityGroupId = this.RecoveryNetworkSecurityGroupId; vMNicInputDetailsList.Add(vMNicInputDetails); // NicId matched for update nicFoundToBeUpdated = true; if (this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.EnableAcceleratedNetworkingOnRecovery))) { vMNicInputDetails.EnableAcceleratedNetworkingOnRecovery = true; } else { vMNicInputDetails.EnableAcceleratedNetworkingOnRecovery = false; } } else { vMNicInputDetails.NicId = nDetails.NicId; vMNicInputDetails.RecoveryVMSubnetName = nDetails.RecoveryVMSubnetName; vMNicInputDetails.ReplicaNicStaticIPAddress = nDetails.ReplicaNicStaticIPAddress; vMNicInputDetails.SelectionType = nDetails.SelectionType; vMNicInputDetailsList.Add(vMNicInputDetails); vMNicInputDetails.EnableAcceleratedNetworkingOnRecovery = nDetails.EnableAcceleratedNetworkingOnRecovery; vMNicInputDetails.RecoveryLBBackendAddressPoolIds = nDetails.RecoveryLBBackendAddressPoolIds; vMNicInputDetails.RecoveryPublicIpAddressId = nDetails.RecoveryPublicIpAddressId; vMNicInputDetails.RecoveryNetworkSecurityGroupId = nDetails.RecoveryNetworkSecurityGroupId; } } } if (!nicFoundToBeUpdated) { throw new PSInvalidOperationException(Resources.NicNotFoundInVMForUpdateVmProperties); } return(vMNicInputDetailsList); }
/// <summary> /// ProcessRecord of the command. /// </summary> public override void ExecuteSiteRecoveryCmdlet() { base.ExecuteSiteRecoveryCmdlet(); ASRVMNicConfig nicConfig = null; switch (this.ParameterSetName) { case ASRParameterSets.AzureToAzure: var providerSpecificDetails = this.ReplicationProtectedItem.ProviderSpecificDetails; if (!(providerSpecificDetails is ASRAzureToAzureSpecificRPIDetails)) { this.WriteWarning( Resources.UnsupportedReplicationProvidedForASRVMNicConfig); return; } var vmNicDetailsList = this.ReplicationProtectedItem.NicDetailsList ?? new List <ASRVMNicDetails>(); var vmNic = vmNicDetailsList.FirstOrDefault( nic => nic.NicId.Equals( this.NicId, StringComparison.OrdinalIgnoreCase)); if (vmNic == null) { this.WriteWarning(string.Format(Resources.NicNotFoundInVM, this.NicId)); return; } if (this.IPConfig != null) { if (!ValidateAndPopulateIPConfigs(vmNic)) { return; } } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryVMNetworkId))) { this.RecoveryVMNetworkId = this.ReplicationProtectedItem.SelectedRecoveryAzureNetworkId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.RecoveryNetworkSecurityGroupId))) { this.RecoveryNetworkSecurityGroupId = vmNic.RecoveryNetworkSecurityGroupId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.EnableAcceleratedNetworkingOnRecovery))) { this.EnableAcceleratedNetworkingOnRecovery = vmNic.EnableAcceleratedNetworkingOnRecovery ?? false; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.TfoVMNetworkId))) { this.TfoVMNetworkId = this.ReplicationProtectedItem.SelectedTfoAzureNetworkId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.TfoNetworkSecurityGroupId))) { this.TfoNetworkSecurityGroupId = vmNic.TfoNetworkSecurityGroupId; } if (!this.MyInvocation.BoundParameters.ContainsKey( Utilities.GetMemberName(() => this.EnableAcceleratedNetworkingOnTfo))) { this.EnableAcceleratedNetworkingOnTfo = vmNic.EnableAcceleratedNetworkingOnTfo ?? false; } List <PSIPConfigInputDetails> ipConfigList = null; if (this.IPConfig == null || this.IPConfig.ToList().Count == 0) { ipConfigList = vmNic.IpConfigs?.Select(ip => ConvertToPSIPConfig(ip))?.ToList() ?? null; } else if (vmNic.IpConfigs != null) { ipConfigList = this.IPConfig.ToList(); // NIC IP config names in lowercase. var inputIPConfigNames = this.IPConfig.Select(ip => ip.IPConfigName.ToLower()); foreach (IPConfigDetails ipConfig in vmNic.IpConfigs) { if (inputIPConfigNames.Contains(ipConfig.Name.ToLower())) { continue; } // Defaulting logic for IP configs whose input is not ipConfigList.Add(ConvertToPSIPConfig(ipConfig)); } } nicConfig = new ASRVMNicConfig { NicId = this.NicId, RecoveryVMNetworkId = this.RecoveryVMNetworkId, RecoveryNicName = this.RecoveryNicName, RecoveryNicResourceGroupName = this.RecoveryNicResourceGroupName, ReuseExistingNic = this.ReuseExistingNic, RecoveryNetworkSecurityGroupId = this.RecoveryNetworkSecurityGroupId, EnableAcceleratedNetworkingOnRecovery = this.EnableAcceleratedNetworkingOnRecovery, IPConfigs = ipConfigList, TfoVMNetworkId = this.TfoVMNetworkId, TfoNicName = this.TfoNicName, TfoNicResourceGroupName = this.TfoNicResourceGroupName, TfoReuseExistingNic = this.TfoReuseExistingNic, TfoNetworkSecurityGroupId = this.TfoNetworkSecurityGroupId, EnableAcceleratedNetworkingOnTfo = this.EnableAcceleratedNetworkingOnTfo }; break; } this.WriteObject(nicConfig); }