Adding support for listing networks

Added network service client
Fixed comments and typos.

Partially implements blueprint support-compute-api
Change-Id: I36fa7df2c4b707ec49250030caf9adc7f068484a
This commit is contained in:
Wayne Foley
2014-08-07 13:39:41 -07:00
parent ae3b0fbe19
commit 87dae39949
27 changed files with 1616 additions and 1 deletions

View File

@@ -0,0 +1,146 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Compute;
using OpenStack.Network;
namespace OpenStack.Test.Network
{
[TestClass]
public class NetworkPayloadConverterTests
{
internal string CreateNetworkJsonFixtrue(string id, string name, NetworkStatus status)
{
var NetworkJsonResponseFixture = @"{{
""status"": ""{2}"",
""subnets"": [
""d3839504-ec4c-47a4-b7c7-07af079a48bb""
],
""name"": ""{1}"",
""router:external"": false,
""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
""admin_state_up"": true,
""shared"": false,
""id"": ""{0}""
}}";
return string.Format(NetworkJsonResponseFixture, id, name, status);
}
[TestMethod]
public void CanParseValidNetworksJsonPayloadWithMultipleNetworks()
{
var validMultipleNetworkJsonFixture = @"{{ ""networks"": [ {0} ] }}";
var firstNetwork = CreateNetworkJsonFixtrue("12345", "MyNetwork", NetworkStatus.Active);
var secondNetwork = CreateNetworkJsonFixtrue("54321", "NetworkMy", NetworkStatus.Down);
var validMultipleNetworksJson = string.Format(validMultipleNetworkJsonFixture,
string.Join(",", new List<string>() { firstNetwork, secondNetwork }));
var converter = new NetworkPayloadConverter();
var networks = converter.ConvertNetworks(validMultipleNetworksJson).ToList();
Assert.AreEqual(2, networks.Count());
var ntw1 =
networks.First(o => string.Equals(o.Id, "12345", StringComparison.InvariantCultureIgnoreCase));
var ntw2 =
networks.First(o => string.Equals(o.Id, "54321", StringComparison.InvariantCultureIgnoreCase));
Assert.IsNotNull(ntw1);
Assert.IsNotNull(ntw2);
Assert.AreEqual("12345", ntw1.Id);
Assert.AreEqual("MyNetwork", ntw1.Name);
Assert.AreEqual(NetworkStatus.Active, ntw1.Status);
Assert.AreEqual("54321", ntw2.Id);
Assert.AreEqual("NetworkMy", ntw2.Name);
Assert.AreEqual(NetworkStatus.Down, ntw2.Status);
}
[TestMethod]
public void CanConvertValidNetworksJsonPayloadWithSingleNetwork()
{
var validMultipleNetworkJsonFixture = @"{{ ""networks"": [ {0} ] }}";
var firstNetwork = CreateNetworkJsonFixtrue("12345", "MyNetwork", NetworkStatus.Active);
var validMultipleNetworksJson = string.Format(validMultipleNetworkJsonFixture,
string.Join(",", new List<string>() { firstNetwork }));
var converter = new NetworkPayloadConverter();
var networks = converter.ConvertNetworks(validMultipleNetworksJson).ToList();
Assert.AreEqual(1, networks.Count());
var ntw1 =
networks.First(o => string.Equals(o.Id, "12345", StringComparison.InvariantCultureIgnoreCase));
Assert.IsNotNull(ntw1);
Assert.AreEqual("12345", ntw1.Id);
Assert.AreEqual("MyNetwork", ntw1.Name);
Assert.AreEqual(NetworkStatus.Active, ntw1.Status);
}
[TestMethod]
public void CanParseValidNetworksPayloadWithEmptyJsonArray()
{
var emptyJsonArray = @"{ ""networks"": [ ] }";
var converter = new NetworkPayloadConverter();
var networks = converter.ConvertNetworks(emptyJsonArray).ToList();
Assert.AreEqual(0, networks.Count());
}
[TestMethod]
public void CanParseAnEmptyNetworksPayload()
{
var payload = string.Empty;
var converter = new NetworkPayloadConverter();
var networks = converter.ConvertNetworks(payload).ToList();
Assert.AreEqual(0, networks.Count());
}
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void CannotParseANullNetworksPayload()
{
var converter = new NetworkPayloadConverter();
converter.ConvertNetworks(null);
}
[TestMethod]
[ExpectedException(typeof(FormatException))]
public void CannotParseInvalidNetworksJsonPayload()
{
var converter = new NetworkPayloadConverter();
converter.ConvertNetworks("[ { \"SomeAtrib\" }]");
}
[TestMethod]
[ExpectedException(typeof(FormatException))]
public void CannotParseInvalidNetworksPayload()
{
var converter = new NetworkPayloadConverter();
converter.ConvertNetworks("NOT JSON");
}
}
}

View File

