Skip to content

Commit dd70b26

Browse files
committed
Merge pull request #68 from AsrOneSdk/vimalth-dev
Powershell changes for SAN (Cloud pairing/unpairing, enable and disable RG)
2 parents 5f9689b + 95a6a5a commit dd70b26

20 files changed

+1180
-47
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,5 +200,12 @@ public void CommitRPTest()
200200
{
201201
this.RunPowerShellTest("Test-CommitRP -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
202202
}
203+
204+
[Fact]
205+
[Trait(Category.AcceptanceType, Category.CheckIn)]
206+
public void RecoveryServicesSanE2ETest()
207+
{
208+
this.RunPowerShellTest("Test-SanE2E -vaultSettingsFilePath \"" + vaultSettingsFilePath + "\"");
209+
}
203210
}
204211
}

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

Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1226,6 +1226,151 @@ function Test-DisableProtection
12261226

12271227
<#
12281228
.SYNOPSIS
1229+
Recovery Services San E2E test
1230+
#>
1231+
function Test-SanE2E
1232+
{
1233+
param([string] $vaultSettingsFilePath)
1234+
1235+
# Import Azure Site Recovery Vault Settings
1236+
Import-AzureSiteRecoveryVaultSettingsFile $vaultSettingsFilePath
1237+
1238+
$servers = Get-AzureSiteRecoveryServer
1239+
$primaryVmm = $servers[0]
1240+
$recoveryVmm = $servers[1]
1241+
$storagePri = Get-AzureSiteRecoveryStorage -Server $primaryVmm
1242+
$storageRec = Get-AzureSiteRecoveryStorage -Server $recoveryVmm
1243+
1244+
# Find primary array and pool.
1245+
foreach($storage in $storagePri)
1246+
{
1247+
# Find primary array
1248+
if ($storage.Name.Contains("HRMPROSVM01"))
1249+
{
1250+
$primaryArray = $storage
1251+
1252+
foreach($pool in $primaryArray.StoragePools)
1253+
{
1254+
# Find primary pool
1255+
if ($pool.Name.Contains("SanOneSDKPrimaryPool"))
1256+
{
1257+
$primaryStoragePool = $pool
1258+
break
1259+
}
1260+
}
1261+
}
1262+
}
1263+
1264+
# Find recovery array and pool.
1265+
foreach($storage in $storageRec)
1266+
{
1267+
# Find recovery array
1268+
if ($storage.Name.Contains("HRMDRSVM01"))
1269+
{
1270+
$recoveryArray = $storage
1271+
1272+
foreach($pool in $recoveryArray.StoragePools)
1273+
{
1274+
# Find recovery pool
1275+
if ($pool.Name.Contains("SanOneSDKRecoveryPool"))
1276+
{
1277+
$recoveryStoragePool = $pool
1278+
break
1279+
}
1280+
}
1281+
}
1282+
}
1283+
1284+
# Pair pools
1285+
$job = New-AzureSiteRecoveryStoragePoolMapping -PrimaryStorage $primaryArray -PrimaryStoragePoolId $primaryStoragePool.Id -RecoveryStorage $recoveryArray -RecoveryStoragePoolId $recoveryStoragePool.Id
1286+
Assert-NotNull($job);
1287+
1288+
$protectionContainers = Get-AzureSiteRecoveryProtectionContainer
1289+
Assert-True { $protectionContainers.Count -gt 0 }
1290+
Assert-NotNull($protectionContainers)
1291+
foreach($protectionContainer in $protectionContainers)
1292+
{
1293+
Assert-NotNull($protectionContainer.Name)
1294+
Assert-NotNull($protectionContainer.ID)
1295+
1296+
# Find primary cloud
1297+
if ($protectionContainer.Name.Contains("SanPrimaryCloud"))
1298+
{
1299+
$primaryContainer = $protectionContainer
1300+
}
1301+
1302+
# Find recovery cloud
1303+
if ($protectionContainer.Name.Contains("SanRecoveryCloud"))
1304+
{
1305+
$recoveryContainer = $protectionContainer
1306+
}
1307+
}
1308+
1309+
# Create protection profile
1310+
$pp = New-AzureSiteRecoveryProtectionProfileObject -ReplicationProvider San -PrimaryContainerId $primaryContainer.ID -RecoveryContainerId $recoveryContainer.ID -PrimaryArrayId $primaryArray.ID -RecoveryArrayId $recoveryArray.ID
1311+
1312+
# Start cloud pairing
1313+
$job = Start-AzureSiteRecoveryProtectionProfileAssociationJob -ProtectionProfile $pp -PrimaryProtectionContainer $primaryContainer -RecoveryProtectionContainer $recoveryContainer
1314+
Assert-NotNull($job);
1315+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 600
1316+
1317+
# Get protection Entity (RG)
1318+
$pe = Get-AzureSiteRecoveryProtectionEntity -ProtectionContainer $primaryContainer
1319+
1320+
# Enable RG
1321+
$job = Set-AzureSiteRecoveryProtectionEntity -ProtectionEntity $pe -Protection Enable -RPO 0 -Replicationtype Async -RecoveryArrayId $recoveryArray.ID
1322+
Assert-NotNull($job);
1323+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 900
1324+
1325+
# Get protection Entity (RG) again after enable
1326+
$pe = Get-AzureSiteRecoveryProtectionEntity -ProtectionContainer $primaryContainer
1327+
1328+
# Test failover RG
1329+
$job = Start-AzureSiteRecoveryTestFailoverJob -ProtectionEntity $pe -WaitForCompletion -Direction PrimaryToRecovery
1330+
Assert-NotNull($job);
1331+
1332+
# Resume Job on manual action
1333+
$job = Resume-AzureSiteRecoveryJob -Id $job.ID
1334+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 900
1335+
1336+
# Planned failover RG
1337+
$job = Start-AzureSiteRecoveryPlannedFailoverJob -ProtectionEntity $pe -Direction PrimaryToRecovery
1338+
Assert-NotNull($job);
1339+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 900
1340+
1341+
# Reverse RG
1342+
$job = Update-AzureSiteRecoveryProtection -ProtectionEntity $pe -Direction RecoveryToPrimary
1343+
Assert-NotNull($job);
1344+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 600
1345+
1346+
# UnPlanned failover RG
1347+
$job = Start-AzureSiteRecoveryUnPlannedFailoverJob -ProtectionEntity $pe -Direction RecoveryToPrimary
1348+
Assert-NotNull($job);
1349+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 900
1350+
1351+
# Reverse RG
1352+
$job = Update-AzureSiteRecoveryProtection -ProtectionEntity $pe -Direction PrimaryToRecovery
1353+
Assert-NotNull($job);
1354+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 600
1355+
1356+
# Disable RG
1357+
$job = Set-AzureSiteRecoveryProtectionEntity -ProtectionEntity $pe -Protection Disable -DeleteReplicaLuns -RecoveryContainerId $recoveryContainer.ID
1358+
Assert-NotNull($job);
1359+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 900
1360+
1361+
# Start cloud unpairing
1362+
$job = Start-AzureSiteRecoveryProtectionProfileDissociationJob -ProtectionProfile $pp -PrimaryProtectionContainer $primaryContainer -RecoveryProtectionContainer $recoveryContainer
1363+
Assert-NotNull($job);
1364+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 600
1365+
1366+
# UnPair pools
1367+
$job = Remove-AzureSiteRecoveryStoragePoolMapping -PrimaryStorage $primaryArray -PrimaryStoragePoolId $primaryStoragePool.Id -RecoveryStorage $recoveryArray -RecoveryStoragePoolId $recoveryStoragePool.Id
1368+
Assert-NotNull($job);
1369+
}
1370+
1371+
<#
1372+
.SYNOPSIS
1373+
Recovery Services Enable Protection Tests
12291374
Wait for CanFailover state
12301375
Usage:
12311376
WaitForCanFailover pcId peId
@@ -1270,3 +1415,18 @@ function WaitForJobCompletion
12701415

