/// <summary> /// Creates Replication Plan Legacy. /// </summary> private void CreateRecoveryPlanLegacy() { CreateRecoveryPlanInputProperties createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties() { FailoverDeploymentModel = failoverDeploymentModel, Groups = new List <RecoveryPlanGroup>(), PrimaryFabricId = this.primaryserver, RecoveryFabricId = this.recoveryserver }; RecoveryPlanGroup recoveryPlanGroup = new RecoveryPlanGroup() { GroupType = Constants.Boot, ReplicationProtectedItems = new List <RecoveryPlanProtectedItem>(), StartGroupActions = new List <RecoveryPlanAction>(), EndGroupActions = new List <RecoveryPlanAction>() }; foreach (ASRProtectionEntity pe in ProtectionEntityList) { string fabricName = Utilities.GetValueFromArmId(pe.ID, ARMResourceTypeConstants.ReplicationFabrics); // fetch the latest PE object ProtectableItemResponse protectableItemResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(fabricName, pe.ProtectionContainerId, pe.Name); ReplicationProtectedItemResponse replicationProtectedItemResponse = RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(fabricName, pe.ProtectionContainerId, Utilities.GetValueFromArmId(protectableItemResponse.ProtectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems)); string VmId = null; if (replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProviderSpecificDetails.GetType() == typeof(HyperVReplicaAzureReplicationDetails)) { VmId = ((HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProviderSpecificDetails.GetType() == typeof(HyperVReplica2012ReplicationDetails)) { VmId = ((HyperVReplica2012ReplicationDetails)replicationProtectedItemResponse.ReplicationProtectedItem.Properties.ProviderSpecificDetails).VmId; } RecoveryPlanProtectedItem recoveryPlanProtectedItem = new RecoveryPlanProtectedItem(); recoveryPlanProtectedItem.Id = replicationProtectedItemResponse.ReplicationProtectedItem.Id; recoveryPlanProtectedItem.VirtualMachineId = VmId; recoveryPlanGroup.ReplicationProtectedItems.Add(recoveryPlanProtectedItem); } createRecoveryPlanInputProperties.Groups.Add(recoveryPlanGroup); CreateRecoveryPlanInput createRecoveryPlanInput = new CreateRecoveryPlanInput() { Properties = createRecoveryPlanInputProperties }; CreateRecoveryPlan(this.Name, createRecoveryPlanInput); }
/// <summary> /// Create Replication Plan: Utility call /// </summary> private void CreateRecoveryPlan(string recoveryPlanName, CreateRecoveryPlanInput createRecoveryPlanInput) { LongRunningOperationResponse response = RecoveryServicesClient.CreateAzureSiteRecoveryRecoveryPlan(recoveryPlanName, createRecoveryPlanInput); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Create Replication Plan: Utility call /// </summary> private void CreateRecoveryPlan( string recoveryPlanName, CreateRecoveryPlanInput createRecoveryPlanInput) { var response = this.RecoveryServicesClient.CreateAzureSiteRecoveryRecoveryPlan( recoveryPlanName, createRecoveryPlanInput); var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails( PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); this.WriteObject(new ASRJob(jobResponse)); }
/// <summary> /// Starts Creating Recovery Plan. /// </summary> /// <param name="recoveryPlanName">Recovery Plan Name</param> /// <param name="input">Create Recovery Plan Input</param> /// <returns>Job response</returns> public PSSiteRecoveryLongRunningOperation CreateAzureSiteRecoveryRecoveryPlan( string recoveryPlanName, CreateRecoveryPlanInput input) { var op = this.GetSiteRecoveryClient() .ReplicationRecoveryPlans.BeginCreateWithHttpMessagesAsync( recoveryPlanName, input, this.GetRequestHeaders(true)) .GetAwaiter() .GetResult(); var result = Mapper.Map <PSSiteRecoveryLongRunningOperation>(op); return(result); }
/// <summary> /// Create Recovery Plan: By Service object /// </summary> private void CreateRecoveryPlan(RecoveryPlan recoveryPlan) { CreateRecoveryPlanInputProperties createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties() { FailoverDeploymentModel = recoveryPlan.Properties.FailoverDeploymentModel, Groups = recoveryPlan.Properties.Groups, PrimaryFabricId = recoveryPlan.Properties.PrimaryFabricId, RecoveryFabricId = recoveryPlan.Properties.RecoveryFabricId }; CreateRecoveryPlanInput createRecoveryPlanInput = new CreateRecoveryPlanInput() { Properties = createRecoveryPlanInputProperties }; CreateRecoveryPlan(recoveryPlan.Name, createRecoveryPlanInput); }
/// <summary> /// Create Recovery Plan: By Service object /// </summary> private void CreateRecoveryPlan( RecoveryPlan recoveryPlan) { var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties { FailoverDeploymentModel = recoveryPlan.Properties.FailoverDeploymentModel, Groups = recoveryPlan.Properties.Groups, PrimaryFabricId = recoveryPlan.Properties.PrimaryFabricId, RecoveryFabricId = recoveryPlan.Properties.RecoveryFabricId }; if (recoveryPlan.Properties.ProviderSpecificDetails != null && recoveryPlan.Properties.ProviderSpecificDetails.Count > 0) { createRecoveryPlanInputProperties.ProviderSpecificInput = new List <RecoveryPlanProviderSpecificInput>(); foreach (var providerSpecificDetails in recoveryPlan.Properties.ProviderSpecificDetails) { if (providerSpecificDetails is RecoveryPlanA2ADetails) { var a2aProviderDetails = (RecoveryPlanA2ADetails)providerSpecificDetails; var psd = new RecoveryPlanA2AInput { RecoveryZone = a2aProviderDetails.RecoveryZone, PrimaryZone = a2aProviderDetails.PrimaryZone }; createRecoveryPlanInputProperties.ProviderSpecificInput.Add(psd); } } } var createRecoveryPlanInput = new CreateRecoveryPlanInput { Properties = createRecoveryPlanInputProperties }; this.CreateRecoveryPlan( recoveryPlan.Name, createRecoveryPlanInput); }
private static CreateRecoveryPlanInput GetE2EInput(string fabricId, string vmId) { CreateRecoveryPlanInput input = new CreateRecoveryPlanInput(); input.Properties = new CreateRecoveryPlanInputProperties(); input.Properties.PrimaryFabricId = fabricId; input.Properties.RecoveryFabricId = fabricId; input.Properties.Groups = new List <RecoveryPlanGroup>(); input.Properties.Groups.Add(new RecoveryPlanGroup() { GroupType = "Boot", ReplicationProtectedItems = new List <RecoveryPlanProtectedItem>() { new RecoveryPlanProtectedItem() { Id = vmId } } }); return(input); }
/// <summary> /// Create Recovery Plan: By Service object /// </summary> private void CreateRecoveryPlan( RecoveryPlan recoveryPlan) { var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties { FailoverDeploymentModel = (FailoverDeploymentModel)Enum.Parse( typeof(FailoverDeploymentModel), recoveryPlan.Properties.FailoverDeploymentModel), Groups = recoveryPlan.Properties.Groups, PrimaryFabricId = recoveryPlan.Properties.PrimaryFabricId, RecoveryFabricId = recoveryPlan.Properties.RecoveryFabricId }; var createRecoveryPlanInput = new CreateRecoveryPlanInput { Properties = createRecoveryPlanInputProperties }; this.CreateRecoveryPlan( recoveryPlan.Name, createRecoveryPlanInput); }
private static CreateRecoveryPlanInput GetE2AInput(string fabricId, string vmId) { CreateRecoveryPlanInput input = new CreateRecoveryPlanInput(); input.Properties = new CreateRecoveryPlanInputProperties(); input.Properties.PrimaryFabricId = fabricId; input.Properties.RecoveryFabricId = "microsoft azure"; input.Properties.FailoverDeploymentModel = "Classic"; input.Properties.Groups = new List <RecoveryPlanGroup>(); input.Properties.Groups.Add(new RecoveryPlanGroup() { GroupType = "Boot", ReplicationProtectedItems = new List <RecoveryPlanProtectedItem>() { new RecoveryPlanProtectedItem() { Id = vmId } } }); return(input); }
/// <summary> /// Creates Replication Plan /// </summary> private void CreateRecoveryPlan() { var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties { FailoverDeploymentModel = (FailoverDeploymentModel)Enum.Parse( typeof(FailoverDeploymentModel), this.failoverDeploymentModel), Groups = new List <RecoveryPlanGroup>(), PrimaryFabricId = this.primaryserver, RecoveryFabricId = this.recoveryserver }; var recoveryPlanGroup = new RecoveryPlanGroup { GroupType = RecoveryPlanGroupType.Boot, ReplicationProtectedItems = new List <RecoveryPlanProtectedItem>(), StartGroupActions = new List <RecoveryPlanAction>(), EndGroupActions = new List <RecoveryPlanAction>() }; foreach (var rpi in this.ReplicationProtectedItem) { var fabricName = Utilities.GetValueFromArmId( rpi.ID, ARMResourceTypeConstants.ReplicationFabrics); var replicationProtectedItemResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryReplicationProtectedItem( fabricName, Utilities.GetValueFromArmId( rpi.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), rpi.Name); string VmId = null; if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails.GetType() == typeof(HyperVReplicaAzureReplicationDetails)) { VmId = ((HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(HyperVReplicaReplicationDetails)) { VmId = ((HyperVReplicaReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(HyperVReplicaBlueReplicationDetails)) { VmId = ((HyperVReplicaBlueReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(InMageAzureV2ReplicationDetails)) { VmId = ((InMageAzureV2ReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(InMageReplicationDetails)) { VmId = ((InMageReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails.GetType() == typeof(A2AReplicationDetails)) { A2AReplicationDetails a2aReplicationDetails = ((A2AReplicationDetails)replicationProtectedItemResponse .Properties .ProviderSpecificDetails); if (a2aReplicationDetails.FabricObjectId.IndexOf( Constants.ClassicCompute, StringComparison.OrdinalIgnoreCase) >= 0) { createRecoveryPlanInputProperties.FailoverDeploymentModel = Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.Classic; } else if (a2aReplicationDetails.FabricObjectId.IndexOf( Constants.Compute, StringComparison.OrdinalIgnoreCase) >= 0) { createRecoveryPlanInputProperties.FailoverDeploymentModel = Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.ResourceManager; } } var recoveryPlanProtectedItem = new RecoveryPlanProtectedItem(); recoveryPlanProtectedItem.Id = replicationProtectedItemResponse.Id; recoveryPlanProtectedItem.VirtualMachineId = VmId; recoveryPlanGroup.ReplicationProtectedItems.Add(recoveryPlanProtectedItem); } createRecoveryPlanInputProperties.Groups.Add(recoveryPlanGroup); var createRecoveryPlanInput = new CreateRecoveryPlanInput { Properties = createRecoveryPlanInputProperties }; this.CreateRecoveryPlan( this.Name, createRecoveryPlanInput); }
/// <summary> /// Creates Replication Plan /// </summary> private void CreateRecoveryPlan() { var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties { FailoverDeploymentModel = this.failoverDeploymentModel, Groups = new List <RecoveryPlanGroup>(), PrimaryFabricId = this.primaryserver, RecoveryFabricId = this.recoveryserver }; var recoveryPlanGroup = new RecoveryPlanGroup { GroupType = RecoveryPlanGroupType.Boot, ReplicationProtectedItems = new List <RecoveryPlanProtectedItem>(), StartGroupActions = new List <RecoveryPlanAction>(), EndGroupActions = new List <RecoveryPlanAction>() }; foreach (var rpi in this.ReplicationProtectedItem) { var fabricName = Utilities.GetValueFromArmId( rpi.ID, ARMResourceTypeConstants.ReplicationFabrics); var replicationProtectedItemResponse = this.RecoveryServicesClient .GetAzureSiteRecoveryReplicationProtectedItem( fabricName, Utilities.GetValueFromArmId( rpi.ID, ARMResourceTypeConstants.ReplicationProtectionContainers), rpi.Name); string VmId = null; if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails.GetType() == typeof(HyperVReplicaAzureReplicationDetails)) { VmId = ((HyperVReplicaAzureReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(HyperVReplicaReplicationDetails)) { VmId = ((HyperVReplicaReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(HyperVReplicaBlueReplicationDetails)) { VmId = ((HyperVReplicaBlueReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(InMageAzureV2ReplicationDetails)) { VmId = ((InMageAzureV2ReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(InMageReplicationDetails)) { VmId = ((InMageReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).VmId; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails.GetType() == typeof(A2AReplicationDetails)) { A2AReplicationDetails a2aReplicationDetails = ((A2AReplicationDetails)replicationProtectedItemResponse .Properties .ProviderSpecificDetails); if (a2aReplicationDetails.FabricObjectId.IndexOf( Constants.ClassicCompute, StringComparison.OrdinalIgnoreCase) >= 0) { createRecoveryPlanInputProperties.FailoverDeploymentModel = Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.Classic; } else if (a2aReplicationDetails.FabricObjectId.IndexOf( Constants.Compute, StringComparison.OrdinalIgnoreCase) >= 0) { createRecoveryPlanInputProperties.FailoverDeploymentModel = Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.ResourceManager; } } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(InMageRcmReplicationDetails)) { VmId = ((InMageRcmReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).InternalIdentifier; createRecoveryPlanInputProperties.FailoverDeploymentModel = Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.ResourceManager; } else if (replicationProtectedItemResponse.Properties.ProviderSpecificDetails .GetType() == typeof(InMageRcmFailbackReplicationDetails)) { VmId = ((InMageRcmFailbackReplicationDetails)replicationProtectedItemResponse .Properties.ProviderSpecificDetails).InternalIdentifier; createRecoveryPlanInputProperties.FailoverDeploymentModel = Management.RecoveryServices.SiteRecovery.Models.FailoverDeploymentModel.ResourceManager; } var recoveryPlanProtectedItem = new RecoveryPlanProtectedItem(); recoveryPlanProtectedItem.Id = replicationProtectedItemResponse.Id; recoveryPlanProtectedItem.VirtualMachineId = VmId; recoveryPlanGroup.ReplicationProtectedItems.Add(recoveryPlanProtectedItem); } createRecoveryPlanInputProperties.Groups.Add(recoveryPlanGroup); // Add zone to zone details. if (this.ParameterSetName == ASRParameterSets.AzureZoneToZone) { var recoveryPlanA2AInput = new RecoveryPlanA2AInput { PrimaryZone = this.PrimaryZone, RecoveryZone = this.RecoveryZone, PrimaryExtendedLocation = this.IsParameterBound(c => c.PrimaryEdgeZone) ? new ExtendedLocation { Name = this.PrimaryEdgeZone } : null, RecoveryExtendedLocation = this.IsParameterBound(c => c.RecoveryEdgeZone) ? new ExtendedLocation { Name = this.RecoveryEdgeZone } : null }; createRecoveryPlanInputProperties.ProviderSpecificInput = new List <RecoveryPlanProviderSpecificInput>(); createRecoveryPlanInputProperties.ProviderSpecificInput.Add(recoveryPlanA2AInput); } var createRecoveryPlanInput = new CreateRecoveryPlanInput { Properties = createRecoveryPlanInputProperties }; this.CreateRecoveryPlan( this.Name, createRecoveryPlanInput); }
/// <summary> /// Creates a recovery plan. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.SiteRecovery.IRecoveryPlanOperations. /// </param> /// <param name='recoveryPlanName'> /// Required. Recovery plan name. /// </param> /// <param name='input'> /// Required. Create recovery plan input. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static Task <LongRunningOperationResponse> BeginCreatingAsync(this IRecoveryPlanOperations operations, string recoveryPlanName, CreateRecoveryPlanInput input, CustomRequestHeaders customRequestHeaders) { return(operations.BeginCreatingAsync(recoveryPlanName, input, customRequestHeaders, CancellationToken.None)); }
/// <summary> /// Creates a recovery plan with the given details. /// </summary> /// <remarks> /// The operation to create a recovery plan. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='recoveryPlanName'> /// Recovery plan name. /// </param> /// <param name='input'> /// Recovery Plan creation input. /// </param> public static RecoveryPlan BeginCreate(this IReplicationRecoveryPlansOperations operations, string recoveryPlanName, CreateRecoveryPlanInput input) { return(operations.BeginCreateAsync(recoveryPlanName, input).GetAwaiter().GetResult()); }
private static CreateRecoveryPlanInput GetCreateInput2(string fabricId, string vmId) { CreateRecoveryPlanInput input = new CreateRecoveryPlanInput(); input.Properties = new CreateRecoveryPlanInputProperties(); input.Properties.PrimaryFabricId = fabricId; input.Properties.RecoveryFabricId = fabricId; input.Properties.Groups = new List <RecoveryPlanGroup>(); input.Properties.Groups.Add(new RecoveryPlanGroup() { GroupType = "Shutdown", ReplicationProtectedItems = new List <RecoveryPlanProtectedItem>() { new RecoveryPlanProtectedItem() { Id = vmId } }, StartGroupActions = new List <RecoveryPlanAction>() { new RecoveryPlanAction() { ActionName = "S2", FailoverTypes = new List <string>() { "PlannedFailover" }, FailoverDirections = new List <string>() { "PrimaryToRecovery" }, CustomDetails = new RecoveryPlanScriptActionDetails() { FabricLocation = "Primary", Path = "path2", Timeout = null } }, new RecoveryPlanAction() { ActionName = "M2", FailoverTypes = new List <string>() { "UnplannedFailover" }, FailoverDirections = new List <string>() { "RecoveryToPrimary" }, CustomDetails = new RecoveryPlanManualActionDetails() { Description = "desc2" } } }, EndGroupActions = new List <RecoveryPlanAction>() { } }); return(input); }
/// <summary> /// Starts Creating Recovery Plan. /// </summary> /// <param name="recoveryPlanName">Recovery Plan Name</param> /// <param name="input">Create Recovery Plan Input</param> /// <returns>Job response</returns> public LongRunningOperationResponse CreateAzureSiteRecoveryRecoveryPlan(string recoveryPlanName, CreateRecoveryPlanInput input) { return(this.GetSiteRecoveryClient().RecoveryPlan.BeginCreating(recoveryPlanName, input, this.GetRequestHeaders())); }
/// <summary> /// Creates a recovery plan with the given details. /// </summary> /// <remarks> /// The operation to create a recovery plan. /// </remarks> /// <param name='operations'> /// The operations group for this extension method. /// </param> /// <param name='recoveryPlanName'> /// Recovery plan name. /// </param> /// <param name='input'> /// Recovery Plan creation input. /// </param> /// <param name='cancellationToken'> /// The cancellation token. /// </param> public static async Task <RecoveryPlan> BeginCreateAsync(this IReplicationRecoveryPlansOperations operations, string recoveryPlanName, CreateRecoveryPlanInput input, CancellationToken cancellationToken = default(CancellationToken)) { using (var _result = await operations.BeginCreateWithHttpMessagesAsync(recoveryPlanName, input, null, cancellationToken).ConfigureAwait(false)) { return(_result.Body); } }
/// <summary> /// Creates a recovery plan. /// </summary> /// <param name='operations'> /// Reference to the /// Microsoft.Azure.Management.SiteRecovery.IRecoveryPlanOperations. /// </param> /// <param name='recoveryPlanName'> /// Required. Recovery plan name. /// </param> /// <param name='input'> /// Required. Create recovery plan input. /// </param> /// <param name='customRequestHeaders'> /// Optional. Request header parameters. /// </param> /// <returns> /// A standard service response for long running operations. /// </returns> public static LongRunningOperationResponse BeginCreating(this IRecoveryPlanOperations operations, string recoveryPlanName, CreateRecoveryPlanInput input, CustomRequestHeaders customRequestHeaders) { return(Task.Factory.StartNew((object s) => { return ((IRecoveryPlanOperations)s).BeginCreatingAsync(recoveryPlanName, input, customRequestHeaders); } , operations, CancellationToken.None, TaskCreationOptions.None, TaskScheduler.Default).Unwrap().GetAwaiter().GetResult()); }