@@ -0,0 +1,172 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Mime;
using System.Text;
using System.Threading;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenStack.Common;
using OpenStack.Common.Http;
using OpenStack.Network;
namespace OpenStack.Test.Network
{
public class NetworkRestSimulator : RestSimulator
{
internal ICollection<OpenStack.Network.Network> Networks { get; private set; }
public NetworkRestSimulator() : base()
{
this.Networks = new List<OpenStack.Network.Network>();
}
public NetworkRestSimulator(CancellationToken token)
: this()
{
}
protected override IHttpResponseAbstraction HandleGet()
{
if (this.Uri.Segments.Count() >= 4)
{
switch (this.Uri.Segments[3].TrimEnd('/').ToLower())
{
case "networks":
return HandleGetNetworks();
}
}
throw new NotImplementedException();
}
internal IHttpResponseAbstraction HandleGetNetworks()
{
Stream networkContent;
switch (this.Uri.Segments.Count())
{
case 4:
//no flavor id given, list all flavors
networkContent = TestHelper.CreateStream(GenerateNetworksPayload(this.Networks));
break;
default:
//Unknown Uri format
throw new NotImplementedException();
}
return TestHelper.CreateResponse(HttpStatusCode.OK, new Dictionary<string, string>(), networkContent);
}
protected override IHttpResponseAbstraction HandlePost()
{
throw new NotImplementedException();
}
protected override IHttpResponseAbstraction HandlePut()
{
throw new NotImplementedException();
}
protected override IHttpResponseAbstraction HandleDelete()
{
throw new NotImplementedException();
}
protected override IHttpResponseAbstraction HandleHead()
{
throw new NotImplementedException();
}
protected override IHttpResponseAbstraction HandleCopy()
{
throw new NotImplementedException();
}
private string GenerateNetworksPayload(IEnumerable<OpenStack.Network.Network> networks)
{
var payload = new StringBuilder();
payload.Append("{{ \"networks\": [");
var first = true;
foreach (var item in networks)
{
if (!first)
{
payload.Append(",");
}
payload.Append(GenerateNetworkPayload(item));
first = false;
}
payload.Append("] }");
return payload.ToString();
}
private string GenerateNetworkPayload(OpenStack.Network.Network network)
{
var payloadFixture = @"{{
""status"": ""{2}"",
""subnets"": [
""d3839504-ec4c-47a4-b7c7-07af079a48bb""
],
""name"": ""{0}"",
""router:external"": false,
""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
""admin_state_up"": true,
""shared"": false,
""id"": ""{1}""
}}";
return string.Format(payloadFixture, network.Name, network.Id, network.Status.ToString().ToUpper());
}
}
public class NetworkRestSimulatorFactory : IHttpAbstractionClientFactory
{
internal NetworkRestSimulator Simulator = null;
public NetworkRestSimulatorFactory(NetworkRestSimulator simulator)
{
this.Simulator = simulator;
}
public IHttpAbstractionClient Create()
{
throw new NotImplementedException();
}
public IHttpAbstractionClient Create(CancellationToken token)
{
if (this.Simulator != null)
{
this.Simulator.Headers.Clear();
}
return this.Simulator ?? new NetworkRestSimulator(token);
}
public IHttpAbstractionClient Create(TimeSpan timeout)
{
throw new NotImplementedException();
}
public IHttpAbstractionClient Create(TimeSpan timeout, CancellationToken token)
{
throw new NotImplementedException();
}
}
}

View File

@@ -0,0 +1,89 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
using OpenStack.Network;
namespace OpenStack.Test.Network
{
[TestClass]
public class NetworkServiceClientTests
{
internal TestNetworkServicePocoClient ServicePocoClient;
internal string authId = "12345";
internal string endpoint = "http://testcomputeendpoint.com/v2/1234567890";
internal ServiceLocator ServiceLocator;
[TestInitialize]
public void TestSetup()
{
this.ServicePocoClient = new TestNetworkServicePocoClient();
this.ServiceLocator = new ServiceLocator();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(INetworkServicePocoClientFactory), new TestNetworkServicePocoClientFactory(this.ServicePocoClient));
}
[TestCleanup]
public void TestCleanup()
{
this.ServicePocoClient = new TestNetworkServicePocoClient();
this.ServiceLocator = new ServiceLocator();
}
IOpenStackCredential GetValidCreds()
{
var catalog = new OpenStackServiceCatalog();
catalog.Add(new OpenStackServiceDefinition("Neutron", "Network Service",
new List<OpenStackServiceEndpoint>()
{
new OpenStackServiceEndpoint(endpoint, string.Empty, "some version", "some version info", "1,2,3")
}));
var creds = new OpenStackCredential(new Uri(this.endpoint), "SomeUser", "Password", "SomeTenant");
creds.SetAccessTokenId(this.authId);
creds.SetServiceCatalog(catalog);
return creds;
}
[TestMethod]
public async Task CanGetFlavors()
{
var ntw1 = new OpenStack.Network.Network("12345","MyNetwork", NetworkStatus.Active);
var ntw2 = new OpenStack.Network.Network("54321", "NetworkMy", NetworkStatus.Down);
var networks = new List<OpenStack.Network.Network>() { ntw1, ntw2 };
this.ServicePocoClient.GetNetworksDelegate = () => Task.Factory.StartNew(() => (IEnumerable<OpenStack.Network.Network>)networks);
var client = new NetworkServiceClient(GetValidCreds(), "Neutron", CancellationToken.None, this.ServiceLocator);
var resp = await client.GetNetworks();
Assert.IsNotNull(resp);
var respNetworks = resp.ToList();
Assert.AreEqual(2, respNetworks.Count());
Assert.AreEqual(ntw1, respNetworks[0]);
Assert.AreEqual(ntw2, respNetworks[1]);
}
}
}

