Skip to content

Commit b648f93

Browse files
committed
Validating Azure VM network association with the Subscription
1 parent 4151dbc commit b648f93

File tree

7 files changed

+70
-29
lines changed

7 files changed

+70
-29
lines changed

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

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3-
<Import Project="..\..\..\packages\xunit.core.2.0.0-beta4-build2738\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props" Condition="Exists('..\..\..\packages\xunit.core.2.0.0-beta4-build2738\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props')" />
3+
<Import Project="..\..\..\packages\xunit.core.2.0.0-beta5-build2785\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props" Condition="Exists('..\..\..\packages\xunit.core.2.0.0-beta5-build2785\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props')" />
4+
<Import Project="..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props" Condition="Exists('..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props')" />
45
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
56
<PropertyGroup>
67
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
@@ -63,8 +64,9 @@
6364
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework">
6465
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
6566
</Reference>
66-
<Reference Include="Microsoft.WindowsAzure.Management.SiteRecovery">
67-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.0.1.0-preview\lib\net40\Microsoft.WindowsAzure.Management.SiteRecovery.dll</HintPath>
67+
<Reference Include="Microsoft.WindowsAzure.Management.SiteRecovery, Version=0.9.0.0, Culture=neutral, PublicKeyToken=c66ce9294aae1300, processorArchitecture=MSIL">
68+
<SpecificVersion>False</SpecificVersion>
69+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.0.2.2-preview\lib\net40\Microsoft.WindowsAzure.Management.SiteRecovery.dll</HintPath>
6870
</Reference>
6971
<Reference Include="Microsoft.WindowsAzure.Testing, Version=1.0.5417.13285, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7072
<SpecificVersion>False</SpecificVersion>
@@ -96,14 +98,14 @@
9698
<Reference Include="Microsoft.CSharp" />
9799
<Reference Include="System.Data" />
98100
<Reference Include="System.Xml" />
99-
<Reference Include="xunit.abstractions">
100-
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0-beta4-build2738\lib\net35\xunit.abstractions.dll</HintPath>
101+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
102+
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0-beta5-build2785\lib\net35\xunit.abstractions.dll</HintPath>
101103
</Reference>
102104
<Reference Include="xunit.assert">
103-
<HintPath>..\..\..\packages\xunit.assert.2.0.0-beta4-build2738\lib\portable-net45+win+wpa81+wp80+monoandroid+monotouch10\xunit.assert.dll</HintPath>
105+
<HintPath>..\..\..\packages\xunit.assert.2.0.0-beta5-build2785\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monoandroid+monotouch10\xunit.assert.dll</HintPath>
104106
</Reference>
105107
<Reference Include="xunit.core">
106-
<HintPath>..\..\..\packages\xunit.core.2.0.0-beta4-build2738\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.dll</HintPath>
108+
<HintPath>..\..\..\packages\xunit.core.2.0.0-beta5-build2785\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid\xunit.core.dll</HintPath>
107109
</Reference>
108110
</ItemGroup>
109111
<ItemGroup>
@@ -150,7 +152,8 @@
150152
<ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
151153
</PropertyGroup>
152154
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
153-
<Error Condition="!Exists('..\..\..\packages\xunit.core.2.0.0-beta4-build2738\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.core.2.0.0-beta4-build2738\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props'))" />
155+
<Error Condition="!Exists('..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.runner.visualstudio.0.99.9-build1021\build\net20\xunit.runner.visualstudio.props'))" />
156+
<Error Condition="!Exists('..\..\..\packages\xunit.core.2.0.0-beta5-build2785\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props')" Text="$([System.String]::Format('$(ErrorText)', '..\..\..\packages\xunit.core.2.0.0-beta5-build2785\build\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.props'))" />
154157
</Target>
155158
<Import Project="..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\..\..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
156159
<Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices.Test/packages.config

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<packages>
33
<package id="Hydra.HttpRecorder" version="1.0.5417.13285-prerelease" targetFramework="net45" />
44
<package id="Hydra.SpecTestSupport" version="1.0.5417.13285-prerelease" targetFramework="net45" />
5-
<package id="Microsoft.Azure.Management.RecoveryServices" version="0.1.0-preview" targetFramework="net45" />
5+
<package id="Microsoft.Azure.Management.RecoveryServices" version="0.2.2-preview" targetFramework="net45" />
66
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
77
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
88
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />
@@ -11,8 +11,9 @@
1111
<package id="Microsoft.WindowsAzure.Common" version="1.4.0" targetFramework="net45" />
1212
<package id="Microsoft.WindowsAzure.Common.Dependencies" version="1.1.0" targetFramework="net45" />
1313
<package id="Newtonsoft.Json" version="6.0.4" targetFramework="net45" />
14-
<package id="xunit" version="2.0.0-beta4-build2738" targetFramework="net45" />
15-
<package id="xunit.abstractions" version="2.0.0-beta4-build2738" targetFramework="net45" />
16-
<package id="xunit.assert" version="2.0.0-beta4-build2738" targetFramework="net45" />
17-
<package id="xunit.core" version="2.0.0-beta4-build2738" targetFramework="net45" />
14+
<package id="xunit" version="2.0.0-beta5-build2785" targetFramework="net45" />
15+
<package id="xunit.abstractions" version="2.0.0-beta5-build2785" targetFramework="net45" />
16+
<package id="xunit.assert" version="2.0.0-beta5-build2785" targetFramework="net45" />
17+
<package id="xunit.core" version="2.0.0-beta5-build2785" targetFramework="net45" />
18+
<package id="xunit.runner.visualstudio" version="0.99.9-build1021" targetFramework="net45" />
1819
</packages>

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

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -200,13 +200,13 @@ public class CreateAzureNetworkMappingInput
200200
/// Gets or sets Azure VM Network Id.
201201
/// </summary>
202202
[DataMember(Order = 3)]
203-
public string AzureVMNetworkId { get; set; }
203+
public string RecoveryNetworkId { get; set; }
204204

