/// <summary> /// Creates an E2A Policy Object /// </summary> private void EnterpriseToAzurePolicyObject() { if (string.Compare(this.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Properties.Resources.IncorrectReplicationProvider, this.ReplicationProvider)); } PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime); ushort replicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds); var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput() { ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours, Encryption = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Encryption)) ? this.Encryption : Constants.Disable, OnlineIrStartTime = this.ReplicationStartTime, RecoveryPointHistoryDuration = this.RecoveryPoints, ReplicationInterval = replicationFrequencyInSeconds }; hyperVReplicaAzurePolicyInput.StorageAccounts = new System.Collections.Generic.List <string>(); if (RecoveryAzureStorageAccountId != null) { string storageAccount = this.RecoveryAzureStorageAccountId; hyperVReplicaAzurePolicyInput.StorageAccounts.Add(storageAccount); } var createPolicyInputProperties = new CreatePolicyInputProperties() { ProviderSpecificInput = hyperVReplicaAzurePolicyInput }; var createPolicyInput = new CreatePolicyInput() { Properties = createPolicyInputProperties }; LongRunningOperationResponse response = RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Creates an E2A Policy Object /// </summary> private void EnterpriseToAzurePolicyObject() { if (string.Compare(this.Policy.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Properties.Resources.IncorrectReplicationProvider, this.Policy.ReplicationProvider)); } var replicationProviderSettings = this.Policy.ReplicationProviderSettings as ASRHyperVReplicaAzurePolicyDetails; this.replicationFrequencyInSeconds = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicationFrequencyInSeconds)) ? PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds) : (ushort)replicationProviderSettings.ReplicationFrequencyInSeconds; this.recoveryPoints = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.RecoveryPoints)) ? this.RecoveryPoints : replicationProviderSettings.RecoveryPoints; this.applicationConsistentSnapshotFrequencyInHours = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ApplicationConsistentSnapshotFrequencyInHours)) ? this.ApplicationConsistentSnapshotFrequencyInHours : replicationProviderSettings.ApplicationConsistentSnapshotFrequencyInHours; this.replicationStartTime = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicationStartTime)) ? this.replicationStartTime : replicationProviderSettings.OnlineReplicationStartTime; this.recoveryAzureStorageAccountId = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.RecoveryAzureStorageAccountId)) ? this.RecoveryAzureStorageAccountId : replicationProviderSettings.ActiveStorageAccountId; this.encryption = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Encryption)) ? this.Encryption : ((string.Compare(replicationProviderSettings.Encryption, "Disabled", StringComparison.OrdinalIgnoreCase) == 0) ? Constants.Disable : Constants.Enable); var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput() { ApplicationConsistentSnapshotFrequencyInHours = this.applicationConsistentSnapshotFrequencyInHours, Encryption = this.encryption, OnlineIrStartTime = this.replicationStartTime, RecoveryPointHistoryDuration = this.recoveryPoints, ReplicationInterval = this.replicationFrequencyInSeconds }; hyperVReplicaAzurePolicyInput.StorageAccounts = new System.Collections.Generic.List <string>(); if (RecoveryAzureStorageAccountId != null) { string storageAccount = this.recoveryAzureStorageAccountId; hyperVReplicaAzurePolicyInput.StorageAccounts.Add(storageAccount); } var updatePolicyProperties = new UpdatePolicyProperties() { ReplicationProviderSettings = hyperVReplicaAzurePolicyInput }; var updatePolicyInput = new UpdatePolicyInput() { Properties = updatePolicyProperties }; LongRunningOperationResponse response = RecoveryServicesClient.UpdatePolicy(this.Policy.Name, updatePolicyInput); JobResponse jobResponse = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location)); WriteObject(new ASRJob(jobResponse.Job)); }
/// <summary> /// Creates an E2E Policy object /// </summary> private void EnterpriseToEnterprisePolicyObject() { if (string.Compare(this.Policy.ReplicationProvider, Constants.HyperVReplica2012, StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(this.Policy.ReplicationProvider, Constants.HyperVReplica2012R2, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Properties.Resources.IncorrectReplicationProvider, this.Policy.ReplicationProvider)); } var replicationProviderSettings = this.Policy.ReplicationProviderSettings as ASRHyperVReplicaPolicyDetails; this.replicationMethod = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicationMethod)) ? ((string.Compare(this.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0) ? "OverNetwork" : "Offline") : ((string.Compare(replicationProviderSettings.InitialReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0) ? "OverNetwork" : "Offline"); this.replicationFrequencyInSeconds = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicationFrequencyInSeconds)) ? PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds) : replicationProviderSettings.ReplicationFrequencyInSeconds; this.recoveryPoints = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.RecoveryPoints)) ? this.RecoveryPoints : replicationProviderSettings.RecoveryPoints; this.applicationConsistentSnapshotFrequencyInHours = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ApplicationConsistentSnapshotFrequencyInHours)) ? this.ApplicationConsistentSnapshotFrequencyInHours : replicationProviderSettings.ApplicationConsistentSnapshotFrequencyInHours; this.compression = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Compression)) ? this.Compression : replicationProviderSettings.Compression; this.replicationPort = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicationPort)) ? this.ReplicationPort : replicationProviderSettings.ReplicationPort; this.authentication = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Authentication)) ? ((ushort)((string.Compare(this.Authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2)) : ((ushort)((string.Compare(replicationProviderSettings.AllowedAuthenticationType, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2)); this.replicationStartTime = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicationStartTime)) ? this.replicationStartTime : replicationProviderSettings.OnlineReplicationStartTime; this.replicaDeletion = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicaDeletion)) ? this.ReplicaDeletion : replicationProviderSettings.ReplicaDeletionOption; var updatePolicyProperties = new UpdatePolicyProperties(); if (string.Compare(this.Policy.ReplicationProvider, Constants.HyperVReplica2012, StringComparison.OrdinalIgnoreCase) == 0) { updatePolicyProperties.ReplicationProviderSettings = new HyperVReplica2012PolicyInput() { AllowedAuthenticationType = this.authentication, ApplicationConsistentSnapshotFrequencyInHours = this.applicationConsistentSnapshotFrequencyInHours, Compression = this.compression, InitialReplicationMethod = this.replicationMethod, OnlineReplicationStartTime = this.replicationStartTime, RecoveryPoints = this.recoveryPoints, ReplicaDeletion = this.replicaDeletion, ReplicationPort = this.replicationPort }; } else { updatePolicyProperties.ReplicationProviderSettings = new HyperVReplica2012R2PolicyInput() { AllowedAuthenticationType = this.authentication, ApplicationConsistentSnapshotFrequencyInHours = this.applicationConsistentSnapshotFrequencyInHours, Compression = this.compression, InitialReplicationMethod = this.replicationMethod, OnlineReplicationStartTime = this.replicationStartTime, RecoveryPoints = this.recoveryPoints, ReplicaDeletion = this.replicaDeletion, ReplicationPort = this.replicationPort, ReplicationFrequencyInSeconds = replicationFrequencyInSeconds }; } var updatePolicyInput = new UpdatePolicyInput() { Properties = updatePolicyProperties }; LongRunningOperationResponse responseBlue = RecoveryServicesClient.UpdatePolicy(this.Policy.Name, updatePolicyInput); JobResponse jobResponseBlue = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(responseBlue.Location)); WriteObject(new ASRJob(jobResponseBlue.Job)); }
/// <summary> /// Creates an E2E Policy object /// </summary> private void EnterpriseToEnterprisePolicyObject() { if (string.Compare(this.ReplicationProvider, Constants.HyperVReplica2012, StringComparison.OrdinalIgnoreCase) != 0 && string.Compare(this.ReplicationProvider, Constants.HyperVReplica2012R2, StringComparison.OrdinalIgnoreCase) != 0) { throw new InvalidOperationException( string.Format( Properties.Resources.IncorrectReplicationProvider, this.ReplicationProvider)); } PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime); ushort replicationFrequencyInSeconds = PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(this.ReplicationFrequencyInSeconds); var createPolicyInputProperties = new CreatePolicyInputProperties(); if (string.Compare(this.ReplicationProvider, Constants.HyperVReplica2012, StringComparison.OrdinalIgnoreCase) == 0) { createPolicyInputProperties.ProviderSpecificInput = new HyperVReplica2012PolicyInput() { AllowedAuthenticationType = (ushort)((string.Compare(this.Authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2), ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours, Compression = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Compression)) ? this.Compression : Constants.Disable, InitialReplicationMethod = (string.Compare(this.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0) ? "OverNetwork" : "Offline", OnlineReplicationStartTime = this.ReplicationStartTime, RecoveryPoints = this.RecoveryPoints, ReplicaDeletion = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicaDeletion)) ? this.ReplicaDeletion : Constants.NotRequired, ReplicationPort = this.ReplicationPort }; } else { createPolicyInputProperties.ProviderSpecificInput = new HyperVReplica2012R2PolicyInput() { AllowedAuthenticationType = (ushort)((string.Compare(this.Authentication, Constants.AuthenticationTypeKerberos, StringComparison.OrdinalIgnoreCase) == 0) ? 1 : 2), ApplicationConsistentSnapshotFrequencyInHours = this.ApplicationConsistentSnapshotFrequencyInHours, Compression = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.Compression)) ? this.Compression : Constants.Disable, InitialReplicationMethod = (string.Compare(this.ReplicationMethod, Constants.OnlineReplicationMethod, StringComparison.OrdinalIgnoreCase) == 0) ? "OverNetwork" : "Offline", OnlineReplicationStartTime = this.ReplicationStartTime, RecoveryPoints = this.RecoveryPoints, ReplicaDeletion = this.MyInvocation.BoundParameters.ContainsKey(Utilities.GetMemberName(() => this.ReplicaDeletion)) ? this.ReplicaDeletion : Constants.NotRequired, ReplicationFrequencyInSeconds = replicationFrequencyInSeconds, ReplicationPort = this.ReplicationPort }; } var createPolicyInput = new CreatePolicyInput() { Properties = createPolicyInputProperties }; LongRunningOperationResponse responseBlue = RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput); JobResponse jobResponseBlue = RecoveryServicesClient .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(responseBlue.Location)); WriteObject(new ASRJob(jobResponseBlue.Job)); }