/// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.InputObject != null)
            {
                this.Name = this.InputObject.Name;
            }

            if (this.ShouldProcess(
                    this.Name,
                    VerbsCommon.Remove))
            {
                if (string.Compare(
                        this.ParameterSetName,
                        ASRParameterSets.ByObject,
                        StringComparison.OrdinalIgnoreCase) ==
                    0)
                {
                    this.Name = this.InputObject.Name;
                }

                var response =
                    this.RecoveryServicesClient.RemoveAzureSiteRecoveryRecoveryPlan(this.Name);

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

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
示例#2
0
        /// <summary>
        ///     Starts RP cancel failover.
        /// </summary>
        private void StartRpCancelFailover()
        {
            var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
                this.RecoveryPlan.Name);

            foreach (var replicationProvider in rp.Properties.ReplicationProviders)
            {
                if (string.Compare(
                        replicationProvider,
                        Constants.InMageRcmFailback,
                        StringComparison.OrdinalIgnoreCase) !=
                    0)
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  Resources.UnsupportedReplicationProtectionActionForCancelFailover,
                                  replicationProvider));
                }
            }

            var response =
                this.RecoveryServicesClient.StartAzureSiteRecoveryCancelFailover(
                    this.RecoveryPlan.Name);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(this.InputObject.Name, VerbsCommon.Remove))
            {
                var protectionContainer =
                    this.RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainer(
                        Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics),
                        this.InputObject.Name);
                if (protectionContainer == null)
                {
                    throw new Exception(
                              string.Format(
                                  Resources.ProtectionContainerNotFound,
                                  this.InputObject.Name,
                                  PSRecoveryServicesClient.asrVaultCreds.ResourceName));
                }

                var response = this.RecoveryServicesClient.RemoveProtectionContainer(
                    Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics),
                    protectionContainer.Name);

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

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
        /// <summary>
        ///     Resumes by Name.
        /// </summary>
        private void ResumesByName()
        {
            var resumeJobParams = new ResumeJobParams();

            if (string.IsNullOrEmpty(this.Comment))
            {
                this.Comment = " ";
            }

            resumeJobParams.Properties          = new ResumeJobParamsProperties();
            resumeJobParams.Properties.Comments = this.Comment;
            var job = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(this.Name);

            if (job != null)
            {
                if (job.Properties.ScenarioName.Equals("TestFailover", System.StringComparison.CurrentCultureIgnoreCase))
                {
                    throw new InvalidOperationException(
                              string.Format(Resources.ResumeTFOJobNotSupported, job.Name));
                }
            }
            var response = this.RecoveryServicesClient.ResumeAzureSiteRecoveryJob(
                this.Name,
                resumeJobParams);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
示例#5
0
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    this.Name,
                    VerbsCommon.New))
            {
                var fabricType = string.IsNullOrEmpty(this.Type) ? FabricProviders.HyperVSite
                    : this.Type;

                var input = new FabricCreationInput();
                input.Properties = new FabricCreationInputProperties();

                input.Properties.CustomDetails = new FabricSpecificCreationInput();

                var response = this.RecoveryServicesClient.CreateAzureSiteRecoveryFabric(
                    this.Name,
                    input);

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

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    this.InputObject.FriendlyName,
                    VerbsCommon.Remove))
            {
                var response = this.RecoveryServicesClient.RemoveAzureSiteRecoveryNetworkMapping(
                    Utilities.GetValueFromArmId(
                        this.InputObject.ID,
                        ARMResourceTypeConstants.ReplicationFabrics),
                    Utilities.GetValueFromArmId(
                        this.InputObject.ID,
                        "replicationNetworks"),
                    Utilities.GetValueFromArmId(
                        this.InputObject.ID,
                        "replicationNetworkMappings"));

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

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
示例#7
0
        /// <summary>
        /// Azure to Azure network mapping.
        /// </summary>
        private void AzureToAzureNetworkMapping()
        {
            CreateNetworkMappingInput input = new CreateNetworkMappingInput
            {
                Properties = new CreateNetworkMappingInputProperties
                {
                    RecoveryFabricName    = this.RecoveryFabric.Name,
                    RecoveryNetworkId     = this.RecoveryAzureNetworkId,
                    FabricSpecificDetails = new AzureToAzureCreateNetworkMappingInput()
                    {
                        PrimaryNetworkId = this.PrimaryAzureNetworkId
                    }
                }
            };

            var response =
                RecoveryServicesClient
                .NewAzureSiteRecoveryNetworkMapping(
                    this.PrimaryFabric.Name,
                    ARMResourceTypeConstants.AzureNetwork,
                    this.Name,
                    input);

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

            WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///      Update replication protection direction for recovery plan.
        /// </summary>
        private void SetRPReprotect()
        {
            // Check if the Recovery Plan contains any InMageAzureV2 and InMage Replication Provider Entities.
            var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
                this.RecoveryPlan
                .Name);

            foreach (var replicationProvider in rp.Properties.ReplicationProviders)
            {
                if (Constants.InMageAzureV2.Equals(replicationProvider, StringComparison.OrdinalIgnoreCase) ||
                    Constants.InMage.Equals(replicationProvider, StringComparison.OrdinalIgnoreCase) ||
                    Constants.A2A.Equals(replicationProvider, StringComparison.OrdinalIgnoreCase))
                {
                    throw new InvalidOperationException(
                              string.Format(
                                  Resources.UnsupportedReplicationProviderForReprotect,
                                  replicationProvider));
                }
            }

            var response =
                this.RecoveryServicesClient.UpdateAzureSiteRecoveryProtection(
                    this.RecoveryPlan.Name);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
示例#9
0
        /// <summary>
        ///     Remove Server
        /// </summary>
        private void RemoveServiceProvider()
        {
            PSSiteRecoveryLongRunningOperation response;

            if (!this.Force.IsPresent)
            {
                response = this.RecoveryServicesClient.RemoveAzureSiteRecoveryProvider(
                    Utilities.GetValueFromArmId(
                        this.InputObject.ID,
                        ARMResourceTypeConstants.ReplicationFabrics),
                    this.InputObject.Name);
            }
            else
            {
                response = this.RecoveryServicesClient.PurgeAzureSiteRecoveryProvider(
                    Utilities.GetValueFromArmId(
                        this.InputObject.ID,
                        ARMResourceTypeConstants.ReplicationFabrics),
                    this.InputObject.Name);
            }

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    this.InputObject.FriendlyName,
                    VerbsCommon.Remove))
            {
                PSSiteRecoveryLongRunningOperation response;

                if (!this.Force.IsPresent)
                {
                    response =
                        this.RecoveryServicesClient.DeleteAzureSiteRecoveryFabric(
                            this.InputObject.Name);
                }
                else
                {
                    response =
                        this.RecoveryServicesClient.PurgeAzureSiteRecoveryFabric(
                            this.InputObject.Name);
                }

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

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
        /// <summary>
        ///     Update Azure to Azure network mapping.
        /// </summary>
        private void UpdateAzureToAzureNetworkMapping()
        {
            // Add following checks if needed:
            // Verify whether the subscription is associated with the account or not.
            // Check if the Azure VM Network is associated with the Subscription or not.

            var input = new UpdateNetworkMappingInput
            {
                Properties = new UpdateNetworkMappingInputProperties
                {
                    RecoveryFabricName    = this.InputObject.RecoveryFabricFriendlyName,
                    RecoveryNetworkId     = this.RecoveryAzureNetworkId,
                    FabricSpecificDetails = new AzureToAzureUpdateNetworkMappingInput
                    {
                        PrimaryNetworkId = this.InputObject.PrimaryNetworkId
                    }
                }
            };
            var response = this.RecoveryServicesClient.UpdateAzureSiteRecoveryNetworkMapping(
                this.InputObject.PrimaryFabricFriendlyName,
                ARMResourceTypeConstants.AzureNetwork,
                this.InputObject.Name,
                input);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
示例#12
0
        /// <summary>
        ///     Starts RPI Unplanned failover.
        /// </summary>
        private void StartRPIUnplannedFailover()
        {
            var unplannedFailoverInputProperties = new UnplannedFailoverInputProperties
            {
                FailoverDirection       = this.Direction,
                SourceSiteOperations    = this.PerformSourceSideAction ? "Required" : "NotRequired",
                ProviderSpecificDetails = new ProviderSpecificFailoverInput()
            };

            var input =
                new UnplannedFailoverInput {
                Properties = unplannedFailoverInputProperties
            };

            if (0 ==
                string.Compare(
                    this.ReplicationProtectedItem.ReplicationProvider,
                    Constants.HyperVReplicaAzure,
                    StringComparison.OrdinalIgnoreCase))
            {
                if (this.Direction == Constants.PrimaryToRecovery)
                {
                    var failoverInput = new HyperVReplicaAzureFailoverProviderInput
                    {
                        PrimaryKekCertificatePfx   = this.primaryKekCertpfx,
                        SecondaryKekCertificatePfx = this.secondaryKekCertpfx,
                        VaultLocation   = "dummy",
                        RecoveryPointId = this.RecoveryPoint == null ? null : this.RecoveryPoint.ID
                    };
                    input.Properties.ProviderSpecificDetails = failoverInput;
                }
            }
            else if (string.Compare(
                         this.ReplicationProtectedItem.ReplicationProvider,
                         Constants.InMageAzureV2,
                         StringComparison.OrdinalIgnoreCase) ==
                     0)
            {
                this.InMageAzureV2UnplannedFailover(input);
            }
            else if (string.Compare(
                         this.ReplicationProtectedItem.ReplicationProvider,
                         Constants.InMage,
                         StringComparison.OrdinalIgnoreCase) ==
                     0)
            {
                this.InMageUnplannedFailover(input);
            }

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover(
                this.fabricName,
                this.protectionContainerName,
                this.ReplicationProtectedItem.Name,
                input);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Helper to configure cloud
        /// </summary>
        private void Associate(
            string targetProtectionContainerId)
        {
            var inputProperties = new CreateProtectionContainerMappingInputProperties
            {
                PolicyId = this.Policy.ID,
                ProviderSpecificInput       = new ReplicationProviderSpecificContainerMappingInput(),
                TargetProtectionContainerId = targetProtectionContainerId
            };

            var input = new CreateProtectionContainerMappingInput {
                Properties = inputProperties
            };

            var response = this.RecoveryServicesClient.ConfigureProtection(
                Utilities.GetValueFromArmId(
                    this.PrimaryProtectionContainer.ID,
                    ARMResourceTypeConstants.ReplicationFabrics),
                this.PrimaryProtectionContainer.Name,
                this.Name,
                input);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Enterprise to enterprise network mapping.
        /// </summary>
        private void EnterpriseToEnterpriseNetworkMapping()
        {
            var mappingName = this.Name;

            var input = new CreateNetworkMappingInput
            {
                Properties = new CreateNetworkMappingInputProperties
                {
                    RecoveryFabricName = Utilities.GetValueFromArmId(
                        this.RecoveryNetwork.ID,
                        ARMResourceTypeConstants.ReplicationFabrics),
                    RecoveryNetworkId     = this.RecoveryNetwork.ID,
                    FabricSpecificDetails = new VmmToVmmCreateNetworkMappingInput()
                }
            };

            var response = this.RecoveryServicesClient.NewAzureSiteRecoveryNetworkMapping(
                Utilities.GetValueFromArmId(
                    this.PrimaryNetwork.ID,
                    ARMResourceTypeConstants.ReplicationFabrics),
                Utilities.GetValueFromArmId(
                    this.PrimaryNetwork.ID,
                    ARMResourceTypeConstants.ReplicationNetworks),
                mappingName,
                input);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Enterprise to Azure network mapping.
        /// </summary>
        private void EnterpriseToAzureNetworkMapping()
        {
            // Add following checks if needed:
            // Verify whether the subscription is associated with the account or not.
            // Check if the Azure VM Network is associated with the Subscription or not.

            var mappingName = this.Name;

            var input = new CreateNetworkMappingInput
            {
                Properties = new CreateNetworkMappingInputProperties
                {
                    RecoveryFabricName    = "Microsoft Azure",
                    RecoveryNetworkId     = this.RecoveryAzureNetworkId,
                    FabricSpecificDetails = new VmmToAzureCreateNetworkMappingInput()
                }
            };

            var response = this.RecoveryServicesClient.NewAzureSiteRecoveryNetworkMapping(
                Utilities.GetValueFromArmId(
                    this.PrimaryNetwork.ID,
                    ARMResourceTypeConstants.ReplicationFabrics),
                Utilities.GetValueFromArmId(
                    this.PrimaryNetwork.ID,
                    ARMResourceTypeConstants.ReplicationNetworks),
                mappingName,
                input);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Creates an E2A Policy Object
        /// </summary>
        private void HyperVToAzurePolicyObject()
        {
            if (string.Compare(
                    this.ReplicationProvider,
                    Constants.HyperVReplicaAzure,
                    StringComparison.OrdinalIgnoreCase) !=
                0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.IncorrectReplicationProvider,
                              this.ReplicationProvider));
            }

            PSRecoveryServicesClient.ValidateReplicationStartTime(this.ReplicationStartTime);

            var replicationFrequencyInSeconds =
                PSRecoveryServicesClient.ConvertReplicationFrequencyToUshort(
                    this.ReplicationFrequencyInSeconds);

            var hyperVReplicaAzurePolicyInput = new HyperVReplicaAzurePolicyInput
            {
                ApplicationConsistentSnapshotFrequencyInHours =
                    this.ApplicationConsistentSnapshotFrequencyInHours,
                OnlineReplicationStartTime =
                    this.ReplicationStartTime == null ? null : this.ReplicationStartTime.ToString(),
                RecoveryPointHistoryDuration = this.NumberOfRecoveryPointsToRetain,
                ReplicationInterval          = replicationFrequencyInSeconds
            };

            hyperVReplicaAzurePolicyInput.StorageAccounts = new List <string>();

            if (this.RecoveryAzureStorageAccountId != null)
            {
                var storageAccount = this.RecoveryAzureStorageAccountId;
                hyperVReplicaAzurePolicyInput.StorageAccounts.Add(storageAccount);
            }

            var createPolicyInputProperties =
                new CreatePolicyInputProperties
            {
                ProviderSpecificInput = hyperVReplicaAzurePolicyInput
            };

            var createPolicyInput =
                new CreatePolicyInput {
                Properties = createPolicyInputProperties
            };

            var response = this.RecoveryServicesClient.CreatePolicy(
                this.Name,
                createPolicyInput);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
示例#17
0
        /// <summary>
        ///     Restart by Name.
        /// </summary>
        private void RestartByName()
        {
            var response = this.RecoveryServicesClient.RestartAzureSiteRecoveryJob(this.Name);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
示例#18
0
        /// <summary>
        ///     Starts RP Unplanned failover.
        /// </summary>
        private void StartRpUnplannedFailover()
        {
            // Refresh RP Object
            var rp = this.RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(
                this.RecoveryPlan.Name);

            var recoveryPlanUnplannedFailoverInputProperties =
                new RecoveryPlanUnplannedFailoverInputProperties
            {
                FailoverDirection =
                    this.Direction == PossibleOperationsDirections.PrimaryToRecovery.ToString()
                            ? PossibleOperationsDirections.PrimaryToRecovery
                            : PossibleOperationsDirections.RecoveryToPrimary,
                SourceSiteOperations = this.PerformSourceSideAction
                        ? SourceSiteOperations.Required
                        : SourceSiteOperations.NotRequired, //Required|NotRequired
                ProviderSpecificDetails = new List <RecoveryPlanProviderSpecificFailoverInput>()
            };

            foreach (var replicationProvider in rp.Properties.ReplicationProviders)
            {
                if (0 ==
                    string.Compare(
                        replicationProvider,
                        Constants.HyperVReplicaAzure,
                        StringComparison.OrdinalIgnoreCase))
                {
                    if (this.Direction == Constants.PrimaryToRecovery)
                    {
                        var recoveryPlanHyperVReplicaAzureFailoverInput =
                            new RecoveryPlanHyperVReplicaAzureFailoverInput
                        {
                            PrimaryKekCertificatePfx   = this.primaryKekCertpfx,
                            SecondaryKekCertificatePfx = this.secondaryKekCertpfx,
                            VaultLocation = "dummy"
                        };
                        recoveryPlanUnplannedFailoverInputProperties.ProviderSpecificDetails.Add(
                            recoveryPlanHyperVReplicaAzureFailoverInput);
                    }
                }
            }

            var recoveryPlanUnplannedFailoverInput = new RecoveryPlanUnplannedFailoverInput
            {
                Properties = recoveryPlanUnplannedFailoverInputProperties
            };

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryUnplannedFailover(
                this.RecoveryPlan.Name,
                recoveryPlanUnplannedFailoverInput);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(this.InputObject.Name, VerbsData.Update))
            {
                if (this.ShouldProcess(this.InputObject.Name, VerbsData.Update))
                {
                    var protectionContainerMapping =
                        this.RecoveryServicesClient.GetAzureSiteRecoveryProtectionContainerMapping(
                            Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics),
                            Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers),
                            Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ProtectionContainerMappings));
                    if (protectionContainerMapping == null)
                    {
                        throw new Exception(
                                  string.Format(
                                      Resources.ProtectionContainerNotFound,
                                      this.InputObject.Name,
                                      PSRecoveryServicesClient.asrVaultCreds.ResourceName));
                    }

                    var updateInput = new UpdateProtectionContainerMappingInput();
                    updateInput.Properties = new UpdateProtectionContainerMappingInputProperties();
                    updateInput.Properties.ProviderSpecificInput = new A2AUpdateContainerMappingInput();

                    switch (this.ParameterSetName)
                    {
                    case AzureToAzureEnableAutoUpdate:
                        updateInput.Properties.ProviderSpecificInput = new A2AUpdateContainerMappingInput
                        {
                            AgentAutoUpdateStatus  = AgentAutoUpdateStatus.Enabled,
                            AutomationAccountArmId = this.AutomationAccountId
                        };
                        break;

                    case AzureToAzureDisableAutoUpdate:
                        updateInput.Properties.ProviderSpecificInput = new A2AUpdateContainerMappingInput
                        {
                            AgentAutoUpdateStatus = AgentAutoUpdateStatus.Disabled
                        };
                        break;
                    }

                    var response = this.RecoveryServicesClient.UpdateAzureSiteRecoveryProtectionContainerMapping(
                        Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationFabrics),
                        Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ReplicationProtectionContainers),
                        Utilities.GetValueFromArmId(this.InputObject.ID, ARMResourceTypeConstants.ProtectionContainerMappings),
                        updateInput);
                    var jobResponse = this.RecoveryServicesClient.GetAzureSiteRecoveryJobDetails(
                        PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location));

                    this.WriteObject(new ASRJob(jobResponse));
                }
            }
        }
