/// <summary>
        /// Queries by friendly name.
        /// </summary>
        private void GetByFriendlyName()
        {
            bool found = false;

            ProtectableItemListResponse protectableItemListResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(
                Utilities.GetValueFromArmId(this.ProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics),
                this.ProtectionContainer.Name);
            ProtectableItem protectableItem =
                protectableItemListResponse.ProtectableItems.SingleOrDefault(t =>
                                                                             string.Compare(t.Properties.FriendlyName, this.FriendlyName, StringComparison.OrdinalIgnoreCase) == 0);

            if (protectableItem != null)
            {
                ProtectableItemResponse protectableItemResponse = RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(
                    Utilities.GetValueFromArmId(this.ProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics),
                    this.ProtectionContainer.Name,
                    protectableItem.Name);
                WriteProtectableItem(protectableItemResponse.ProtectableItem);

                found = true;
            }

            if (!found)
            {
                throw new InvalidOperationException(
                          string.Format(
                              Properties.Resources.ProtectionEntityNotFound,
                              this.FriendlyName,
                              this.ProtectionContainer.FriendlyName));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ASRVirtualMachine" /> class when it is protected
        /// </summary>
        /// <param name="pi">Protectable Item to read values from</param>
        /// <param name="rpi">Replication Protected Item to read values from</param>
        public ASRVirtualMachine(ProtectableItem pi, ReplicationProtectedItem rpi, Policy policy = null)
            : base(pi, rpi, policy)
        {
            if (0 == string.Compare(
                    rpi.Properties.ProviderSpecificDetails.InstanceType,
                    Constants.HyperVReplicaAzure,
                    StringComparison.OrdinalIgnoreCase))
            {
                HyperVReplicaAzureReplicationDetails providerSpecificDetails =
                           (HyperVReplicaAzureReplicationDetails)rpi.Properties.ProviderSpecificDetails;

                RecoveryAzureVMName = providerSpecificDetails.RecoveryAzureVMName;
                RecoveryAzureVMSize = providerSpecificDetails.RecoveryAzureVMSize;
                RecoveryAzureStorageAccount = providerSpecificDetails.RecoveryAzureStorageAccount;
                SelectedRecoveryAzureNetworkId = providerSpecificDetails.SelectedRecoveryAzureNetworkId;
                if (providerSpecificDetails.VMNics != null)
                {
                    NicDetailsList = new List<ASRVMNicDetails>();
                    foreach(VMNicDetails n in providerSpecificDetails.VMNics)
                    {
                        NicDetailsList.Add(new ASRVMNicDetails(n));
                    }
                }
            }
           
        }
Beispiel #3
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ASRProtectionEntity" /> class when it is not protected
        /// </summary>
        /// <param name="pi">Protectable Item to read values from</param>
        public ASRProtectionEntity(ProtectableItem pi)
        {
            this.ID = pi.Id;
            this.ProtectionContainerId = Utilities.GetValueFromArmId(pi.Id, ARMResourceTypeConstants.ReplicationProtectionContainers);
            this.Name = pi.Name;
            this.FriendlyName = pi.Properties.FriendlyName;
            this.ProtectionStatus = pi.Properties.ProtectionStatus;   
            if (pi.Properties.CustomDetails != null)
            {
                if (0 == string.Compare(
                    pi.Properties.CustomDetails.InstanceType,
                    "HyperVVirtualMachine",
                    StringComparison.OrdinalIgnoreCase))
                {
                    if (pi.Properties.CustomDetails is HyperVVirtualMachineDetails)
                    {
                        HyperVVirtualMachineDetails providerSettings =
                            (HyperVVirtualMachineDetails)pi.Properties.CustomDetails;

                        IList<DiskDetails> diskDetails = providerSettings.DiskDetailsList;
                        this.UpdateDiskDetails(diskDetails);
                        this.OS = providerSettings.OSDetails == null ? null : providerSettings.OSDetails.OsType;
                        this.FabricObjectId = providerSettings.SourceItemId;
                    }

                }                
            } 
        }
Beispiel #4
0
        /// <summary>
        /// Write Protection Entity
        /// </summary>
        /// <param name="protectableItem"></param>
        private void WriteProtectionEntity(ProtectableItem protectableItem)
        {
            ASRVirtualMachine entity = RecoveryServicesClient.FetchProtectionEntityData <ASRVirtualMachine>(
                protectableItem, this.ProtectionContainer.ID, this.ProtectionContainer.Name);

            this.WriteObject(entity);
        }
Beispiel #5
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)));
                }
            }
        }
        /// <summary>
        /// Write Protection Entity
        /// </summary>
        /// <param name="protectableItem"></param>
        private void WriteProtectionEntity(ProtectableItem protectableItem)
        {
            ReplicationProtectedItemResponse replicationProtectedItemResponse = null;

            if (!String.IsNullOrEmpty(protectableItem.Properties.ReplicationProtectedItemId))
            {
                replicationProtectedItemResponse = RecoveryServicesClient.GetAzureSiteRecoveryReplicationProtectedItem(
                    Utilities.GetValueFromArmId(this.ProtectionContainer.ID, ARMResourceTypeConstants.ReplicationFabrics),
                    this.ProtectionContainer.Name,
                    Utilities.GetValueFromArmId(protectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems));
            }

            if (replicationProtectedItemResponse != null && replicationProtectedItemResponse.ReplicationProtectedItem != null)
            {
                PolicyResponse policyResponse = RecoveryServicesClient.GetAzureSiteRecoveryPolicy(Utilities.GetValueFromArmId(replicationProtectedItemResponse.ReplicationProtectedItem.Properties.PolicyID, ARMResourceTypeConstants.ReplicationPolicies));
                this.WriteObject(new ASRProtectionEntity(protectableItem, replicationProtectedItemResponse.ReplicationProtectedItem, policyResponse.Policy));
            }
            else
            {
                this.WriteObject(new ASRProtectionEntity(protectableItem));
            }
        }