View File

@@ -0,0 +1,146 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
using OpenStack.Network;
namespace OpenStack.Test.Network
{
[TestClass]
public class NetworkServicePocoClientTests
{
internal TestNetworkServiceRestClient NetworkServiceRestClient;
internal string authId = "12345";
internal Uri endpoint = new Uri("http://testnetworkendpoint.com/v2.0/1234567890");
internal IServiceLocator ServiceLocator;
[TestInitialize]
public void TestSetup()
{
this.NetworkServiceRestClient = new TestNetworkServiceRestClient();
this.ServiceLocator = new ServiceLocator();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(INetworkServiceRestClientFactory), new TestNetworkServiceRestClientFactory(this.NetworkServiceRestClient));
}
[TestCleanup]
public void TestCleanup()
{
this.NetworkServiceRestClient = new TestNetworkServiceRestClient();
this.ServiceLocator = new ServiceLocator();
}
ServiceClientContext GetValidContext()
{
var creds = new OpenStackCredential(this.endpoint, "SomeUser", "Password", "SomeTenant", "region-a.geo-1");
creds.SetAccessTokenId(this.authId);
return new ServiceClientContext(creds, CancellationToken.None, "Object Storage", endpoint);
}
#region Get Networks Tests
[TestMethod]
public async Task CanGetNetworksWithOkResponse()
{
var payload = @"{
""networks"": [
{
""status"": ""ACTIVE"",
""subnets"": [
""d3839504-ec4c-47a4-b7c7-07af079a48bb""
],
""name"": ""myNetwork"",
""router:external"": false,
""tenant_id"": ""ffe683d1060449d09dac0bf9d7a371cd"",
""admin_state_up"": true,
""shared"": false,
""id"": ""12345""
}
]
}";
var content = TestHelper.CreateStream(payload);
var restResp = new HttpResponseAbstraction(content, new HttpHeadersAbstraction(), HttpStatusCode.OK);
this.NetworkServiceRestClient.Responses.Enqueue(restResp);
var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
var result = await client.GetNetworks();
Assert.IsNotNull(result);
var networks = result.ToList();
Assert.AreEqual(1, networks.Count());
var network = networks.First();
Assert.AreEqual("myNetwork", network.Name);
Assert.AreEqual("12345", network.Id);
Assert.AreEqual(NetworkStatus.Active, network.Status);
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public async Task CannotGetNetworksWithNoContent()
{
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.NoContent);
this.NetworkServiceRestClient.Responses.Enqueue(restResp);
var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetNetworks();
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public async Task ExceptionthrownWhenGettingNetworksAndNotAuthed()
{
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.Unauthorized);
this.NetworkServiceRestClient.Responses.Enqueue(restResp);
var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetNetworks();
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public async Task ExceptionthrownWhenGettingNetworksAndServerError()
{
var restResp = new HttpResponseAbstraction(new MemoryStream(), new HttpHeadersAbstraction(), HttpStatusCode.InternalServerError);
this.NetworkServiceRestClient.Responses.Enqueue(restResp);
var client = new NetworkServicePocoClient(GetValidContext(), this.ServiceLocator);
await client.GetNetworks();
}
#endregion
}
}

View File