示例#20
0
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    TargetProcessServer.FriendlyName,
                    "Switch the process server"))
            {
                // Set the Fabric Name and Protection Container Name.
                this.fabricName = this.Fabric.Name;
                var protectionContainerList = this.RecoveryServicesClient
                                              .GetAzureSiteRecoveryProtectionContainer(this.fabricName);
                this.protectionContainerName = protectionContainerList[0].Name;

                var failoverPSRequestProperties = new FailoverProcessServerRequestProperties();
                failoverPSRequestProperties.SourceProcessServerId = this.SourceProcessServer.Id;
                failoverPSRequestProperties.TargetProcessServerId = this.TargetProcessServer.Id;
                failoverPSRequestProperties.ContainerName         = this.protectionContainerName;

                if (this.ReplicationProtectedItem != null)
                {
                    this.protectedItemsIdsForRpi = new List <string>();
                    foreach (var replicationProtectedItem in this.ReplicationProtectedItem)
                    {
                        this.protectedItemsIdsForRpi.Add(
                            Utilities.GetValueFromArmId(
                                replicationProtectedItem.ProtectableItemId,
                                ARMResourceTypeConstants.ProtectableItems));
                    }

                    failoverPSRequestProperties.VmsToMigrate = this.protectedItemsIdsForRpi;
                    failoverPSRequestProperties.UpdateType   =
                        ProcessServerFailoverType.ServerLevel.ToString();
                }
                else
                {
                    failoverPSRequestProperties.UpdateType =
                        ProcessServerFailoverType.SystemLevel.ToString();
                }

                var failoverPSRequest = new FailoverProcessServerRequest
                {
                    Properties = failoverPSRequestProperties
                };

                // Switch the process server.
                var response = this.RecoveryServicesClient.ReassociateProcessServer(
                    this.fabricName,
                    failoverPSRequest);

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

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
示例#21
0
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    this.InputObject.FriendlyName,
                    VerbsCommon.Remove))
            {
                if (!this.Force.IsPresent)
                {
                    var input = new DisableProtectionInput();
                    input.Properties = new DisableProtectionInputProperties
                    {
                        ReplicationProviderInput = new DisableProtectionProviderSpecificInput()
                    };
                    this.response = this.RecoveryServicesClient.DisableProtection(
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationFabrics),
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationProtectionContainers),
                        this.InputObject.Name,
                        input);
                }
                else
                {
                    this.response = this.RecoveryServicesClient.PurgeProtection(
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationFabrics),
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationProtectionContainers),
                        this.InputObject.Name);
                }

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

                this.WriteObject(new ASRJob(this.jobResponse));

                if (this.WaitForCompletion.IsPresent)
                {
                    this.WaitForJobCompletion(this.jobResponse.Name);

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

                    this.WriteObject(new ASRJob(this.jobResponse));
                }
            }
        }
