/// <summary> /// Triggers the enable protection operation for the given item /// </summary> /// <returns>The job response returned from the service</returns> public BaseRecoveryServicesJobResponse EnableProtection() { string azureVMName = (string)ProviderData[ItemParams.AzureVMName]; string azureVMCloudServiceName = (string)ProviderData[ItemParams.AzureVMCloudServiceName]; string azureVMResourceGroupName = (string)ProviderData[ItemParams.AzureVMResourceGroupName]; string parameterSetName = (string)ProviderData[ItemParams.ParameterSetName]; PolicyBase policy = (PolicyBase) ProviderData[ItemParams.Policy]; ItemBase itemBase = (ItemBase) ProviderData[ItemParams.Item]; AzureVmItem item = (AzureVmItem) ProviderData[ItemParams.Item]; // do validations string containerUri = ""; string protectedItemUri = ""; bool isComputeAzureVM = false; string sourceResourceId = null; if (itemBase == null) { isComputeAzureVM = string.IsNullOrEmpty(azureVMCloudServiceName) ? true : false; string azureVMRGName = (isComputeAzureVM) ? azureVMResourceGroupName : azureVMCloudServiceName; ValidateAzureVMWorkloadType(policy.WorkloadType); ValidateAzureVMEnableProtectionRequest( azureVMName, azureVMCloudServiceName, azureVMResourceGroupName, policy); ProtectableObjectResource protectableObjectResource = GetAzureVMProtectableObject(azureVMName, azureVMRGName, isComputeAzureVM); Dictionary<UriEnums, string> keyValueDict = HelperUtils.ParseUri(protectableObjectResource.Id); containerUri = HelperUtils.GetContainerUri( keyValueDict, protectableObjectResource.Id); protectedItemUri = HelperUtils.GetProtectableItemUri( keyValueDict, protectableObjectResource.Id); AzureIaaSVMProtectableItem iaasVmProtectableItem = (AzureIaaSVMProtectableItem)protectableObjectResource.Properties; if (iaasVmProtectableItem != null) { sourceResourceId = iaasVmProtectableItem.VirtualMachineId; } } else { ValidateAzureVMWorkloadType(item.WorkloadType, policy.WorkloadType); ValidateAzureVMModifyProtectionRequest(itemBase, policy); isComputeAzureVM = IsComputeAzureVM(item.VirtualMachineId); Dictionary<UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); sourceResourceId = item.SourceResourceId; } // construct Service Client protectedItem request AzureIaaSVMProtectedItem properties; if (isComputeAzureVM == false) { properties = new AzureIaaSClassicComputeVMProtectedItem(); } else { properties = new AzureIaaSComputeVMProtectedItem(); } properties.PolicyId = policy.Id; properties.SourceResourceId = sourceResourceId; ProtectedItemCreateOrUpdateRequest serviceClientRequest = new ProtectedItemCreateOrUpdateRequest() { Item = new ProtectedItemResource() { Properties = properties, } }; return ServiceClientAdapter.CreateOrUpdateProtectedItem( containerUri, protectedItemUri, serviceClientRequest); }
/// <summary> /// Triggers the disable protection operation for the given item /// </summary> /// <returns>The job response returned from the service</returns> public BaseRecoveryServicesJobResponse DisableProtection() { bool deleteBackupData = (bool)ProviderData[ItemParams.DeleteBackupData]; ItemBase itemBase = (ItemBase) ProviderData[ItemParams.Item]; AzureVmItem item = (AzureVmItem) ProviderData[ItemParams.Item]; // do validations ValidateAzureVMDisableProtectionRequest(itemBase); Dictionary<UriEnums, string> keyValueDict = HelperUtils.ParseUri(item.Id); string containerUri = HelperUtils.GetContainerUri(keyValueDict, item.Id); string protectedItemUri = HelperUtils.GetProtectedItemUri(keyValueDict, item.Id); bool isComputeAzureVM = false; if (deleteBackupData) { return ServiceClientAdapter.DeleteProtectedItem( containerUri, protectedItemUri); } else { isComputeAzureVM = IsComputeAzureVM(item.VirtualMachineId); // construct Service Client protectedItem request AzureIaaSVMProtectedItem properties; if (isComputeAzureVM == false) { properties = new AzureIaaSClassicComputeVMProtectedItem(); } else { properties = new AzureIaaSComputeVMProtectedItem(); } properties.PolicyId = string.Empty; properties.ProtectionState = ItemProtectionState.ProtectionStopped.ToString(); properties.SourceResourceId = item.SourceResourceId; ProtectedItemCreateOrUpdateRequest serviceClientRequest = new ProtectedItemCreateOrUpdateRequest() { Item = new ProtectedItemResource() { Properties = properties, } }; return ServiceClientAdapter.CreateOrUpdateProtectedItem( containerUri, protectedItemUri, serviceClientRequest); } }