@@ -0,0 +1,116 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Newtonsoft.Json.Linq;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Compute;
using OpenStack.Identity;
using OpenStack.Network;
namespace OpenStack.Test.Network
{
[TestClass]
public class NetworkServiceRestClientTests
{
internal NetworkRestSimulator simulator;
internal string authId = "12345";
internal Uri endpoint = new Uri("http://testnetworkendpoint.com/v2/1234567890");
internal IServiceLocator ServiceLocator;
[TestInitialize]
public void TestSetup()
{
this.simulator = new NetworkRestSimulator();
this.ServiceLocator = new ServiceLocator();
var manager = this.ServiceLocator.Locate<IServiceLocationOverrideManager>();
manager.RegisterServiceInstance(typeof(IHttpAbstractionClientFactory), new NetworkRestSimulatorFactory(simulator));
}
[TestCleanup]
public void TestCleanup()
{
this.simulator = new NetworkRestSimulator();
this.ServiceLocator = new ServiceLocator();
}
ServiceClientContext GetValidContext()
{
return GetValidContext(CancellationToken.None);
}
ServiceClientContext GetValidContext(CancellationToken token)
{
var creds = new OpenStackCredential(this.endpoint, "SomeUser", "Password", "SomeTenant", "region-a.geo-1");
creds.SetAccessTokenId(this.authId);
return new ServiceClientContext(creds, token, "Nova", endpoint);
}
#region Get Networks Test
[TestMethod]
public async Task GetNetworksIncludesAuthHeader()
{
var client =
new NetworkServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetNetworks();
Assert.IsTrue(this.simulator.Headers.ContainsKey("X-Auth-Token"));
Assert.AreEqual(this.authId, this.simulator.Headers["X-Auth-Token"]);
}
[TestMethod]
public async Task GetNetworksFormsCorrectUrlAndMethod()
{
var client =
new NetworkServiceRestClient(GetValidContext(), this.ServiceLocator);
await client.GetNetworks();
Assert.AreEqual(string.Format("{0}/networks", endpoint), this.simulator.Uri.ToString());
Assert.AreEqual(HttpMethod.Get, this.simulator.Method);
}
[TestMethod]
public async Task CanGetNetworks()
{
this.simulator.Networks.Add(new OpenStack.Network.Network("12345","MyNetwork", NetworkStatus.Active));
var client =
new NetworkServiceRestClient(GetValidContext(), this.ServiceLocator);
var resp = await client.GetNetworks();
Assert.AreEqual(HttpStatusCode.OK, resp.StatusCode);
var respContent = TestHelper.GetStringFromStream(resp.Content);
Assert.IsTrue(respContent.Length > 0);
}
#endregion
}
}

View File

@@ -0,0 +1,50 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenStack.Common.ServiceLocation;
using OpenStack.Network;
namespace OpenStack.Test.Network
{
public class TestNetworkServicePocoClient : INetworkServicePocoClient
{
public Func<Task<IEnumerable<OpenStack.Network.Network>>> GetNetworksDelegate { get; set; }
public async Task<IEnumerable<OpenStack.Network.Network>> GetNetworks()
{
return await this.GetNetworksDelegate();
}
}
public class TestNetworkServicePocoClientFactory : INetworkServicePocoClientFactory
{
internal INetworkServicePocoClient client;
public TestNetworkServicePocoClientFactory(INetworkServicePocoClient client)
{
this.client = client;
}
public INetworkServicePocoClient Create(ServiceClientContext context, IServiceLocator serviceLocator)
{
return client;
}
}
}

View File

@@ -0,0 +1,54 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System.Collections.Generic;
using System.Threading.Tasks;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Network;
namespace OpenStack.Test.Network
{
public class TestNetworkServiceRestClient : INetworkServiceRestClient
{
public TestNetworkServiceRestClient()
{
this.Responses = new Queue<IHttpResponseAbstraction>();
}
public Queue<IHttpResponseAbstraction> Responses { get; set; }
public Task<IHttpResponseAbstraction> GetNetworks()
{
return Task.Factory.StartNew(() => Responses.Dequeue());
}
}
public class TestNetworkServiceRestClientFactory : INetworkServiceRestClientFactory
{
internal INetworkServiceRestClient Client;
public TestNetworkServiceRestClientFactory(INetworkServiceRestClient client)
{
this.Client = client;
}
public INetworkServiceRestClient Create(ServiceClientContext context, IServiceLocator serviceLocator)
{
return Client;
}
}
}

View File

@@ -82,6 +82,13 @@
<Compile Include="Identity\OpenStackServiceCatalogTests.cs" />
<Compile Include="Identity\IdentityServiceClientDefinitionTests.cs" />
<Compile Include="Identity\OpenStackRegionResolverTests.cs" />
<Compile Include="Network\NetworkServiceClientTests.cs" />
<Compile Include="Network\NetworkServicePocoClientTests.cs" />
<Compile Include="Network\NetworkPayloadConverterTests.cs" />
<Compile Include="Network\NetworkRestSimulator.cs" />
<Compile Include="Network\NetworkServiceRestClientTests.cs" />
<Compile Include="Network\TestNetworkServicePocoClient.cs" />
<Compile Include="Network\TestNetworkServiceRestClient.cs" />
<Compile Include="RestSimulator.cs" />
<Compile Include="ServiceLocation\ServiceLocationAssemblyScannerTests.cs" />
<Compile Include="ServiceLocation\ServiceLocatorTests.cs" />

View File

@@ -31,7 +31,7 @@ namespace OpenStack.Compute
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the StorageServiceClient class.
/// Creates a new instance of the ComputeServiceClient class.
/// </summary>
/// <param name="credentials">The credential to be used by this client.</param>
/// <param name="token">The cancellation token to be used by this client.</param>

View File

@@ -0,0 +1,40 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System.Collections.Generic;
namespace OpenStack.Network
{
/// <summary>
/// Converter that can be used to convert an HTTP payload into a Network Poco object.
/// </summary>
public interface INetworkPayloadConverter
{
/// <summary>
/// Converts an HTTP payload into a Network object.
/// </summary>
/// <param name="payload">The HTTP payload to convert. </param>
/// <returns>A Network object.</returns>
Network Convert(string payload);
/// <summary>
/// Converts an HTTP payload into a list of Network objects.
/// </summary>
/// <param name="payload">The HTTP payload to convert.</param>
/// <returns>An enumerable list of Network objects.</returns>
IEnumerable<Network> ConvertNetworks(string payload);
}
}

