Problem with NetworkingService regarding different version
Hi, I believe there is a problem with how the URL is created for the Networking Service - there is no way (I can see) to add the version to the URL, so the request always fails. for example - I use the in-package integration test "ListNetworkTest()" to try and get all of my networks. I get this: Flurl.Http.FlurlHttpException Request to http://<IP>:9696/networks failed with status code 404 (Not Found).
However, when I debug I can modify the URL that it gets (from the endpoint) to this: http://<IP>:9696/v2.0/networks and then the service is working and I can see the networks.
BTW, Compute service is working fine with no problems.
Is there a way to add the version to the request URL without changing the core code ? or is this a real bug\over-looked problem ?
Thanks.
Try this and let me know if it gets you unstuck. On my local openstack dev env, I always end up changing the service catalog to append /v2.0 to the Neutron endpoint to avoid this problem.
What this does is have the SDK retrieve and cache the service catalog, then use reflection to update the networking endpoint to add /v2.0. Then use the networking service as usual.
using System;
using System.Linq;
using net.openstack.Core.Domain;
using net.openstack.Core.Providers;
using OpenStack.Networking.v2;
using OpenStack.Synchronous;
namespace AppendVersionToNeutronEndpoint
{
class Program
{
static void Main(string[] args)
{
// 1. Authenticate and fill the service catalog cache
var region = "RegionOne";
var identityUrl = "http://example.com:5000/v2";
var user = new CloudIdentityWithProject
{
Username = "username",
Password = "password",
ProjectName = "project"
};
var identity = new OpenStackIdentityProvider(new Uri(identityUrl), user);
var userAccess = identity.Authenticate();
// 2. Update the cached networking endpoint
var networkingEndpoint = userAccess.ServiceCatalog.Single(svc => svc.Type == "network")
.Endpoints.Single(e => e.Region == "RegionOne");
networkingEndpoint.GetType().GetProperty("PublicURL")
.SetValue(networkingEndpoint, $"{networkingEndpoint.PublicURL}/v2.0");
// 3. Access the networking service using the updated endpoint
var networking = new NetworkingService(identity, "RegionOne");
var networks = networking.ListNetworks();
Console.WriteLine($"Found {networks.Count()} network(s)!");
Console.ReadLine();
}
}
}
This is working great, thanks! I'll follow to see how this will be fixed. Thanks again for the quick response.