/// <summary>
 ///     validate parameter values for recovery plan.
 /// </summary>
 private void validateRPSwitchParam(RecoveryPlan rp, string replicationProvider)
 {
     if ((this.HyperVToAzure.IsPresent &&
          !replicationProvider.Equals(Constants.HyperVReplicaAzure)) ||
         (this.VmmToVmm.IsPresent &&
          !(this.ReplicationProtectedItem.ReplicationProvider.Equals(Constants.HyperVReplica2012) ||
            replicationProvider.Equals(Constants.HyperVReplica2012R2))))
     {
         throw new PSInvalidOperationException(Resources.InvalidParameterSet);
     }
 }
コード例 #2
0
        /// <summary>
        /// Update Recovery Plan: By Service object
        /// </summary>
        private void UpdateRecoveryPlan(RecoveryPlan recoveryPlan)
        {
            UpdateRecoveryPlanInputProperties updateRecoveryPlanInputProperties = new UpdateRecoveryPlanInputProperties()
            {
                Groups = recoveryPlan.Properties.Groups,
            };

            UpdateRecoveryPlanInput updateRecoveryPlanInput = new UpdateRecoveryPlanInput()
            {
                Properties = updateRecoveryPlanInputProperties
            };

            UpdateRecoveryPlan(recoveryPlan.Name, updateRecoveryPlanInput);
        }
コード例 #3
0
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            switch (this.ParameterSetName)
            {
            case ASRParameterSets.EnterpriseToEnterprise:
                failoverDeploymentModel = Constants.NotApplicable;
                this.primaryserver      = RecoveryServicesClient.GetAzureSiteRecoveryFabric(Utilities.GetValueFromArmId(this.PrimaryServer.ID, ARMResourceTypeConstants.ReplicationFabrics)).Fabric.Id;
                this.recoveryserver     = RecoveryServicesClient.GetAzureSiteRecoveryFabric(Utilities.GetValueFromArmId(this.RecoveryServer.ID, ARMResourceTypeConstants.ReplicationFabrics)).Fabric.Id;
                break;

            case ASRParameterSets.EnterpriseToAzure:
                failoverDeploymentModel = this.FailoverDeploymentModel;
                this.primaryserver      = RecoveryServicesClient.GetAzureSiteRecoveryFabric(Utilities.GetValueFromArmId(this.PrimaryServer.ID, ARMResourceTypeConstants.ReplicationFabrics)).Fabric.Id;
                this.recoveryserver     = Constants.AzureContainer;
                break;

            case ASRParameterSets.HyperVSiteToAzure:
                failoverDeploymentModel = this.FailoverDeploymentModel;
                this.primaryserver      = this.PrimarySite.ID;
                this.recoveryserver     = Constants.AzureContainer;
                break;

            case ASRParameterSets.ByRPFile:

                if (!File.Exists(this.Path))
                {
                    throw new FileNotFoundException(string.Format(Properties.Resources.FileNotFound, this.Path));;
                }

                string filePath = this.Path;

                using (System.IO.StreamReader file = new System.IO.StreamReader(filePath))
                {
                    recoveryPlan = JsonConvert.DeserializeObject <RecoveryPlan>(file.ReadToEnd(), new RecoveryPlanActionDetailsConverter());
                }

                break;
            }

            if (string.Compare(this.ParameterSetName, ASRParameterSets.ByRPFile, StringComparison.OrdinalIgnoreCase) == 0)
            {
                CreateRecoveryPlan(recoveryPlan);
            }
            else
            {
                this.CreateRecoveryPlan();
            }
        }
        /// <summary>
        ///     Update Recovery Plan: By Service object
        /// </summary>
        private void UpdateRecoveryPlan(
            RecoveryPlan recoveryPlan)
        {
            var updateRecoveryPlanInputProperties =
                new UpdateRecoveryPlanInputProperties {
                Groups = recoveryPlan.Properties.Groups
            };

            var updateRecoveryPlanInput =
                new UpdateRecoveryPlanInput {
                Properties = updateRecoveryPlanInputProperties
            };

            this.UpdateRecoveryPlan(
                recoveryPlan.Name,
                updateRecoveryPlanInput);
        }