View File

@@ -0,0 +1,33 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System.Collections.Generic;
using System.Threading.Tasks;
namespace OpenStack.Network
{
/// <summary>
/// Client that can interact with an OpenStack network service.
/// </summary>
public interface INetworkServiceClient : IOpenStackServiceClient
{
/// <summary>
/// Gets a list of networks available on the remote OpenStack instance.
/// </summary>
/// <returns>An enumerable list of networks.</returns>
Task<IEnumerable<Network>> GetNetworks();
}
}

View File

@@ -0,0 +1,33 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System.Collections.Generic;
using System.Threading.Tasks;
namespace OpenStack.Network
{
/// <summary>
/// Client that can interact with an OpenStack network service.
/// </summary>
public interface INetworkServicePocoClient
{
/// <summary>
/// Gets a list of networks available on the remote OpenStack instance.
/// </summary>
/// <returns>An enumerable list of networks.</returns>
Task<IEnumerable<Network>> GetNetworks();
}
}

View File

@@ -0,0 +1,34 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
namespace OpenStack.Network
{
using OpenStack.Common.ServiceLocation;
/// <summary>
/// Constructs a client that can be used to interact with the POCO objects related to the OpenStack network service.
/// </summary>
public interface INetworkServicePocoClientFactory
{
/// <summary>
/// Creates a client that can be used to interact with the OpenStack network service.
/// </summary>
/// <param name="context">A service context to be used by the client.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
/// <returns>The client.</returns>
INetworkServicePocoClient Create(ServiceClientContext context, IServiceLocator serviceLocator);
}
}

View File

@@ -0,0 +1,33 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System.Threading.Tasks;
using OpenStack.Common.Http;
namespace OpenStack.Network
{
/// <summary>
/// Client that can connect to the REST endpoints of an OpenStack Network Service
/// </summary>
public interface INetworkServiceRestClient
{
/// <summary>
/// Gets a list of Networks from the remote OpenStack instance.
/// </summary>
/// <returns>An HTTP response from the remote server.</returns>
Task<IHttpResponseAbstraction> GetNetworks();
}
}

View File

@@ -0,0 +1,34 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
namespace OpenStack.Network
{
using OpenStack.Common.ServiceLocation;
/// <summary>
/// Factory for creating network service clients.
/// </summary>
public interface INetworkServiceRestClientFactory
{
/// <summary>
/// Constructs a client that can be used to connect to the REST endpoints of an OpenStack network service.
/// </summary>
/// <param name="context">A network service context to be used by the client.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
/// <returns>The client.</returns>
INetworkServiceRestClient Create(ServiceClientContext context, IServiceLocator serviceLocator);
}
}

View File

@@ -0,0 +1,52 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
namespace OpenStack.Network
{
/// <summary>
/// Represents a network on a remote OpenStack instance.
/// </summary>
public class Network
{
/// <summary>
/// Gets the name of the Network.
/// </summary>
public string Name { get; internal set; }
/// <summary>
/// Gets the id of the Network.
/// </summary>
public string Id { get; internal set; }
/// <summary>
/// Gets the status of the Network.
/// </summary>
public NetworkStatus Status { get; internal set; }
/// <summary>
/// Create a new instance of the ComputeItem class.
/// </summary>
/// <param name="id">The Id of the network.</param>
/// <param name="name">The name of the network.</param>
/// <param name="status">The status of the network.</param>
internal Network(string id, string name, NetworkStatus status)
{
this.Id = id;
this.Name = name;
this.Status = status;
}
}
}

View File