205205
/// <summary>
206206
/// Gets or sets Azure VM Network name.
207207
/// </summary>
208208
[DataMember(Order = 4)]
209-
public string AzureVMNetworkName { get; set; }
209+
public string RecoveryNetworkName { get; set; }
210210
}
211211

212212
/// <summary>
@@ -281,8 +281,8 @@ public JobResponse NewAzureSiteRecoveryAzureNetworkMapping(
281281
new CreateAzureNetworkMappingInput();
282282
createAzureNetworkMappingInput.PrimaryServerId = primaryServerId;
283283
createAzureNetworkMappingInput.PrimaryNetworkId = primaryNetworkId;
284-
createAzureNetworkMappingInput.AzureVMNetworkName = recoveryNetworkName;
285-
createAzureNetworkMappingInput.AzureVMNetworkId = recoveryNetworkId;
284+
createAzureNetworkMappingInput.RecoveryNetworkName = recoveryNetworkName;
285+
createAzureNetworkMappingInput.RecoveryNetworkId = recoveryNetworkId;
286286

287287
NetworkMappingInput networkMappingInput = new NetworkMappingInput();
288288
networkMappingInput.NetworkTargetType = NetworkTargetType.Azure.ToString();
@@ -325,16 +325,38 @@ public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
325325
/// <summary>
326326
/// Validates whether the Azure VM Network is associated with the subscription or not.
327327
/// </summary>
328-
/// <param name="subscriptionId">Subscription Id</param>
329-
/// <param name="azureNetworkId">Azure Network Id</param>
330-
public void ValidateVMNetworkSubscriptionAssociation(string subscriptionId, string azureNetworkId)
328+
/// <param name="azureSubscriptionId">Subscription Id</param>
329+
/// <param name="azureVMNetworkId">Azure VM Network Id</param>
330+
/// <param name="azureVMNetworkName">Azure VM Network name</param>
331+
public void ValidateVMNetworkSubscriptionAssociation(
332+
string azureSubscriptionId,
333+
string azureVMNetworkId,
334+
out string azureVMNetworkName)
331335
{
332-
/*
333-
NetworkManagementClient networkClient =
334-
AzureSession.ClientFactory.CreateClient<NetworkManagementClient>(AzureSession.CurrentContext.Subscription, AzureEnvironment.Endpoint.ServiceManagement);
335-
var response = this.networkClient.Networks.List();
336-
var sites = response.VirtualNetworkSites;
337-
*/
336+
bool associatedVMNetwork = false;
337+
azureVMNetworkName = string.Empty;
338+
339+
AzureNetworkListResponse azureNetworkListResponse =
340+
this.GetSiteRecoveryClient().Networks.ListAzureNetworks(azureSubscriptionId);
341+
342+
foreach (AzureNetworkListResponse.VirtualNetworkSite site in azureNetworkListResponse.VirtualNetworkSites)
343+
{
344+
if (azureVMNetworkId.Equals(site.Id))
345+
{
346+
associatedVMNetwork = true;
347+
azureVMNetworkName = site.Name;
348+
break;
349+
}
350+
}
351+
352+
if (!associatedVMNetwork)
353+
{
354+
throw new InvalidOperationException(
355+
string.Format(
356+
Properties.Resources.AzureVMNetworkIsNotAssociatedWithTheSubscription,
357+
azureVMNetworkId,
358+
azureSubscriptionId));
359+
}
338360
}
339361

340362
/// <summary>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.Designer.cs

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Properties/Resources.resx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,4 +200,7 @@ ClientRequestId: {3}</value>
200200
<data name="ProtectionEntityAlreadyEnabled" xml:space="preserve">
201201
<value>Protection entity {0} is already enabled</value>
202202
</data>
203+
<data name="AzureVMNetworkIsNotAssociatedWithTheSubscription" xml:space="preserve">
204+
<value>AzureVMNetwork {0} is not associated with the Subscription {1}</value>
205+
</data>
203206
</root>

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/Service/NewAzureSiteRecoveryNetworkMapping.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,12 @@ private void EnterpriseToAzureNetworkMapping()
113113
RecoveryServicesClient.ValidateSubscriptionAccountAssociation(this.AzureSubscriptionId);
114114

115115
// Check if the Azure VM Network is associated with the Subscription or not.
116-
RecoveryServicesClient.ValidateVMNetworkSubscriptionAssociation(this.AzureSubscriptionId, this.AzureVMNetworkId);
116+
string azureVMNetworkName;
117+
RecoveryServicesClient.ValidateVMNetworkSubscriptionAssociation(
118+
this.AzureSubscriptionId,
119+
this.AzureVMNetworkId,
120+
out azureVMNetworkName);
117121

118-
string azureVMNetworkName = string.Empty;
119122
this.jobResponse =
120123
RecoveryServicesClient
121124
.NewAzureSiteRecoveryAzureNetworkMapping(

src/ServiceManagement/RecoveryServices/Commands.RecoveryServices/packages.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<packages>
33
<package id="BuildTools.StyleCop" version="4.7.49.0" targetFramework="net45" />
4-
<package id="Microsoft.Azure.Management.RecoveryServices" version="0.1.1-preview" targetFramework="net45" />
4+
<package id="Microsoft.Azure.Management.RecoveryServices" version="0.2.2-preview" targetFramework="net45" />
55
<package id="Microsoft.Bcl" version="1.1.9" targetFramework="net45" />
66
<package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net45" />
77
<package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net45" />

0 commit comments

Comments
 (0)