コード例 #5
0
        /// <summary>
        /// Create Recovery Plan: By Service object
        /// </summary>
        private void CreateRecoveryPlan(RecoveryPlan recoveryPlan)
        {
            CreateRecoveryPlanInputProperties createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties()
            {
                FailoverDeploymentModel = recoveryPlan.Properties.FailoverDeploymentModel,
                Groups           = recoveryPlan.Properties.Groups,
                PrimaryFabricId  = recoveryPlan.Properties.PrimaryFabricId,
                RecoveryFabricId = recoveryPlan.Properties.RecoveryFabricId
            };

            CreateRecoveryPlanInput createRecoveryPlanInput = new CreateRecoveryPlanInput()
            {
                Properties = createRecoveryPlanInputProperties
            };

            CreateRecoveryPlan(recoveryPlan.Name, createRecoveryPlanInput);
        }
コード例 #6
0
        private void GetRecoveryPlanFile(RecoveryPlan recoveryPlan)
        {
            recoveryPlan = RecoveryServicesClient.GetAzureSiteRecoveryRecoveryPlan(recoveryPlan.Name).RecoveryPlan;

            if (string.IsNullOrEmpty(this.Path) || !Directory.Exists(System.IO.Path.GetDirectoryName(this.Path)))
            {
                throw new DirectoryNotFoundException(string.Format(Properties.Resources.DirectoryNotFound, System.IO.Path.GetDirectoryName(this.Path)));
            }

            string fullFileName = this.Path;

            using (System.IO.StreamWriter file = new System.IO.StreamWriter(@fullFileName, false))
            {
                string json = JsonConvert.SerializeObject(recoveryPlan, Formatting.Indented);
                file.WriteLine(json);
            }
        }
コード例 #7
0
        private static void ValidateCreateInput1(
            RecoveryPlan rp,
            string fabricId,
            string vmId)
        {
            Assert.True(rp.Properties.PrimaryFabricId == fabricId);
            Assert.True(rp.Properties.RecoveryFabricId == fabricId);

            Assert.True(rp.Properties.Groups.Count == 3);
            Assert.True(rp.Properties.Groups[0].GroupType == "Shutdown");
            Assert.True(rp.Properties.Groups[0].ReplicationProtectedItems.Count == 0);
            Assert.True(rp.Properties.Groups[1].GroupType == "Failover");
            Assert.True(rp.Properties.Groups[1].ReplicationProtectedItems.Count == 0);

            Assert.True(rp.Properties.Groups[2].GroupType == "Boot");
            Assert.True(rp.Properties.Groups[2].ReplicationProtectedItems.Count == 1);
            Assert.True(rp.Properties.Groups[2].ReplicationProtectedItems[0].Id == vmId);

            Assert.True(rp.Properties.Groups[2].StartGroupActions.Count == 1);
            Assert.True(rp.Properties.Groups[2].StartGroupActions[0].ActionName == "S1");
            Assert.True(rp.Properties.Groups[2].StartGroupActions[0].FailoverTypes.Count == 1);
            Assert.True(rp.Properties.Groups[2].StartGroupActions[0].FailoverTypes[0] == "PlannedFailover");
            Assert.True(rp.Properties.Groups[2].StartGroupActions[0].FailoverDirections.Count == 1);
            Assert.True(rp.Properties.Groups[2].StartGroupActions[0].FailoverDirections[0] == "PrimaryToRecovery");
            Assert.True(rp.Properties.Groups[2].StartGroupActions[0].CustomDetails.InstanceType == "ScriptActionDetails");

            Assert.True(rp.Properties.Groups[2].EndGroupActions.Count == 1);
            Assert.True(rp.Properties.Groups[2].EndGroupActions[0].ActionName == "M1");
            Assert.True(rp.Properties.Groups[2].EndGroupActions[0].FailoverTypes.Count == 1);
            Assert.True(rp.Properties.Groups[2].EndGroupActions[0].FailoverTypes[0] == "UnplannedFailover");
            Assert.True(rp.Properties.Groups[2].EndGroupActions[0].FailoverDirections.Count == 1);
            Assert.True(rp.Properties.Groups[2].EndGroupActions[0].FailoverDirections[0] == "RecoveryToPrimary");
            Assert.True(rp.Properties.Groups[2].EndGroupActions[0].CustomDetails.InstanceType == "ManualActionDetails");

            RecoveryPlanScriptActionDetails scriptAction =
                rp.Properties.Groups[2].StartGroupActions[0].CustomDetails as RecoveryPlanScriptActionDetails;

            Assert.True(scriptAction.Path == "path1");
            Assert.True(scriptAction.FabricLocation == "Recovery");

            RecoveryPlanManualActionDetails manualAction =
                rp.Properties.Groups[2].EndGroupActions[0].CustomDetails as RecoveryPlanManualActionDetails;

            Assert.True(manualAction.Description == "desc1");
        }
