Skip to content

Commit a5f8146

Browse files
committed
Merge pull request #2 from AsrOneSdk/neha-dev
Moving to correct branch: Powershell cmdlet for SyncOwnerInformation
2 parents 77f5b03 + 9b40824 commit a5f8146

File tree

5 files changed

+308
-0
lines changed

5 files changed

+308
-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
@@ -157,6 +157,7 @@
157157
<Compile Include="Service\GetAzureSiteRecoveryVaultSettings.cs" />
158158
<Compile Include="Service\GetAzureSiteRecoveryVM.cs" />
159159
<Compile Include="Service\ImportAzureSiteRecoveryVaultSettingsFile.cs" />
160+
<Compile Include="Service\UpdateAzureSiteRecoveryProtectionEntity.cs" />
160161
</ItemGroup>
161162
<ItemGroup>
162163
<ProjectReference Include="..\..\..\Common\Commands.Common\Commands.Common.csproj">

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Microsoft.Azure.Commands.RecoveryServices.dll-help.xml

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4703,4 +4703,166 @@
47034703
</maml:relatedLinks>
47044704
</command:command>
47054705

4706+
<!--Update-AzureSiteRecoveryProtectionEntity-->
4707+
<command:command xmlns:maml="http://schemas.microsoft.com/maml/2004/10" xmlns:command="http://schemas.microsoft.com/maml/dev/command/2004/10" xmlns:dev="http://schemas.microsoft.com/maml/dev/2004/10">
4708+
<command:details>
4709+
<command:name>
4710+
Update-AzureSiteRecoveryProtectionEntity
4711+
</command:name>
4712+
<maml:description>
4713+
<maml:para>Updates the property of Azure Site Recovery Protection Entity like virtual machine owner information.</maml:para>
4714+
</maml:description>
4715+
<maml:copyright>
4716+
<maml:para></maml:para>
4717+
</maml:copyright>
4718+
<command:verb>Update</command:verb>
4719+
<command:noun>AzureSiteRecoveryProtectionEntity</command:noun>
4720+
<dev:version></dev:version>
4721+
</command:details>
4722+
<maml:description>
4723+
<maml:para>Updates the property of Azure Site Recovery Protection Entity. This command can be used to update the owner information on the replica virtual machine. Supported only for VMM to VMM protected protection entities.</maml:para>
4724+
</maml:description>
4725+
<!-- Cmdlet syntax section-->
4726+
<command:syntax>
4727+
<command:syntaxItem>
4728+
<maml:name>Update-AzureSiteRecoveryProtectionEntity</maml:name>
4729+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named">
4730+
<maml:name>ProtectionEntity</maml:name>
4731+
<maml:description>
4732+
<maml:para>Protection Entity object</maml:para>
4733+
</maml:description>
4734+
<command:parameterValue required="true" variableLength="false">ASRProtectionEntity</command:parameterValue>
4735+
</command:parameter>
4736+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
4737+
<maml:name>WaitForCompletion</maml:name>
4738+
<maml:description>
4739+
<maml:para>Waits till the operation completes</maml:para>
4740+
</maml:description>
4741+
</command:parameter>
4742+
</command:syntaxItem>
4743+
</command:syntax>
4744+
<!-- Cmdlet parameter section -->
4745+
<command:parameters>
4746+
<command:parameter required="true" variableLength="false" globbing="false" pipelineInput="true (ByValue)" position="named">
4747+
<maml:name>ProtectionEntity</maml:name>
4748+
<maml:description>
4749+
<maml:para>Protection Entity object</maml:para>
4750+
4751+
</maml:description>
4752+
<command:parameterValue required="true" variableLength="false">ASRProtectionEntity</command:parameterValue>
4753+
<dev:type>
4754+
<maml:name>ASRProtectionEntity</maml:name>
4755+
<maml:uri/>
4756+
</dev:type>
4757+
<dev:defaultValue></dev:defaultValue>
4758+
</command:parameter>
4759+
<command:parameter required="false" variableLength="false" globbing="false" pipelineInput="false" position="named">
4760+
<maml:name>WaitForCompletion</maml:name>
4761+
<maml:description>
4762+
<maml:para>Waits till the operation completes</maml:para>
4763+
4764+
</maml:description>
4765+
<command:parameterValue required="false" variableLength="false">SwitchParameter</command:parameterValue>
4766+
<dev:type>
4767+
<maml:name>SwitchParameter</maml:name>
4768+
<maml:uri/>
4769+
</dev:type>
4770+
<dev:defaultValue></dev:defaultValue>
4771+
</command:parameter>
4772+
</command:parameters>
4773+
<!-- Input - Output section-->
4774+
<command:inputTypes>
4775+
<command:inputType>
4776+
<dev:type>
4777+
<maml:name></maml:name>
4778+
<maml:uri/>
4779+
<maml:description />
4780+
</dev:type>
4781+
<maml:description>
4782+
<maml:para>
4783+
<!-- description -->
4784+
4785+
</maml:para>
4786+
</maml:description>
4787+
</command:inputType>
4788+
</command:inputTypes>
4789+
<command:returnValues>
4790+
<command:returnValue>
4791+
<dev:type>
4792+
<maml:name></maml:name>
4793+
<maml:uri />
4794+
<maml:description />
4795+
</dev:type>
4796+
<maml:description>
4797+
<maml:para>
4798+
<!-- description -->
4799+
4800+
</maml:para>
4801+
</maml:description>
4802+
</command:returnValue>
4803+
</command:returnValues>
4804+
<!-- Error section-->
4805+
<command:terminatingErrors />
4806+
<command:nonTerminatingErrors />
4807+
<!-- Notes section -->
4808+
<maml:alertSet>
4809+
<maml:title></maml:title>
4810+
<maml:alert>
4811+
<maml:para>
4812+
4813+
</maml:para>
4814+
</maml:alert>
4815+
<maml:alert>
4816+
<maml:para></maml:para>
4817+
</maml:alert>
4818+
</maml:alertSet>
4819+
<!-- Example section -->
4820+
<command:examples>
4821+
4822+
<command:example>
4823+
<maml:title>
4824+
-------------------------- EXAMPLE 1 --------------------------
4825+
</maml:title>
4826+
<maml:introduction>
4827+
<maml:para>C:\PS&gt;</maml:para>
4828+
</maml:introduction>
4829+
<dev:code>
4830+
Update-AzureSiteRecoveryProtectionEntity -ProtectionEntity $PE
4831+
4832+
Name :
4833+
ID : 680ffe0f-6236-465e-8c94-81242fa67e6d
4834+
ClientRequestId : 2c47e6ce-1460-4187-8a0f-b9073735fa38-2014-12-30 06:44:40Z-P
4835+
State : NotStarted
4836+
StateDescription : NotStarted
4837+
StartTime :
4838+
EndTime :
4839+
AllowedActions : {}
4840+
Tasks : {}
4841+
Errors : {}
4842+
</dev:code>
4843+
<dev:remarks>
4844+
<maml:para>Description</maml:para>
4845+
<maml:para>-----------</maml:para>
4846+
<maml:para></maml:para>
4847+
<maml:para></maml:para>
4848+
<maml:para></maml:para>
4849+
<maml:para></maml:para>
4850+
<maml:para></maml:para>
4851+
</dev:remarks>
4852+
<command:commandLines>
4853+
<command:commandLine>
4854+
<command:commandText></command:commandText>
4855+
</command:commandLine>
4856+
</command:commandLines>
4857+
</command:example>
4858+
</command:examples>
4859+
<!-- Link section -->
4860+
<maml:relatedLinks>
4861+
<maml:navigationLink>
4862+
<maml:linkText></maml:linkText>
4863+
<maml:uri/>
4864+
</maml:navigationLink>
4865+
</maml:relatedLinks>
4866+
</command:command>
4867+
47064868
</helpItems>

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,5 +192,22 @@ public JobResponse StartAzureSiteRecoveryReprotection(
192192
request,
193193
this.GetRequestHeaders());
194194
}
195+
196+
/// <summary>
197+
/// Currently available only for E2E replication provider,
198+
/// syncs owner role information on Protection entity.
199+
/// </summary>
200+
/// <param name="protectionContainerId">Protection Container ID</param>
201+
/// <param name="protectionEntityId">Protection Entity ID</param>
202+
/// <returns>Job response</returns>
203+
public JobResponse UpdateAzureSiteRecoveryProtectionEntity(
204+
string protectionContainerId,
205+
string protectionEntityId)
206+
{
207+
return this.GetSiteRecoveryClient().ProtectionEntity.SyncOwnerInformation(
208+
protectionContainerId,
209+
protectionEntityId,
210+
this.GetRequestHeaders());
211+
}
195212
}
196213
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
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 UpdateAzureSiteRecoveryProtectionEntity : 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+
/// Job response.
48+
/// </summary>
49+
private JobResponse jobResponse = null;
50+
51+
/// <summary>
52+
/// Gets or sets Protection Entity object.
53+
/// </summary>
54+
[Parameter(Mandatory = true, ValueFromPipeline = true)]
55+
[ValidateNotNullOrEmpty]
56+
public ASRProtectionEntity ProtectionEntity
57+
{
58+
get;
59+
set;
60+
}
61+
62+
/// <summary>
63+
/// Gets or sets switch parameter. This is required to wait for job completion.
64+
/// </summary>
65+
[Parameter]
66+
public SwitchParameter WaitForCompletion
67+
{
68+
get;
69+
set;
70+
}
71+
72+
#endregion Parameters
73+
74+
/// <summary>
75+
/// ProcessRecord of the command.
76+
/// </summary>
77+
public override void ExecuteCmdlet()
78+
{
79+
try
80+
{
81+
this.protectionContainerId = this.ProtectionEntity.ProtectionContainerId;
82+
this.protectionEntityId = this.ProtectionEntity.ID;
83+
this.SyncOwnerInformationOnPE();
84+
}
85+
catch (Exception exception)
86+
{
87+
this.HandleException(exception);
88+
}
89+
}
90+
91+
/// <summary>
92+
/// Handles interrupts.
93+
/// </summary>
94+
protected override void StopProcessing()
95+
{
96+
// Ctrl + C and etc
97+
base.StopProcessing();
98+
this.StopProcessingFlag = true;
99+
}
100+
101+
/// <summary>
102+
/// Syncs the owner information.
103+
/// </summary>
104+
private void SyncOwnerInformationOnPE()
105+
{
106+
this.jobResponse = RecoveryServicesClient.UpdateAzureSiteRecoveryProtectionEntity(
107+
this.protectionContainerId,
108+
this.protectionEntityId);
109+
110+
this.WriteJob(this.jobResponse.Job);
111+
112+
if (this.WaitForCompletion)
113+
{
114+
this.WaitForJobCompletion(this.jobResponse.Job.ID);
115+
}
116+
}
117+
118+
/// <summary>
119+
/// Writes Job
120+
/// </summary>
121+
/// <param name="job">Job object</param>
122+
private void WriteJob(Microsoft.WindowsAzure.Management.SiteRecovery.Models.Job job)
123+
{
124+
this.WriteObject(new ASRJob(job));
125+
}
126+
}
127+
}

0 commit comments

Comments
 (0)