Skip to content

Commit f5c40c6

Browse files
committed
Skeleton for Associate, dissociate and update protectionProfile
1 parent d9e027e commit f5c40c6

File tree

3 files changed

+493
-0
lines changed

3 files changed

+493
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,206 @@
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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
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+
21+
namespace Microsoft.Azure.Commands.RecoveryServices
22+
{
23+
/// <summary>
24+
/// Adds Azure Site Recovery Protection Profile settings to a Protection Container.
25+
/// </summary>
26+
[Cmdlet(VerbsLifecycle.Start, "AzureSiteRecoveryProtectionProfileAssociationJob", DefaultParameterSetName = ASRParameterSets.EnterpriseToEnterprise)]
27+
[OutputType(typeof(ASRJob))]
28+
public class StartAzureSiteRecoveryProtectionProfileJob : RecoveryServicesCmdletBase
29+
{
30+
#region Parameters
31+
32+
/// <summary>
33+
/// Job response.
34+
/// </summary>
35+
private JobResponse jobResponse = null;
36+
37+
/// <summary>
38+
/// Gets or sets Protection Container to be applied the Protection Profile settings on.
39+
/// </summary>
40+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToEnterprise, Mandatory = true)]
41+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)]
42+
[ValidateNotNullOrEmpty]
43+
public ASRProtectionContainer PrimaryProtectionContainer { get; set; }
44+
45+
/// <summary>
46+
/// Gets or sets Protection Container to be applied the Protection Profile settings on.
47+
/// </summary>
48+
[Parameter(ParameterSetName = ASRParameterSets.EnterpriseToAzure, Mandatory = true)]
49+
[ValidateNotNullOrEmpty]
50+
public ASRProtectionContainer RecoveryProtectionContainer { get; set; }
51+
52+
/// <summary>
53+
/// Gets or sets Protection Profile object.
54+
/// </summary>
55+
[Parameter(ParameterSetName = ASRParameterSets.Default, Mandatory = true)]
56+
[ValidateNotNullOrEmpty]
57+
public ASRProtectionProfile ProtectionProfile { get; set; }
58+
59+
#endregion Parameters
60+
61+
/// <summary>
62+
/// ProcessRecord of the command.
63+
/// </summary>
64+
public override void ExecuteCmdlet()
65+
{
66+
try
67+
{
68+
switch (this.ParameterSetName)
69+
{
70+
case ASRParameterSets.EnterpriseToAzure:
71+
this.EnterpriseToEnterpriseAssociation();
72+
break;
73+
case ASRParameterSets.EnterpriseToEnterprise:
74+
this.EnterpriseToAzureAssociation();
75+
break;
76+
}
77+
}
78+
catch (Exception exception)
79+
{
80+
this.HandleException(exception);
81+
}
82+
}
83+
84+
/// <summary>
85+
/// Handles interrupts.
86+
/// </summary>
87+
protected override void StopProcessing()
88+
{
89+
// Ctrl + C and etc
90+
base.StopProcessing();
91+
this.StopProcessingFlag = true;
92+
}
93+
94+
/// <summary>
95+
/// Associates protection profile with one enterprise based and an Azure protection container
96+
/// </summary>
97+
private void EnterpriseToAzureAssociation()
98+
{
99+
HyperVReplicaAzureProtectionProfileInput hyperVReplicaAzureProtectionProfileInput
100+
= new HyperVReplicaAzureProtectionProfileInput()
101+
{
102+
AppConsistencyFreq = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ApplicationConsistentSnapshotFrequencyInHours,
103+
ReplicationInterval = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationFrequencyInSeconds,
104+
OnlineIrStartTime = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationStartTime
105+
};
106+
107+
var storageAccount = new CustomerStorageAccount();
108+
storageAccount.StorageAccountName = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureStorageAccountName;
109+
storageAccount.SubscriptionId = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureSubscription;
110+
hyperVReplicaAzureProtectionProfileInput.StorageAccounts.Add(storageAccount);
111+
112+
CreateProtectionProfileInput createProtectionProfileInput =
113+
new CreateProtectionProfileInput(
114+
this.ProtectionProfile.Name,
115+
this.ProtectionProfile.ReplicationProvider,
116+
DataContractUtils<HyperVReplicaAzureProtectionProfileInput>.Serialize(hyperVReplicaAzureProtectionProfileInput));
117+
118+
ProtectionProfileAssociationInput protectionProfileAssociationInput =
119+
new ProtectionProfileAssociationInput(
120+
this.PrimaryProtectionContainer.ID,
121+
this.RecoveryProtectionContainer.ID);
122+
123+
CreateAndAssociateProtectionProfileInput createAndAssociateProtectionProfileInput =
124+
new CreateAndAssociateProtectionProfileInput(
125+
createProtectionProfileInput,
126+
protectionProfileAssociationInput);
127+
128+
this.jobResponse = RecoveryServicesClient.StartCreateAndAssociateAzureSiteRecoveryProtectionProfileJob(
129+
createAndAssociateProtectionProfileInput);
130+
131+
this.WriteJob(this.jobResponse.Job);
132+
}
133+
134+
/// <summary>
135+
/// Associates protection profile with enterprise based protection containers
136+
/// </summary>
137+
private void EnterpriseToEnterpriseAssociation()
138+
{
139+
HyperVReplicaAzureProtectionProfileInput hyperVReplicaAzureProtectionProfileInput
140+
= new HyperVReplicaAzureProtectionProfileInput()
141+
{
142+
AppConsistencyFreq = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ApplicationConsistentSnapshotFrequencyInHours,
143+
ReplicationInterval = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationFrequencyInSeconds,
144+
OnlineIrStartTime = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.ReplicationStartTime
145+
};
146+
147+
var storageAccount = new CustomerStorageAccount();
148+
storageAccount.StorageAccountName = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureStorageAccountName;
149+
storageAccount.SubscriptionId = this.ProtectionProfile.HyperVReplicaAzureProviderSettingsObject.RecoveryAzureSubscription;
150+
hyperVReplicaAzureProtectionProfileInput.StorageAccounts.Add(storageAccount);
151+
152+
CreateProtectionProfileInput createProtectionProfileInput =
153+
new CreateProtectionProfileInput(
154+
this.ProtectionProfile.Name,
155+
this.ProtectionProfile.ReplicationProvider,
156+
DataContractUtils<HyperVReplicaAzureProtectionProfileInput>.Serialize(hyperVReplicaAzureProtectionProfileInput));
157+
158+
ProtectionProfileAssociationInput protectionProfileAssociationInput =
159+
new ProtectionProfileAssociationInput(
160+
this.PrimaryProtectionContainer.ID,
161+
this.RecoveryProtectionContainer.ID);
162+
163+
CreateAndAssociateProtectionProfileInput createAndAssociateProtectionProfileInput =
164+
new CreateAndAssociateProtectionProfileInput(
165+
createProtectionProfileInput,
166+
protectionProfileAssociationInput);
167+
168+
this.jobResponse = RecoveryServicesClient.StartCreateAndAssociateAzureSiteRecoveryProtectionProfileJob(
169+
createAndAssociateProtectionProfileInput);
170+
171+
this.WriteJob(this.jobResponse.Job);
172+
}
173+
174+
/// <summary>
175+
/// Writes Job
176+
/// </summary>
177+
/// <param name="job">Job object</param>
178+
private void WriteJob(Microsoft.WindowsAzure.Management.SiteRecovery.Models.Job job)
179+
{
180+
this.WriteObject(new ASRJob(job));
181+
}
182+
}
183+
}

0 commit comments

Comments
 (0)