コード例 #8
0
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    "Recovery plan",
                    VerbsData.Update))
            {
                switch (this.ParameterSetName)
                {
                case ASRParameterSets.ByRPObject:
                    this.UpdateRecoveryPlan(this.InputObject);
                    break;

                case ASRParameterSets.ByRPFile:

                    if (!File.Exists(this.Path))
                    {
                        throw new FileNotFoundException(
                                  string.Format(
                                      Resources.FileNotFound,
                                      this.Path));

                        ;
                    }

                    var filePath = this.Path;

                    RecoveryPlan recoveryPlan = null;

                    using (var file = new StreamReader(filePath))
                    {
                        recoveryPlan = JsonConvert.DeserializeObject <RecoveryPlan>(
                            file.ReadToEnd(),
                            new RecoveryPlanActionDetailsConverter());
                    }

                    this.UpdateRecoveryPlan(recoveryPlan);

                    break;
                }
            }
        }
        /// <summary>
        ///     Create Recovery Plan: By Service object
        /// </summary>
        private void CreateRecoveryPlan(
            RecoveryPlan recoveryPlan)
        {
            var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties
            {
                FailoverDeploymentModel = recoveryPlan.Properties.FailoverDeploymentModel,
                Groups           = recoveryPlan.Properties.Groups,
                PrimaryFabricId  = recoveryPlan.Properties.PrimaryFabricId,
                RecoveryFabricId = recoveryPlan.Properties.RecoveryFabricId
            };

            if (recoveryPlan.Properties.ProviderSpecificDetails != null &&
                recoveryPlan.Properties.ProviderSpecificDetails.Count > 0)
            {
                createRecoveryPlanInputProperties.ProviderSpecificInput =
                    new List <RecoveryPlanProviderSpecificInput>();
                foreach (var providerSpecificDetails in recoveryPlan.Properties.ProviderSpecificDetails)
                {
                    if (providerSpecificDetails is RecoveryPlanA2ADetails)
                    {
                        var a2aProviderDetails = (RecoveryPlanA2ADetails)providerSpecificDetails;
                        var psd = new RecoveryPlanA2AInput
                        {
                            RecoveryZone = a2aProviderDetails.RecoveryZone,
                            PrimaryZone  = a2aProviderDetails.PrimaryZone
                        };

                        createRecoveryPlanInputProperties.ProviderSpecificInput.Add(psd);
                    }
                }
            }

            var createRecoveryPlanInput =
                new CreateRecoveryPlanInput {
                Properties = createRecoveryPlanInputProperties
            };

            this.CreateRecoveryPlan(
                recoveryPlan.Name,
                createRecoveryPlanInput);
        }
