/// <summary> /// Initializes a new instance of the <see cref="ASRVirtualMachine" /> class when it is protected /// </summary> /// <param name="pi">Protectable Item to read values from</param> /// <param name="rpi">Replication Protected Item to read values from</param> public ASRVirtualMachine(ProtectableItem pi, ReplicationProtectedItem rpi, Policy policy = null) : base(pi, rpi, policy) { if (0 == string.Compare( rpi.Properties.ProviderSpecificDetails.InstanceType, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { HyperVReplicaAzureReplicationDetails providerSpecificDetails = (HyperVReplicaAzureReplicationDetails)rpi.Properties.ProviderSpecificDetails; RecoveryAzureVMName = providerSpecificDetails.RecoveryAzureVMName; RecoveryAzureVMSize = providerSpecificDetails.RecoveryAzureVMSize; RecoveryAzureStorageAccount = providerSpecificDetails.RecoveryAzureStorageAccount; SelectedRecoveryAzureNetworkId = providerSpecificDetails.SelectedRecoveryAzureNetworkId; if (providerSpecificDetails.VMNics != null) { NicDetailsList = new List<ASRVMNicDetails>(); foreach(VMNicDetails n in providerSpecificDetails.VMNics) { NicDetailsList.Add(new ASRVMNicDetails(n)); } } } }
/// <summary> /// Initializes a new instance of the <see cref="ASRProtectionEntity" /> class when it is protected /// </summary> /// <param name="pi">Protectable Item to read values from</param> /// <param name="rpi">Replication Protected Item to read values from</param> public ASRProtectionEntity(ProtectableItem pi, ReplicationProtectedItem rpi, Policy policy = null) : this(pi) { this.Type = rpi.Type; this.ProtectionStateDescription = rpi.Properties.ProtectionStateDescription; if (rpi.Properties.AllowedOperations != null) { this.AllowedOperations = new List<string>(); foreach (String op in rpi.Properties.AllowedOperations) { AllowedOperations.Add(op); } } this.ReplicationProvider = rpi.Properties.ProviderSpecificDetails.InstanceType; this.ActiveLocation = rpi.Properties.ActiveLocation; this.ReplicationHealth = rpi.Properties.ReplicationHealth; this.TestFailoverStateDescription = rpi.Properties.TestFailoverStateDescription; this.ProtectionStatus = rpi.Properties.ProtectionState; if (policy != null) { this.Policy = new ASRPolicy(policy); } }
/// <summary> /// Write Protected Items /// </summary> /// <param name="replicationProtectedItem"></param> private void WriteReplicationProtectedItem(ReplicationProtectedItem replicationProtectedItem) { this.WriteObject(new ASRReplicationProtectedItem(replicationProtectedItem)); }
/// <summary> /// Initializes a new instance of the <see cref="ASRReplicationProtectedItem" /> class when it is protected /// </summary> /// <param name="pi">Protectable Item to read values from</param> /// <param name="rpi">Replication Protected Item to read values from</param> public ASRReplicationProtectedItem(ReplicationProtectedItem rpi) { this.ID = rpi.Id; this.Name = rpi.Name; this.FriendlyName = rpi.Properties.FriendlyName; this.Type = rpi.Type; this.ActiveLocation = rpi.Properties.ActiveLocation; this.AllowedOperations = rpi.Properties.AllowedOperations; this.ReplicationProvider = rpi.Properties.ProviderSpecificDetails.InstanceType; this.CurrentScenario = rpi.Properties.CurrentScenario; this.FailoverRecoveryPointId = rpi.Properties.FailoverRecoveryPointId; this.LastSuccessfulFailoverTime = rpi.Properties.LastSuccessfulFailoverTime; this.LastSuccessfulTestFailoverTime = rpi.Properties.LastSuccessfulTestFailoverTime; this.PolicyFriendlyName = rpi.Properties.PolicyFriendlyName; this.PolicyID = rpi.Properties.PolicyID; this.PrimaryFabricFriendlyName = rpi.Properties.PrimaryFabricFriendlyName; this.PrimaryProtectionContainerFriendlyName = rpi.Properties.PrimaryProtectionContainerFriendlyName; this.ProtectableItemId = rpi.Properties.ProtectableItemId; this.ProtectedItemType = rpi.Properties.ProtectedItemType; this.ProtectionState = rpi.Properties.ProtectionState; this.ProtectionStateDescription = rpi.Properties.ProtectionStateDescription; this.RecoveryFabricFriendlyName = rpi.Properties.RecoveryFabricFriendlyName; this.RecoveryFabricId = rpi.Properties.RecoveryFabricId; this.RecoveryProtectionContainerFriendlyName = rpi.Properties.RecoveryProtectionContainerFriendlyName; this.RecoveryServicesProviderId = rpi.Properties.RecoveryServicesProviderId; this.ReplicationHealth = rpi.Properties.ReplicationHealth; this.ReplicationHealthErrors = rpi.Properties.ReplicationHealthErrors; this.TestFailoverState = rpi.Properties.TestFailoverState; this.TestFailoverStateDescription = rpi.Properties.TestFailoverStateDescription; if (0 == string.Compare( rpi.Properties.ProviderSpecificDetails.InstanceType, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase)) { HyperVReplicaAzureReplicationDetails providerSpecificDetails = (HyperVReplicaAzureReplicationDetails)rpi.Properties.ProviderSpecificDetails; RecoveryAzureVMName = providerSpecificDetails.RecoveryAzureVMName; RecoveryAzureVMSize = providerSpecificDetails.RecoveryAzureVMSize; RecoveryAzureStorageAccount = providerSpecificDetails.RecoveryAzureStorageAccount; SelectedRecoveryAzureNetworkId = providerSpecificDetails.SelectedRecoveryAzureNetworkId; if (providerSpecificDetails.VMNics != null) { NicDetailsList = new List<ASRVMNicDetails>(); foreach (VMNicDetails n in providerSpecificDetails.VMNics) { NicDetailsList.Add(new ASRVMNicDetails(n)); } } } }
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 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()); }
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(); } }
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 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; }