Beispiel #7
0
        /// <summary>
        /// Initializes a new instance of the <see cref="ASRProtectionEntity" /> class when it is protected
        /// </summary>
        /// <param name="pi">Protectable Item to read values from</param>
        /// <param name="rpi">Replication Protected Item to read values from</param>
        public ASRProtectionEntity(ProtectableItem pi, ReplicationProtectedItem rpi, Policy policy = null) : this(pi)
        {
            this.Type = rpi.Type;
            this.ProtectionStateDescription = rpi.Properties.ProtectionStateDescription;

            if (rpi.Properties.AllowedOperations != null)
            {
                this.AllowedOperations = new List<string>();
                foreach (String op in rpi.Properties.AllowedOperations)
                {
                    AllowedOperations.Add(op);
                }
            }
            this.ReplicationProvider = rpi.Properties.ProviderSpecificDetails.InstanceType;
            this.ActiveLocation = rpi.Properties.ActiveLocation;
            this.ReplicationHealth = rpi.Properties.ReplicationHealth;
            this.TestFailoverStateDescription = rpi.Properties.TestFailoverStateDescription;
            this.ProtectionStatus = rpi.Properties.ProtectionState;
            if (policy != null)
            {
                this.Policy = new ASRPolicy(policy);
            }
        }
 /// <summary>
 /// Write Protection Items
 /// </summary>
 /// <param name="protectableItem"></param>
 private void WriteProtectableItem(ProtectableItem protectableItem)
 {
     this.WriteObject(new ASRProtectableItem(protectableItem));
 }
Beispiel #9
0
 /// <summary>
 /// Initializes a new instance of the <see cref="ASRVirtualMachine" /> class when it is not protected
 /// </summary>
 /// <param name="pi">Protectable Item to read values from</param>
 public ASRVirtualMachine(ProtectableItem pi)
     : base(pi)
 {
 }
        /// <summary>
        /// ProcessRecord of the command.
        /// </summary>
        public override void ExecuteSiteRecoveryCmdlet()
        {
            base.ExecuteSiteRecoveryCmdlet();

            this.targetNameOrId = this.ProtectionEntity.FriendlyName;
            this.ConfirmAction(
                this.Force.IsPresent || 0 != string.CompareOrdinal(this.Protection, Constants.DisableProtection),
                string.Format(Properties.Resources.DisableProtectionWarning, this.targetNameOrId),
                string.Format(Properties.Resources.DisableProtectionWhatIfMessage, this.Protection),
                this.targetNameOrId,
                () =>
            {
                if (this.Protection == Constants.EnableProtection)
                {
                    if (string.Compare(this.ParameterSetName, ASRParameterSets.DisableDR, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        throw new PSArgumentException(Properties.Resources.PassingPolicyMandatoryForEnablingDR);
                    }

                    EnableProtectionProviderSpecificInput enableProtectionProviderSpecificInput = new EnableProtectionProviderSpecificInput();

                    EnableProtectionInputProperties inputProperties = new EnableProtectionInputProperties()
                    {
                        PolicyId                = this.Policy.ID,
                        ProtectableItemId       = this.ProtectionEntity.ID,
                        ProviderSpecificDetails = enableProtectionProviderSpecificInput
                    };

                    EnableProtectionInput input = new EnableProtectionInput()
                    {
                        Properties = inputProperties
                    };

                    // Process if block only if policy is not null, policy is created for E2A or B2A and parameter set is for enable DR of E2A or B2A
                    if (this.Policy != null &&
                        0 == string.Compare(this.Policy.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) &&
                        (0 == string.Compare(this.ParameterSetName, ASRParameterSets.EnterpriseToAzure, StringComparison.OrdinalIgnoreCase) ||
                         0 == string.Compare(this.ParameterSetName, ASRParameterSets.HyperVSiteToAzure, StringComparison.OrdinalIgnoreCase)))
                    {
                        HyperVReplicaAzureEnableProtectionInput providerSettings = new HyperVReplicaAzureEnableProtectionInput();
                        providerSettings.HvHostVmId = this.ProtectionEntity.FabricObjectId;
                        providerSettings.VmName     = this.ProtectionEntity.FriendlyName;

                        // Id disk details are missing in input PE object, get the latest PE.
                        if (string.IsNullOrEmpty(this.ProtectionEntity.OS))
                        {
                            // Just checked for OS to see whether the disk details got filled up or not
                            ProtectableItemResponse protectableItemResponse =
                                RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(
                                    Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationFabrics),
                                    this.ProtectionEntity.ProtectionContainerId,
                                    this.ProtectionEntity.Name);

                            this.ProtectionEntity = new ASRProtectionEntity(protectableItemResponse.ProtectableItem);
                        }

                        if (string.IsNullOrWhiteSpace(this.OS))
                        {
                            providerSettings.OSType = ((string.Compare(this.ProtectionEntity.OS, Constants.OSWindows) == 0) || (string.Compare(this.ProtectionEntity.OS, Constants.OSLinux) == 0)) ? this.ProtectionEntity.OS : Constants.OSWindows;
                        }
                        else
                        {
                            providerSettings.OSType = this.OS;
                        }

                        if (string.IsNullOrWhiteSpace(this.OSDiskName))
                        {
                            providerSettings.VhdId = this.ProtectionEntity.OSDiskId;
                        }
                        else
                        {
                            foreach (var disk in this.ProtectionEntity.Disks)
                            {
                                if (0 == string.Compare(disk.Name, this.OSDiskName, true))
                                {
                                    providerSettings.VhdId = disk.Id;
                                    break;
                                }
                            }
                        }

                        if (RecoveryAzureStorageAccountId != null)
                        {
                            providerSettings.TargetStorageAccountId = RecoveryAzureStorageAccountId;
                        }

                        input.Properties.ProviderSpecificDetails = providerSettings;
                    }
                    else if (this.Policy != null &&
                             0 == string.Compare(this.Policy.ReplicationProvider, Constants.HyperVReplicaAzure, StringComparison.OrdinalIgnoreCase) &&
                             0 == string.Compare(this.ParameterSetName, ASRParameterSets.EnterpriseToEnterprise, StringComparison.OrdinalIgnoreCase))
                    {
                        throw new PSArgumentException(Properties.Resources.PassingStorageMandatoryForEnablingDRInAzureScenarios);
                    }

                    this.response =
                        RecoveryServicesClient.EnableProtection(
                            Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationFabrics),
                            Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationProtectionContainers),
                            this.ProtectionEntity.Name,
                            input);
                }
                else
                {
                    // fetch the latest PE object
                    ProtectableItemResponse protectableItemResponse =
                        RecoveryServicesClient.GetAzureSiteRecoveryProtectableItem(Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationFabrics),
                                                                                   this.ProtectionEntity.ProtectionContainerId, this.ProtectionEntity.Name);
                    ProtectableItem protectableItem = protectableItemResponse.ProtectableItem;

                    if (!this.Force.IsPresent)
                    {
                        DisableProtectionInput input = new DisableProtectionInput();
                        input.Properties             = new DisableProtectionInputProperties()
                        {
                            ProviderSettings = new DisableProtectionProviderSpecificInput()
                        };

                        this.response =
                            RecoveryServicesClient.DisableProtection(
                                Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationFabrics),
                                Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationProtectionContainers),
                                Utilities.GetValueFromArmId(protectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems),
                                input);
                    }
                    else
                    {
                        this.response =
                            RecoveryServicesClient.PurgeProtection(
                                Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationFabrics),
                                Utilities.GetValueFromArmId(this.ProtectionEntity.ID, ARMResourceTypeConstants.ReplicationProtectionContainers),
                                Utilities.GetValueFromArmId(protectableItem.Properties.ReplicationProtectedItemId, ARMResourceTypeConstants.ReplicationProtectedItems)
                                );
                    }
                }

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

                WriteObject(new ASRJob(jobResponse.Job));

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

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

                    WriteObject(new ASRJob(jobResponse.Job));
                }
            });
        }
        /// <summary>
        /// Lists all the protectable objects within your subscription
        /// according to the query filter and the pagination parameters.
        /// </summary>
        /// <param name='resourceGroupName'>
        /// Required. Resource group name of your recovery services vault.
        /// </param>
        /// <param name='resourceName'>
        /// Required. Name of your recovery services vault.
        /// </param>
        /// <param name='queryFilter'>
        /// Optional.
        /// </param>
        /// <param name='paginationParams'>
        /// Optional. Pagination parameters for controlling the response.
        /// </param>
        /// <param name='customRequestHeaders'>
        /// Optional. Request header parameters.
        /// </param>
        /// <param name='cancellationToken'>
        /// Cancellation token.
        /// </param>
        /// <returns>
        /// List of protectable object resonses as returned by the list
        /// protectable objects API.
        /// </returns>
        public async Task <ProtectableObjectListResponse> ListAsync(string resourceGroupName, string resourceName, ProtectableObjectListQueryParameters queryFilter, PaginationRequest paginationParams, CustomRequestHeaders customRequestHeaders, CancellationToken cancellationToken)
        {
            // Validate
            if (resourceGroupName == null)
            {
                throw new ArgumentNullException("resourceGroupName");
            }
            if (resourceName == null)
            {
                throw new ArgumentNullException("resourceName");
            }

            // Tracing
            bool   shouldTrace  = TracingAdapter.IsEnabled;
            string invocationId = null;

            if (shouldTrace)
            {
                invocationId = TracingAdapter.NextInvocationId.ToString();
                Dictionary <string, object> tracingParameters = new Dictionary <string, object>();
                tracingParameters.Add("resourceGroupName", resourceGroupName);
                tracingParameters.Add("resourceName", resourceName);
                tracingParameters.Add("queryFilter", queryFilter);
                tracingParameters.Add("paginationParams", paginationParams);
                tracingParameters.Add("customRequestHeaders", customRequestHeaders);
                TracingAdapter.Enter(invocationId, this, "ListAsync", tracingParameters);
            }

            // Construct URL
            string url = "";

            url = url + "/Subscriptions/";
            if (this.Client.Credentials.SubscriptionId != null)
            {
                url = url + Uri.EscapeDataString(this.Client.Credentials.SubscriptionId.ToString());
            }
            url = url + "/resourceGroups/";
            url = url + Uri.EscapeDataString(resourceGroupName);
            url = url + "/providers/";
            if (this.Client.ResourceNamespace != null)
            {
                url = url + Uri.EscapeDataString(this.Client.ResourceNamespace);
            }
            url = url + "/";
            url = url + "vaults";
            url = url + "/";
            url = url + Uri.EscapeDataString(resourceName);
            url = url + "/backupProtectableItems";
            List <string> queryParameters = new List <string>();

            queryParameters.Add("api-version=2016-05-01");
            List <string> odataFilter = new List <string>();

            if (queryFilter != null && queryFilter.BackupManagementType != null)
            {
                odataFilter.Add("backupManagementType eq '" + Uri.EscapeDataString(queryFilter.BackupManagementType) + "'");
            }
            if (queryFilter != null && queryFilter.Status != null)
            {
                odataFilter.Add("status eq '" + Uri.EscapeDataString(queryFilter.Status) + "'");
            }
            if (queryFilter != null && queryFilter.FriendlyName != null)
            {
                odataFilter.Add("friendlyName eq '" + Uri.EscapeDataString(queryFilter.FriendlyName) + "'");
            }
            if (odataFilter.Count > 0)
            {
                queryParameters.Add("$filter=" + string.Join(" and ", odataFilter));
            }
            if (paginationParams != null && paginationParams.SkipToken != null)
            {
                queryParameters.Add("$skiptoken=" + Uri.EscapeDataString(paginationParams.SkipToken));
            }
            if (paginationParams != null && paginationParams.Top != null)
            {
                queryParameters.Add("$top=" + Uri.EscapeDataString(paginationParams.Top));
            }
            if (queryParameters.Count > 0)
            {
                url = url + "?" + string.Join("&", queryParameters);
            }
            string baseUrl = this.Client.BaseUri.AbsoluteUri;

            // Trim '/' character from the end of baseUrl and beginning of url.
            if (baseUrl[baseUrl.Length - 1] == '/')
            {
                baseUrl = baseUrl.Substring(0, baseUrl.Length - 1);
            }
            if (url[0] == '/')
            {
                url = url.Substring(1);
            }
            url = baseUrl + "/" + url;
            url = url.Replace(" ", "%20");

            // Create HTTP transport objects
            HttpRequestMessage httpRequest = null;

            try
            {
                httpRequest            = new HttpRequestMessage();
                httpRequest.Method     = HttpMethod.Get;
                httpRequest.RequestUri = new Uri(url);

                // Set Headers
                httpRequest.Headers.Add("Accept-Language", customRequestHeaders.Culture);
                httpRequest.Headers.Add("x-ms-client-request-id", customRequestHeaders.ClientRequestId);

                // Set Credentials
                cancellationToken.ThrowIfCancellationRequested();
                await this.Client.Credentials.ProcessHttpRequestAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                // Send Request
                HttpResponseMessage httpResponse = null;
                try
                {
                    if (shouldTrace)
                    {
                        TracingAdapter.SendRequest(invocationId, httpRequest);
                    }
                    cancellationToken.ThrowIfCancellationRequested();
                    httpResponse = await this.Client.HttpClient.SendAsync(httpRequest, cancellationToken).ConfigureAwait(false);

                    if (shouldTrace)
                    {
                        TracingAdapter.ReceiveResponse(invocationId, httpResponse);
                    }
                    HttpStatusCode statusCode = httpResponse.StatusCode;
                    if (statusCode != HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        CloudException ex = CloudException.Create(httpRequest, null, httpResponse, await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false));
                        if (shouldTrace)
                        {
                            TracingAdapter.Error(invocationId, ex);
                        }
                        throw ex;
                    }

                    // Create Result
                    ProtectableObjectListResponse result = null;
                    // Deserialize Response
                    if (statusCode == HttpStatusCode.OK)
                    {
                        cancellationToken.ThrowIfCancellationRequested();
                        string responseContent = await httpResponse.Content.ReadAsStringAsync().ConfigureAwait(false);

                        result = new ProtectableObjectListResponse();
                        JToken responseDoc = null;
                        if (string.IsNullOrEmpty(responseContent) == false)
                        {
                            responseDoc = JToken.Parse(responseContent);
                        }

                        if (responseDoc != null && responseDoc.Type != JTokenType.Null)
                        {
                            ProtectableObjectResourceList itemListInstance = new ProtectableObjectResourceList();
                            result.ItemList = itemListInstance;

                            JToken valueArray = responseDoc["value"];
                            if (valueArray != null && valueArray.Type != JTokenType.Null)
                            {
                                foreach (JToken valueValue in ((JArray)valueArray))
                                {
                                    ProtectableObjectResource protectableObjectResourceInstance = new ProtectableObjectResource();
                                    itemListInstance.ProtectableObjects.Add(protectableObjectResourceInstance);

                                    JToken propertiesValue = valueValue["properties"];
                                    if (propertiesValue != null && propertiesValue.Type != JTokenType.Null)
                                    {
                                        string typeName = ((string)propertiesValue["protectableItemType"]);
                                        if (typeName == "ProtectableItem")
                                        {
                                            ProtectableItem protectableItemInstance = new ProtectableItem();

                                            JToken friendlyNameValue = propertiesValue["friendlyName"];
                                            if (friendlyNameValue != null && friendlyNameValue.Type != JTokenType.Null)
                                            {
                                                string friendlyNameInstance = ((string)friendlyNameValue);
                                                protectableItemInstance.FriendlyName = friendlyNameInstance;
                                            }

                                            JToken protectionStateValue = propertiesValue["protectionState"];
                                            if (protectionStateValue != null && protectionStateValue.Type != JTokenType.Null)
                                            {
                                                string protectionStateInstance = ((string)protectionStateValue);
                                                protectableItemInstance.ProtectionState = protectionStateInstance;
                                            }

                                            JToken protectableItemTypeValue = propertiesValue["protectableItemType"];
                                            if (protectableItemTypeValue != null && protectableItemTypeValue.Type != JTokenType.Null)
                                            {
                                                string protectableItemTypeInstance = ((string)protectableItemTypeValue);
                                                protectableItemInstance.ProtectableItemType = protectableItemTypeInstance;
                                            }

                                            JToken backupManagementTypeValue = propertiesValue["backupManagementType"];
                                            if (backupManagementTypeValue != null && backupManagementTypeValue.Type != JTokenType.Null)
                                            {
                                                string backupManagementTypeInstance = ((string)backupManagementTypeValue);
                                                protectableItemInstance.BackupManagementType = backupManagementTypeInstance;
                                            }
                                            protectableObjectResourceInstance.Properties = protectableItemInstance;
                                        }
                                        if (typeName == "IaaSVMProtectableItem")
                                        {
                                            AzureIaaSVMProtectableItem azureIaaSVMProtectableItemInstance = new AzureIaaSVMProtectableItem();

                                            JToken virtualMachineIdValue = propertiesValue["virtualMachineId"];
                                            if (virtualMachineIdValue != null && virtualMachineIdValue.Type != JTokenType.Null)
                                            {
                                                string virtualMachineIdInstance = ((string)virtualMachineIdValue);
                                                azureIaaSVMProtectableItemInstance.VirtualMachineId = virtualMachineIdInstance;
                                            }

                                            JToken friendlyNameValue2 = propertiesValue["friendlyName"];
                                            if (friendlyNameValue2 != null && friendlyNameValue2.Type != JTokenType.Null)
                                            {
                                                string friendlyNameInstance2 = ((string)friendlyNameValue2);
                                                azureIaaSVMProtectableItemInstance.FriendlyName = friendlyNameInstance2;
                                            }

                                            JToken protectionStateValue2 = propertiesValue["protectionState"];
                                            if (protectionStateValue2 != null && protectionStateValue2.Type != JTokenType.Null)
                                            {
                                                string protectionStateInstance2 = ((string)protectionStateValue2);
                                                azureIaaSVMProtectableItemInstance.ProtectionState = protectionStateInstance2;
                                            }

                                            JToken protectableItemTypeValue2 = propertiesValue["protectableItemType"];
                                            if (protectableItemTypeValue2 != null && protectableItemTypeValue2.Type != JTokenType.Null)
                                            {
                                                string protectableItemTypeInstance2 = ((string)protectableItemTypeValue2);
                                                azureIaaSVMProtectableItemInstance.ProtectableItemType = protectableItemTypeInstance2;
                                            }

                                            JToken backupManagementTypeValue2 = propertiesValue["backupManagementType"];
                                            if (backupManagementTypeValue2 != null && backupManagementTypeValue2.Type != JTokenType.Null)
                                            {
                                                string backupManagementTypeInstance2 = ((string)backupManagementTypeValue2);
                                                azureIaaSVMProtectableItemInstance.BackupManagementType = backupManagementTypeInstance2;
                                            }
                                            protectableObjectResourceInstance.Properties = azureIaaSVMProtectableItemInstance;
                                        }
                                        if (typeName == "Microsoft.ClassicCompute/virtualMachines")
                                        {
                                            AzureIaaSClassicComputeVMProtectableItem azureIaaSClassicComputeVMProtectableItemInstance = new AzureIaaSClassicComputeVMProtectableItem();

                                            JToken virtualMachineIdValue2 = propertiesValue["virtualMachineId"];
                                            if (virtualMachineIdValue2 != null && virtualMachineIdValue2.Type != JTokenType.Null)
                                            {
                                                string virtualMachineIdInstance2 = ((string)virtualMachineIdValue2);
                                                azureIaaSClassicComputeVMProtectableItemInstance.VirtualMachineId = virtualMachineIdInstance2;
                                            }

                                            JToken friendlyNameValue3 = propertiesValue["friendlyName"];
                                            if (friendlyNameValue3 != null && friendlyNameValue3.Type != JTokenType.Null)
                                            {
                                                string friendlyNameInstance3 = ((string)friendlyNameValue3);
                                                azureIaaSClassicComputeVMProtectableItemInstance.FriendlyName = friendlyNameInstance3;
                                            }

                                            JToken protectionStateValue3 = propertiesValue["protectionState"];
                                            if (protectionStateValue3 != null && protectionStateValue3.Type != JTokenType.Null)
                                            {
                                                string protectionStateInstance3 = ((string)protectionStateValue3);
                                                azureIaaSClassicComputeVMProtectableItemInstance.ProtectionState = protectionStateInstance3;
                                            }

                                            JToken protectableItemTypeValue3 = propertiesValue["protectableItemType"];
                                            if (protectableItemTypeValue3 != null && protectableItemTypeValue3.Type != JTokenType.Null)
                                            {
                                                string protectableItemTypeInstance3 = ((string)protectableItemTypeValue3);
                                                azureIaaSClassicComputeVMProtectableItemInstance.ProtectableItemType = protectableItemTypeInstance3;
                                            }

                                            JToken backupManagementTypeValue3 = propertiesValue["backupManagementType"];
                                            if (backupManagementTypeValue3 != null && backupManagementTypeValue3.Type != JTokenType.Null)
                                            {
                                                string backupManagementTypeInstance3 = ((string)backupManagementTypeValue3);
                                                azureIaaSClassicComputeVMProtectableItemInstance.BackupManagementType = backupManagementTypeInstance3;
                                            }
                                            protectableObjectResourceInstance.Properties = azureIaaSClassicComputeVMProtectableItemInstance;
                                        }
                                        if (typeName == "Microsoft.Compute/virtualMachines")
                                        {
                                            AzureIaaSComputeVMProtectableItem azureIaaSComputeVMProtectableItemInstance = new AzureIaaSComputeVMProtectableItem();

                                            JToken virtualMachineIdValue3 = propertiesValue["virtualMachineId"];
                                            if (virtualMachineIdValue3 != null && virtualMachineIdValue3.Type != JTokenType.Null)
                                            {
                                                string virtualMachineIdInstance3 = ((string)virtualMachineIdValue3);
                                                azureIaaSComputeVMProtectableItemInstance.VirtualMachineId = virtualMachineIdInstance3;
                                            }

                                            JToken friendlyNameValue4 = propertiesValue["friendlyName"];
                                            if (friendlyNameValue4 != null && friendlyNameValue4.Type != JTokenType.Null)
                                            {
                                                string friendlyNameInstance4 = ((string)friendlyNameValue4);
                                                azureIaaSComputeVMProtectableItemInstance.FriendlyName = friendlyNameInstance4;
                                            }

                                            JToken protectionStateValue4 = propertiesValue["protectionState"];
                                            if (protectionStateValue4 != null && protectionStateValue4.Type != JTokenType.Null)
                                            {
                                                string protectionStateInstance4 = ((string)protectionStateValue4);
                                                azureIaaSComputeVMProtectableItemInstance.ProtectionState = protectionStateInstance4;
                                            }

                                            JToken protectableItemTypeValue4 = propertiesValue["protectableItemType"];
                                            if (protectableItemTypeValue4 != null && protectableItemTypeValue4.Type != JTokenType.Null)
                                            {
                                                string protectableItemTypeInstance4 = ((string)protectableItemTypeValue4);
                                                azureIaaSComputeVMProtectableItemInstance.ProtectableItemType = protectableItemTypeInstance4;
                                            }

                                            JToken backupManagementTypeValue4 = propertiesValue["backupManagementType"];
                                            if (backupManagementTypeValue4 != null && backupManagementTypeValue4.Type != JTokenType.Null)
                                            {
                                                string backupManagementTypeInstance4 = ((string)backupManagementTypeValue4);
                                                azureIaaSComputeVMProtectableItemInstance.BackupManagementType = backupManagementTypeInstance4;
                                            }
                                            protectableObjectResourceInstance.Properties = azureIaaSComputeVMProtectableItemInstance;
                                        }
                                    }

                                    JToken idValue = valueValue["id"];
                                    if (idValue != null && idValue.Type != JTokenType.Null)
                                    {
                                        string idInstance = ((string)idValue);
                                        protectableObjectResourceInstance.Id = idInstance;
                                    }

                                    JToken nameValue = valueValue["name"];
                                    if (nameValue != null && nameValue.Type != JTokenType.Null)
                                    {
                                        string nameInstance = ((string)nameValue);
                                        protectableObjectResourceInstance.Name = nameInstance;
                                    }

                                    JToken typeValue = valueValue["type"];
                                    if (typeValue != null && typeValue.Type != JTokenType.Null)
                                    {
                                        string typeInstance = ((string)typeValue);
                                        protectableObjectResourceInstance.Type = typeInstance;
                                    }

                                    JToken locationValue = valueValue["location"];
                                    if (locationValue != null && locationValue.Type != JTokenType.Null)
                                    {
                                        string locationInstance = ((string)locationValue);
                                        protectableObjectResourceInstance.Location = locationInstance;
                                    }

                                    JToken tagsSequenceElement = ((JToken)valueValue["tags"]);
                                    if (tagsSequenceElement != null && tagsSequenceElement.Type != JTokenType.Null)
                                    {
                                        foreach (JProperty property in tagsSequenceElement)
                                        {
                                            string tagsKey   = ((string)property.Name);
                                            string tagsValue = ((string)property.Value);
                                            protectableObjectResourceInstance.Tags.Add(tagsKey, tagsValue);
                                        }
                                    }

                                    JToken eTagValue = valueValue["eTag"];
                                    if (eTagValue != null && eTagValue.Type != JTokenType.Null)
                                    {
                                        string eTagInstance = ((string)eTagValue);
                                        protectableObjectResourceInstance.ETag = eTagInstance;
                                    }
                                }
                            }

                            JToken nextLinkValue = responseDoc["nextLink"];
                            if (nextLinkValue != null && nextLinkValue.Type != JTokenType.Null)
                            {
                                string nextLinkInstance = ((string)nextLinkValue);
                                itemListInstance.NextLink = nextLinkInstance;
                            }
                        }
                    }
                    result.StatusCode = statusCode;

                    if (shouldTrace)
                    {
                        TracingAdapter.Exit(invocationId, result);
                    }
                    return(result);
                }
                finally
                {
                    if (httpResponse != null)
                    {
                        httpResponse.Dispose();
                    }
                }
            }
            finally
            {
                if (httpRequest != null)
                {
                    httpRequest.Dispose();
                }
            }
        }
