Skip to content

Commit 2d14377

Browse files
committed
Moving to correct branch: Powershell cmdlet for SyncOwnerInformation
1 parent 14b5be8 commit 2d14377

File tree

4 files changed

+155
-0
lines changed

4 files changed

+155
-0
lines changed

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices.Test/ScenarioTests/RecoveryServicesTests.ps1

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ function Test-RecoveryServicesProtectionTests
9191
if ($protectionEntity.Protected)
9292
{
9393
Set-AzureSiteRecoveryProtectionEntity -ProtectionEntity $protectionEntity -Protection "Enable" -Force
94+
Update-AzureSiteRecoveryProtectionEntity -ProtectionEntity $protectionEntity
9495
}
9596
else
9697
{

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Commands.RecoveryServices.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@
139139
<Compile Include="Service\GetAzureSiteRecoveryVaultSettings.cs" />
140140
<Compile Include="Service\GetAzureSiteRecoveryVM.cs" />
141141
<Compile Include="Service\ImportAzureSiteRecoveryVaultSettingsFile.cs" />
142+
<Compile Include="Service\UpdateSyncOwnerInformation.cs" />
142143
</ItemGroup>
143144
<ItemGroup>
144145
<ProjectReference Include="..\..\..\Common\Commands.Common\Commands.Common.csproj">

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/PSRecoveryServicesClient/PSRecoveryServicesPEClient.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,21 @@ public JobResponse StartAzureSiteRecoveryReprotection(
192192
request,
193193
this.GetRequestHeaders());
194194
}
195+
196+
/// <summary>
197+
/// Syncs owner role information on Protection entity.
198+
/// </summary>
199+
/// <param name="protectionContainerId">Protection Container ID</param>
200+
/// <param name="virtualMachineId">Virtual Machine ID</param>
201+
/// <returns>Job response</returns>
202+
public JobResponse UpdateSyncOwnerInformationOnProtectionEntity(
203+
string protectionContainerId,
204+
string protectionEntityId)
205+
{
206+
return this.GetSiteRecoveryClient().ProtectionEntity.SyncOwnerInformation(
207+
protectionContainerId,
208+
protectionEntityId,
209+
this.GetRequestHeaders());
210+
}
195211
}
196212
}
Lines changed: 137 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,137 @@
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+
namespace Microsoft.Azure.Commands.RecoveryServices
16+
{
17+
#region Using directives
18+
using System;
19+
using System.Diagnostics;
20+
using System.Management.Automation;
21+
using System.Threading;
22+
using Microsoft.Azure.Commands.RecoveryServices.SiteRecovery;
23+
using Microsoft.WindowsAzure;
24+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
25+
#endregion
26+
27+
/// <summary>
28+
/// Used to initiate a commit operation.
29+
/// </summary>
30+
[Cmdlet(VerbsData.Update, "AzureSiteRecoveryProtectionEntity")]
31+
[OutputType(typeof(ASRJob))]
32+
public class UpdateSyncOwnerInformation : RecoveryServicesCmdletBase
33+
{
34+
#region Parameters
35+
36+
/// <summary>
37+
/// ID of the PE object to Update user information on.
38+
/// </summary>
39+
private string protectionEntityId;
40+
41+
/// <summary>
42+
/// Protection container ID of the object to Update user information on.
43+
/// </summary>
44+
private string protectionContainerId;
45+
46+
/// <summary>
47+
/// Recovery Plan object.
48+
/// </summary>
49+
private ASRProtectionEntity protectionEntity;
50+
51+
/// <summary>
52+
/// Wait / hold prompt till the Job completes.
53+
/// </summary>
54+
private bool waitForCompletion;
55+
56+
/// <summary>
57+
/// Job response.
58+
/// </summary>
59+
private JobResponse jobResponse = null;
60+
61+
/// <summary>
62+
/// Gets or sets Protection Entity object.
63+
/// </summary>
64+
[Parameter(Mandatory = true, ValueFromPipeline = true)]
65+
[ValidateNotNullOrEmpty]
66+
public ASRProtectionEntity ProtectionEntity
67+
{
68+
get { return this.protectionEntity; }
69+
set { this.protectionEntity = value; }
70+
}
71+
72+
/// <summary>
73+
/// Gets or sets switch parameter. This is required to wait for job completion.
74+
/// </summary>
75+
[Parameter]
76+
public SwitchParameter WaitForCompletion
77+
{
78+
get { return this.waitForCompletion; }
79+
set { this.waitForCompletion = value; }
80+
}
81+
82+
#endregion Parameters
83+
84+
/// <summary>
85+
/// ProcessRecord of the command.
86+
/// </summary>
87+
public override void ExecuteCmdlet()
88+
{
89+
try
90+
{
91+
this.protectionContainerId = this.ProtectionEntity.ProtectionContainerId;
92+
this.protectionEntityId = this.ProtectionEntity.ID;
93+
this.SyncOwnerInformationOnPE();
94+
}
95+
catch (Exception exception)
96+
{
97+
this.HandleException(exception);
98+
}
99+
}
100+
101+
/// <summary>
102+
/// Handles interrupts.
103+
/// </summary>
104+
protected override void StopProcessing()
105+
{
106+
// Ctrl + C and etc
107+
base.StopProcessing();
108+
this.StopProcessingFlag = true;
109+
}
110+
111+
/// <summary>
112+
/// Syncs the owner information.
113+
/// </summary>
114+
private void SyncOwnerInformationOnPE()
115+
{
116+
this.jobResponse = RecoveryServicesClient.UpdateSyncOwnerInformationOnProtectionEntity(
117+
this.protectionContainerId,
118+
this.protectionEntityId);
119+
120+
this.WriteJob(this.jobResponse.Job);
121+
122+
if (this.waitForCompletion)
123+
{
124+
this.WaitForJobCompletion(this.jobResponse.Job.ID);
125+
}
126+
}
127+
128+
/// <summary>
129+
/// Writes Job
130+
/// </summary>
131+
/// <param name="job">Job object</param>
132+
private void WriteJob(Microsoft.WindowsAzure.Management.SiteRecovery.Models.Job job)
133+
{
134+
this.WriteObject(new ASRJob(job));
135+
}
136+
}
137+
}

0 commit comments

Comments
 (0)