Skip to content

Commit 9ea53f8

Browse files
committed
Merge pull request #35 from alanquillin/AddListVirtualInterfacesToCloudServer
Add list virtual interfaces to cloud server
2 parents a120821 + f6de2bf commit 9ea53f8

11 files changed

Lines changed: 265 additions & 3 deletions

File tree

src/corelib/Core/Domain/Mapping/NetworkResponseJsonMapper.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
using System.Linq;
2-
using Newtonsoft.Json;
32
using Newtonsoft.Json.Linq;
43

54
namespace net.openstack.Core.Domain.Mapping
65
{
7-
public class NetworkResponseJsonMapper : IJsonObjectMapper<Network>
6+
internal class NetworkResponseJsonMapper : IJsonObjectMapper<Network>
87
{
98
public Network Map(JObject @from)
109
{

src/corelib/Core/Domain/Server.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,5 +263,34 @@ public bool Delete()
263263
{
264264
return Provider.DeleteServer(Id, Region);
265265
}
266+
267+
/// <summary>
268+
/// Lists the server's virtual interfaces.
269+
/// </summary>
270+
/// <returns>List of <see cref="VirtualInterface"/></returns>
271+
public IEnumerable<VirtualInterface> ListVirtualInterfaces()
272+
{
273+
return Provider.ListVirtualInterfaces(Id, Region);
274+
}
275+
276+
/// <summary>
277+
/// Creates a virtual interface for the specified network and attaches the network to the server
278+
/// </summary>
279+
/// <param name="networkId">The network ID</param>
280+
/// <returns>The newly created <see cref="VirtualInterface"/></returns>
281+
public VirtualInterface CreateVirtualInterface(string networkId)
282+
{
283+
return Provider.CreateVirtualInterface(Id, networkId, Region);
284+
}
285+
286+
/// <summary>
287+
/// Deletes the specified virtual interface from the server
288+
/// </summary>
289+
/// <param name="virtualInterfaceId">The virtual interface ID</param>
290+
/// <returns><c>bool</c> indicating if the action was successful</returns>
291+
public bool DeleteVirtualInterface(string virtualInterfaceId)
292+
{
293+
return Provider.DeleteVirtualInterface(Id, virtualInterfaceId, Region);
294+
}
266295
}
267296
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace net.openstack.Core.Domain
4+
{
5+
[DataContract]
6+
public class VirtualInterface
7+
{
8+
[DataMember(Name = "id")]
9+
public string Id { get; set; }
10+
11+
[DataMember(Name = "ip_addresses")]
12+
public VirtualInterfaceAddress[] Addresses { get; set; }
13+
14+
[DataMember(Name = "mac_address")]
15+
public string MACAddress { get; set; }
16+
}
17+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace net.openstack.Core.Domain
4+
{
5+
[DataContract]
6+
public class VirtualInterfaceAddress
7+
{
8+
[DataMember(Name = "address")]
9+
public string Address { get; set; }
10+
11+
[DataMember(Name = "network_id")]
12+
public string NetworkId { get; set; }
13+
14+
[DataMember(Name = "network_label")]
15+
public string NetworkLabel { get; set; }
16+
}
17+
}

src/corelib/Core/Providers/IComputeProvider.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,36 @@ public interface IComputeProvider
247247
/// <returns><c>bool</c> indicating if the action was successful</returns>
248248
bool DetachServerVolume(string serverId, string volumeId, string region = null, CloudIdentity identity = null);
249249

250+
/// <summary>
251+
/// Lists the virtual interfaces for the specified server.
252+
/// </summary>
253+
/// <param name="serverId">The server ID.</param>
254+
/// <param name="region">The region in which to execute this action.<remarks>If not specified, the user’s default region will be used.</remarks></param>
255+
/// <param name="identity">The users Cloud Identity <see cref="net.openstack.Core.Domain.CloudIdentity" /><remarks>If not specified, the default identity given in the constructor will be used.</remarks></param>
256+
/// <returns>List of <see cref="VirtualInterface"/></returns>
257+
IEnumerable<VirtualInterface> ListVirtualInterfaces(string serverId, string region = null, CloudIdentity identity = null);
258+
259+
/// <summary>
260+
/// Creates a virtual interface for the specified network and attaches the network to the specified server
261+
/// </summary>
262+
/// <param name="serverId">The server ID.</param>
263+
/// <param name="networkId">The network ID</param>
264+
/// <param name="region">The region in which to execute this action.<remarks>If not specified, the user’s default region will be used.</remarks></param>
265+
/// <param name="identity">The users Cloud Identity <see cref="net.openstack.Core.Domain.CloudIdentity" /><remarks>If not specified, the default identity given in the constructor will be used.</remarks></param>
266+
/// <returns>The newly created <see cref="VirtualInterface"/></returns>
267+
VirtualInterface CreateVirtualInterface(string serverId, string networkId, string region = null, CloudIdentity identity = null);
268+
269+
/// <summary>
270+
/// Deletes the specified virtual interface from the specified server
271+
/// </summary>
272+
/// <param name="serverId">The server ID.</param>
273+
/// <param name="virtualInterfaceId">The virtual interface ID</param>
274+
/// <param name="region">The region in which to execute this action.<remarks>If not specified, the user’s default region will be used.</remarks></param>
275+
/// <param name="identity">The users Cloud Identity <see cref="net.openstack.Core.Domain.CloudIdentity" /><remarks>If not specified, the default identity given in the constructor will be used.</remarks></param>
276+
/// <returns><c>bool</c> indicating if the action was successful</returns>
277+
bool DeleteVirtualInterface(string serverId, string virtualInterfaceId, string region = null, CloudIdentity identity = null);
278+
279+
250280
/// <summary>
251281
/// Lists all available flavors.
252282
/// </summary>

src/corelib/Providers/Rackspace/CloudServersProvider.cs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -489,6 +489,49 @@ public bool DetachServerVolume(string serverId, string volumeId, string region =
489489

490490
#endregion
491491

492+
#region Virtual Interfaces
493+
494+
/// <inheritdoc />
495+
public IEnumerable<VirtualInterface> ListVirtualInterfaces(string serverId, string region = null, CloudIdentity identity = null)
496+
{
497+
var urlPath = new Uri(string.Format("{0}/servers/{1}/os-virtual-interfacesv2", GetServiceEndpoint(identity, region), serverId));
498+
499+
var response = ExecuteRESTRequest<ListVirtualInterfacesResponse>(identity, urlPath, HttpMethod.GET);
500+
501+
if (response == null || response.Data == null)
502+
return null;
503+
504+
return response.Data.VirtualInterfaces;
505+
}
506+
507+
/// <inheritdoc />
508+
public VirtualInterface CreateVirtualInterface(string serverId, string networkId, string region = null, CloudIdentity identity = null)
509+
{
510+
var urlPath = new Uri(string.Format("{0}/servers/{1}/os-virtual-interfacesv2", GetServiceEndpoint(identity, region), serverId));
511+
512+
var request = new CreateVirtualInterfaceRequest(networkId);
513+
var response = ExecuteRESTRequest<ListVirtualInterfacesResponse>(identity, urlPath, HttpMethod.POST, request);
514+
515+
if (response == null || response.Data == null || response.Data.VirtualInterfaces == null)
516+
return null;
517+
518+
return response.Data.VirtualInterfaces.FirstOrDefault();
519+
}
520+
521+
/// <inheritdoc />
522+
public bool DeleteVirtualInterface(string serverId, string virtualInterfaceId, string region = null, CloudIdentity identity = null)
523+
{
524+
var urlPath = new Uri(string.Format("{0}/servers/{1}/os-virtual-interfacesv2/{2}", GetServiceEndpoint(identity, region), serverId, virtualInterfaceId));
525+
526+
var response = ExecuteRESTRequest(identity, urlPath, HttpMethod.DELETE);
527+
528+
if (response == null || !_validServerActionResponseCode.Contains(response.StatusCode))
529+
return false;
530+
531+
return true;
532+
}
533+
#endregion
534+
492535
#region Flavors
493536

494537
/// <inheritdoc />
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Runtime.Serialization;
2+
3+
namespace net.openstack.Providers.Rackspace.Objects.Request
4+
{
5+
[DataContract]
6+
internal class CreateVirtualInterfaceRequest
7+
{
8+
[DataMember(Name = "virtual_interface")]
9+
public CreateVirtualInterface VirtualInterface { get; set; }
10+
11+
public CreateVirtualInterfaceRequest(string networkId)
12+
{
13+
VirtualInterface = new CreateVirtualInterface {NetworkId = networkId};
14+
}
15+
}
16+
17+
[DataContract]
18+
internal class CreateVirtualInterface
19+
{
20+
[DataMember(Name = "network_id")]
21+
public string NetworkId { get; set; }
22+
}
23+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
using System.Collections.Generic;
2+
using System.Runtime.Serialization;
3+
using net.openstack.Core.Domain;
4+
5+
namespace net.openstack.Providers.Rackspace.Objects.Response
6+
{
7+
[DataContract]
8+
internal class ListVirtualInterfacesResponse
9+
{
10+
[DataMember(Name = "virtual_interfaces")]
11+
public IEnumerable<VirtualInterface> VirtualInterfaces { get; set; }
12+
}
13+
}

src/corelib/corelib.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@
5555
<Compile Include="Core\Domain\SimpleServer.cs" />
5656
<Compile Include="Core\Domain\SimpleServerImage.cs" />
5757
<Compile Include="Core\Domain\Snapshot.cs" />
58+
<Compile Include="Core\Domain\VirtualInterface.cs" />
59+
<Compile Include="Core\Domain\VirtualInterfaceAddress.cs" />
5860
<Compile Include="Core\Domain\Volume.cs" />
5961
<Compile Include="Core\Domain\VolumeState.cs" />
6062
<Compile Include="Core\Domain\VolumeType.cs" />
@@ -114,7 +116,9 @@
114116
<Compile Include="Providers\Rackspace\Objects\BulkDeletionResults.cs" />
115117
<Compile Include="Providers\Rackspace\Objects\Domain.cs" />
116118
<Compile Include="Providers\Rackspace\Objects\Mapping\BulkDeletionResultMapper.cs" />
119+
<Compile Include="Providers\Rackspace\Objects\Request\CreateVirtualInterfaceRequest.cs" />
117120
<Compile Include="Providers\Rackspace\Objects\Response\BulkDeleteResponse.cs" />
121+
<Compile Include="Providers\Rackspace\Objects\Response\ListVirtualInterfacesResponse.cs" />
118122
<Compile Include="Providers\Rackspace\Validators\CloudFilesValidator.cs" />
119123
<Compile Include="Core\Validators\IObjectStorageValidator.cs" />
120124
<Compile Include="Providers\Rackspace\EncodeDecodeProvider.cs" />

src/testing/integration/Providers/Rackspace/CloudServersFull.orderedtest

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@
8888
<TestLink id="748ace8e-6714-1f5a-1beb-a9232cabbd42" name="Should_Wait_For_Server_To_Go_Into_Rescue_Status" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
8989
<TestLink id="b1d4a2c8-8fcc-e960-a79f-c5235e0636f1" name="Should_Mark_Server_To_Be_UnRescued" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
9090
<TestLink id="3a073400-759d-e00f-d524-284a7abed727" name="Should_Wait_For_Server_To_Go_Into_Active_Status_After_UnRescue" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
91+
<TestLink id="1b737c2f-48ba-e843-dae4-8b2a37607268" name="Should_Get_List_Of_Virtual_Interfaces" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
92+
<TestLink id="1dca0df7-7f76-28cd-e9ab-9554323dfa06" name="Should_Creat_Virtual_Interface_For_Test_Network" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
93+
<TestLink id="733baef1-f070-7d28-d2f4-c69bff9ec49c" name="Should_Get_List_Of_Virtual_Interfaces_Including_New_Virtual_Interface" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
94+
<TestLink id="df91b55e-8119-89fc-cc94-52ba442cd6d6" name="Should_Delete_New_Virtual_Interface_For_Test_Network" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
95+
<TestLink id="da020aec-a2ac-493f-41ad-dbaa35ec286b" name="Should_Get_List_Of_Virtual_Interfaces_Without_New_Virtual_Interface" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
9196
<TestLink id="eac8bd06-0fa5-04f7-9066-6b31826dcebb" name="Should_Attach_Server_Volume" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
9297
<TestLink id="e3fd1342-cc82-9b97-ec4f-8cfd3f5021be" name="Should_Wait_Until_Volume_Is_Attached_To_The_Server" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
9398
<TestLink id="7c84c3af-8bdd-6f74-6c5f-afc6d415a99b" name="Should_List_All_Volumes" storage="..\..\bin\debug\openstacknet.testing.integration.dll" type="Microsoft.VisualStudio.TestTools.TestTypes.Unit.UnitTestElement, Microsoft.VisualStudio.QualityTools.Tips.UnitTest.ObjectModel, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />

0 commit comments

Comments
 (0)