コード例 #10
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="ASRRecoveryPlan" /> class with required
        ///     parameters.
        /// </summary>
        /// <param name="recoveryPlan">Recovery plan object</param>
        public ASRRecoveryPlan(
            RecoveryPlan recoveryPlan,
            IList <ReplicationProtectedItem> replicationProtectedItems)
        {
            this.Id                      = recoveryPlan.Id;
            this.Name                    = recoveryPlan.Name;
            this.FriendlyName            = recoveryPlan.Properties.FriendlyName;
            this.ServerId                = recoveryPlan.Properties.PrimaryFabricId;
            this.TargetServerId          = recoveryPlan.Properties.RecoveryFabricId;
            this.FailoverDeploymentModel = recoveryPlan.Properties.FailoverDeploymentModel;
            this.Groups                  = new List <ASRRecoveryPlanGroup>();
            var    groupCount = 0;
            string groupName  = null;

            foreach (var recoveryPlanGroup in recoveryPlan.Properties.Groups)
            {
                switch (recoveryPlanGroup.GroupType)
                {
                case RecoveryPlanGroupType.Boot:
                    groupCount++;
                    groupName = "Group " + groupCount;
                    break;

                case RecoveryPlanGroupType.Failover:
                    groupName = Constants.Failover;
                    break;

                case RecoveryPlanGroupType.Shutdown:
                    groupName = Constants.Shutdown;
                    break;
                }

                this.Groups.Add(
                    new ASRRecoveryPlanGroup(
                        groupName,
                        recoveryPlanGroup,
                        replicationProtectedItems));
            }

            this.ReplicationProvider = recoveryPlan.Properties.ReplicationProviders;
        }
        /// <summary>
        ///     Create Recovery Plan: By Service object
        /// </summary>
        private void CreateRecoveryPlan(
            RecoveryPlan recoveryPlan)
        {
            var createRecoveryPlanInputProperties = new CreateRecoveryPlanInputProperties
            {
                FailoverDeploymentModel = (FailoverDeploymentModel)Enum.Parse(
                    typeof(FailoverDeploymentModel),
                    recoveryPlan.Properties.FailoverDeploymentModel),
                Groups           = recoveryPlan.Properties.Groups,
                PrimaryFabricId  = recoveryPlan.Properties.PrimaryFabricId,
                RecoveryFabricId = recoveryPlan.Properties.RecoveryFabricId
            };

            var createRecoveryPlanInput =
                new CreateRecoveryPlanInput {
                Properties = createRecoveryPlanInputProperties
            };

            this.CreateRecoveryPlan(
                recoveryPlan.Name,
                createRecoveryPlanInput);
        }
        /// <summary>
        ///     ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            if (this.ShouldProcess(
                    "Recovery plan",
                    VerbsCommon.New))
            {
                switch (this.ParameterSetName)
                {
                case ASRParameterSets.EnterpriseToEnterprise:
                    this.failoverDeploymentModel = Constants.NotApplicable;
                    this.primaryserver           = this.PrimaryFabric.ID;
                    this.recoveryserver          = this.RecoveryFabric.ID;
                    break;

                case ASRParameterSets.AzureZoneToZone:
                    this.failoverDeploymentModel = Constants.NotApplicable;
                    this.primaryserver           = this.PrimaryFabric.ID;
                    this.recoveryserver          = this.PrimaryFabric.ID;
                    break;

                case ASRParameterSets.EnterpriseToAzure:
                    this.failoverDeploymentModel = this.FailoverDeploymentModel;
                    this.primaryserver           = this.PrimaryFabric.ID;
                    this.recoveryserver          = Constants.AzureContainer;
                    break;

                case ASRParameterSets.ByRPFile:

                    if (!File.Exists(this.Path))
                    {
                        throw new FileNotFoundException(
                                  string.Format(
                                      Resources.FileNotFound,
                                      this.Path));

                        ;
                    }

                    var filePath = this.Path;

                    using (var file = new StreamReader(filePath))
                    {
                        this.recoveryPlan = JsonConvert.DeserializeObject <RecoveryPlan>(
                            file.ReadToEnd(),
                            new RecoveryPlanActionDetailsConverter(),
                            new RecoveryPlanProviderSpecificDetailsConverter());
                    }

                    break;
                }

                if (string.Compare(
                        this.ParameterSetName,
                        ASRParameterSets.ByRPFile,
                        StringComparison.OrdinalIgnoreCase) ==
                    0)
                {
                    this.CreateRecoveryPlan(this.recoveryPlan);
                }
                else
                {
                    this.CreateRecoveryPlan();
                }
            }
        }
コード例 #13
0
 /// <summary>
 /// Writes Recovery Plan.
 /// </summary>
 /// <param name="recoveryPlan">Recovery Plan</param>
 private void WriteRecoveryPlan(RecoveryPlan recoveryPlan)
 {
     this.WriteObject(new ASRRecoveryPlan(recoveryPlan));
 }
コード例 #14
0
        /// <summary>
        /// Write Recovery Plan.
        /// </summary>
        /// <param name="recoveryPlan">Recovery Plan object</param>
        private void WriteRecoveryPlan(RecoveryPlan recoveryPlan)
        {
            var replicationProtectedItemListResponse = RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItemInRP(recoveryPlan.Name);

            this.WriteObject(new ASRRecoveryPlan(recoveryPlan, replicationProtectedItemListResponse.ReplicationProtectedItems));
        }