2015-10-16 62 views
0

我在嘗試連接我的OpenStack時遇到了一些問題。我使用jclouds,這是我的代碼:jclouds中的第一步

context = ContextBuilder.newBuilder("openstack-nova") 
      .endpoint("http://xxx.xxx.xxx.xxx:5000/v2.0/") 
      .credentials("tenantname:username", "password") 
      .modules(ImmutableSet.<Module> of(new SLF4JLoggingModule(), new SshjSshClientModule())) 
      .buildView(ComputeServiceContext.class); 

    service = context.getComputeService(); 

    for(ComputeMetadata node: service.listNodes()) { 
     System.out.println("NODE: " + node.getId()); 
    } 

但它總是返回以下錯誤:

DEBUG [org.jclouds.rest.internal.InvokeHttpMethod] [main] >> invoking AuthenticationApi.authenticateWithTenantNameAndCredentials 
DEBUG [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Sending request -1502473400: POST http://xxx.xxx.xxx.xxx:5000/v2.0/tokens HTTP/1.1 
ERROR [org.jclouds.http.internal.JavaUrlHttpCommandExecutorService] [main] Command not considered safe to retry because request method is POST: [method=org.jclouds.openstack.keystone.v2_0.AuthenticationApi.public abstract org.jclouds.openstack.keystone.v2_0.domain.Access org.jclouds.openstack.keystone.v2_0.AuthenticationApi.authenticateWithTenantNameAndCredentials(java.lang.String,org.jclouds.openstack.keystone.v2_0.domain.PasswordCredentials)[tenantname, PasswordCredentials{username=username, password=*****}], request=POST http://xxx.xxx.xxx.xxx:5000/v2.0/tokens HTTP/1.1] 

我在Eclipse和IntelliJ IDEA的發展。我一直在審查代理配置,但一切都很正常。

請問任何人都可以幫我嗎?

謝謝!

回答

0

該代碼看起來不錯,但如果您需要通過代理,則可能需要在jclouds中配置代理屬性。類似下面,爲您的代理權值:

Properties overrides = new Properties(); 
overrides.setProperty(Constants.PROPERTY_PROXY_HOST, "localhost"); 
overrides.setProperty(Constants.PROPERTY_PROXY_PORT, "8888"); 

你可以通過屬性的中,ContextBuilder的overrides方法。

您還可以啓用jclouds.wire日誌來查看正在發送的每個請求和響應。這將顯示確切的網絡錯誤或OpenStack安裝返回的錯誤。看看:http://jclouds.apache.org/reference/logging/

+0

謝謝你!你的答案是完美的,我已經在我的代碼中使用它,它運行良好!非常感謝!! –