@@ -0,0 +1,123 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System.Collections.Generic;
using Newtonsoft.Json.Linq;
using OpenStack.Common;
using System.Linq;
namespace OpenStack.Network
{
using System;
/// <inheritdoc/>
internal class NetworkPayloadConverter : INetworkPayloadConverter
{
/// <inheritdoc/>
public Network Convert(string payload)
{
payload.AssertIsNotNullOrEmpty("payload", "A null or empty network payload cannot be converted.");
try
{
var token = JToken.Parse(payload);
return ConvertNetwork(token["network"]);
}
catch (FormatException)
{
throw;
}
catch (Exception ex)
{
throw new FormatException(
string.Format("Network payload could not be parsed. Payload: '{0}'", payload), ex);
}
}
/// <summary>
/// Converts a json token into a Network object.
/// </summary>
/// <param name="networkToken">The json Token to convert.</param>
/// <returns>A Network object.</returns>
internal Network ConvertNetwork(JToken networkToken)
{
var name = string.Empty;
var id = string.Empty;
var status = string.Empty;
try
{
name = (string)networkToken["name"];
id = (string)networkToken["id"];
status = (string) networkToken["status"];
if (string.IsNullOrEmpty(name) || string.IsNullOrEmpty(id) || string.IsNullOrEmpty(status))
{
throw new FormatException();
}
return new Network(id, name, status.GetNetworkStatus());
}
catch (Exception ex)
{
var msg = "Network payload could not be parsed.";
if (!string.IsNullOrEmpty(name) && networkToken != null)
{
msg = string.Format(
"Network '{0}' with Id '{1}' payload could not be parsed. Payload: '{2}'", name, id,
networkToken);
}
else if (networkToken != null)
{
msg = string.Format("Network payload could not be parsed. Payload: '{0}'", networkToken);
}
throw new FormatException(msg, ex);
}
}
/// <inheritdoc/>
public IEnumerable<Network> ConvertNetworks(string payload)
{
payload.AssertIsNotNull("payload", "A null networks payload cannot be converted.");
var networks = new List<Network>();
if (String.IsNullOrEmpty(payload))
{
return networks;
}
try
{
var payloadToken = JToken.Parse(payload);
var networksArray = payloadToken["networks"];
networks.AddRange(networksArray.Select(ConvertNetwork));
}
catch (FormatException)
{
throw;
}
catch (Exception ex)
{
throw new FormatException(
string.Format("Networks payload could not be parsed. Payload: '{0}'", payload), ex);
}
return networks;
}
}
}

View File

@@ -0,0 +1,65 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
using OpenStack.Common;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack.Network
{
/// <inheritdoc/>
internal class NetworkServiceClient : INetworkServiceClient
{
internal ServiceClientContext Context;
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the NetworkServiceClient class.
/// </summary>
/// <param name="credentials">The credential to be used by this client.</param>
/// <param name="token">The cancellation token to be used by this client.</param>
/// <param name="serviceName">The name of the service to be used by this client.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
public NetworkServiceClient(IOpenStackCredential credentials, string serviceName, CancellationToken token, IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a network service client with a null service locator.");
this.ServiceLocator = serviceLocator;
var endpoint = new Uri(credentials.ServiceCatalog.GetPublicEndpoint(serviceName, credentials.Region));
this.Context = new ServiceClientContext(credentials, token, serviceName, endpoint);
}
/// <inheritdoc/>
public async Task<IEnumerable<Network>> GetNetworks()
{
var client = this.GetPocoClient();
return await client.GetNetworks();
}
/// <summary>
/// Gets a client to interact with the remote OpenStack instance.
/// </summary>
/// <returns>A POCO client.</returns>
internal INetworkServicePocoClient GetPocoClient()
{
return this.ServiceLocator.Locate<INetworkServicePocoClientFactory>().Create(this.Context, this.ServiceLocator);
}
}
}

View File

@@ -0,0 +1,72 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using OpenStack.Common.ServiceLocation;
using OpenStack.Identity;
namespace OpenStack.Network
{
/// <inheritdoc/>
class NetworkServiceClientDefinition :IOpenStackServiceClientDefinition
{
internal const string DefaultServiceName = "Neutron";
/// <inheritdoc/>
public string Name { get; private set; }
/// <inheritdoc/>
public IOpenStackServiceClient Create(ICredential credential, string serviceName, CancellationToken cancellationToken,
IServiceLocator serviceLocator)
{
return new NetworkServiceClient((IOpenStackCredential)credential, GetServiceName(serviceName), cancellationToken, serviceLocator);
}
/// <inheritdoc/>
public IEnumerable<string> ListSupportedVersions()
{
return new List<string>() { "2.0", "2" };
}
/// <inheritdoc/>
public bool IsSupported(ICredential credential, string serviceName)
{
if (credential == null || credential.ServiceCatalog == null)
{
return false;
}
var catalog = credential.ServiceCatalog;
return
catalog.Any(
s =>
string.Equals(s.Name, GetServiceName(serviceName), StringComparison.OrdinalIgnoreCase));
}
/// <summary>
/// Gets the service name to use.
/// </summary>
/// <param name="serviceName">The given service name.</param>
/// <returns>The given service name if it is not empty or null, otherwise the default service name will be returned.</returns>
internal string GetServiceName(string serviceName)
{
return string.IsNullOrEmpty(serviceName) ? DefaultServiceName : serviceName;
}
}
}

View File

