public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; WriteDebug(string.Format("Input params - Name:{0}, WorkloadType:{1}, " + "BackupManagementType: {2}, " + "RetentionPolicy:{3}, SchedulePolicy:{4}", Name, WorkloadType.ToString(), BackupManagementType.HasValue ? BackupManagementType.ToString() : "NULL", RetentionPolicy == null ? "NULL" : RetentionPolicy.ToString(), SchedulePolicy == null ? "NULL" : SchedulePolicy.ToString())); // validate policy name PolicyCmdletHelpers.ValidateProtectionPolicyName(Name); // Validate if policy already exists if (PolicyCmdletHelpers.GetProtectionPolicyByName( Name, ServiceClientAdapter, vaultName: vaultName, resourceGroupName: resourceGroupName) != null) { throw new ArgumentException(string.Format(Resources.PolicyAlreadyExistException, Name)); } Dictionary <Enum, object> providerParameters = new Dictionary <Enum, object>(); providerParameters.Add(VaultParams.VaultName, vaultName); providerParameters.Add(VaultParams.ResourceGroupName, resourceGroupName); providerParameters.Add(PolicyParams.PolicyName, Name); providerParameters.Add(PolicyParams.WorkloadType, WorkloadType); providerParameters.Add(PolicyParams.RetentionPolicy, RetentionPolicy); providerParameters.Add(PolicyParams.SchedulePolicy, SchedulePolicy); PsBackupProviderManager providerManager = new PsBackupProviderManager(providerParameters, ServiceClientAdapter); IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(WorkloadType, BackupManagementType); psBackupProvider.CreatePolicy(); WriteDebug("Successfully created policy, now fetching it from service: " + Name); // now get the created policy and return ServiceClientModel.ProtectionPolicyResource policy = PolicyCmdletHelpers.GetProtectionPolicyByName( Name, ServiceClientAdapter, vaultName: vaultName, resourceGroupName: resourceGroupName); // now convert service Policy to PSObject WriteObject(ConversionHelpers.GetPolicyModel(policy)); }, ShouldProcess(Name, VerbsCommon.New)); }
/// <summary> /// A string representation of the PSLogSettings /// </summary> /// <returns>A string representation of the PSLogSettings</returns> public override string ToString() { StringBuilder output = new StringBuilder(); output.AppendLine(); output.AppendLine("Enabled : " + Enabled); output.AppendLine("Category : " + Category); output.Append("RetentionPolicy : " + RetentionPolicy.ToString(1)); return(output.ToString()); }
/// <summary> /// A string representation of the PSMetricSettings /// </summary> /// <returns>A string representation of the PSMetricSettings</returns> public override string ToString() { StringBuilder output = new StringBuilder(); output.AppendLine(); output.AppendLine("Enabled : " + Enabled); output.AppendLine("TimeGrain : " + XmlConvert.ToString(TimeGrain)); output.Append("RetentionPolicy : " + RetentionPolicy.ToString(1)); return(output.ToString()); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); WriteDebug(string.Format("Input params - Name:{0}, WorkloadType:{1}, " + "BackupManagementType: {2}, " + "RetentionPolicy:{3}, SchedulePolicy:{4}", Name, WorkloadType.ToString(), BackupManagementType.HasValue ? BackupManagementType.ToString() : "NULL", RetentionPolicy == null ? "NULL" : RetentionPolicy.ToString(), SchedulePolicy == null ? "NULL" : SchedulePolicy.ToString())); // validate policy name PolicyCmdletHelpers.ValidateProtectionPolicyName(Name); // Validate if policy already exists if (PolicyCmdletHelpers.GetProtectionPolicyByName(Name, ServiceClientAdapter) != null) { throw new ArgumentException(string.Format(Resources.PolicyAlreadyExistException, Name)); } PsBackupProviderManager providerManager = new PsBackupProviderManager(new Dictionary <System.Enum, object>() { { PolicyParams.PolicyName, Name }, { PolicyParams.WorkloadType, WorkloadType }, { PolicyParams.RetentionPolicy, RetentionPolicy }, { PolicyParams.SchedulePolicy, SchedulePolicy }, }, ServiceClientAdapter); IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance(WorkloadType, BackupManagementType); psBackupProvider.CreatePolicy(); WriteDebug("Successfully created policy, now fetching it from service: " + Name); // now get the created policy and return ServiceClientModel.ProtectionPolicyResponse policy = PolicyCmdletHelpers.GetProtectionPolicyByName( Name, ServiceClientAdapter); // now convert service Policy to PSObject WriteObject(ConversionHelpers.GetPolicyModel(policy.Item)); }); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); WriteDebug(string.Format("Input params - Policy: {0}" + "RetentionPolicy:{1}, SchedulePolicy:{2}", Policy == null ? "NULL" : Policy.ToString(), RetentionPolicy == null ? "NULL" : RetentionPolicy.ToString(), SchedulePolicy == null ? "NULL" : SchedulePolicy.ToString())); // Validate policy name PolicyCmdletHelpers.ValidateProtectionPolicyName(Policy.Name); // Validate if policy already exists ProtectionPolicyResponse servicePolicy = PolicyCmdletHelpers.GetProtectionPolicyByName( Policy.Name, ServiceClientAdapter); if (servicePolicy == null) { throw new ArgumentException(string.Format(Resources.PolicyNotFoundException, Policy.Name)); } PsBackupProviderManager providerManager = new PsBackupProviderManager( new Dictionary <System.Enum, object>() { { PolicyParams.ProtectionPolicy, Policy }, { PolicyParams.RetentionPolicy, RetentionPolicy }, { PolicyParams.SchedulePolicy, SchedulePolicy }, }, ServiceClientAdapter); IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance( Policy.WorkloadType, Policy.BackupManagementType); ProtectionPolicyResponse policyResponse = psBackupProvider.ModifyPolicy(); WriteDebug("ModifyPolicy http response from service: " + policyResponse.StatusCode.ToString()); if (policyResponse.StatusCode == System.Net.HttpStatusCode.Accepted) { WriteDebug("Tracking operation status URL for completion: " + policyResponse.AzureAsyncOperation); // Track OperationStatus URL for operation completion BackUpOperationStatusResponse operationResponse = TrackingHelpers.WaitForOperationCompletionUsingStatusLink( policyResponse.AzureAsyncOperation, ServiceClientAdapter.GetProtectionPolicyOperationStatusByURL); WriteDebug("Final operation status: " + operationResponse.OperationStatus.Status); if (operationResponse.OperationStatus.Properties != null && ((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds != null) { // get list of jobIds and return jobResponses WriteObject(GetJobObject( ((OperationStatusJobsExtendedInfo)operationResponse.OperationStatus.Properties).JobIds)); } if (operationResponse.OperationStatus.Status == OperationStatusValues.Failed.ToString()) { // if operation failed, then trace error and throw exception if (operationResponse.OperationStatus.OperationStatusError != null) { WriteDebug(string.Format( "OperationStatus Error: {0} " + "OperationStatus Code: {1}", operationResponse.OperationStatus.OperationStatusError.Message, operationResponse.OperationStatus.OperationStatusError.Code)); } } } else { // ServiceClient will return OK if NO datasources are associated with this policy WriteDebug("No datasources are associated with Policy, http response code: " + policyResponse.StatusCode.ToString()); } }); }
public override void ExecuteCmdlet() { ExecutionBlock(() => { base.ExecuteCmdlet(); ResourceIdentifier resourceIdentifier = new ResourceIdentifier(VaultId); string vaultName = resourceIdentifier.ResourceName; string resourceGroupName = resourceIdentifier.ResourceGroupName; WriteDebug(string.Format("Input params - Policy: {0}" + "RetentionPolicy:{1}, SchedulePolicy:{2}", Policy == null ? "NULL" : Policy.ToString(), RetentionPolicy == null ? "NULL" : RetentionPolicy.ToString(), SchedulePolicy == null ? "NULL" : SchedulePolicy.ToString())); // Validate policy name PolicyCmdletHelpers.ValidateProtectionPolicyName(Policy.Name); // Validate if policy already exists ProtectionPolicyResource servicePolicy = PolicyCmdletHelpers.GetProtectionPolicyByName( Policy.Name, ServiceClientAdapter, vaultName: vaultName, resourceGroupName: resourceGroupName); if (servicePolicy == null) { throw new ArgumentException(string.Format(Resources.PolicyNotFoundException, Policy.Name)); } PsBackupProviderManager providerManager = new PsBackupProviderManager( new Dictionary <System.Enum, object>() { { VaultParams.VaultName, vaultName }, { VaultParams.ResourceGroupName, resourceGroupName }, { PolicyParams.ProtectionPolicy, Policy }, { PolicyParams.RetentionPolicy, RetentionPolicy }, { PolicyParams.SchedulePolicy, SchedulePolicy }, }, ServiceClientAdapter); IPsBackupProvider psBackupProvider = providerManager.GetProviderInstance( Policy.WorkloadType, Policy.BackupManagementType); AzureOperationResponse <ProtectionPolicyResource> policyResponse = psBackupProvider.ModifyPolicy(); WriteDebug("ModifyPolicy http response from service: " + policyResponse.Response.StatusCode.ToString()); if (policyResponse.Response.StatusCode == System.Net.HttpStatusCode.Accepted) { // Track OperationStatus URL for operation completion string policyName = Policy.Name; ServiceClientModel.OperationStatus operationStatus = TrackingHelpers.GetOperationStatus( policyResponse, operationId => ServiceClientAdapter.GetProtectionPolicyOperationStatus( policyName, operationId, vaultName: vaultName, resourceGroupName: resourceGroupName)); WriteDebug("Final operation status: " + operationStatus.Status); if (operationStatus.Properties != null && ((OperationStatusJobsExtendedInfo)operationStatus.Properties) .JobIds != null) { // get list of jobIds and return jobResponses WriteObject(GetJobObject( ((OperationStatusJobsExtendedInfo)operationStatus.Properties).JobIds, vaultName: vaultName, resourceGroupName: resourceGroupName)); } if (operationStatus.Status == OperationStatusValues.Failed) { // if operation failed, then trace error and throw exception if (operationStatus.Error != null) { WriteDebug(string.Format( "OperationStatus Error: {0} " + "OperationStatus Code: {1}", operationStatus.Error.Message, operationStatus.Error.Code)); } } } else { // ServiceClient will return OK if NO datasources are associated with this policy WriteDebug("No datasources are associated with Policy, http response code: " + policyResponse.Response.StatusCode.ToString()); } }, ShouldProcess(Policy.Name, VerbsCommon.Set)); }