Skip to content

Commit 75fafee

Browse files
committed
Merge pull request #11 from AsrOneSdk/sriramvu-dev
Validated Azure VM Network association with the subscription and fixed bugs
2 parents e33f51b + b6c1bee commit 75fafee

12 files changed

+92
-48
lines changed

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

Lines changed: 12 additions & 6 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>
@@ -67,6 +68,10 @@
6768
<Reference Include="Microsoft.WindowsAzure.Common.NetFramework">
6869
<HintPath>..\..\..\packages\Microsoft.WindowsAzure.Common.1.4.0\lib\net45\Microsoft.WindowsAzure.Common.NetFramework.dll</HintPath>
6970
</Reference>
71+
<Reference Include="Microsoft.WindowsAzure.Management.SiteRecovery, Version=0.9.0.0, Culture=neutral, PublicKeyToken=c66ce9294aae1300, processorArchitecture=MSIL">
72+
<SpecificVersion>False</SpecificVersion>
73+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.0.2.2-preview\lib\net40\Microsoft.WindowsAzure.Management.SiteRecovery.dll</HintPath>
74+
</Reference>
7075
<Reference Include="Microsoft.WindowsAzure.Testing, Version=1.0.5417.13285, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
7176
<SpecificVersion>False</SpecificVersion>
7277
<HintPath>..\..\..\packages\Hydra.SpecTestSupport.1.0.5417.13285-prerelease\lib\net45\Microsoft.WindowsAzure.Testing.dll</HintPath>
@@ -97,14 +102,14 @@
97102
<Reference Include="Microsoft.CSharp" />
98103
<Reference Include="System.Data" />
99104
<Reference Include="System.Xml" />
100-
<Reference Include="xunit.abstractions">
101-
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0-beta4-build2738\lib\net35\xunit.abstractions.dll</HintPath>
105+
<Reference Include="xunit.abstractions, Version=2.0.0.0, Culture=neutral, PublicKeyToken=8d05b1bb7a6fdb6c, processorArchitecture=MSIL">
106+
<HintPath>..\..\..\packages\xunit.abstractions.2.0.0-beta5-build2785\lib\net35\xunit.abstractions.dll</HintPath>
102107
</Reference>
103108
<Reference Include="xunit.assert">
104-
<HintPath>..\..\..\packages\xunit.assert.2.0.0-beta4-build2738\lib\portable-net45+win+wpa81+wp80+monoandroid+monotouch10\xunit.assert.dll</HintPath>
109+
<HintPath>..\..\..\packages\xunit.assert.2.0.0-beta5-build2785\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monoandroid+monotouch10\xunit.assert.dll</HintPath>
105110
</Reference>
106111
<Reference Include="xunit.core">
107-
<HintPath>..\..\..\packages\xunit.core.2.0.0-beta4-build2738\lib\portable-net45+win+wpa81+wp80+monotouch+monoandroid\xunit.core.dll</HintPath>
112+
<HintPath>..\..\..\packages\xunit.core.2.0.0-beta5-build2785\lib\portable-net45+aspnetcore50+win+wpa81+wp80+monotouch+monoandroid\xunit.core.dll</HintPath>
108113
</Reference>
109114
</ItemGroup>
110115
<ItemGroup>
@@ -151,7 +156,8 @@
151156
<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>
152157
</PropertyGroup>
153158
<Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" />
154-
<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'))" />
159+
<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'))" />
160+
<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'))" />
155161
</Target>
156162
<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')" />
157163
<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/Commands.RecoveryServices.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@
155155
<Compile Include="Service\GetAzureSiteRecoveryNetwork.cs" />
156156
<Compile Include="Service\CreateAzureSiteRecoveryRecoveryPlan.cs" />
157157
<Compile Include="Service\GetAzureSiteRecoveryRecoveryPlanFile.cs" />
158-
<Compile Include="Service\GetAzureSiteRecoveryVaultCredential.cs" />
158+
<Compile Include="Service\GetAzureSiteRecoveryVaultSettingsFile.cs" />
159159
<Compile Include="Service\RemoveAzureSiteRecoveryRecoveryPlan.cs" />
160160
<Compile Include="Service\GetAzureSiteRecoveryProtectionEntity.cs" />
161161
<Compile Include="Service\RestartAzureSiteRecoveryJob.cs" />

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();
@@ -296,16 +296,38 @@ public JobResponse NewAzureSiteRecoveryAzureNetworkMapping(
296296
/// <summary>
297297
/// Validates whether the Azure VM Network is associated with the subscription or not.
298298
/// </summary>
299-
/// <param name="subscriptionId">Subscription Id</param>
300-
/// <param name="azureNetworkId">Azure Network Id</param>
301-
public void ValidateVMNetworkSubscriptionAssociation(string subscriptionId, string azureNetworkId)
299+
/// <param name="azureSubscriptionId">Subscription Id</param>
300+
/// <param name="azureVMNetworkId">Azure VM Network Id</param>
301+
/// <param name="azureVMNetworkName">Azure VM Network name</param>
302+
public void ValidateVMNetworkSubscriptionAssociation(
303+
string azureSubscriptionId,
304+
string azureVMNetworkId,
305+
out string azureVMNetworkName)
302306
{
303-
/*
304-
NetworkManagementClient networkClient =
305-
AzureSession.ClientFactory.CreateClient<NetworkManagementClient>(AzureSession.CurrentContext.Subscription, AzureEnvironment.Endpoint.ServiceManagement);
306-
var response = this.networkClient.Networks.List();
307-
var sites = response.VirtualNetworkSites;
308-
*/
307+
bool associatedVMNetwork = false;
308+
azureVMNetworkName = string.Empty;
309+
310+
AzureNetworkListResponse azureNetworkListResponse =
311+
this.GetSiteRecoveryClient().Networks.ListAzureNetworks(azureSubscriptionId);
312+
313+
foreach (AzureNetworkListResponse.VirtualNetworkSite site in azureNetworkListResponse.VirtualNetworkSites)
314+
{
315+
if (azureVMNetworkId.Equals(site.Id))
316+
{
317+
associatedVMNetwork = true;
318+
azureVMNetworkName = site.Name;
319+
break;
320+
}
321+
}
322+
323+
if (!associatedVMNetwork)
324+
{
325+
throw new InvalidOperationException(
326+
string.Format(
327+
Properties.Resources.AzureVMNetworkIsNotAssociatedWithTheSubscription,
328+
azureVMNetworkId,
329+
azureSubscriptionId));
330+
}
309331
}
310332

311333
/// <summary>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ private async Task<string> GetChannelIntegrityKey()
157157
{
158158
// In case this condition is true that means the credential was first generated in portal
159159
// and hence can not be fetched here.
160-
throw new CloudException(Resources.VaultCredentialGenerationUnSupported);
160+
throw new CloudException(Resources.VaultSettingsGenerationUnSupported);
161161
}
162162
}
163163

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