示例#22
0
        /// <summary>
        ///     Starts RP Reprotect.
        /// </summary>
        private void SetRPReprotect()
        {
            var response =
                this.RecoveryServicesClient.UpdateAzureSiteRecoveryProtection(
                    this.RecoveryPlan.Name);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
示例#23
0
        /// <summary>
        ///     Starts RP Commit.
        /// </summary>
        private void StartRpCommit()
        {
            var response =
                this.RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
                    this.RecoveryPlan.Name);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            switch (this.ParameterSetName)
            {
            case ASRParameterSets.Default:

                this.fabricName = Utilities.GetValueFromArmId(
                    this.ReplicationProtectedItem.ID,
                    ARMResourceTypeConstants.ReplicationFabrics);

                this.protectionContainerName = Utilities.GetValueFromArmId(
                    this.ReplicationProtectedItem.ID,
                    ARMResourceTypeConstants.ReplicationProtectionContainers);

                this.rpiName = this.ReplicationProtectedItem.Name;

                break;

            case ASRParameterSets.ByResourceId:

                this.fabricName = Utilities.GetValueFromArmId(
                    this.ResourceId,
                    ARMResourceTypeConstants.ReplicationFabrics);

                this.protectionContainerName = Utilities.GetValueFromArmId(
                    this.ResourceId,
                    ARMResourceTypeConstants.ReplicationProtectionContainers);

                this.rpiName = Utilities.GetValueFromArmId(
                    this.ResourceId,
                    ARMResourceTypeConstants.ReplicationProtectedItems);

                break;
            }

            if (this.ShouldProcess(
                    this.rpiName,
                    "Resyncronize replicated item "))
            {
                // Resync Replication of the Protected Item.
                var response = this.RecoveryServicesClient.StartAzureSiteRecoveryResynchronizeReplication(
                    this.fabricName,
                    this.protectionContainerName,
                    this.rpiName);

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

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
示例#25
0
        /// <summary>
        ///     Start RPI Commit.
        /// </summary>
        private void SetRPICommit()
        {
            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryCommitFailover(
                this.fabricName,
                this.protectionContainerName,
                this.ReplicationProtectedItem.Name);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Create Replication Plan: Utility call
        /// </summary>
        private void CreateRecoveryPlan(
            string recoveryPlanName,
            CreateRecoveryPlanInput createRecoveryPlanInput)
        {
            var response = this.RecoveryServicesClient.CreateAzureSiteRecoveryRecoveryPlan(
                recoveryPlanName,
                createRecoveryPlanInput);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
示例#27
0
        /// <summary>
        ///     Refresh Server
        /// </summary>
        private void RefreshServicesProvider()
        {
            var response = this.RecoveryServicesClient.RefreshAzureSiteRecoveryProvider(
                Utilities.GetValueFromArmId(
                    this.InputObject.ID,
                    ARMResourceTypeConstants.ReplicationFabrics),
                this.InputObject.Name);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    this.InputObject.Name,
                    VerbsCommon.Remove))
            {
                PSSiteRecoveryLongRunningOperation response = null;

                if (!this.Force.IsPresent)
                {
                    var inputProperties = new RemoveProtectionContainerMappingInputProperties
                    {
                        ProviderSpecificInput = new ReplicationProviderContainerUnmappingInput()
                    };

                    var input =
                        new RemoveProtectionContainerMappingInput {
                        Properties = inputProperties
                    };

                    response = this.RecoveryServicesClient.UnConfigureProtection(
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationFabrics),
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationProtectionContainers),
                        this.InputObject.Name,
                        input);
                }
                else
                {
                    response = this.RecoveryServicesClient.PurgeCloudMapping(
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationFabrics),
                        Utilities.GetValueFromArmId(
                            this.InputObject.ID,
                            ARMResourceTypeConstants.ReplicationProtectionContainers),
                        this.InputObject.Name);
                }

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

                this.WriteObject(new ASRJob(jobResponse));
            }
        }
