public static CreatePolicyOperationResponse CreateHyperVReplicaAzurePolicy( this SiteRecoveryManagementClient client, string armResourceName, string storageAccountArmId) { HyperVReplicaAzurePolicyInput hvrAPolicy = new HyperVReplicaAzurePolicyInput() { ApplicationConsistentSnapshotFrequencyInHours = 0, Encryption = "Disable", OnlineIrStartTime = null, RecoveryPointHistoryDuration = 0, ReplicationInterval = 30, StorageAccounts = new List <string>() { storageAccountArmId } }; CreatePolicyInputProperties createInputProp = new CreatePolicyInputProperties() { ProviderSpecificInput = hvrAPolicy }; CreatePolicyInput policyInput = new CreatePolicyInput() { Properties = createInputProp }; return(client.Policies.Create(armResourceName, policyInput, GetRequestHeaders()) as CreatePolicyOperationResponse); }
public static CreatePolicyOperationResponse CreateHyperV2012R2Policy( this SiteRecoveryManagementClient client, string armResourceName) { HyperVReplica2012R2PolicyInput hvrProfileInput = new HyperVReplica2012R2PolicyInput() { ApplicationConsistentSnapshotFrequencyInHours = 0, AllowedAuthenticationType = 1, Compression = "Enable", InitialReplicationMethod = "OverNetwork", OnlineReplicationStartTime = null, RecoveryPoints = 0, ReplicaDeletion = "Required", ReplicationPort = 8083, ReplicationFrequencyInSeconds = 300 }; CreatePolicyInputProperties policyCreationProp = new CreatePolicyInputProperties() { ProviderSpecificInput = hvrProfileInput }; CreatePolicyInput policyCreationInput = new CreatePolicyInput() { Properties = policyCreationProp }; return(client.Policies.Create( armResourceName, policyCreationInput, GetRequestHeaders()) as CreatePolicyOperationResponse); }
public static List <ProtectableItem> GetUnprotectedItems( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer container) { List <ProtectableItem> protectableItemList = new List <ProtectableItem>(); ProtectableItemListResponse protectableItemListResponse = client.ProtectableItem.List( primaryFabric.Name, container.Name, "Unprotected", null, "1000", GetRequestHeaders()); protectableItemList.AddRange(protectableItemListResponse.ProtectableItems); while (protectableItemListResponse.NextLink != null) { protectableItemListResponse = client.ProtectableItem.ListNext( protectableItemListResponse.NextLink, GetRequestHeaders()); protectableItemList.AddRange(protectableItemListResponse.ProtectableItems); } return(protectableItemList); }
public static MappingOperationResponse PairCloudToAzure( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer primaryContainer, Policy policy, string armResourceName) { CreateProtectionContainerMappingInputProperties pairingProps = new CreateProtectionContainerMappingInputProperties() { PolicyId = policy.Id, TargetProtectionContainerId = "Microsoft Azure", ProviderSpecificInput = new ReplicationProviderContainerMappingInput() }; CreateProtectionContainerMappingInput pairingInput = new CreateProtectionContainerMappingInput() { Properties = pairingProps }; return(client.ProtectionContainerMapping.ConfigureProtection( primaryFabric.Name, primaryContainer.Name, armResourceName, pairingInput, GetRequestHeaders()) as MappingOperationResponse); }
/// <summary> /// Monitors jobs for specific object id. /// </summary> /// <param name="jobName">Name of the job to monitor.</param> /// <param name="startTime">Start time of job</param> /// <param name="client">SiteRecovery client.</param> /// <param name="requestHeaders">Request headers.</param> public static void MonitorJobs( string jobName, DateTime startTime, SiteRecoveryManagementClient client, CustomRequestHeaders requestHeaders) { bool trackingFinished = false; while (!trackingFinished) { if (!trackingFinished) { Thread.Sleep(new TimeSpan(0, 1, 0)); } JobQueryParameter queryParam = new JobQueryParameter(); JobListResponse jobList = client.Jobs.List(queryParam, requestHeaders); trackingFinished = true; foreach (var job in jobList.Jobs) { if (job.Properties.ScenarioName.Contains(jobName) && job.Properties.State.Equals( "InProgress", StringComparison.InvariantCultureIgnoreCase)) { trackingFinished = false; break; } } } }
public T GetServiceClient <T>() where T : class { var factory = (TestEnvironmentFactory) new CSMTestEnvironmentFactory(); var testEnvironment = factory.GetTestEnvironment(); ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler; var credentials = new SubscriptionCredentialsAdapter( testEnvironment.AuthorizationContext.TokenCredentials[TokenAudience.Management], testEnvironment.SubscriptionId); if (typeof(T) == typeof(SiteRecoveryVaultManagementClient)) { SiteRecoveryVaultManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new SiteRecoveryVaultManagementClient( "Microsoft.SiteRecoveryBVTD2", "SiteRecoveryVault", credentials, testEnvironment.BaseUri); } else { client = new SiteRecoveryVaultManagementClient( "Microsoft.SiteRecovery", "SiteRecoveryVault", credentials); } return(GetRSMServiceClient <T>(factory, client)); } else { SiteRecoveryManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new SiteRecoveryManagementClient( asrVaultCreds.ResourceName, asrVaultCreds.ResourceGroupName, "Microsoft.SiteRecoveryBVTD2", "SiteRecoveryVault", credentials, testEnvironment.BaseUri); } else { client = new SiteRecoveryManagementClient( asrVaultCreds.ResourceName, asrVaultCreds.ResourceGroupName, "Microsoft.SiteRecovery", "vaults", credentials); } return(GetSRMServiceClient <T>(factory, client)); } }
public static LongRunningOperationResponse RemovePolicy( this SiteRecoveryManagementClient client, string armResourceName) { return(client.Policies.Delete( armResourceName, GetRequestHeaders())); }
public T GetServiceClient <T>() where T : class { var factory = (TestEnvironmentFactory) new CSMTestEnvironmentFactory(); var testEnvironment = factory.GetTestEnvironment(); ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler; if (typeof(T) == typeof(RecoveryServicesManagementClient)) { RecoveryServicesManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new RecoveryServicesManagementClient( "Microsoft.RecoveryServices", "vaults", testEnvironment.Credentials as SubscriptionCloudCredentials, testEnvironment.BaseUri); } else { client = new RecoveryServicesManagementClient( "Microsoft.RecoveryServices", "vaults", testEnvironment.Credentials as SubscriptionCloudCredentials); } return(GetRSMServiceClient <T>(factory, client)); } else { SiteRecoveryManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new SiteRecoveryManagementClient( asrVaultCreds.ResourceName, asrVaultCreds.ResourceGroupName, "Microsoft.RecoveryServices", "vaults", testEnvironment.Credentials as SubscriptionCloudCredentials, testEnvironment.BaseUri); } else { client = new SiteRecoveryManagementClient( asrVaultCreds.ResourceName, asrVaultCreds.ResourceGroupName, "Microsoft.RecoveryServices", "vaults", testEnvironment.Credentials as SubscriptionCloudCredentials); } return(GetSRMServiceClient <T>(factory, client)); } }
public static LongRunningOperationResponse TestFailover( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer protectionContainer, ReplicationProtectedItem protectedItem) { TestFailoverInput tfoInput = new TestFailoverInput() { Properties = new TestFailoverInputProperties() { ProviderSpecificDetails = new ProviderSpecificFailoverInput() } }; if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure") { HyperVReplicaAzureFailoverProviderInput hvrAFOInput = new HyperVReplicaAzureFailoverProviderInput() { VaultLocation = "West US", }; string networkId = (protectedItem.Properties.ProviderSpecificDetails as HyperVReplicaAzureReplicationDetails) .SelectedRecoveryAzureNetworkId; TestFailoverInputProperties tfoProp = new TestFailoverInputProperties() { ProviderSpecificDetails = hvrAFOInput, NetworkType = string.IsNullOrEmpty(networkId) ? null : "VmNetworkAsInput", NetworkId = networkId }; tfoInput.Properties = tfoProp; } DateTime startTFO = DateTime.UtcNow; var tfoOp = client.ReplicationProtectedItem.TestFailover( primaryFabric.Name, protectionContainer.Name, protectedItem.Name, tfoInput, GetRequestHeaders()); var jobs = MonitoringHelper.GetJobId(MonitoringHelper.TestFailoverJobName, startTFO, client, GetRequestHeaders()); ResumeJobParamsProperties resProp = new ResumeJobParamsProperties() { Comments = "Res TFO" }; ResumeJobParams resParam = new ResumeJobParams() { Properties = resProp }; return(client.Jobs.Resume(jobs.Name, resParam, GetRequestHeaders())); }
protected void SetupManagementClients(string scenario, RestTestFramework.MockContext context) { RmRestClient = GetRmRestClient(context); RecoveryServicesMgmtClient = GetRecoveryServicesManagementClient(context); SiteRecoveryMgmtClient = GetSiteRecoveryManagementClient(scenario, context); _helper.SetupManagementClients( RmRestClient, RecoveryServicesMgmtClient, SiteRecoveryMgmtClient); }
public static List <ProtectionContainer> GetPairedContainers( this SiteRecoveryManagementClient client, Fabric primaryFabric) { var protectionContainers = client.ProtectionContainer.List( primaryFabric.Name, GetRequestHeaders()); return(protectionContainers.ProtectionContainers .ToList().TakeWhile(item => item.Properties.PairingStatus == "Paired").ToList()); }
public static LongRunningOperationResponse UnpairStorageClassification( this SiteRecoveryManagementClient client, Fabric primaryFabric, StorageClassification primaryClassification, string armResourceName) { return(client.StorageClassificationMapping.UnpairStorageClassification( primaryFabric.Name, primaryClassification.Name, armResourceName, GetRequestHeaders())); }
public static ReplicationProtectedItemOperationResponse CommitFailover( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer protectionContainer, ReplicationProtectedItem protectedItem) { return(client.ReplicationProtectedItem.CommitFailover( primaryFabric.Name, protectionContainer.Name, protectedItem.Name, GetRequestHeaders()) as ReplicationProtectedItemOperationResponse); }
public static LongRunningOperationResponse DisableDR( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer protectionContainer, string armResourceName) { return(client.ReplicationProtectedItem.DisableProtection( primaryFabric.Name, protectionContainer.Name, armResourceName, new DisableProtectionInput(), GetRequestHeaders())); }
protected void WaitForJobToComplete(SiteRecoveryManagementClient client, string jobId) { var responseJob = client.Jobs.Get(jobId, RequestHeaders); while (responseJob.Job.StateDescription != "Completed") { // Sleep for 1 min System.Threading.Thread.Sleep(60 * 1000); responseJob = client.Jobs.Get(jobId, RequestHeaders); } Assert.NotEqual(responseJob.Job.State, "Failed"); }
/// <summary> /// Gets Site Recovery client. /// </summary> /// <returns>Site Recovery Management client</returns> private SiteRecoveryManagementClient GetSiteRecoveryClient() { CloudServiceListResponse services = this.recoveryServicesClient.CloudServices.List(); this.ValidateVaultSettings( asrVaultCreds.ResourceName, asrVaultCreds.CloudServiceName, services); CloudService selectedCloudService = null; Vault selectedResource = null; foreach (CloudService cloudService in services) { if (cloudService.Name == asrVaultCreds.CloudServiceName) { selectedCloudService = cloudService; } } if (null == selectedCloudService) { throw new ArgumentException(Properties.Resources.InvalidCloudService); } foreach (Vault vault in selectedCloudService.Resources) { if (vault.Name == asrVaultCreds.ResourceName) { selectedResource = vault; } } if (null == selectedResource) { throw new ArgumentException(Properties.Resources.InvalidResource); } SiteRecoveryManagementClient siteRecoveryClient = AzureSession.ClientFactory.CreateCustomClient <SiteRecoveryManagementClient>(asrVaultCreds.CloudServiceName, asrVaultCreds.ResourceName, recoveryServicesClient.Credentials, Profile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement)); if (null == siteRecoveryClient) { throw new InvalidOperationException(Properties.Resources.NullRecoveryServicesClient); } return(siteRecoveryClient); }
protected void SetupManagementClients( string scenario, RestTestFramework.MockContext context) { this.RmRestClient = this.GetRmRestClient(context); this.RecoveryServicesMgmtClient = this.GetRecoveryServicesManagementClient(context); this.SiteRecoveryMgmtClient = this.GetSiteRecoveryManagementClient( scenario, context); this.helper.SetupManagementClients( this.RmRestClient, this.RecoveryServicesMgmtClient, this.SiteRecoveryMgmtClient); }
public static List <Fabric> GetHyperVSites( this SiteRecoveryManagementClient client) { var fabricList = client.Fabrics.List(GetRequestHeaders()); List <Fabric> sites = new List <Fabric>(); foreach (var fabric in fabricList.Fabrics) { if (fabric.Properties.CustomDetails.InstanceType == "HyperVSite") { sites.Add(fabric); } } return(sites); }
public static ReplicationProtectedItemOperationResponse PlannedFailover( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer protectionContainer, ReplicationProtectedItem protectedItem) { PlannedFailoverInputProperties plannedFailoverProp = new PlannedFailoverInputProperties(); if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure") { if (protectedItem.Properties.ActiveLocation == "Recovery") { HyperVReplicaAzureFailbackProviderInput hvrAFBInput = new HyperVReplicaAzureFailbackProviderInput() { RecoveryVmCreationOption = "NoAction", DataSyncOption = "ForSyncronization" }; plannedFailoverProp.ProviderSpecificDetails = hvrAFBInput; } else { HyperVReplicaAzureFailoverProviderInput hvrAFOInput = new HyperVReplicaAzureFailoverProviderInput() { VaultLocation = "West US", }; plannedFailoverProp.ProviderSpecificDetails = hvrAFOInput; } } PlannedFailoverInput pfoInput = new PlannedFailoverInput() { Properties = plannedFailoverProp }; return(client.ReplicationProtectedItem.PlannedFailover( primaryFabric.Name, protectionContainer.Name, protectedItem.Name, pfoInput, GetRequestHeaders()) as ReplicationProtectedItemOperationResponse); }
/// <summary> /// Returns job id of the job. /// </summary> /// <param name="jobName">Name of the job to check for.</param> /// <param name="startTime">Start time of job</param> /// <param name="client">SiteRecovery client.</param> /// <param name="requestHeaders">Request headers.</param> /// <returns>Job object of the job queried.</returns> public static Job GetJobId( string jobName, DateTime startTime, SiteRecoveryManagementClient client, CustomRequestHeaders requestHeaders) { JobListResponse jobList = client.Jobs.List(requestHeaders); foreach (var job in jobList.Jobs) { if (job.Properties.ScenarioName.Contains(jobName)) { return(job); } } return(new Job()); }
/// <summary> /// Gets Site Recovery client. /// </summary> /// <returns>Site Recovery Management client</returns> private SiteRecoveryManagementClient GetSiteRecoveryClient() { SiteRecoveryManagementClient siteRecoveryClient = AzureSession.ClientFactory.CreateCustomClient <SiteRecoveryManagementClient>( asrVaultCreds.ResourceName, asrVaultCreds.ResourceGroupName, asrVaultCreds.ResourceNamespace, asrVaultCreds.ARMResourceType, cloudCredentials, endPointUri); if (null == siteRecoveryClient) { throw new InvalidOperationException(Properties.Resources.NullRecoveryServicesClient); } return(siteRecoveryClient); }
public static LongRunningOperationResponse UnpairClouds( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer primaryContainer, string armResourceName) { ProtectionContainerMapping mapping = client.ProtectionContainerMapping.Get( primaryFabric.Name, primaryContainer.Name, armResourceName, GetRequestHeaders()).ProtectionContainerMapping; return(client.ProtectionContainerMapping.UnconfigureProtection( primaryFabric.Name, primaryContainer.Name, armResourceName, new RemoveProtectionContainerMappingInput(), GetRequestHeaders())); }
/// <summary> /// Gets Site Recovery client. /// </summary> /// <returns>Site Recovery Management client</returns> private SiteRecoveryManagementClient GetSiteRecoveryClient() { this.ValidateVaultSettings( asrVaultCreds.ResourceName, asrVaultCreds.ResourceGroupName); SiteRecoveryManagementClient siteRecoveryClient = AzureSession.ClientFactory.CreateCustomClient <SiteRecoveryManagementClient>( asrVaultCreds.ResourceGroupName, asrVaultCreds.ResourceName, asrVaultCreds.ResourceGroupName, recoveryServicesClient.Credentials, Profile.Context.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ResourceManager)); if (null == siteRecoveryClient) { throw new InvalidOperationException(Properties.Resources.NullRecoveryServicesClient); } return(siteRecoveryClient); }
public static T GetSRMServiceClient <T>(TestEnvironmentFactory factory, SiteRecoveryManagementClient client) where T : class { TestEnvironment testEnvironment = factory.GetTestEnvironment(); HttpMockServer instance; try { instance = HttpMockServer.CreateInstance(); } catch (ApplicationException) { HttpMockServer.Initialize("TestEnvironment", "InitialCreation"); instance = HttpMockServer.CreateInstance(); } T obj2 = typeof(T).GetMethod("WithHandler", new Type[1] { typeof(DelegatingHandler) }).Invoke((object)client, new object[1] { (object)instance }) as T; if (HttpMockServer.Mode == HttpRecorderMode.Record) { HttpMockServer.Variables[TestEnvironment.SubscriptionIdKey] = testEnvironment.SubscriptionId; } if (HttpMockServer.Mode == HttpRecorderMode.Playback) { PropertyInfo property1 = typeof(T).GetProperty("LongRunningOperationInitialTimeout", typeof(int)); PropertyInfo property2 = typeof(T).GetProperty("LongRunningOperationRetryTimeout", typeof(int)); if (property1 != (PropertyInfo)null && property2 != (PropertyInfo)null) { property1.SetValue((object)obj2, (object)0); property2.SetValue((object)obj2, (object)0); } } return(obj2); }
public static ReplicationProtectedItemOperationResponse UnplannedFailover( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer protectionContainer, ReplicationProtectedItem protectedItem) { UnplannedFailoverInput ufoInput = new UnplannedFailoverInput() { Properties = new UnplannedFailoverInputProperties() { ProviderSpecificDetails = new ProviderSpecificFailoverInput() } }; if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure") { HyperVReplicaAzureFailoverProviderInput hvrAFOInput = new HyperVReplicaAzureFailoverProviderInput() { VaultLocation = "West US", }; UnplannedFailoverInputProperties ufoProp = new UnplannedFailoverInputProperties() { ProviderSpecificDetails = new ProviderSpecificFailoverInput(), SourceSiteOperations = "NotRequired" }; ufoInput.Properties = ufoProp; } return(client.ReplicationProtectedItem.UnplannedFailover( primaryFabric.Name, protectionContainer.Name, protectedItem.Name, ufoInput, GetRequestHeaders()) as ReplicationProtectedItemOperationResponse); }
public static StorageClassificationMappingOperationResponse PairStorageClassification( this SiteRecoveryManagementClient client, Fabric primaryFabric, StorageClassification primaryClassification, StorageClassification recoveryClassification, string armResourceName) { StorageClassificationMappingInputProperties props = new StorageClassificationMappingInputProperties() { TargetStorageClassificationId = recoveryClassification.Id }; StorageClassificationMappingInput input = new StorageClassificationMappingInput() { Properties = props }; return(client.StorageClassificationMapping.PairStorageClassification( primaryFabric.Name, primaryClassification.Name, armResourceName, input, GetRequestHeaders()) as StorageClassificationMappingOperationResponse); }
public void Initialize(MockContext context, string rgName, string vault) { this.SiteRecoveryClient = this.GetSiteRecoveryClient(context); this.SiteRecoveryClient.ResourceGroupName = rgName; this.SiteRecoveryClient.ResourceName = vault; }
//[Fact] //public void EndToEndE2ESingleVM() //{ // using (UndoContext context = UndoContext.Current) // { // context.Start(); // var client = GetSiteRecoveryClient(CustomHttpHandler); // bool pairClouds = true; // bool StorageClassificationMapping = true; // bool enableDR = true; // bool pfo = true; // bool commit = true; // bool tfo = true; // bool pfoReverse = true; // bool commitReverse = true; // bool rr = true; // bool rrReverse = true; // bool disableDR = true; // bool unpair = true; // bool StorageClassificationUnmap = true; // bool removePolicy = true; // var fabrics = client.Fabrics.List(RequestHeaders); // Fabric selectedFabric = null; // foreach (var fabric in fabrics.Fabrics) // { // if (fabric.Properties.CustomDetails.InstanceType.Contains("VMM")) // { // selectedFabric = fabric; // } // } // string priCld = string.Empty; // string recCldGuid = string.Empty; // string recCld = string.Empty; // string policyName = "Hydra-EndToEndE2ESingleVM-" + (new Random()).Next(); // string mappingName = "Mapping-EndToEndE2ESingleVM-" + (new Random()).Next(); // string StorageClassificationMappingName = "StrgMapping-EndToEndE2ESingleVM-453834979";// "StrgMapping-EndToEndE2ESingleVM-" + (new Random()).Next(); // string replicationProtectedItemName = "PE" + (new Random()).Next(); // string enableDRVmName = string.Empty; // Policy currentPolicy = null; // var policies = client.Policies.List(RequestHeaders); // if (string.IsNullOrEmpty(recCldGuid)) // { // var containers = client.ProtectionContainer.List(selectedFabric.Name, RequestHeaders); // foreach (var container in containers.ProtectionContainers) // { // if (container.Properties.PairingStatus.Equals("NotPaired", StringComparison.InvariantCultureIgnoreCase)) // { // if (string.IsNullOrEmpty(priCld)) // { // priCld = container.Name; // } // else if (string.IsNullOrEmpty(recCld) && priCld != container.Name) // { // recCld = container.Id; // recCldGuid = container.Name; // } // } // } // } // else // { // recCld = client.ProtectionContainer.Get(selectedFabric.Name, recCldGuid, RequestHeaders).ProtectionContainer.Id; // } // StorageClassification selectedStorageClassification = null; // if (StorageClassificationMapping) // { // IList<StorageClassification> StorageClassifications = client.StorageClassification.List(selectedFabric.Name, RequestHeaders).StorageClassifications; // if (StorageClassifications.Count > 1) // { // StorageClassificationMappingInputProperties strgInputProps = new StorageClassificationMappingInputProperties() // { // TargetStorageClassificationId = StorageClassifications[1].Id // }; // StorageClassificationMappingInput strgInput = new StorageClassificationMappingInput() // { // Properties = strgInputProps // }; // var mapStorageClassifications = client.StorageClassificationMapping.PairStorageClassification(selectedFabric.Name, StorageClassifications[0].Name, StorageClassificationMappingName, strgInput, RequestHeaders); // selectedStorageClassification = StorageClassifications[0]; // } // } // if (pairClouds) // { // HyperVReplica2012R2PolicyInput hvrProfileInput = new HyperVReplica2012R2PolicyInput() // { // ApplicationConsistentSnapshotFrequencyInHours = 0, // AllowedAuthenticationType = 1, // Compression = "Enable", // InitialReplicationMethod = "OverNetwork", // OnlineReplicationStartTime = null, // RecoveryPoints = 0, // ReplicaDeletion = "Required", // ReplicationPort = 8083, // ReplicationFrequencyInSeconds = 300 // }; // CreatePolicyInputProperties policyCreationProp = new CreatePolicyInputProperties() // { // ProviderSpecificInput = hvrProfileInput // }; // CreatePolicyInput policyCreationInput = new CreatePolicyInput() // { // Properties = policyCreationProp // }; // var policyCreateResp = client.Policies.Create(policyName, policyCreationInput, RequestHeaders); // currentPolicy = client.Policies.Get(policyName, RequestHeaders).Policy; // CreateProtectionContainerMappingInputProperties pairingProps = new CreateProtectionContainerMappingInputProperties() // { // PolicyId = currentPolicy.Id, // TargetProtectionContainerId = recCld, // ProviderSpecificInput = new ReplicationProviderContainerMappingInput() // }; // CreateProtectionContainerMappingInput pairingInput = new CreateProtectionContainerMappingInput() // { // Properties = pairingProps // }; // var pairingResponse = client.ProtectionContainerMapping.ConfigureProtection( // selectedFabric.Name, // priCld, // mappingName, // pairingInput, // RequestHeaders); // // Adding SP1 Profile too // HyperVReplica2012PolicyInput hvrsp1ProfileInput = new HyperVReplica2012PolicyInput() // { // ApplicationConsistentSnapshotFrequencyInHours = 0, // AllowedAuthenticationType = 1, // Compression = "Enable", // InitialReplicationMethod = "OverNetwork", // OnlineReplicationStartTime = null, // RecoveryPoints = 0, // ReplicaDeletion = "Required", // ReplicationPort = 8083 // }; // CreatePolicyInputProperties policySp1CreationProp = new CreatePolicyInputProperties() // { // ProviderSpecificInput = hvrsp1ProfileInput // }; // CreatePolicyInput policySp1CreationInput = new CreatePolicyInput() // { // Properties = policySp1CreationProp // }; // var policySp1CreateResp = client.Policies.Create(policyName + "SP1", policySp1CreationInput, RequestHeaders); // var currentSp1Policy = client.Policies.Get(policyName + "SP1", RequestHeaders).Policy; // CreateProtectionContainerMappingInputProperties pairingSp1Props = new CreateProtectionContainerMappingInputProperties() // { // PolicyId = currentSp1Policy.Id, // TargetProtectionContainerId = recCld, // ProviderSpecificInput = new ReplicationProviderContainerMappingInput() // }; // CreateProtectionContainerMappingInput pairingSp1Input = new CreateProtectionContainerMappingInput() // { // Properties = pairingSp1Props // }; // var pairingSp1Response = client.ProtectionContainerMapping.ConfigureProtection( // selectedFabric.Name, // priCld, // mappingName + "sp1", // pairingSp1Input, // RequestHeaders); // } // else // { // currentPolicy = client.Policies.Get(policyName, RequestHeaders).Policy; // } // if (enableDR) // { // EnableProtectionInputProperties enableDRProp = new EnableProtectionInputProperties(); // if (string.IsNullOrEmpty(enableDRVmName)) // { // var protectableItem = GetUnprotectedItem(client, selectedFabric.Name, priCld); // enableDRProp = new EnableProtectionInputProperties() // { // PolicyId = currentPolicy.Id, // ProtectableItemId = protectableItem.Id, // ProviderSpecificDetails = new EnableProtectionProviderSpecificInput() // }; // } // else // { // var item = client.ProtectableItem.Get(selectedFabric.Name, priCld, enableDRVmName, RequestHeaders); // enableDRProp = new EnableProtectionInputProperties() // { // PolicyId = currentPolicy.Id, // ProtectableItemId = item.ProtectableItem.Id, // ProviderSpecificDetails = new EnableProtectionProviderSpecificInput() // }; // } // EnableProtectionInput enableInput = new EnableProtectionInput() // { // Properties = enableDRProp // }; // var enableDRStartTime = DateTime.Now; // var enableDRresp = client.ReplicationProtectedItem.EnableProtection( // selectedFabric.Name, // priCld, // replicationProtectedItemName, // enableInput, // RequestHeaders); // MonitoringHelper.MonitorJobs(MonitoringHelper.SecondaryIrJobName, enableDRStartTime, client, RequestHeaders); // } // ///////////////////////////// PFO //////////////////////////////// // PlannedFailoverInputProperties plannedFailoverProp = new PlannedFailoverInputProperties() // { // ProviderSpecificDetails = new ProviderSpecificFailoverInput() // }; // PlannedFailoverInput plannedFailoverInput = new PlannedFailoverInput() // { // Properties = plannedFailoverProp // }; // ////////////////////////////// RR //////////////////////////////// // ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties() // { // ProviderSpecificDetails = new ReverseReplicationProviderSpecificInput() // }; // ReverseReplicationInput rrInput = new ReverseReplicationInput() // { // Properties = rrProp // }; // ////////////////////////////////// UFO ///////////////////////////// // UnplannedFailoverInputProperties ufoProp = new UnplannedFailoverInputProperties() // { // ProviderSpecificDetails = new ProviderSpecificFailoverInput(), // SourceSiteOperations = "NotRequired" // }; // UnplannedFailoverInput ufoInput = new UnplannedFailoverInput() // { // Properties = ufoProp // }; // /////////////////////////////////// TFO ////////////////////////////// // TestFailoverInputProperties tfoProp = new TestFailoverInputProperties() // { // ProviderSpecificDetails = new ProviderSpecificFailoverInput() // }; // TestFailoverInput tfoInput = new TestFailoverInput() // { // Properties = tfoProp // }; // ///////////////////////////////////// // if (pfo) // { // var protectedItem = client.ReplicationProtectedItem.Get( // selectedFabric.Name, // priCld, // replicationProtectedItemName, // RequestHeaders); // var plannedfailover = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, priCld, replicationProtectedItemName, plannedFailoverInput, RequestHeaders); // //var unplannedFailoverReverse = client.ReplicationProtectedItem.UnplannedFailover( // // selectedFabric.Name, // // priCld, // // replicationProtectedItemName, // // ufoInput, // // RequestHeaders); // } // if (commit) // { // var commitFailover = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, priCld, replicationProtectedItemName, RequestHeaders); // } // if (rr) // { // var rrOp = client.ReplicationProtectedItem.Reprotect(selectedFabric.Name, priCld, replicationProtectedItemName, rrInput, RequestHeaders); // } // if (pfoReverse) // { // //var unplannedFailoverReverse = client.ReplicationProtectedItem.UnplannedFailover( // // selectedFabric.Name, priCld, replicationProtectedItemName, ufoInput, RequestHeaders); // var plannedFailoverReverse = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, priCld, replicationProtectedItemName, plannedFailoverInput, RequestHeaders); // } // if (commitReverse) // { // var commitFailoverReverse = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, priCld, replicationProtectedItemName, RequestHeaders); // } // if (rrReverse) // { // DateTime rrPostUfoStartTime = DateTime.UtcNow; // var rrReverseOp = client.ReplicationProtectedItem.Reprotect(selectedFabric.Name, priCld, replicationProtectedItemName, rrInput, RequestHeaders); // /*while (true) // { // Thread.Sleep(5000 * 60); // Job ufoJob = MonitoringHelper.GetJobId( // MonitoringHelper.ReverseReplicationJobName, // rrPostUfoStartTime, // client, // RequestHeaders); // if (ufoJob.Properties.StateDescription.Equals( // "WaitingForFinalizeProtection", // StringComparison.InvariantCultureIgnoreCase)) // { // break; // } // } // MonitoringHelper.MonitorJobs(MonitoringHelper.PrimaryIrJobName, rrPostUfoStartTime, client, RequestHeaders); // MonitoringHelper.MonitorJobs(MonitoringHelper.SecondaryIrJobName, rrPostUfoStartTime, client, RequestHeaders);*/ // } // if (tfo) // { // DateTime startTFO = DateTime.UtcNow; // var tfoOp = client.ReplicationProtectedItem.TestFailover(selectedFabric.Name, priCld, replicationProtectedItemName, tfoInput, RequestHeaders); // var jobs = MonitoringHelper.GetJobId(MonitoringHelper.TestFailoverJobName, startTFO, client, RequestHeaders); // ResumeJobParamsProperties resProp = new ResumeJobParamsProperties() // { // Comments = "Res TFO" // }; // ResumeJobParams resParam = new ResumeJobParams() // { // Properties = resProp // }; // var resJob = client.Jobs.Resume(jobs.Name, resParam, RequestHeaders); // } // if (disableDR) // { // var disableDROperation = client.ReplicationProtectedItem.DisableProtection(selectedFabric.Name, priCld, replicationProtectedItemName, new DisableProtectionInput(), RequestHeaders); // } // if (unpair) // { // var unpaiClouds = client.ProtectionContainerMapping.UnconfigureProtection( // selectedFabric.Name, // priCld, // mappingName, // new RemoveProtectionContainerMappingInput(), // RequestHeaders); // } // if (StorageClassificationUnmap) // { // var unmapStorageClassifications = client.StorageClassificationMapping.UnpairStorageClassification(selectedFabric.Name, selectedStorageClassification.Name, StorageClassificationMappingName, RequestHeaders); // } // if (removePolicy) // { // var policyDeletion = client.Policies.Delete(currentPolicy.Name, RequestHeaders); // } // } //} //[Fact] //public void EndToEndE2ASingleVM() //{ // using (UndoContext context = UndoContext.Current) // { // context.Start(); // var client = GetSiteRecoveryClient(CustomHttpHandler); // bool createPolicy = true; // bool pairClouds = true; // bool enableDR = true; // bool pfo = true; // bool commit = true; // bool tfo = true; // bool pfoReverse = true; // bool commitReverse = true; // bool reprotect = true; // bool disableDR = true; // bool unpair = true; // bool removePolicy = true; // // Process Variables // string fabricName = string.Empty; // string recCldName = "Microsoft Azure"; // string priCldName = string.Empty; // string policyName = "Hydra-EndToEndE2ASingleVM-" + (new Random()).Next(); // string mappingName = "Mapping-EndToEndE2ASingleVM-" + (new Random()).Next(); // string enableDRName = string.Empty; // string protectedItemName = "PE" + (new Random()).Next(); // // Data Variables // Fabric selectedFabric = null; // ProtectionContainer primaryCloud = null; // Policy selectedPolicy = null; // ProtectableItem protectableItem = null; // ReplicationProtectedItem protectedItem = null; // // Fetch VMMs // if (string.IsNullOrEmpty(fabricName)) // { // var fabrics = client.Fabrics.List(RequestHeaders); // foreach (var fabric in fabrics.Fabrics) // { // if (fabric.Properties.CustomDetails.InstanceType.Contains("VMM")) // { // selectedFabric = fabric; // fabricName = selectedFabric.Name; // } // } // } // else // { // selectedFabric = client.Fabrics.Get(fabricName, RequestHeaders).Fabric; // } // // Fetch Cloud // if (string.IsNullOrEmpty(priCldName)) // { // var clouds = client.ProtectionContainer.List(selectedFabric.Name, RequestHeaders); // foreach (var cloud in clouds.ProtectionContainers) // { // if (cloud.Properties.PairingStatus.Equals("NotPaired", StringComparison.InvariantCultureIgnoreCase)) // { // priCldName = cloud.Name; // primaryCloud = cloud; // break; // } // } // } // else // { // primaryCloud = client.ProtectionContainer.Get(selectedFabric.Name, priCldName, RequestHeaders).ProtectionContainer; // } // if (createPolicy) // { // HyperVReplicaAzurePolicyInput hvrAPolicy = new HyperVReplicaAzurePolicyInput() // { // ApplicationConsistentSnapshotFrequencyInHours = 0, // Encryption = "Disable", // OnlineIrStartTime = null, // RecoveryPointHistoryDuration = 0, // ReplicationInterval = 30, // StorageAccounts = new List<string>() { "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/StorageAccounts/bvtmapped2storacc" } // }; // CreatePolicyInputProperties createInputProp = new CreatePolicyInputProperties() // { // ProviderSpecificInput = hvrAPolicy // }; // CreatePolicyInput policyInput = new CreatePolicyInput() // { // Properties = createInputProp // }; // selectedPolicy = (client.Policies.Create(policyName, policyInput, RequestHeaders) as CreatePolicyOperationResponse).Policy; // } // else // { // selectedPolicy = client.Policies.Get(policyName, RequestHeaders).Policy; // } // if (pairClouds) // { // CreateProtectionContainerMappingInputProperties pairingProps = new CreateProtectionContainerMappingInputProperties() // { // PolicyId = selectedPolicy.Id, // TargetProtectionContainerId = recCldName, // ProviderSpecificInput = new ReplicationProviderContainerMappingInput() // }; // CreateProtectionContainerMappingInput pairingInput = new CreateProtectionContainerMappingInput() // { // Properties = pairingProps // }; // var pairingResponse = client.ProtectionContainerMapping.ConfigureProtection( // selectedFabric.Name, // primaryCloud.Name, // mappingName, // pairingInput, // RequestHeaders); // } // if (enableDR) // { // if (string.IsNullOrEmpty(enableDRName)) // { // protectableItem = GetUnprotectedItem(client, selectedFabric.Name, primaryCloud.Name); // enableDRName = protectableItem.Name; // } // else // { // protectableItem = client.ProtectableItem.Get(selectedFabric.Name, primaryCloud.Name, enableDRName, RequestHeaders).ProtectableItem; // } // HyperVReplicaAzureEnableProtectionInput hvrAEnableDRInput = new HyperVReplicaAzureEnableProtectionInput() // { // HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId, // OSType = "Windows", // VhdId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList[0].VhdId, // VmName = protectableItem.Properties.FriendlyName, // TargetStorageAccountId = "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorageClassification/StorageClassificationAccounts/bvtmapped2storacc", // }; // EnableProtectionInputProperties enableDRProp = new EnableProtectionInputProperties() // { // PolicyId = selectedPolicy.Id, // ProtectableItemId = protectableItem.Id, // ProviderSpecificDetails = hvrAEnableDRInput // }; // EnableProtectionInput enableDRInput = new EnableProtectionInput() // { // Properties = enableDRProp // }; // protectedItem = ( // client.ReplicationProtectedItem.EnableProtection( // selectedFabric.Name, // primaryCloud.Name, // protectedItemName, // enableDRInput, // RequestHeaders) as ReplicationProtectedItemOperationResponse).ReplicationProtectedItem; // } // if (pfo || commit || tfo || pfoReverse || commitReverse || reprotect || disableDR) // { // protectableItem = client.ProtectableItem.Get(selectedFabric.Name, primaryCloud.Name, enableDRName, RequestHeaders).ProtectableItem; // protectedItem = client.ReplicationProtectedItem.Get(selectedFabric.Name, primaryCloud.Name, protectedItemName, RequestHeaders).ReplicationProtectedItem; // // Create Input for Operations // ///////////////////////////// PFO ///////////////////////////////////// // HyperVReplicaAzureFailoverProviderInput hvrAFOInput = new HyperVReplicaAzureFailoverProviderInput() // { // VaultLocation = "West US", // }; // PlannedFailoverInputProperties plannedFailoverProp = new PlannedFailoverInputProperties() // { // FailoverDirection = "", // ProviderSpecificDetails = hvrAFOInput // }; // PlannedFailoverInput plannedFailoverInput = new PlannedFailoverInput() // { // Properties = plannedFailoverProp // }; // HyperVReplicaAzureFailbackProviderInput hvrAFBInput = new HyperVReplicaAzureFailbackProviderInput() // { // RecoveryVmCreationOption = "NoAction", // DataSyncOption = "ForSyncronization" // }; // PlannedFailoverInputProperties plannedFailbackProp = new PlannedFailoverInputProperties() // { // FailoverDirection = "", // ProviderSpecificDetails = hvrAFBInput // }; // PlannedFailoverInput plannedFailbackInput = new PlannedFailoverInput() // { // Properties = plannedFailbackProp // }; // ////////////////////////////// Reprotect ////////////////////////////////////// // HyperVReplicaAzureReprotectInput hvrARRInput = new HyperVReplicaAzureReprotectInput() // { // HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId, // OSType = "Windows", // VHDId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList[0].VhdId, // VmName = protectableItem.Properties.FriendlyName, // StorageAccountId = "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/StorageAccounts/bvtmapped2storacc", // }; // ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties() // { // FailoverDirection = "", // ProviderSpecificDetails = hvrARRInput // }; // ReverseReplicationInput rrInput = new ReverseReplicationInput() // { // Properties = rrProp // }; // ////////////////////////////////// UFO ///////////////////////////////////////// // UnplannedFailoverInputProperties ufoProp = new UnplannedFailoverInputProperties() // { // ProviderSpecificDetails = hvrAFOInput, // SourceSiteOperations = "NotRequired" // }; // UnplannedFailoverInput ufoInput = new UnplannedFailoverInput() // { // Properties = ufoProp // }; // /////////////////////////////////// TFO ///////////////////////////////////////////// // TestFailoverInputProperties tfoProp = new TestFailoverInputProperties() // { // ProviderSpecificDetails = hvrAFOInput // }; // TestFailoverInput tfoInput = new TestFailoverInput() // { // Properties = tfoProp // }; // ////////////////////////////////////////////////////////////////////////////////////////// // if (pfo) // { // var plannedfailover = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, plannedFailoverInput, RequestHeaders); // } // if (commit) // { // var commitFailover = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, RequestHeaders); // } // if (pfoReverse) // { // //var unplannedFailoverReverse = client.ReplicationProtectedItem.UnplannedFailover(selectedFabric.Name, priCld, replicationProtectedItems.ReplicationProtectedItems[0].Name, ufoInput, RequestHeaders); // var plannedFailoverReverse = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, plannedFailbackInput, RequestHeaders); // } // if (commitReverse) // { // var commitFailoverReverse = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, RequestHeaders); // } // if (reprotect) // { // var reprotectStartTime = DateTime.UtcNow; // var rrReverseOp = client.ReplicationProtectedItem.Reprotect(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, rrInput, RequestHeaders); // MonitoringHelper.MonitorJobs(MonitoringHelper.AzureIrJobName, reprotectStartTime, client, RequestHeaders); // } // if (tfo) // { // DateTime startTFO = DateTime.UtcNow; // var tfoOp = client.ReplicationProtectedItem.TestFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, tfoInput, RequestHeaders); // var jobs = MonitoringHelper.GetJobId(MonitoringHelper.TestFailoverJobName, startTFO, client, RequestHeaders); // ResumeJobParamsProperties resProp = new ResumeJobParamsProperties() // { // Comments = "Res TFO" // }; // ResumeJobParams resParam = new ResumeJobParams() // { // Properties = resProp // }; // var resJob = client.Jobs.Resume(jobs.Name, resParam, RequestHeaders); // } // if (disableDR) // { // var disableDROperation = client.ReplicationProtectedItem.DisableProtection(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, new DisableProtectionInput(), RequestHeaders); // } // if (unpair) // { // if (unpair) // { // var unpairClouds = client.ProtectionContainerMapping.UnconfigureProtection( // selectedFabric.Name, // primaryCloud.Name, // mappingName, // new RemoveProtectionContainerMappingInput(), // RequestHeaders); // } // } // } // if (removePolicy) // { // var policyDeletion = client.Policies.Delete(selectedPolicy.Name, RequestHeaders); // } // } //} //[Fact] //public void EndToEndB2ASingleVM() //{ // using (UndoContext context = UndoContext.Current) // { // context.Start(); // var client = GetSiteRecoveryClient(CustomHttpHandler); // bool createPolicy = true; // bool pairClouds = true; // bool enableDR = true; // bool pfo = true; // bool commit = true; // bool tfo = true; // bool pfoReverse = true; // bool commitReverse = true; // bool reprotect = true; // bool disableDR = true; // bool unpair = true; // bool removePolicy = true; // // Process Variables // string fabricName = string.Empty; // string recCldName = "Microsoft Azure"; // string priCldName = string.Empty; // string policyName = "Hydra-EndToEndB2ASingleVM-" + (new Random()).Next(); // string mappingName = "Mapping-EndToEndB2ASingleVM-" + (new Random()).Next(); // string enableDRName = string.Empty; // string protectedItemName = "PE" + (new Random()).Next(); // // Data Variables // Fabric selectedFabric = null; // ProtectionContainer primaryCloud = null; // Policy selectedPolicy = null; // ProtectableItem protectableItem = null; // ReplicationProtectedItem protectedItem = null; // // Fetch HyperV // if (string.IsNullOrEmpty(fabricName)) // { // var fabrics = client.Fabrics.List(RequestHeaders); // foreach (var fabric in fabrics.Fabrics) // { // if (fabric.Properties.CustomDetails.InstanceType.Contains("HyperV")) // { // selectedFabric = fabric; // fabricName = selectedFabric.Name; // } // } // } // else // { // selectedFabric = client.Fabrics.Get(fabricName, RequestHeaders).Fabric; // } // // Fetch Cloud // primaryCloud = client.ProtectionContainer.List(selectedFabric.Name, RequestHeaders).ProtectionContainers[0]; // priCldName = primaryCloud.Name; // if (createPolicy) // { // HyperVReplicaAzurePolicyInput hvrAPolicy = new HyperVReplicaAzurePolicyInput() // { // ApplicationConsistentSnapshotFrequencyInHours = 0, // Encryption = "Disable", // OnlineIrStartTime = null, // RecoveryPointHistoryDuration = 0, // ReplicationInterval = 30, // StorageAccounts = new List<string>() { "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/StorageAccounts/bvtmapped2storacc" } // }; // CreatePolicyInputProperties createInputProp = new CreatePolicyInputProperties() // { // ProviderSpecificInput = hvrAPolicy // }; // CreatePolicyInput policyInput = new CreatePolicyInput() // { // Properties = createInputProp // }; // selectedPolicy = (client.Policies.Create(policyName, policyInput, RequestHeaders) as CreatePolicyOperationResponse).Policy; // } // else // { // selectedPolicy = client.Policies.Get(policyName, RequestHeaders).Policy; // } // if (pairClouds) // { // CreateProtectionContainerMappingInputProperties pairingProps = new CreateProtectionContainerMappingInputProperties() // { // PolicyId = selectedPolicy.Id, // TargetProtectionContainerId = recCldName, // ProviderSpecificInput = new ReplicationProviderContainerMappingInput() // }; // CreateProtectionContainerMappingInput pairingInput = new CreateProtectionContainerMappingInput() // { // Properties = pairingProps // }; // var pairingResponse = client.ProtectionContainerMapping.ConfigureProtection( // selectedFabric.Name, // primaryCloud.Name, // mappingName, // pairingInput, // RequestHeaders); // } // if (enableDR) // { // if (string.IsNullOrEmpty(enableDRName)) // { // protectableItem = GetUnprotectedItem(client, selectedFabric.Name, primaryCloud.Name); // enableDRName = protectableItem.Name; // } // else // { // protectableItem = client.ProtectableItem.Get(selectedFabric.Name, primaryCloud.Name, enableDRName, RequestHeaders).ProtectableItem; // } // HyperVReplicaAzureEnableProtectionInput hvrAEnableDRInput = new HyperVReplicaAzureEnableProtectionInput() // { // HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId, // OSType = "Windows", // VhdId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList[0].VhdId, // VmName = protectableItem.Properties.FriendlyName, // TargetStorageAccountId = "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/StorageAccounts/bvtmapped2storacc", // }; // EnableProtectionInputProperties enableDRProp = new EnableProtectionInputProperties() // { // PolicyId = selectedPolicy.Id, // ProtectableItemId = protectableItem.Id, // ProviderSpecificDetails = hvrAEnableDRInput // }; // EnableProtectionInput enableDRInput = new EnableProtectionInput() // { // Properties = enableDRProp // }; // DateTime enablStartTime = DateTime.UtcNow; // protectedItem = ( // client.ReplicationProtectedItem.EnableProtection( // selectedFabric.Name, // primaryCloud.Name, // protectedItemName, // enableDRInput, // RequestHeaders) as ReplicationProtectedItemOperationResponse).ReplicationProtectedItem; // MonitoringHelper.MonitorJobs(MonitoringHelper.AzureIrJobName, enablStartTime, client, RequestHeaders); // } // if (pfo || commit || tfo || pfoReverse || commitReverse || reprotect || disableDR) // { // protectableItem = client.ProtectableItem.Get(selectedFabric.Name, primaryCloud.Name, enableDRName, RequestHeaders).ProtectableItem; // protectedItem = client.ReplicationProtectedItem.Get(selectedFabric.Name, primaryCloud.Name, protectedItemName, RequestHeaders).ReplicationProtectedItem; // // Create Input for Operations // ///////////////////////////// PFO ///////////////////////////////////// // HyperVReplicaAzureFailoverProviderInput hvrAFOInput = new HyperVReplicaAzureFailoverProviderInput() // { // VaultLocation = "West US", // }; // PlannedFailoverInputProperties plannedFailoverProp = new PlannedFailoverInputProperties() // { // FailoverDirection = "", // ProviderSpecificDetails = hvrAFOInput // }; // PlannedFailoverInput plannedFailoverInput = new PlannedFailoverInput() // { // Properties = plannedFailoverProp // }; // HyperVReplicaAzureFailbackProviderInput hvrAFBInput = new HyperVReplicaAzureFailbackProviderInput() // { // RecoveryVmCreationOption = "NoAction", // DataSyncOption = "ForSyncronization" // }; // PlannedFailoverInputProperties plannedFailbackProp = new PlannedFailoverInputProperties() // { // FailoverDirection = "", // ProviderSpecificDetails = hvrAFBInput // }; // PlannedFailoverInput plannedFailbackInput = new PlannedFailoverInput() // { // Properties = plannedFailbackProp // }; // ////////////////////////////// Reprotect ////////////////////////////////////// // HyperVReplicaAzureReprotectInput hvrARRInput = new HyperVReplicaAzureReprotectInput() // { // HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId, // OSType = "Windows", // VHDId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList[0].VhdId, // VmName = protectableItem.Properties.FriendlyName, // StorageAccountId = "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/StorageAccounts/bvtmapped2storacc", // }; // ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties() // { // FailoverDirection = "", // ProviderSpecificDetails = hvrARRInput // }; // ReverseReplicationInput rrInput = new ReverseReplicationInput() // { // Properties = rrProp // }; // ////////////////////////////////// UFO ///////////////////////////////////////// // UnplannedFailoverInputProperties ufoProp = new UnplannedFailoverInputProperties() // { // ProviderSpecificDetails = hvrAFOInput, // SourceSiteOperations = "NotRequired" // }; // UnplannedFailoverInput ufoInput = new UnplannedFailoverInput() // { // Properties = ufoProp // }; // /////////////////////////////////// TFO ///////////////////////////////////////////// // TestFailoverInputProperties tfoProp = new TestFailoverInputProperties() // { // ProviderSpecificDetails = hvrAFOInput // }; // TestFailoverInput tfoInput = new TestFailoverInput() // { // Properties = tfoProp // }; // ////////////////////////////////////////////////////////////////////////////////////////// // if (pfo) // { // var plannedfailover = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, plannedFailoverInput, RequestHeaders); // } // if (commit) // { // var commitFailover = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, RequestHeaders); // } // if (pfoReverse) // { // //var unplannedFailoverReverse = client.ReplicationProtectedItem.UnplannedFailover(selectedFabric.Name, priCld, replicationProtectedItems.ReplicationProtectedItems[0].Name, ufoInput, RequestHeaders); // var plannedFailoverReverse = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, plannedFailbackInput, RequestHeaders); // } // if (commitReverse) // { // var commitFailoverReverse = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, RequestHeaders); // } // if (reprotect) // { // var reprotectStartTime = DateTime.UtcNow; // var rrReverseOp = client.ReplicationProtectedItem.Reprotect(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, rrInput, RequestHeaders); // MonitoringHelper.MonitorJobs(MonitoringHelper.AzureIrJobName,reprotectStartTime, client, RequestHeaders); // } // if (tfo) // { // DateTime startTFO = DateTime.UtcNow; // var tfoOp = client.ReplicationProtectedItem.TestFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, tfoInput, RequestHeaders); // var jobs = MonitoringHelper.GetJobId(MonitoringHelper.TestFailoverJobName, startTFO, client, RequestHeaders); // ResumeJobParamsProperties resProp = new ResumeJobParamsProperties() // { // Comments = "Res TFO" // }; // ResumeJobParams resParam = new ResumeJobParams() // { // Properties = resProp // }; // var resJob = client.Jobs.Resume(jobs.Name, resParam, RequestHeaders); // } // if (disableDR) // { // var disableDROperation = client.ReplicationProtectedItem.DisableProtection(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, new DisableProtectionInput(), RequestHeaders); // } // if (unpair) // { // var unpairClouds = client.ProtectionContainerMapping.UnconfigureProtection( // selectedFabric.Name, // primaryCloud.Name, // mappingName, // new RemoveProtectionContainerMappingInput(), // RequestHeaders); // } // } // if (removePolicy) // { // var policyDeletion = client.Policies.Delete(selectedPolicy.Name, RequestHeaders); // } // } //} #endregion /// <summary> /// Returns an unprotected item. /// </summary> /// <param name="client">Site Recovery management client.</param> /// <param name="fabricId">Fabric Id.</param> /// <param name="containerId">Container Id.</param> /// <returns>Unprotected VM.</returns> private ProtectableItem GetUnprotectedItem(SiteRecoveryManagementClient client, string fabricId, string containerId) { List<ProtectableItem> protectableItemList = new List<ProtectableItem>(); ProtectableItemListResponse protectableItemListResponse = client.ProtectableItem.List(fabricId, containerId, "Unprotected", null, "1000", RequestHeaders); protectableItemList.AddRange(protectableItemListResponse.ProtectableItems); while (protectableItemListResponse.NextLink != null) { protectableItemListResponse = client.ProtectableItem.ListNext(protectableItemListResponse.NextLink, RequestHeaders); protectableItemList.AddRange(protectableItemListResponse.ProtectableItems); } return protectableItemList[0]; }
public T GetServiceClient <T>(String scenario) where T : class { var factory = (TestEnvironmentFactory) new CSMTestEnvironmentFactory(); var testEnvironment = factory.GetTestEnvironment(); ServicePointManager.ServerCertificateValidationCallback = IgnoreCertificateErrorHandler; var credentials = new SubscriptionCredentialsAdapter( testEnvironment.AuthorizationContext.TokenCredentials[TokenAudience.Management], testEnvironment.SubscriptionId); var resourceNamespace = ""; var resourceType = ""; var resourceName = ""; var resourceGroupName = ""; switch (scenario) { case Constants.NewModel: resourceNamespace = "Microsoft.SiteRecovery"; resourceType = "SiteRecoveryVault"; resourceName = "ReleaseVault"; resourceGroupName = "ReleaseResourceGroup"; break; default: resourceNamespace = "Microsoft.SiteRecoveryBVTD2"; resourceType = "SiteRecoveryVault"; resourceName = asrVaultCreds.ResourceName; resourceGroupName = asrVaultCreds.ResourceGroupName; break; } ; if (typeof(T) == typeof(SiteRecoveryVaultManagementClient)) { SiteRecoveryVaultManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new SiteRecoveryVaultManagementClient( resourceNamespace, resourceType, credentials, testEnvironment.BaseUri); } else { client = new SiteRecoveryVaultManagementClient( resourceNamespace, resourceType, credentials); } return(GetRSMServiceClient <T>(factory, client)); } else { SiteRecoveryManagementClient client; if (testEnvironment.UsesCustomUri()) { client = new SiteRecoveryManagementClient( resourceName, resourceGroupName, resourceNamespace, resourceType, credentials, testEnvironment.BaseUri); } else { client = new SiteRecoveryManagementClient( resourceName, resourceGroupName, resourceNamespace, resourceType, credentials); } return(GetSRMServiceClient <T>(factory, client)); } }
public static ReplicationProtectedItemOperationResponse EnableDR( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer protectionContainer, Policy policy, ProtectableItem protectableItem, string armResourceName) { if (policy.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure") { string vhdId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails) .DiskDetailsList[0].VhdId; DiskDetails osDisk = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList .FirstOrDefault(item => item.VhdType == "OperatingSystem"); if (osDisk != null) { vhdId = osDisk.VhdId; } HyperVReplicaAzureEnableProtectionInput hvrAEnableDRInput = new HyperVReplicaAzureEnableProtectionInput() { HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId, OSType = "Windows", VhdId = vhdId, VmName = protectableItem.Properties.FriendlyName, TargetStorageAccountId = (policy.Properties.ProviderSpecificDetails as HyperVReplicaAzurePolicyDetails) .ActiveStorageAccountId, }; EnableProtectionInputProperties enableDRProp = new EnableProtectionInputProperties() { PolicyId = policy.Id, ProtectableItemId = protectableItem.Id, ProviderSpecificDetails = hvrAEnableDRInput }; EnableProtectionInput enableDRInput = new EnableProtectionInput() { Properties = enableDRProp }; return(client.ReplicationProtectedItem.EnableProtection( primaryFabric.Name, protectionContainer.Name, armResourceName, enableDRInput, GetRequestHeaders()) as ReplicationProtectedItemOperationResponse); } else if (policy.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012" || policy.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012R2") { var enableDRProp = new EnableProtectionInputProperties() { PolicyId = policy.Id, ProtectableItemId = protectableItem.Id, ProviderSpecificDetails = new EnableProtectionProviderSpecificInput() }; EnableProtectionInput enableInput = new EnableProtectionInput() { Properties = enableDRProp }; return(client.ReplicationProtectedItem.EnableProtection( primaryFabric.Name, protectionContainer.Name, armResourceName, enableInput, GetRequestHeaders()) as ReplicationProtectedItemOperationResponse); } else { throw new NotImplementedException(); } }
public static ReplicationProtectedItemOperationResponse ReverseReplication( this SiteRecoveryManagementClient client, Fabric primaryFabric, ProtectionContainer protectionContainer, ReplicationProtectedItem protectedItem) { if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure") { ProtectableItem protectableItem = client.ProtectableItem.Get( primaryFabric.Name, protectionContainer.Name, protectedItem.Properties.ProtectableItemId.Substring( protectedItem.Properties.ProtectableItemId.LastIndexOf("/") + 1), GetRequestHeaders()).ProtectableItem; string vhdId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails) .DiskDetailsList[0].VhdId; DiskDetails osDisk = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails) .DiskDetailsList .FirstOrDefault(item => item.VhdType == "OperatingSystem"); if (osDisk != null) { vhdId = osDisk.VhdId; } string storageAccount = (protectedItem.Properties.ProviderSpecificDetails as HyperVReplicaAzureReplicationDetails) .RecoveryAzureStorageAccount; HyperVReplicaAzureReprotectInput hvrARRInput = new HyperVReplicaAzureReprotectInput() { HvHostVmId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId, OSType = "Windows", VHDId = vhdId, VmName = protectableItem.Properties.FriendlyName, StorageAccountId = storageAccount, }; ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties() { FailoverDirection = "", ProviderSpecificDetails = hvrARRInput }; ReverseReplicationInput rrInput = new ReverseReplicationInput() { Properties = rrProp }; return(client.ReplicationProtectedItem.Reprotect( primaryFabric.Name, protectionContainer.Name, protectedItem.Name, rrInput, GetRequestHeaders()) as ReplicationProtectedItemOperationResponse); } else if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012" || protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012R2") { ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties() { ProviderSpecificDetails = new ReverseReplicationProviderSpecificInput() }; ReverseReplicationInput rrInput = new ReverseReplicationInput() { Properties = rrProp }; return(client.ReplicationProtectedItem.Reprotect( primaryFabric.Name, protectionContainer.Name, protectedItem.Name, rrInput, GetRequestHeaders()) as ReplicationProtectedItemOperationResponse); } else { throw new NotImplementedException(); } }