Lines changed: 15 additions & 6 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: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,11 @@ ClientRequestId: {3}</value>
200200
<data name="ProtectionEntityAlreadyEnabled" xml:space="preserve">
201201
<value>Protection entity {0} is already enabled</value>
202202
</data>
203-
<data name="VaultCredentialGenerationUnSupported" xml:space="preserve">
204-
<value>Cannot generate vault credentials for this vault. Download it from the Azure Portal.</value>
203+
<data name="AzureVMNetworkIsNotAssociatedWithTheSubscription" xml:space="preserve">
204+
<value>AzureVMNetwork {0} is not associated with the Subscription {1}</value>
205+
</data>
206+
<data name="VaultSettingsGenerationUnSupported" xml:space="preserve">
207+
<value>Cannot generate vault settings file for this vault. Download it from the Azure Portal.</value>
205208
</data>
206209
<data name="StorageIsNotAssociatedWithTheAccount" xml:space="preserve">
207210
<value>Storage account {0} is not associated with the account</value>
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,9 @@ namespace Microsoft.Azure.Commands.RecoveryServices
2828
/// <summary>
2929
/// Retrieves Azure Site Recovery Server.
3030
/// </summary>
31-
[Cmdlet(VerbsCommon.Get, "AzureSiteRecoveryVaultCredential", DefaultParameterSetName = ASRParameterSets.ByObject)]
32-
[OutputType(typeof(VaultCredentialOutput))]
33-
public class GetVaultCredentialsFile : RecoveryServicesCmdletBase
31+
[Cmdlet(VerbsCommon.Get, "AzureSiteRecoveryVaultSettingsFile", DefaultParameterSetName = ASRParameterSets.ByObject)]
32+
[OutputType(typeof(VaultSettingsFilePath))]
33+
public class GetAzureSiteRecoveryVaultSettingsFile : RecoveryServicesCmdletBase
3434
{
3535
/// <summary>
3636
/// Expiry in hours for generated certificate.
@@ -158,7 +158,7 @@ private void GetByObject()
158158
string fileName = this.GenerateFileName();
159159

160160
// write the content to a file.
161-
VaultCredentialOutput output = new VaultCredentialOutput()
161+
VaultSettingsFilePath output = new VaultSettingsFilePath()
162162
{
163163
FilePath = Utilities.WriteToFile<ASRVaultCreds>(vaultCreds, filePath, fileName)
164164
};
@@ -174,14 +174,14 @@ private void GetByObject()
174174
private string GenerateFileName()
175175
{
176176
string fileName;
177-
177+
string format = "yyyy-MM-ddTHH-mm-ss";
178178
if (string.IsNullOrEmpty(this.Site.Name))
179179
{
180-
fileName = string.Format("{0}_{1}.VaultCredentials", this.Vault.Name, DateTime.UtcNow.ToLongDateString());
180+
fileName = string.Format("{0}_{1}.VaultCredentials", this.Vault.Name, DateTime.UtcNow.ToString(format));
181181
}
182182
else
183183
{
184-
fileName = string.Format("{0}_{1}_{2}.VaultCredentials", this.Site.Name, this.Vault.Name, DateTime.UtcNow.ToLongDateString());
184+
fileName = string.Format("{0}_{1}_{2}.VaultCredentials", this.Site.Name, this.Vault.Name, DateTime.UtcNow.ToString(format));
185185
}
186186

187187
return fileName;

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
PSRecoveryServicesClientHelper.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/lib/PSObjects.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1308,16 +1308,16 @@ public ASRServiceError(ServiceError serviceError)
13081308
}
13091309

13101310
/// <summary>
1311-
/// Class to define the output of the vault credential generation.
1311+
/// Class to define the output of the vault settings file generation.
13121312
/// </summary>
1313-
public class VaultCredentialOutput
1313+
public class VaultSettingsFilePath
13141314
{
13151315
#region Constructor
13161316

13171317
/// <summary>
1318-
/// Initializes a new instance of the <see cref="VaultCredentialOutput" /> class
1318+
/// Initializes a new instance of the <see cref="VaultSettingsFilePath" /> class
13191319
/// </summary>
1320-
public VaultCredentialOutput()
1320+
public VaultSettingsFilePath()
13211321
{
13221322
}
13231323

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.0-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)