2016-08-29 79 views
0

您好大家看這篇文章,OpenStack的授權

我想列出從OpenStack的所有圖像在C#下面的代碼:

using System; 
using Microsoft.VisualStudio.TestTools.UnitTesting; 
using net.openstack.Providers.Rackspace; 
using net.openstack.Core.Domain; 
using net.openstack.Core.Providers; 
namespace RepositoriesTests 
{ 
    [TestClass] 
    public class RackspaceTests 
    { 
     public string username = "mbar"; 
     public string password = "password"; 
     public string url = "http://192.168.5.55:5001/v3"; 
     public string project_id = "a9b2b59f093f44d881b8ebccbba00901"; 
     public string project_name = "test-nsix"; 
    [TestMethod] 
    public void TestConnection() 
    { 
     try 
     { 
      var identity = new CloudIdentityWithProject() 
      { 
       Username = username, 
       Password = password, 
       ProjectId = new ProjectId(project_id), 
       ProjectName = project_name 
      }; 
      var identityProvider = new OpenStackIdentityProvider(new Uri(url)); 


      var serverProvider = new CloudServersProvider(identity, identityProvider); 

      var images = serverProvider.ListImages(region: "RegionOne"); 
     }catch(Exception ex) 
     { 
      Assert.Fail(ex.Message); 
     } 
    } 

} 
} 

當我運行這個例子,我收到以下錯誤:的要求你做出了要求認證的要求。 我在瀏覽器窗口中選中我從網址獲得:http://192.168.5.55:5001/v3和我看到的服務器是否存在:

{"version": {"status": "stable", "updated": "2016-04-04T00:00:00Z", "media-types": [{"base": "application/json", "type": "application/vnd.openstack.identity-v3+json"}], "id": "v3.6", "links": [{"href": "http://192.168.5.55:5001/v3/", "rel": "self"}]}} 

我不知道問題出在哪裏,爲什麼我不能授權。

這是堆棧跟蹤:

w net.openstack.Providers.Rackspace.Validators.HttpResponseCodeValidator.Validate(Response response) w C:\Bamboo\xml-data\build-dir\OSTK-NET19-BLD\src\corelib\Providers\Rackspace\Validators\HttpResponseCodeValidator.cs:wiersz 48 
    w net.openstack.Providers.Rackspace.ProviderBase`1.CheckResponse(Response response) w C:\Bamboo\xml-data\build-dir\OSTK-NET19-BLD\src\corelib\Providers\Rackspace\ProviderBase`1.cs:wiersz 861 
    w net.openstack.Providers.Rackspace.ProviderBase`1.ExecuteRESTRequest[T](CloudIdentity identity, Uri absoluteUri, HttpMethod method, Object body, Dictionary`2 queryStringParameter, Dictionary`2 headers, Boolean isRetry, Boolean isTokenRequest, RequestSettings requestSettings, Func`7 callback) w C:\Bamboo\xml-data\build-dir\OSTK-NET19-BLD\src\corelib\Providers\Rackspace\ProviderBase`1.cs:wiersz 505 
    w net.openstack.Providers.Rackspace.ProviderBase`1.ExecuteRESTRequest[T](CloudIdentity identity, Uri absoluteUri, HttpMethod method, Object body, Dictionary`2 queryStringParameter, Dictionary`2 headers, Boolean isRetry, Boolean isTokenRequest, RequestSettings settings) w C:\Bamboo\xml-data\build-dir\OSTK-NET19-BLD\src\corelib\Providers\Rackspace\ProviderBase`1.cs:wiersz 294 
    w net.openstack.Core.Providers.OpenStackIdentityProvider.<>c__DisplayClass4_0.<GetUserAccess>b__0() w C:\Bamboo\xml-data\build-dir\OSTK-NET19-BLD\src\corelib\Core\Providers\OpenStackIdentityProvider.cs:wiersz 108 
    w net.openstack.Core.Caching.UserAccessCache.<>c__DisplayClass2_0.<Get>b__0(String k) w C:\Bamboo\xml-data\build-dir\OSTK-NET19-BLD\src\corelib\Core\Caching\UserAccessCache.cs:wiersz 58 
    w System.Collections.Concurrent.ConcurrentDictionary`2.AddOrUpdate(TKey key, Func`2 addValueFactory, Func`3 updateValueFactory) 
    w net.openstack.Core.Caching.UserAccessCache.Get(String key, Func`1 refreshCallback, Boolean forceCacheRefresh) w C:\Bamboo\xml-data\build-dir\OSTK-NET19-BLD\src\corelib\Core\Caching\UserAccessCache.cs:wiersz 58 
    w net.openstack.Core.Providers.OpenStackIdentityProvider.GetUserAccess(CloudIdentity identity, Boolean forceCacheRefresh) w C:\Bamboo\xml-data\build-dir\OSTK-NET19-BLD\src\corelib\Core\Providers\OpenStackIdentityProvider.cs:wiersz 123 
    w net.openstack.Providers.Rackspace.CloudIdentityProvider.Authenticate(CloudIdentity identity) w C:\Bamboo\xml-data\build-dir\OSTK-NET19-BLD\src\corelib\Providers\Rackspace\CloudIdentityProvider.cs:wiersz 948 
    w RepositoriesTests.RackspaceTests.TestConnection() w D:\Projekty\NSIX\RepositoriesTests\RackspaceTests.cs:wiersz 35 

回答

0

通行證identityProvider的CloudIdentityWithProject對象:

var identityProvider = new OpenStackIdentityProvider(new Uri(url), projectCloudId); 
+0

什麼是projectCloudId? OpenStackIdentityProvider沒有帶這樣的參數的構造函數。 –

+0

identity - > projectCloudId – SilentTremor

+0

http://stackoverflow.com/questions/24307286/openstack-net-sdk-cannot-access-service-with-region – SilentTremor