示例#29
0
        /// <summary>
        ///     Starts RPI Test failover.
        /// </summary>
        private void StartRPITestFailover()
        {
            var testFailoverInputProperties = new TestFailoverInputProperties
            {
                FailoverDirection       = this.Direction,
                NetworkId               = this.networkId,
                NetworkType             = this.networkType,
                ProviderSpecificDetails = new ProviderSpecificFailoverInput()
            };

            var input = new TestFailoverInput {
                Properties = testFailoverInputProperties
            };

            if (0 ==
                string.Compare(
                    this.ReplicationProtectedItem.ReplicationProvider,
                    Constants.HyperVReplicaAzure,
                    StringComparison.OrdinalIgnoreCase))
            {
                if (this.Direction == Constants.PrimaryToRecovery)
                {
                    var failoverInput = new HyperVReplicaAzureFailoverProviderInput
                    {
                        PrimaryKekCertificatePfx   = this.primaryKekCertpfx,
                        SecondaryKekCertificatePfx = this.secondaryKekCertpfx
                    };

                    input.Properties.ProviderSpecificDetails = failoverInput;
                }
                else
                {
                    new ArgumentException(
                        Resources
                        .UnsupportedDirectionForTFO);     // Throw Unsupported Direction Exception
                }
            }

            var response = this.RecoveryServicesClient.StartAzureSiteRecoveryTestFailover(
                this.fabricName,
                this.protectionContainerName,
                this.ReplicationProtectedItem.Name,
                input);

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

            this.WriteObject(new ASRJob(jobResponse));
        }
        /// <summary>
        ///     Creates an InMageRcm policy.
        /// </summary>
        private void CreateInMageRcmPolicy()
        {
            if (string.Compare(
                    this.ReplicationProvider,
                    Constants.InMageRcm,
                    StringComparison.OrdinalIgnoreCase) !=
                0)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Resources.IncorrectReplicationProvider,
                              this.ReplicationProvider));
            }

            this.MultiVmSyncStatus =
                this.MyInvocation.BoundParameters.ContainsKey(
                    Utilities.GetMemberName(() => this.MultiVmSyncStatus)) ?
                this.MultiVmSyncStatus :
                Constants.Enable;
            var crashConsistentFrequencyInMinutes = 5;

            var createPolicyInput = new CreatePolicyInput()
            {
                Properties = new CreatePolicyInputProperties()
                {
                    ProviderSpecificInput = new InMageRcmPolicyCreationInput()
                    {
                        RecoveryPointHistoryInMinutes     = this.RecoveryPointRetentionInHours * 60,
                        CrashConsistentFrequencyInMinutes = crashConsistentFrequencyInMinutes,
                        AppConsistentFrequencyInMinutes   =
                            this.ApplicationConsistentSnapshotFrequencyInHours * 60,
                        EnableMultiVmSync = this.MultiVmSyncStatus.Equals(Constants.Enable) ?
                                            Constants.True :
                                            Constants.False
                    }
                }
            };

            var response =
                RecoveryServicesClient.CreatePolicy(this.Name, createPolicyInput);

            string jobId       = PSRecoveryServicesClient.GetJobIdFromReponseLocation(response.Location);
            var    jobResponse =
                RecoveryServicesClient
                .GetAzureSiteRecoveryJobDetails(jobId);

            WriteObject(new ASRJob(jobResponse));
        }