|
| 1 | +// ---------------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// Copyright Microsoft Corporation |
| 4 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +// you may not use this file except in compliance with the License. |
| 6 | +// You may obtain a copy of the License at |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// Unless required by applicable law or agreed to in writing, software |
| 9 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 10 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 11 | +// See the License for the specific language governing permissions and |
| 12 | +// limitations under the License. |
| 13 | +// ---------------------------------------------------------------------------------- |
| 14 | + |
| 15 | +using System; |
| 16 | +using System.Management.Automation; |
| 17 | +using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery; |
| 18 | +using Microsoft.Azure.Portal.RecoveryServices.Models.Common; |
| 19 | +using Microsoft.WindowsAzure.Management.SiteRecovery.Models; |
| 20 | +using Microsoft.WindowsAzure.Management.Storage.Models; |
| 21 | + |
| 22 | +namespace Microsoft.Azure.Commands.RecoveryServices |
| 23 | +{ |
| 24 | + /// <summary> |
| 25 | + /// Updates Azure Site Recovery Protection Profile. |
| 26 | + /// Protection profile must be associated with the protection container. |
| 27 | + /// </summary> |
| 28 | + [Cmdlet(VerbsCommon.Set, "AzureSiteRecoveryProtectionProfile", DefaultParameterSetName = ASRParameterSets.EnterpriseToEnterprise)] |
| 29 | + [OutputType(typeof(ASRJob))] |
| 30 | + public class SetAzureSiteRecoveryProtectionProfile : RecoveryServicesCmdletBase |
| 31 | + { |
| 32 | + #region Parameters |
| 33 | + |
| 34 | + /// <summary> |
| 35 | + /// Job response. |
| 36 | + /// </summary> |
| 37 | + private JobResponse jobResponse = null; |
| 38 | + |
| 39 | + /// <summary> |
| 40 | + /// Gets or sets Protection Profile object. |
| 41 | + /// </summary> |
| 42 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)] |
| 43 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)] |
| 44 | + [ValidateNotNullOrEmpty] |
| 45 | + public ASRProtectionProfile ProtectionProfile { get; set; } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Gets or sets Recovery Azure Storage Account Name of the Protection Profile for E2A scenarios. |
| 49 | + /// </summary> |
| 50 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)] |
| 51 | + [ValidateNotNullOrEmpty] |
| 52 | + public string RecoveryAzureStorageAccount { get; set; } |
| 53 | + |
| 54 | + /// <summary> |
| 55 | + /// Gets or sets Replication Frequency of the Protection Profile in seconds. |
| 56 | + /// </summary> |
| 57 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)] |
| 58 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)] |
| 59 | + [ValidateNotNullOrEmpty] |
| 60 | + public int ReplicationFrequencyInSeconds { get; set; } |
| 61 | + |
| 62 | + /// <summary> |
| 63 | + /// Gets or sets Recovery Points of the Protection Profile. |
| 64 | + /// </summary> |
| 65 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)] |
| 66 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)] |
| 67 | + [ValidateNotNullOrEmpty] |
| 68 | + public int RecoveryPoints { get; set; } |
| 69 | + |
| 70 | + /// <summary> |
| 71 | + /// Gets or sets Application Consistent Snapshot Frequency of the Protection Profile in hours. |
| 72 | + /// </summary> |
| 73 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)] |
| 74 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)] |
| 75 | + [ValidateNotNullOrEmpty] |
| 76 | + public int ApplicationConsistentSnapshotFrequencyInHours { get; set; } |
| 77 | + |
| 78 | + /// <summary> |
| 79 | + /// Gets or sets a value indicating whether Compression needs to be Enabled on the Protection Profile. |
| 80 | + /// </summary> |
| 81 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)] |
| 82 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)] |
| 83 | + [ValidateNotNullOrEmpty] |
| 84 | + public bool CompressionEnabled { get; set; } |
| 85 | + |
| 86 | + /// <summary> |
| 87 | + /// Gets or sets the Replication Port of the Protection Profile. |
| 88 | + /// </summary> |
| 89 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)] |
| 90 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)] |
| 91 | + [ValidateNotNullOrEmpty] |
| 92 | + public int ReplicationPort { get; set; } |
| 93 | + |
| 94 | + /// <summary> |
| 95 | + /// Gets or sets Replication Start time of the Protection Profile. |
| 96 | + /// </summary> |
| 97 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise)] |
| 98 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure)] |
| 99 | + [ValidateNotNullOrEmpty] |
| 100 | + public TimeSpan? ReplicationStartTime { get; set; } |
| 101 | + |
| 102 | + /// <summary> |
| 103 | + /// Gets or sets a value indicating whether Replica should be Deleted on |
| 104 | + /// disabling protection of a protection entity protected by the Protection Profile. |
| 105 | + /// </summary> |
| 106 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)] |
| 107 | + [Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)] |
| 108 | + [ValidateNotNullOrEmpty] |
| 109 | + public bool AllowReplicaDeletion { get; set; } |
| 110 | + |
| 111 | + #endregion Parameters |
| 112 | + |
| 113 | + /// <summary> |
| 114 | + /// ProcessRecord of the command. |
| 115 | + /// </summary> |
| 116 | + public override void ExecuteCmdlet() |
| 117 | + { |
| 118 | + try |
| 119 | + { |
| 120 | + switch (this.ParameterSetName) |
| 121 | + { |
| 122 | + case ASRParameterSets.EnterpriseToAzure: |
| 123 | + this.EnterpriseToEnterpriseUpdate(); |
| 124 | + break; |
| 125 | + case ASRParameterSets.EnterpriseToEnterprise: |
| 126 | + this.EnterpriseToAzureUpdate(); |
| 127 | + break; |
| 128 | + } |
| 129 | + } |
| 130 | + catch (Exception exception) |
| 131 | + { |
| 132 | + this.HandleException(exception); |
| 133 | + } |
| 134 | + } |
| 135 | + |
| 136 | + /// <summary> |
| 137 | + /// Handles interrupts. |
| 138 | + /// </summary> |
| 139 | + protected override void StopProcessing() |
| 140 | + { |
| 141 | + // Ctrl + C and etc |
| 142 | + base.StopProcessing(); |
| 143 | + this.StopProcessingFlag = true; |
| 144 | + } |
| 145 | + |
| 146 | + /// <summary> |
| 147 | + /// Updates an E2A Protection Profile |
| 148 | + /// </summary> |
| 149 | + private void EnterpriseToAzureUpdate() |
| 150 | + { |
| 151 | + // Verify whether the storage account is associated with the account or not. |
| 152 | + PSRecoveryServicesClientHelper.ValidateStorageAccountAssociation(this.RecoveryAzureStorageAccount); |
| 153 | + |
| 154 | + HyperVReplicaAzureProtectionProfileInput hyperVReplicaAzureProtectionProfileInput |
| 155 | + = new HyperVReplicaAzureProtectionProfileInput() |
| 156 | + { |
| 157 | + AppConsistencyFreq = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ApplicationConsistentSnapshotFrequencyInHours, |
| 158 | + ReplicationInterval = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationFrequencyInSeconds, |
| 159 | + OnlineIrStartTime = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationStartTime |
| 160 | + }; |
| 161 | + |
| 162 | + UpdateProtectionProfileInput updateProtectionProfileInput = |
| 163 | + new UpdateProtectionProfileInput( |
| 164 | + DataContractUtils<HyperVReplicaAzureProtectionProfileInput>.Serialize(hyperVReplicaAzureProtectionProfileInput)); |
| 165 | + |
| 166 | + this.jobResponse = RecoveryServicesClient.UpdateAzureSiteRecoveryProtectionProfile( |
| 167 | + updateProtectionProfileInput, |
| 168 | + this.ProtectionProfile.ID); |
| 169 | + |
| 170 | + this.WriteJob(this.jobResponse.Job); |
| 171 | + } |
| 172 | + |
| 173 | + /// <summary> |
| 174 | + /// Updates an E2E Protection Profile |
| 175 | + /// </summary> |
| 176 | + private void EnterpriseToEnterpriseUpdate() |
| 177 | + { |
| 178 | + HyperVReplicaAzureProtectionProfileInput hyperVReplicaAzureProtectionProfileInput |
| 179 | + = new HyperVReplicaAzureProtectionProfileInput() |
| 180 | + { |
| 181 | + AppConsistencyFreq = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ApplicationConsistentSnapshotFrequencyInHours, |
| 182 | + ReplicationInterval = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationFrequencyInSeconds, |
| 183 | + OnlineIrStartTime = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationStartTime |
| 184 | + }; |
| 185 | + |
| 186 | + UpdateProtectionProfileInput updateProtectionProfileInput = |
| 187 | + new UpdateProtectionProfileInput( |
| 188 | + DataContractUtils<HyperVReplicaAzureProtectionProfileInput>.Serialize(hyperVReplicaAzureProtectionProfileInput)); |
| 189 | + |
| 190 | + this.jobResponse = RecoveryServicesClient.UpdateAzureSiteRecoveryProtectionProfile( |
| 191 | + updateProtectionProfileInput, |
| 192 | + this.ProtectionProfile.ID); |
| 193 | + |
| 194 | + this.WriteJob(this.jobResponse.Job); |
| 195 | + } |
| 196 | + |
| 197 | + /// <summary> |
| 198 | + /// Writes Job |
| 199 | + /// </summary> |
| 200 | + /// <param name="job">Job object</param> |
| 201 | + private void WriteJob(Microsoft.WindowsAzure.Management.SiteRecovery.Models.Job job) |
| 202 | + { |
| 203 | + this.WriteObject(new ASRJob(job)); |
| 204 | + } |
| 205 | + } |
| 206 | +} |
0 commit comments