@@ -0,0 +1,71 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System;
using System.Collections.Generic;
using System.Net;
using System.Threading.Tasks;
using OpenStack.Common;
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Network
{
/// <inheritdoc/>
class NetworkServicePocoClient : INetworkServicePocoClient
{
internal ServiceClientContext _context;
internal IServiceLocator ServiceLocator;
/// <summary>
/// Creates a new instance of the ComputeServicePocoClient class.
/// </summary>
/// <param name="context">The compute service context to use for this client.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
internal NetworkServicePocoClient(ServiceClientContext context, IServiceLocator serviceLocator)
{
serviceLocator.AssertIsNotNull("serviceLocator", "Cannot create a network service poco client with a null service locator.");
this._context = context;
this.ServiceLocator = serviceLocator;
}
/// <inheritdoc/>
public async Task<IEnumerable<Network>> GetNetworks()
{
var client = this.GetRestClient();
var resp = await client.GetNetworks();
if (resp.StatusCode != HttpStatusCode.OK)
{
throw new InvalidOperationException(string.Format("Failed to get networks. The remote server returned the following status code: '{0}'.", resp.StatusCode));
}
var converter = this.ServiceLocator.Locate<INetworkPayloadConverter>();
var networks = converter.ConvertNetworks(await resp.ReadContentAsStringAsync());
return networks;
}
/// <summary>
/// Gets a client that can be used to connect to the REST endpoints of an OpenStack network service.
/// </summary>
/// <returns>The client.</returns>
internal INetworkServiceRestClient GetRestClient()
{
return this.ServiceLocator.Locate<INetworkServiceRestClientFactory>().Create(this._context, this.ServiceLocator);
}
}
}

View File

@@ -0,0 +1,30 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Network
{
/// <inheritdoc/>
internal class NetworkServicePocoClientFactory : INetworkServicePocoClientFactory
{
/// <inheritdoc/>
public INetworkServicePocoClient Create(ServiceClientContext context, IServiceLocator serviceLocator)
{
return new NetworkServicePocoClient(context, serviceLocator);
}
}
}

View File

@@ -0,0 +1,51 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using System.Net.Http;
using System.Threading.Tasks;
using OpenStack.Common;
using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Network
{
/// <inheritdoc/>
internal class NetworkServiceRestClient : OpenStackServiceRestClientBase, INetworkServiceRestClient
{
internal const string NetworksUrlMoniker = "networks";
internal const string NetworkVersionMoniker = "v2.0";
/// <summary>
/// Creates a new instance of the NetworkServiceRestClient class.
/// </summary>
/// <param name="context">The current service context to use.</param>
/// <param name="serviceLocator">A service locator to be used to locate/inject dependent services.</param>
internal NetworkServiceRestClient(ServiceClientContext context, IServiceLocator serviceLocator) : base(context, serviceLocator)
{
}
/// <inheritdoc/>
public async Task<IHttpResponseAbstraction> GetNetworks()
{
var client = this.GetHttpClient(this.Context);
client.Uri = CreateRequestUri(this.Context.PublicEndpoint, NetworkVersionMoniker, NetworksUrlMoniker);
client.Method = HttpMethod.Get;
return await client.SendAsync();
}
}
}

View File

@@ -0,0 +1,30 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using OpenStack.Common.ServiceLocation;
namespace OpenStack.Network
{
/// <inheritdoc/>
internal class NetworkServiceRestClientFactory : INetworkServiceRestClientFactory
{
/// <inheritdoc/>
public INetworkServiceRestClient Create(ServiceClientContext context, IServiceLocator serviceLocator)
{
return new NetworkServiceRestClient(context, serviceLocator);
}
}
}

View File

@@ -0,0 +1,67 @@
// /* ============================================================================
// Copyright 2014 Hewlett Packard
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
// ============================================================================ */
using OpenStack.Common;
namespace OpenStack.Network
{
/// <summary>
/// Represents the states that a Network can be in.
/// </summary>
public enum NetworkStatus
{
/// <summary>
/// The network is active and available.
/// </summary>
Active,
/// <summary>
/// The network is down and unavailable.
/// </summary>
Down,
/// <summary>
/// The network is in an unknown state.
/// </summary>
Unknown
}
/// <summary>
/// Static class for holding NetworkStatus related extention methods.
/// </summary>
public static class NetworkStatusExtentions
{
/// <summary>
/// Creates a NetworkStatus enum from a string.
/// </summary>
/// <param name="input">The input string.</param>
/// <returns>A NetworkStatus enum.</returns>
public static NetworkStatus GetNetworkStatus(this string input)
{
input.AssertIsNotNullOrEmpty("input", "Cannot get network status with null or empty value.");
switch (input.ToLowerInvariant())
{
case "active":
return NetworkStatus.Active;
case "down":
return NetworkStatus.Down;
default:
return NetworkStatus.Unknown;
}
}
}
}

View File

@@ -109,6 +109,21 @@
<Compile Include="IOpenStackServiceClient.cs" />
<Compile Include="IOpenStackServiceClientDefinition.cs" />
<Compile Include="IOpenStackServiceClientManager.cs" />
<Compile Include="Network\INetworkServiceClient.cs" />
<Compile Include="Network\INetworkServicePocoClient.cs" />
<Compile Include="Network\INetworkServicePocoClientFactory.cs" />
<Compile Include="Network\NetworkPayloadConverter.cs" />
<Compile Include="Network\INetworkPayloadConverter.cs" />
<Compile Include="Network\INetworkServiceRestClient.cs" />
<Compile Include="Network\INetworkServiceRestClientFactory.cs" />
<Compile Include="Network\Network.cs" />
<Compile Include="Network\NetworkServiceClient.cs" />
<Compile Include="Network\NetworkServiceClientDefinition.cs" />
<Compile Include="Network\NetworkServicePocoClient.cs" />
<Compile Include="Network\NetworkServicePocoClientFactory.cs" />
<Compile Include="Network\NetworkServiceRestClient.cs" />
<Compile Include="Network\NetworkServiceRestClientFactory.cs" />
<Compile Include="Network\NetworkStatus.cs" />
<Compile Include="OpenStackClient.cs" />
<Compile Include="OpenStackClientFactory.cs" />
<Compile Include="OpenStackClientManager.cs" />

