Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Problem with NetworkingService regarding different version #640

Open
AdamSharon opened this issue Jan 10, 2017 · 2 comments
Open

Problem with NetworkingService regarding different version #640

AdamSharon opened this issue Jan 10, 2017 · 2 comments

Comments

@AdamSharon
Copy link

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://: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://: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.

@carolynvs
Copy link
Member

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();
        }
    }
}

@AdamSharon
Copy link
Author

This is working great, thanks!
I'll follow to see how this will be fixed.
Thanks again for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants