예제 #1
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);
            }
        }
예제 #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));
                    }
                }
            }
           
        }
예제 #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;
                    }

                }                
            } 
        }
예제 #4
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>
 /// 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);
 }
        /// <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));
            }
        }
 /// <summary>
 /// Write Protection Items
 /// </summary>
 /// <param name="protectableItem"></param>
 private void WriteProtectableItem(ProtectableItem protectableItem)
 {
     this.WriteObject(new ASRProtectableItem(protectableItem));
 }
예제 #8
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();
            }
        }