Azure Site Recovery Protection Entity.
        /// <summary>
        /// Write Protection Entity
        /// </summary>
        /// <param name="protectableItem"></param>
        private void WriteProtectionEntity(ProtectableItem protectableItem)
        {
            ASRProtectionEntity entity = RecoveryServicesClient.FetchProtectionEntityData <ASRProtectionEntity>(
                protectableItem, this.ProtectionContainer.ID, this.ProtectionContainer.Name);

            this.WriteObject(entity);
        }
        /// <summary>
        /// Start PE Commit.
        /// </summary>
        private void SetPECommit()
        {
            // fetch the latest PE object
            ProtectableItemResponse protectableItemResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(this.fabricName,
                                                                           this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name);

            ReplicationProtectedItemResponse replicationProtectedItemResponse =
                RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(this.fabricName,
                                                                                    this.ProtectionEntity.ProtectionContainerId, Utilities.GetValueFromArmId(protectableItemResponse.ProtectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));

            PolicyResponse policyResponse = RecoveryServicesClient.GetAzureSiteRecoveryPolicy(Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Properties.PolicyID, ARMResourceTypeConstants.ReplicationPolicies));

            this.ProtectionEntity = new ASRProtectionEntity(protectableItemResponse.ProtectableItem, replicationProtectedItemResponse.ReplicationProtectedItem);

            LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
                this.fabricName,
                this.protectionContainerName,
                Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Id, ARMResourceTypeConstants.ReplicationProtectedItems));

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Write Protection Entity
        /// </summary>
        /// <param name="protectableItem"></param>
        internal T FetchProtectionEntityData <T>(ProtectableItem protectableItem, string protectionContainerId, string protectionContainerName)
        {
            ReplicationProtectedItemResponse replicationProtectedItemResponse = null;

            if (!String.IsNullOrEmpty(protectableItem.Properties.ReplicationProtectedItemId))
            {
                replicationProtectedItemResponse = this.GetAzureSiteRecoveryReplicationProtectedItem(
                    Utilities.GetValueFromArmId(protectionContainerId, ARMResourceTypeConstants.ReplicationFabrics),
                    protectionContainerName,
                    Utilities.GetValueFromArmId(protectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));
            }

            if (replicationProtectedItemResponse != null && replicationProtectedItemResponse.ReplicationProtectedItem != null)
            {
                PolicyResponse policyResponse = this.GetAzureSiteRecoveryPolicy(Utilities.GetValueFromArmId(
                                                                                    replicationProtectedItemResponse.ReplicationProtectedItem.Properties.PolicyID, ARMResourceTypeConstants.ReplicationPolicies));
                if (typeof(T) == typeof(ASRVirtualMachine))
                {
                    var pe = new ASRVirtualMachine(protectableItem, replicationProtectedItemResponse.ReplicationProtectedItem, policyResponse.Policy);
                    return((T)Convert.ChangeType(pe, typeof(T)));
                }
                else
                {
                    var pe = new ASRProtectionEntity(protectableItem, replicationProtectedItemResponse.ReplicationProtectedItem, policyResponse.Policy);
                    return((T)Convert.ChangeType(pe, typeof(T)));
                }
            }
            else
            {
                if (typeof(T) == typeof(ASRVirtualMachine))
                {
                    var pe = new ASRVirtualMachine(protectableItem);
                    return((T)Convert.ChangeType(pe, typeof(T)));
                }
                else
                {
                    var pe = new ASRProtectionEntity(protectableItem);
                    return((T)Convert.ChangeType(pe, typeof(T)));
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts PE Test failover.
        /// </summary>
        private void StartPETestFailover()
        {
            var request = new TestFailoverRequest();

            if (this.ProtectionEntity == null)
            {
                var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
                    this.ProtectionEntity.ProtectionContainerId,
                    this.ProtectionEntity.Name);
                this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);

                /* this.ValidateUsageById(
                 *  this.ProtectionEntity.ReplicationProvider,
                 *  Constants.ProtectionEntityId); */
            }

            request.ReplicationProviderSettings = string.Empty;

            request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
            request.FailoverDirection   = this.Direction;

            request.NetworkID   = this.networkId;
            request.NetworkType = this.networkType;

            LongRunningOperationResponse response =
                RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                    this.ProtectionEntity.ProtectionContainerId,
                    this.ProtectionEntity.Name,
                    request);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Starts PE Test failover.
        /// </summary>
        private void StartPETestFailover()
        {
            var request = new TestFailoverRequest();

            if (this.ProtectionEntity == null)
            {
                var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
                    this.ProtectionEntity.ProtectionContainerId,
                    this.ProtectionEntity.Name);
                this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
            }

            request.FailoverDirection = this.Direction;
            request.NetworkID         = this.networkId;
            request.NetworkType       = this.networkType;

            if (string.IsNullOrEmpty(this.ProtectionEntity.ReplicationProvider))
            {
                // fetch the latest PE object
                // As get PE by name is failing before protection, get all & filter.
                // Once after we fix get pe by name, change the logic to use the same.
                ProtectionEntityListResponse protectionEntityListResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
                        this.ProtectionEntity.ProtectionContainerId);

                foreach (ProtectionEntity pe in protectionEntityListResponse.ProtectionEntities)
                {
                    if (0 == string.Compare(this.ProtectionEntity.FriendlyName, pe.Properties.FriendlyName, true))
                    {
                        this.ProtectionEntity = new ASRProtectionEntity(pe);
                        break;
                    }
                }
            }

            request.ReplicationProvider         = this.ProtectionEntity.ReplicationProvider;
            request.ReplicationProviderSettings = new FailoverReplicationProviderSpecificInput();

            if (0 == string.Compare(
                    this.ProtectionEntity.ReplicationProvider,
                    Constants.HyperVReplicaAzure,
                    StringComparison.OrdinalIgnoreCase))
            {
                AzureFailoverInput failoverInput = new AzureFailoverInput()
                {
                    PrimaryKekCertificatePfx   = string.Empty,
                    SecondaryKekCertificatePfx = string.Empty,
                    VaultLocation = this.GetCurrentValutLocation()
                };
                request.ReplicationProviderSettings = failoverInput;
            }

            LongRunningOperationResponse response =
                RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                    this.ProtectionEntity.ProtectionContainerId,
                    this.ProtectionEntity.Name,
                    request);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
        /// <summary>
        /// Start PE Commit.
        /// </summary>
        private void SetPECommit()
        {
            // fetch the latest PE object
            ProtectableItemResponse protectableItemResponse =
                                        RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(this.fabricName,
                                        this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name);

            ReplicationProtectedItemResponse replicationProtectedItemResponse =
                        RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(this.fabricName,
                        this.ProtectionEntity.ProtectionContainerId, Utilities.GetValueFromArmId(protectableItemResponse.ProtectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));

            PolicyResponse policyResponse = RecoveryServicesClient.GetAzureSiteRecoveryPolicy(Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Properties.PolicyID, ARMResourceTypeConstants.ReplicationPolicies));

            this.ProtectionEntity = new ASRProtectionEntity(protectableItemResponse.ProtectableItem, replicationProtectedItemResponse.ReplicationProtectedItem);

            LongRunningOperationResponse response = RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
                this.fabricName,
                this.protectionContainerName,
                Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Id, ARMResourceTypeConstants.ReplicationProtectedItems));

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
        /// <summary>
        /// Starts PE Test failover.
        /// </summary>
        private void StartPETestFailover()
        {
            var request = new TestFailoverRequest();

            if (this.ProtectionEntity == null)
            {
                var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
                    this.ProtectionEntity.ProtectionContainerId,
                    this.ProtectionEntity.Name);
                this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);
            }

            request.FailoverDirection = this.Direction;
            request.NetworkID = this.networkId;
            request.NetworkType = this.networkType;

            if (string.IsNullOrEmpty(this.ProtectionEntity.ReplicationProvider))
            {
                // fetch the latest PE object
                // As get PE by name is failing before protection, get all & filter.
                // Once after we fix get pe by name, change the logic to use the same.
                ProtectionEntityListResponse protectionEntityListResponse =
                    RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
                    this.ProtectionEntity.ProtectionContainerId);

                foreach (ProtectionEntity pe in protectionEntityListResponse.ProtectionEntities)
                {
                    if (0 == string.Compare(this.ProtectionEntity.FriendlyName, pe.Properties.FriendlyName, true))
                    {
                        this.ProtectionEntity = new ASRProtectionEntity(pe);
                        break;
                    }
                }
            }

            request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
            request.ReplicationProviderSettings = new FailoverReplicationProviderSpecificInput();

            if (0 == string.Compare(
                this.ProtectionEntity.ReplicationProvider,
                Constants.HyperVReplicaAzure,
                StringComparison.OrdinalIgnoreCase))
            {
                AzureFailoverInput failoverInput = new AzureFailoverInput()
                {
                    PrimaryKekCertificatePfx = string.Empty,
                    SecondaryKekCertificatePfx = string.Empty,
                    VaultLocation = this.GetCurrentValutLocation()
                };
                request.ReplicationProviderSettings = failoverInput;
            }

            LongRunningOperationResponse response =
                RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                this.ProtectionEntity.ProtectionContainerId,
                this.ProtectionEntity.Name,
                request);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }
        /// <summary>
        /// Starts PE Test failover.
        /// </summary>
        private void StartPETestFailover()
        {
            var request = new TestFailoverRequest();

            if (this.ProtectionEntity == null)
            {
                var pe = RecoveryServicesClient.GetAzureSiteRecoveryProtectionEntity(
                    this.ProtectionEntity.ProtectionContainerId,
                    this.ProtectionEntity.Name);
                this.ProtectionEntity = new ASRProtectionEntity(pe.ProtectionEntity);

                /* this.ValidateUsageById(
                    this.ProtectionEntity.ReplicationProvider,
                    Constants.ProtectionEntityId); */
            }

            request.ReplicationProviderSettings = string.Empty;

            request.ReplicationProvider = this.ProtectionEntity.ReplicationProvider;
            request.FailoverDirection = this.Direction;

            request.NetworkID = this.networkId;
            request.NetworkType = this.networkType;

            LongRunningOperationResponse response =
                RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                this.ProtectionEntity.ProtectionContainerId,
                this.ProtectionEntity.Name,
                request);

            JobResponse jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

            WriteObject(new ASRJob(jobResponse.Job));
        }