Beispiel #12
0
        public static ReplicationProtectedItemOperationResponse ReverseReplication(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer protectionContainer,
            ReplicationProtectedItem protectedItem)
        {
            if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure")
            {
                ProtectableItem protectableItem = client.ProtectableItem.Get(
                    primaryFabric.Name,
                    protectionContainer.Name,
                    protectedItem.Properties.ProtectableItemId.Substring(
                        protectedItem.Properties.ProtectableItemId.LastIndexOf("/") + 1),
                    GetRequestHeaders()).ProtectableItem;

                string vhdId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails)
                               .DiskDetailsList[0].VhdId;

                DiskDetails osDisk = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails)
                                     .DiskDetailsList
                                     .FirstOrDefault(item => item.VhdType == "OperatingSystem");

                if (osDisk != null)
                {
                    vhdId = osDisk.VhdId;
                }

                string storageAccount =
                    (protectedItem.Properties.ProviderSpecificDetails as HyperVReplicaAzureReplicationDetails)
                    .RecoveryAzureStorageAccount;

                HyperVReplicaAzureReprotectInput hvrARRInput = new HyperVReplicaAzureReprotectInput()
                {
                    HvHostVmId       = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId,
                    OSType           = "Windows",
                    VHDId            = vhdId,
                    VmName           = protectableItem.Properties.FriendlyName,
                    StorageAccountId = storageAccount,
                };

                ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties()
                {
                    FailoverDirection       = "",
                    ProviderSpecificDetails = hvrARRInput
                };

                ReverseReplicationInput rrInput = new ReverseReplicationInput()
                {
                    Properties = rrProp
                };

                return(client.ReplicationProtectedItem.Reprotect(
                           primaryFabric.Name,
                           protectionContainer.Name,
                           protectedItem.Name,
                           rrInput,
                           GetRequestHeaders()) as ReplicationProtectedItemOperationResponse);
            }
            else if (protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012" ||
                     protectedItem.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012R2")
            {
                ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties()
                {
                    ProviderSpecificDetails = new ReverseReplicationProviderSpecificInput()
                };

                ReverseReplicationInput rrInput = new ReverseReplicationInput()
                {
                    Properties = rrProp
                };

                return(client.ReplicationProtectedItem.Reprotect(
                           primaryFabric.Name,
                           protectionContainer.Name,
                           protectedItem.Name,
                           rrInput,
                           GetRequestHeaders()) as ReplicationProtectedItemOperationResponse);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #13
0
        public static ReplicationProtectedItemOperationResponse EnableDR(
            this SiteRecoveryManagementClient client,
            Fabric primaryFabric,
            ProtectionContainer protectionContainer,
            Policy policy,
            ProtectableItem protectableItem,
            string armResourceName)
        {
            if (policy.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplicaAzure")
            {
                string vhdId = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails)
                               .DiskDetailsList[0].VhdId;

                DiskDetails osDisk = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList
                                     .FirstOrDefault(item => item.VhdType == "OperatingSystem");

                if (osDisk != null)
                {
                    vhdId = osDisk.VhdId;
                }

                HyperVReplicaAzureEnableProtectionInput hvrAEnableDRInput =
                    new HyperVReplicaAzureEnableProtectionInput()
                {
                    HvHostVmId             = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId,
                    OSType                 = "Windows",
                    VhdId                  = vhdId,
                    VmName                 = protectableItem.Properties.FriendlyName,
                    TargetStorageAccountId =
                        (policy.Properties.ProviderSpecificDetails as HyperVReplicaAzurePolicyDetails)
                        .ActiveStorageAccountId,
                };

                EnableProtectionInputProperties enableDRProp = new EnableProtectionInputProperties()
                {
                    PolicyId                = policy.Id,
                    ProtectableItemId       = protectableItem.Id,
                    ProviderSpecificDetails = hvrAEnableDRInput
                };

                EnableProtectionInput enableDRInput = new EnableProtectionInput()
                {
                    Properties = enableDRProp
                };

                return(client.ReplicationProtectedItem.EnableProtection(
                           primaryFabric.Name,
                           protectionContainer.Name,
                           armResourceName,
                           enableDRInput,
                           GetRequestHeaders()) as ReplicationProtectedItemOperationResponse);
            }
            else if (policy.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012" ||
                     policy.Properties.ProviderSpecificDetails.InstanceType == "HyperVReplica2012R2")
            {
                var enableDRProp = new EnableProtectionInputProperties()
                {
                    PolicyId                = policy.Id,
                    ProtectableItemId       = protectableItem.Id,
                    ProviderSpecificDetails = new EnableProtectionProviderSpecificInput()
                };

                EnableProtectionInput enableInput = new EnableProtectionInput()
                {
                    Properties = enableDRProp
                };

                return(client.ReplicationProtectedItem.EnableProtection(
                           primaryFabric.Name,
                           protectionContainer.Name,
                           armResourceName,
                           enableInput,
                           GetRequestHeaders()) as ReplicationProtectedItemOperationResponse);
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Beispiel #14
0
        public void EndToEndB2ASingleVM()
        {
            using (UndoContext context = UndoContext.Current)
            {
                context.Start();
                var client = GetSiteRecoveryClient(CustomHttpHandler);

                bool createPolicy  = true;
                bool pairClouds    = true;
                bool enableDR      = true;
                bool pfo           = true;
                bool commit        = true;
                bool tfo           = true;
                bool pfoReverse    = true;
                bool commitReverse = true;
                bool reprotect     = true;
                bool disableDR     = true;
                bool unpair        = true;
                bool removePolicy  = true;

                // Process Variables
                string fabricName        = string.Empty;
                string recCldName        = "Microsoft Azure";
                string priCldName        = string.Empty;
                string policyName        = "Hydra-EndToEndB2ASingleVM-" + (new Random()).Next();
                string mappingName       = "Mapping-EndToEndB2ASingleVM-" + (new Random()).Next();
                string enableDRName      = string.Empty;
                string protectedItemName = "PE" + (new Random()).Next();

                // Data Variables
                Fabric selectedFabric                    = null;
                ProtectionContainer primaryCloud         = null;
                Policy                   selectedPolicy  = null;
                ProtectableItem          protectableItem = null;
                ReplicationProtectedItem protectedItem   = null;

                // Fetch HyperV
                if (string.IsNullOrEmpty(fabricName))
                {
                    var fabrics = client.Fabrics.List(RequestHeaders);

                    foreach (var fabric in fabrics.Fabrics)
                    {
                        if (fabric.Properties.CustomDetails.InstanceType.Contains("HyperV"))
                        {
                            selectedFabric = fabric;
                            fabricName     = selectedFabric.Name;
                        }
                    }
                }
                else
                {
                    selectedFabric = client.Fabrics.Get(fabricName, RequestHeaders).Fabric;
                }

                // Fetch Cloud
                primaryCloud = client.ProtectionContainer.List(selectedFabric.Name, RequestHeaders).ProtectionContainers[0];
                priCldName   = primaryCloud.Name;

                if (createPolicy)
                {
                    HyperVReplicaAzurePolicyInput hvrAPolicy = new HyperVReplicaAzurePolicyInput()
                    {
                        ApplicationConsistentSnapshotFrequencyInHours = 0,
                        Encryption                   = "Disable",
                        OnlineIrStartTime            = null,
                        RecoveryPointHistoryDuration = 0,
                        ReplicationInterval          = 30,
                        StorageAccounts              = new List <string>()
                        {
                            "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/storageAccounts/bvtmapped2storacc"
                        }
                    };

                    CreatePolicyInputProperties createInputProp = new CreatePolicyInputProperties()
                    {
                        ProviderSpecificInput = hvrAPolicy
                    };

                    CreatePolicyInput policyInput = new CreatePolicyInput()
                    {
                        Properties = createInputProp
                    };

                    selectedPolicy = (client.Policies.Create(policyName, policyInput, RequestHeaders) as CreatePolicyOperationResponse).Policy;
                }
                else
                {
                    selectedPolicy = client.Policies.Get(policyName, RequestHeaders).Policy;
                }

                if (pairClouds)
                {
                    CreateProtectionContainerMappingInputProperties pairingProps = new CreateProtectionContainerMappingInputProperties()
                    {
                        PolicyId = selectedPolicy.Id,
                        TargetProtectionContainerId = recCldName,
                        ProviderSpecificInput       = new ReplicationProviderContainerMappingInput()
                    };

                    CreateProtectionContainerMappingInput pairingInput = new CreateProtectionContainerMappingInput()
                    {
                        Properties = pairingProps
                    };

                    var pairingResponse = client.ProtectionContainerMapping.ConfigureProtection(
                        selectedFabric.Name,
                        primaryCloud.Name,
                        mappingName,
                        pairingInput,
                        RequestHeaders);
                }

                if (enableDR)
                {
                    if (string.IsNullOrEmpty(enableDRName))
                    {
                        protectableItem = client.ProtectableItem.List(selectedFabric.Name, primaryCloud.Name, "Unprotected", RequestHeaders).ProtectableItems[0];
                        enableDRName    = protectableItem.Name;
                    }
                    else
                    {
                        protectableItem = client.ProtectableItem.Get(selectedFabric.Name, primaryCloud.Name, enableDRName, RequestHeaders).ProtectableItem;
                    }

                    HyperVReplicaAzureEnableProtectionInput hvrAEnableDRInput = new HyperVReplicaAzureEnableProtectionInput()
                    {
                        HvHostVmId             = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId,
                        OSType                 = "Windows",
                        VhdId                  = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList[0].VhdId,
                        VmName                 = protectableItem.Properties.FriendlyName,
                        TargetStorageAccountId = "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/storageAccounts/bvtmapped2storacc",
                    };

                    EnableProtectionInputProperties enableDRProp = new EnableProtectionInputProperties()
                    {
                        PolicyId                = selectedPolicy.Id,
                        ProtectableItemId       = protectableItem.Id,
                        ProviderSpecificDetails = hvrAEnableDRInput
                    };

                    EnableProtectionInput enableDRInput = new EnableProtectionInput()
                    {
                        Properties = enableDRProp
                    };

                    DateTime enablStartTime = DateTime.UtcNow;
                    protectedItem = (
                        client.ReplicationProtectedItem.EnableProtection(
                            selectedFabric.Name,
                            primaryCloud.Name,
                            protectedItemName,
                            enableDRInput,
                            RequestHeaders) as ReplicationProtectedItemOperationResponse).ReplicationProtectedItem;

                    MonitoringHelper.MonitorJobs(MonitoringHelper.AzureIrJobName, enablStartTime, client, RequestHeaders);
                }

                if (pfo || commit || tfo || pfoReverse || commitReverse || reprotect || disableDR)
                {
                    protectableItem = client.ProtectableItem.Get(selectedFabric.Name, primaryCloud.Name, enableDRName, RequestHeaders).ProtectableItem;
                    protectedItem   = client.ReplicationProtectedItem.Get(selectedFabric.Name, primaryCloud.Name, protectedItemName, RequestHeaders).ReplicationProtectedItem;

                    // Create Input for Operations
                    ///////////////////////////// PFO /////////////////////////////////////
                    HyperVReplicaAzureFailoverProviderInput hvrAFOInput = new HyperVReplicaAzureFailoverProviderInput()
                    {
                        VaultLocation = "West US",
                    };
                    PlannedFailoverInputProperties plannedFailoverProp = new PlannedFailoverInputProperties()
                    {
                        FailoverDirection       = "",
                        ProviderSpecificDetails = hvrAFOInput
                    };

                    PlannedFailoverInput plannedFailoverInput = new PlannedFailoverInput()
                    {
                        Properties = plannedFailoverProp
                    };

                    HyperVReplicaAzureFailbackProviderInput hvrAFBInput = new HyperVReplicaAzureFailbackProviderInput()
                    {
                        RecoveryVmCreationOption = "NoAction",
                        DataSyncOption           = "ForSyncronization"
                    };
                    PlannedFailoverInputProperties plannedFailbackProp = new PlannedFailoverInputProperties()
                    {
                        FailoverDirection       = "",
                        ProviderSpecificDetails = hvrAFBInput
                    };

                    PlannedFailoverInput plannedFailbackInput = new PlannedFailoverInput()
                    {
                        Properties = plannedFailbackProp
                    };
                    ////////////////////////////// Reprotect //////////////////////////////////////
                    HyperVReplicaAzureReprotectInput hvrARRInput = new HyperVReplicaAzureReprotectInput()
                    {
                        HvHostVmId       = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).SourceItemId,
                        OSType           = "Windows",
                        VHDId            = (protectableItem.Properties.CustomDetails as HyperVVirtualMachineDetails).DiskDetailsList[0].VhdId,
                        VmName           = protectableItem.Properties.FriendlyName,
                        StorageAccountId = "/subscriptions/19b823e2-d1f3-4805-93d7-401c5d8230d5/resourceGroups/Default-Storage-WestUS/providers/Microsoft.ClassicStorage/storageAccounts/bvtmapped2storacc",
                    };

                    ReverseReplicationInputProperties rrProp = new ReverseReplicationInputProperties()
                    {
                        FailoverDirection       = "",
                        ProviderSpecificDetails = hvrARRInput
                    };

                    ReverseReplicationInput rrInput = new ReverseReplicationInput()
                    {
                        Properties = rrProp
                    };

                    ////////////////////////////////// UFO /////////////////////////////////////////
                    UnplannedFailoverInputProperties ufoProp = new UnplannedFailoverInputProperties()
                    {
                        ProviderSpecificDetails = hvrAFOInput,
                        SourceSiteOperations    = "NotRequired"
                    };

                    UnplannedFailoverInput ufoInput = new UnplannedFailoverInput()
                    {
                        Properties = ufoProp
                    };

                    /////////////////////////////////// TFO /////////////////////////////////////////////
                    TestFailoverInputProperties tfoProp = new TestFailoverInputProperties()
                    {
                        ProviderSpecificDetails = hvrAFOInput
                    };

                    TestFailoverInput tfoInput = new TestFailoverInput()
                    {
                        Properties = tfoProp
                    };
                    //////////////////////////////////////////////////////////////////////////////////////////

                    if (pfo)
                    {
                        var plannedfailover = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, plannedFailoverInput, RequestHeaders);
                    }

                    if (commit)
                    {
                        var commitFailover = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, RequestHeaders);
                    }

                    if (pfoReverse)
                    {
                        //var unplannedFailoverReverse = client.ReplicationProtectedItem.UnplannedFailover(selectedFabric.Name, priCld, replicationProtectedItems.ReplicationProtectedItems[0].Name, ufoInput, RequestHeaders);

                        var plannedFailoverReverse = client.ReplicationProtectedItem.PlannedFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, plannedFailbackInput, RequestHeaders);
                    }

                    if (commitReverse)
                    {
                        var commitFailoverReverse = client.ReplicationProtectedItem.CommitFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, RequestHeaders);
                    }

                    if (reprotect)
                    {
                        var reprotectStartTime = DateTime.UtcNow;
                        var rrReverseOp        = client.ReplicationProtectedItem.Reprotect(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, rrInput, RequestHeaders);

                        MonitoringHelper.MonitorJobs(MonitoringHelper.AzureIrJobName, reprotectStartTime, client, RequestHeaders);
                    }

                    if (tfo)
                    {
                        DateTime startTFO = DateTime.UtcNow;

                        var tfoOp = client.ReplicationProtectedItem.TestFailover(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, tfoInput, RequestHeaders);

                        var jobs = MonitoringHelper.GetJobId(MonitoringHelper.TestFailoverJobName, startTFO, client, RequestHeaders);

                        ResumeJobParamsProperties resProp = new ResumeJobParamsProperties()
                        {
                            Comments = "Res TFO"
                        };

                        ResumeJobParams resParam = new ResumeJobParams()
                        {
                            Properties = resProp
                        };

                        var resJob = client.Jobs.Resume(jobs.Name, resParam, RequestHeaders);
                    }

                    if (disableDR)
                    {
                        var disableDROperation = client.ReplicationProtectedItem.DisableProtection(selectedFabric.Name, primaryCloud.Name, protectedItem.Name, new DisableProtectionInput(), RequestHeaders);
                    }

                    if (unpair)
                    {
                        var unpairClouds = client.ProtectionContainerMapping.UnconfigureProtection(
                            selectedFabric.Name,
                            primaryCloud.Name,
                            mappingName,
                            new RemoveProtectionContainerMappingInput(),
                            RequestHeaders);
                    }
                }

                if (removePolicy)
                {
                    var policyDeletion = client.Policies.Delete(selectedPolicy.Name, RequestHeaders);
                }
            }
        }