Skip to content

Commit 1c98d6c

Browse files
committed
Merge pull request #1 from AsrOneSdk/sriramvu-dev
Network and Storage operations (E2E, E2A)
2 parents 0a5ea1c + 325b10e commit 1c98d6c

20 files changed

+1454
-10
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,8 @@ private SiteRecoveryManagementClient GetSiteRecoveryManagementClient()
132132
return new SiteRecoveryManagementClient(
133133
asrVaultCreds.CloudServiceName,
134134
asrVaultCreds.ResourceName,
135-
(SubscriptionCloudCredentials)environment.Credentials,
136-
AzureSession.CurrentContext.Environment.GetEndpointAsUri(AzureEnvironment.Endpoint.ServiceManagement)).WithHandler(HttpMockServer.CreateInstance());
135+
RecoveryServicesMgmtClient.Credentials,
136+
RecoveryServicesMgmtClient.BaseUri).WithHandler(HttpMockServer.CreateInstance());
137137
}
138138

139139
private static bool IgnoreCertificateErrorHandler

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
</Reference>
6666
<Reference Include="Microsoft.WindowsAzure.Management.SiteRecovery, Version=0.9.0.0, Culture=neutral, PublicKeyToken=c66ce9294aae1300, processorArchitecture=MSIL">
6767
<SpecificVersion>False</SpecificVersion>
68-
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.0.1.1-preview\lib\net40\Microsoft.WindowsAzure.Management.SiteRecovery.dll</HintPath>
68+
<HintPath>..\..\..\packages\Microsoft.Azure.Management.RecoveryServices.0.2.2-preview\lib\net40\Microsoft.WindowsAzure.Management.SiteRecovery.dll</HintPath>
6969
</Reference>
7070
<Reference Include="Newtonsoft.Json, Version=6.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
7171
<SpecificVersion>False</SpecificVersion>
@@ -97,6 +97,8 @@
9797
<Reference Include="System.Xml" />
9898
</ItemGroup>
9999
<ItemGroup>
100+
<Compile Include="lib\PSStorageObjects.cs" />
101+
<Compile Include="lib\PSNetworkObjects.cs" />
100102
<Compile Include="lib\PSContracts.cs" />
101103
<Compile Include="lib\PSObjects.cs" />
102104
<Compile Include="lib\PSParameterSets.cs" />
@@ -106,6 +108,10 @@
106108
<DesignTime>True</DesignTime>
107109
<DependentUpon>Resources.resx</DependentUpon>
108110
</Compile>
111+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageClient.cs" />
112+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesStorageMappingClient.cs" />
113+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkMappingClient.cs" />
114+
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesNetworkClient.cs" />
109115
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMGroupClient.cs" />
110116
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesPEClient.cs" />
111117
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesClient.cs">
@@ -118,6 +124,14 @@
118124
<Compile Include="PSRecoveryServicesClient\PSRecoveryServicesVMClient.cs" />
119125
<Compile Include="RecoveryServicesCmdletBase.cs" />
120126
<Compile Include="Properties\AssemblyInfo.cs" />
127+
<Compile Include="Service\GetAzureSiteRecoveryStorage.cs" />
128+
<Compile Include="Service\GetAzureSiteRecoveryStorageMapping.cs" />
129+
<Compile Include="Service\NewAzureSiteRecoveryStorageMapping.cs" />
130+
<Compile Include="Service\RemoveAzureSiteRecoveryStorageMapping.cs" />
131+
<Compile Include="Service\RemoveAzureSiteRecoveryNetworkMapping.cs" />
132+
<Compile Include="Service\NewAzureSiteRecoveryNetworkMapping.cs" />
133+
<Compile Include="Service\GetAzureSiteRecoveryNetworkMapping.cs" />
134+
<Compile Include="Service\GetAzureSiteRecoveryNetwork.cs" />
121135
<Compile Include="Service\CreateAzureSiteRecoveryRecoveryPlan.cs" />
122136
<Compile Include="Service\GetAzureSiteRecoveryRecoveryPlanFile.cs" />
123137
<Compile Include="Service\RemoveAzureSiteRecoveryRecoveryPlan.cs" />
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 Networks.
29+
/// </summary>
30+
/// <param name="serverId">Server ID</param>
31+
/// <returns>Network list response</returns>
32+
public NetworkListResponse GetAzureSiteRecoveryNetworks(string serverId)
33+
{
34+
return this.GetSiteRecoveryClient().Networks.List(serverId, this.GetRequestHeaders());
35+
}
36+
}
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,295 @@
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 System.IO;
17+
using System.Runtime.Serialization;
18+
using System.Xml;
19+
using Microsoft.WindowsAzure;
20+
using Microsoft.WindowsAzure.Management.SiteRecovery;
21+
// using Microsoft.WindowsAzure.Management.
22+
using Microsoft.WindowsAzure.Management.SiteRecovery.Models;
23+
using Microsoft.WindowsAzure.Commands.Common.Models;
24+
using Microsoft.WindowsAzure.Commands.Common;
25+
using System.Collections.Generic;
26+
27+
namespace Microsoft.Azure.Commands.RecoveryServices
28+
{
29+
/// <summary>
30+
/// Target network type.
31+
/// </summary>
32+
public enum TargetNetworkType
33+
{
34+
/// <summary>
35+
/// Server.
36+
/// </summary>
37+
Server = 0,
38+
39+
/// <summary>
40+
/// Azure.
41+
/// </summary>
42+
Azure,
43+
}
44+
45+
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
46+
public class CreateNetworkMappingInput
47+
{
48+
[DataMember(Order = 1)]
49+
public string PrimaryServerId { get; set; }
50+
51+
[DataMember(Order = 2)]
52+
public string PrimaryNetworkId { get; set; }
53+
54+
[DataMember(Order = 3)]
55+
public string RecoveryServerId { get; set; }
56+
57+
[DataMember(Order = 4)]
58+
public string RecoveryNetworkId { get; set; }
59+
}
60+
61+
[DataContract(Namespace = "http://schemas.microsoft.com/windowsazure")]
62+
public class CreateAzureNetworkMappingInput
63+
{
64+
[DataMember(Order = 1)]
65+
public string PrimaryServerId { get; set; }
66+
67+
[DataMember(Order = 2)]
68+
public string PrimaryNetworkId { get; set; }
69+
70+
[DataMember(Order = 3)]
71+
public string AzureVMNetworkId { get; set; }
72+
73+
[DataMember(Order = 4)]
74+
public string AzureVMNetworkName { get; set; }
75+
}
76+
77+
/// <summary>
78+
/// Recovery services convenience client.
79+
/// </summary>
80+
public partial class PSRecoveryServicesClient
81+
{
82+
/// <summary>
83+
/// Gets Azure Site Recovery Network mappings.
84+
/// </summary>
85+
/// <param name="primaryServerId">Primary server ID</param>
86+
/// <param name="recoveryServerId">Recovery server ID</param>
87+
/// <returns>Network mapping list response</returns>
88+
public NetworkMappingListResponse GetAzureSiteRecoveryNetworkMappings(
89+
string primaryServerId,
90+
string recoveryServerId)
91+
{
92+
return this.GetSiteRecoveryClient()
93+
.NetworkMappings
94+
.List(primaryServerId, recoveryServerId, this.GetRequestHeaders());
95+
}
96+
97+
/// <summary>
98+
/// Create Azure Site Recovery Network Mapping.
99+
/// </summary>
100+
/// <param name="primaryServerId">Primary server Id</param>
101+
/// <param name="primaryNetworkId">Primary network Id</param>
102+
/// <param name="recoveryServerId">Recovery server Id</param>
103+
/// <param name="recoveryNetworkId">Recovery network Id</param>
104+
/// <returns>Job response</returns>
105+
public JobResponse NewAzureSiteRecoveryNetworkMapping(
106+
string primaryServerId,
107+
string primaryNetworkId,
108+
string recoveryServerId,
109+
string recoveryNetworkId)
110+
{
111+
CreateNetworkMappingInput createNetworkMappingInput =
112+
new CreateNetworkMappingInput();
113+
createNetworkMappingInput.PrimaryServerId = primaryServerId;
114+
createNetworkMappingInput.PrimaryNetworkId = primaryNetworkId;
115+
createNetworkMappingInput.RecoveryServerId = recoveryServerId;
116+
createNetworkMappingInput.RecoveryNetworkId = recoveryNetworkId;
117+
118+
NetworkMappingInput networkMappingInput = new NetworkMappingInput();
119+
networkMappingInput.TargetNetworkType = TargetNetworkType.Server.ToString();
120+
networkMappingInput.CreateNetworkMappingInput =
121+
DataContractUtils.Serialize<CreateNetworkMappingInput>(createNetworkMappingInput);
122+
return this.GetSiteRecoveryClient()
123+
.NetworkMappings
124+
.Create(networkMappingInput, this.GetRequestHeaders());
125+
}
126+
127+
/// <summary>
128+
/// Create Azure Site Recovery Azure Network Mapping.
129+
/// </summary>
130+
/// <param name="primaryServerId">Primary server Id</param>
131+
/// <param name="primaryNetworkId">Primary network Id</param>
132+
/// <param name="recoveryNetworkName">Recovery server Id</param>
133+
/// <param name="recoveryNetworkId">Recovery network Id</param>
134+
/// <returns>Job response</returns>
135+
public JobResponse NewAzureSiteRecoveryAzureNetworkMapping(
136+
string primaryServerId,
137+
string primaryNetworkId,
138+
string recoveryNetworkName,
139+
string recoveryNetworkId)
140+
{
141+
CreateAzureNetworkMappingInput createAzureNetworkMappingInput =
142+
new CreateAzureNetworkMappingInput();
143+
createAzureNetworkMappingInput.PrimaryServerId = primaryServerId;
144+
createAzureNetworkMappingInput.PrimaryNetworkId = primaryNetworkId;
145+
createAzureNetworkMappingInput.AzureVMNetworkName = recoveryNetworkName;
146+
createAzureNetworkMappingInput.AzureVMNetworkId = recoveryNetworkId;
147+
148+
NetworkMappingInput networkMappingInput = new NetworkMappingInput();
149+
networkMappingInput.TargetNetworkType = TargetNetworkType.Azure.ToString();
150+
networkMappingInput.CreateNetworkMappingInput =
151+
DataContractUtils.Serialize<CreateAzureNetworkMappingInput>(createAzureNetworkMappingInput);
152+
return this.GetSiteRecoveryClient()
153+
.NetworkMappings
154+
.Create(networkMappingInput, this.GetRequestHeaders());
155+
}
156+
157+
public void ValidateSubscriptionAccountAssociation(string azureSubscriptionId)
158+
{
159+
bool associatedSubscription = false;
160+
ProfileClient pc = new ProfileClient();
161+
List<AzureSubscription> subscriptions =
162+
pc.RefreshSubscriptions(AzureSession.CurrentContext.Environment);
163+
164+
foreach (AzureSubscription sub in subscriptions)
165+
{
166+
if (azureSubscriptionId.Equals(sub.Id.ToString(), StringComparison.OrdinalIgnoreCase))
167+
{
168+
associatedSubscription = true;
169+
break;
170+
}
171+
}
172+
173+
if (!associatedSubscription)
174+
{
175+
throw new InvalidOperationException(
176+
string.Format(
177+
Properties.Resources.SubscriptionIsNotAssociatedWithTheAccount,
178+
azureSubscriptionId));
179+
}
180+
}
181+
182+
public void ValidateVMNetworkSubscriptionAssociation(string subscriptionId, string azureNetworkId)
183+
{
184+
/*
185+
NetworkManagementClient networkClient =
186+
AzureSession.ClientFactory.CreateClient<NetworkManagementClient>(AzureSession.CurrentContext.Subscription, AzureEnvironment.Endpoint.ServiceManagement);
187+
var response = this.networkClient.Networks.List();
188+
var sites = response.VirtualNetworkSites;
189+
*/
190+
}
191+
/// <summary>
192+
/// Delete Azure Site Recovery Network Mapping.
193+
/// </summary>
194+
/// <param name="primaryServerId">Primary server Id</param>
195+
/// <param name="primaryNetworkId">Primary network Id</param>
196+
/// <param name="recoveryServerId">Recovery server Id</param>
197+
/// <returns>Job response</returns>
198+
public JobResponse RemoveAzureSiteRecoveryNetworkMapping(
199+
string primaryServerId,
200+
string primaryNetworkId,
201+
string recoveryServerId)
202+
{
203+
NetworkUnMappingInput networkUnMappingInput = new NetworkUnMappingInput();
204+
networkUnMappingInput.PrimaryServerId = primaryServerId;
205+
networkUnMappingInput.PrimaryNetworkId = primaryNetworkId;
206+
networkUnMappingInput.RecoveryServerId = recoveryServerId;
207+
208+
return this.GetSiteRecoveryClient()
209+
.NetworkMappings
210+
.Delete(networkUnMappingInput, this.GetRequestHeaders());
211+
}
212+
}
213+
214+
/// <summary>
215+
/// Helper around serialization/deserialization of objects. This one is a thin wrapper around
216+
/// DataContractUtils<T> which is the one doing the heavy lifting.
217+
/// </summary>
218+
public static class DataContractUtils
219+
{
220+
/// <summary>
221+
/// Serializes the supplied object to the string.
222+
/// </summary>
223+
/// <typeparam name="T">The object type.</typeparam>
224+
/// <param name="The object to serialize."></param>
225+
/// <returns>Serialized string.</returns>
226+
public static string Serialize<T>(T obj)
227+
{
228+
return DataContractUtils<T>.Serialize(obj);
229+
}
230+
231+
/// <summary>
232+
/// Deserialize the string to the expected object type.
233+
/// </summary>
234+
/// <param name="xmlString">Serialized string.</param>
235+
/// <param name="result">Deserialized object.</param>
236+
public static void Deserialize<T>(string xmlString, out T result)
237+
{
238+
result = DataContractUtils<T>.Deserialize(xmlString);
239+
}
240+
}
241+
242+
public static class DataContractUtils<T>
243+
{
244+
/// <summary>
245+
/// Serializes the propertyBagContainer to the string.
246+
/// </summary>
247+
/// <param name="propertyBagContainer"></param>
248+
/// <returns></returns>
249+
public static string Serialize(T propertyBagContainer)
250+
{
251+
var serializer = new DataContractSerializer(typeof(T));
252+
string xmlString;
253+
StringWriter sw = null;
254+
try
255+
{
256+
sw = new StringWriter();
257+
using (var writer = new XmlTextWriter(sw))
258+
{
259+
// Indent the XML so it's human readable.
260+
writer.Formatting = Formatting.Indented;
261+
serializer.WriteObject(writer, propertyBagContainer);
262+
writer.Flush();
263+
xmlString = sw.ToString();
264+
}
265+
}
266+
finally
267+
{
268+
if (sw != null)
269+
sw.Close();
270+
}
271+
272+
return xmlString;
273+
}
274+
275+
/// <summary>
276+
/// Deserialize the string to the propertyBagContainer.
277+
/// </summary>
278+
/// <param name="xmlString"></param>
279+
/// <returns></returns>
280+
public static T Deserialize(string xmlString)
281+
{
282+
T propertyBagContainer;
283+
using (Stream stream = new MemoryStream())
284+
{
285+
byte[] data = System.Text.Encoding.UTF8.GetBytes(xmlString);
286+
stream.Write(data, 0, data.Length);
287+
stream.Position = 0;
288+
DataContractSerializer deserializer = new DataContractSerializer(typeof(T));
289+
propertyBagContainer = (T)deserializer.ReadObject(stream);
290+
}
291+
292+
return propertyBagContainer;
293+
}
294+
}
295+
}

0 commit comments

Comments
 (0)