View File

@@ -18,6 +18,7 @@ using OpenStack.Common.Http;
using OpenStack.Common.ServiceLocation;
using OpenStack.Compute;
using OpenStack.Identity;
using OpenStack.Network;
using OpenStack.Storage;
namespace OpenStack
@@ -42,6 +43,10 @@ namespace OpenStack
manager.RegisterServiceInstance(typeof(IComputeServicePocoClientFactory), new ComputeServicePocoClientFactory());
manager.RegisterServiceInstance(typeof(IComputeServiceRestClientFactory), new ComputeServiceRestClientFactory());
//Network related clients/services
manager.RegisterServiceInstance(typeof(INetworkServicePocoClientFactory), new NetworkServicePocoClientFactory());
manager.RegisterServiceInstance(typeof(INetworkServiceRestClientFactory), new NetworkServiceRestClientFactory());
//Identity related clients/services
manager.RegisterServiceInstance(typeof(IIdentityServicePocoClientFactory), new IdentityServicePocoClientFactory());
manager.RegisterServiceInstance(typeof(IIdentityServiceRestClientFactory), new IdentityServiceRestClientFactory());
@@ -57,6 +62,7 @@ namespace OpenStack
manager.RegisterServiceInstance(typeof(IOpenStackServiceDefinitionPayloadConverter), new OpenStackServiceDefinitionPayloadConverter(locator));
manager.RegisterServiceInstance(typeof(IOpenStackServiceEndpointPayloadConverter), new OpenStackServiceEndpointPayloadConverter());
manager.RegisterServiceInstance(typeof(IComputeFlavorPayloadConverter), new ComputeFlavorPayloadConverter());
manager.RegisterServiceInstance(typeof(INetworkPayloadConverter), new NetworkPayloadConverter());
manager.RegisterServiceInstance(typeof(IComputeImagePayloadConverter), new ComputeImagePayloadConverter());
manager.RegisterServiceInstance(typeof(IComputeItemMetadataPayloadConverter), new ComputeItemMetadataPayloadConverter());
@@ -70,6 +76,7 @@ namespace OpenStack
serviceManager.RegisterServiceClient<StorageServiceClient>(new StorageServiceClientDefinition());
serviceManager.RegisterServiceClient<IdentityServiceClient>(new IdentityServiceClientDefinition());
serviceManager.RegisterServiceClient<ComputeServiceClient>(new ComputeServiceClientDefinition());
serviceManager.RegisterServiceClient<NetworkServiceClient>(new NetworkServiceClientDefinition());
manager.RegisterServiceInstance(typeof(IOpenStackServiceClientManager), serviceManager);
}
}

View File

@@ -271,6 +271,51 @@
<Compile Include="..\OpenStack\IOpenStackServiceClientManager.cs">
<Link>IOpenStackServiceClientManager.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\INetworkPayloadConverter.cs">
<Link>Network\INetworkPayloadConverter.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\INetworkServiceClient.cs">
<Link>Network\INetworkServiceClient.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\INetworkServicePocoClient.cs">
<Link>Network\INetworkServicePocoClient.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\INetworkServicePocoClientFactory.cs">
<Link>Network\INetworkServicePocoClientFactory.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\INetworkServiceRestClient.cs">
<Link>Network\INetworkServiceRestClient.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\INetworkServiceRestClientFactory.cs">
<Link>Network\INetworkServiceRestClientFactory.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\Network.cs">
<Link>Network\Network.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\NetworkPayloadConverter.cs">
<Link>Network\NetworkPayloadConverter.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\NetworkServiceClient.cs">
<Link>Network\NetworkServiceClient.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\NetworkServiceClientDefinition.cs">
<Link>Network\NetworkServiceClientDefinition.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\NetworkServicePocoClient.cs">
<Link>Network\NetworkServicePocoClient.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\NetworkServicePocoClientFactory.cs">
<Link>Network\NetworkServicePocoClientFactory.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\NetworkServiceRestClient.cs">
<Link>Network\NetworkServiceRestClient.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\NetworkServiceRestClientFactory.cs">
<Link>Network\NetworkServiceRestClientFactory.cs</Link>
</Compile>
<Compile Include="..\OpenStack\Network\NetworkStatus.cs">
<Link>Network\NetworkStatus.cs</Link>
</Compile>
<Compile Include="..\OpenStack\OpenStackClient.cs">
<Link>OpenStackClient.cs</Link>
</Compile>