12711416
Assert-True { $endStateDescription -ccontains $job.State } "Job did not reached desired state within $NumOfSecondsToWait seconds."
12721417
}
1418+
1419+
<#
1420+
.SYNOPSIS
1421+
Wait for job completion and validate the job
1422+
Usage:
1423+
WaitAndValidatetheJob -JobId $job.ID
1424+
WaitAndValidatetheJob -JobId $job.ID -NumOfSecondsToWait 10
1425+
#>
1426+
function WaitAndValidatetheJob
1427+
{
1428+
param([string] $JobId, [Int] $NumOfSecondsToWait = 120)
1429+
WaitForJobCompletion -JobId $JobId -NumOfSecondsToWait $NumOfSecondsToWait
1430+
$job = Get-AzureSiteRecoveryJob -Id $job.ID
1431+
Assert-True { $job.State -eq "Succeeded" }
1432+
}

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@
150150
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageMappingClient.cs" />
151151
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkMappingClient.cs" />
152152
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkClient.cs" />
153+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStoragePoolMappingClient.cs" />
153154
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVaultClient.cs" />
154155
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVaultExtendedInfoClient.cs" />
155156
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMGroupClient.cs" />
@@ -164,10 +165,13 @@
164165
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMClient.cs" />
165166
<Compile Include="RecoveryServicesCmdletBase.cs" />
166167
<Compile Include="Properties\AssemblyInfo.cs" />
168+
<Compile Include="Service\GetAzureSiteRecoveryStoragePoolMapping.cs" />
167169
<Compile Include="Service\GetAzureSiteRecoveryVault.cs" />
168170
<Compile Include="Service\RemoveAzureSiteRecoverySite.cs" />
169171
<Compile Include="Service\NewAzureSiteRecoverySite.cs" />
170172
<Compile Include="Service\GetAzureSiteRecoverySite.cs" />
173+
<Compile Include="Service\NewAzureSiteRecoveryStoragePoolMapping.cs" />
174+
<Compile Include="Service\RemoveAzureSiteRecoveryStoragePoolMapping.cs" />
171175
<Compile Include="Service\RemoveAzureSiteRecoveryVault.cs" />
172176
<Compile Include="Service\SetAzureSiteRecoveryProtectionProfile.cs" />
173177
<Compile Include="Service\SetAzureSiteRecoveryVM.cs" />

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -59,17 +59,17 @@ public ProtectionEntityResponse GetAzureSiteRecoveryProtectionEntity(
5959
/// Sets protection on Protection entity.
6060
/// </summary>
6161
/// <param name="protectionContainerId">Protection Container ID</param>
62-
/// <param name="virtualMachineId">Virtual Machine ID</param>
62+
/// <param name="protectionEntityId">Virtual Machine ID or Replication group Id</param>
6363
/// <param name="input">Enable protection input.</param>
6464
/// <returns>Job response</returns>
6565
public JobResponse EnableProtection(
6666
string protectionContainerId,
67-
string virtualMachineId,
67+
string protectionEntityId,
6868
EnableProtectionInput input)
6969
{
7070
return this.GetSiteRecoveryClient().ProtectionEntity.EnableProtection(
7171
protectionContainerId,
72-
virtualMachineId,
72+
protectionEntityId,
7373
input,
7474
this.GetRequestHeaders());
7575
}
@@ -78,15 +78,18 @@ public JobResponse EnableProtection(
7878
/// Sets protection on Protection entity.
7979
/// </summary>
8080
/// <param name="protectionContainerId">Protection Container ID</param>
81-
/// <param name="virtualMachineId">Virtual Machine ID</param>
81+
/// <param name="protectionEntityId">Virtual Machine ID or Replication group Id</param>
82+
/// <param name="input">Disable protection input.</param>
8283
/// <returns>Job response</returns>
83-
public JobResponse DisbleProtection(
84+
public JobResponse DisableProtection(
8485
string protectionContainerId,
85-
string virtualMachineId)
86+
string protectionEntityId,
87+
DisableProtectionInput input)
8688
{
8789
return this.GetSiteRecoveryClient().ProtectionEntity.DisableProtection(
8890
protectionContainerId,
89-
virtualMachineId,
91+
protectionEntityId,
92+
input,
9093
this.GetRequestHeaders());
9194
}
9295

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,15 +78,15 @@ public JobResponse StartCreateAndAssociateAzureSiteRecoveryProtectionProfileJob(
7878
/// Deletes and Dissociates Azure Site Recovery Protection Profile.
7979
/// </summary>
8080
/// <param name="protectionProfileId">Protection Profile ID</param>
81-
/// <param name="protectionProfileAssociationInput">Protection Profile Association Input</param>
81+
/// <param name="createAndAssociateProtectionProfileInput">Protection Profile Association Input</param>
8282
/// <returns>Job response</returns>
8383
public JobResponse StartDeleteAndDissociateAzureSiteRecoveryProtectionProfileJob(
8484
string protectionProfileId,
85-
ProtectionProfileAssociationInput protectionProfileAssociationInput)
85+
CreateAndAssociateProtectionProfileInput createAndAssociateProtectionProfileInput)
8686
{
8787
return this.GetSiteRecoveryClient().ProtectionProfile.DissociateAndDelete(
8888
protectionProfileId,
89-
protectionProfileAssociationInput,
89+
createAndAssociateProtectionProfileInput,
9090
this.GetRequestHeaders());
9191
}
9292
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
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 Microsoft.WindowsAzure;
17+
using Microsoft.WindowsAzure.Management.SiteRecovery;
18+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
19+
20+
namespace Microsoft.Azure.Commands.RecoveryServices
21+
{
22+
/// <summary>
23+
/// Recovery services convenience client.
24+
/// </summary>
25+
public partial class PSRecoveryServicesClient
26+
{
27+
/// <summary>
28+
/// Gets Azure Site Recovery Storage pool mappings.
29+
/// </summary>
30+
/// <param name="primaryServerId">Primary server ID</param>
31+
/// <param name="recoveryServerId">Recovery server ID</param>
32+
/// <returns>Storage pool mapping list response</returns>
33+
public StoragePoolMappingListResponse GetAzureSiteRecoveryStoragePoolMappings(
34+
string primaryServerId,
35+
string recoveryServerId)
36+
{
37+
return this.GetSiteRecoveryClient()
38+
.StoragePoolMappings
39+
.List(primaryServerId, recoveryServerId, this.GetRequestHeaders());
40+
}
41+
42+
/// <summary>
43+
/// Create Azure Site Recovery Storage pool mapping.
44+
/// </summary>
45+
/// <param name="primaryServerId">Primary server Id</param>
46+
/// <param name="primaryArrayId">Primary array Id</param>
47+
/// <param name="primaryStoragePoolId">Primary storage pool Id</param>
48+
/// <param name="recoveryServerId">Recovery server Id</param>
49+
/// <param name="recoveryArrayId">Recovery array Id</param>
50+
/// <param name="recoveryStoragePoolId">Recovery storage pool Id</param>
51+
/// <returns>Job response</returns>
52+
public JobResponse NewAzureSiteRecoveryStoragePoolMapping(
53+
string primaryServerId,
54+
string primaryArrayId,
55+
string primaryStoragePoolId,
56+
string recoveryServerId,
57+
string recoveryArrayId,
58+
string recoveryStoragePoolId)
59+
{
60+
StoragePoolMappingInput parameters = new StoragePoolMappingInput();
61+
parameters.PrimaryServerId = primaryServerId;
62+
parameters.PrimaryArrayId = primaryArrayId;
63+
parameters.PrimaryStoragePoolId = primaryStoragePoolId;
64+
parameters.RecoveryServerId = recoveryServerId;
65+
parameters.RecoveryArrayId = recoveryArrayId;
66+
parameters.RecoveryStoragePoolId = recoveryStoragePoolId;
67+
68+
return this.GetSiteRecoveryClient()
69+
.StoragePoolMappings
70+
.Create(parameters, this.GetRequestHeaders());
71+
}
72+
73+
/// <summary>
74+
/// Delete Azure Site Recovery Storage pool mapping.
75+
/// </summary>
76+
/// <param name="primaryServerId">Primary server Id</param>
77+
/// <param name="primaryArrayId">Primary array Id</param>
78+
/// <param name="primaryStoragePoolId">Primary storage pool Id</param>
79+
/// <param name="recoveryServerId">Recovery server Id</param>
80+
/// <param name="recoveryArrayId">Recovery array Id</param>
81+
/// <param name="recoveryStoragePoolId">Recovery storage pool Id</param>
82+
/// <returns>Job response</returns>
83+
public JobResponse RemoveAzureSiteRecoveryStoragePoolMapping(
84+
string primaryServerId,
85+
string primaryArrayId,
86+
string primaryStoragePoolId,
87+
string recoveryServerId,
88+
string recoveryArrayId,
89+
string recoveryStoragePoolId)
90+
{
91+
StoragePoolMappingInput parameters = new StoragePoolMappingInput();
92+
parameters.PrimaryServerId = primaryServerId;
93+
parameters.PrimaryArrayId = primaryArrayId;
94+
parameters.PrimaryStoragePoolId = primaryStoragePoolId;
95+
parameters.RecoveryServerId = recoveryServerId;
96+
parameters.RecoveryArrayId = recoveryArrayId;
97+
parameters.RecoveryStoragePoolId = recoveryStoragePoolId;
98+
99+
return this.GetSiteRecoveryClient()
100+
.StoragePoolMappings
101+
.Delete(parameters, this.GetRequestHeaders());
102+
}
103+
}
104+
}

0 commit comments

Comments
 (0)