OpenStack4j简洁易用,项目中一直使用方便,构造OS如下:

OSClientV2 os = OSFactory
    .builderV2()
    .endpoint(cred.getCloudURI())
    .credentials(cred.getUsername(), cred.getPassword())
    .tenantName(cred.getProject())
    .withConfig(
        Config.newConfig()
            .withConnectionTimeout(1000 * 60)
            .withReadTimeout(1000 * 60 * 5))
    .authenticate();

近期用于访问OpenStack却发生如下异常:

2018-09-28 11:30:02 DEBUG HttpExecutor:50 - Executing Request: https://my-openstack-cloud:5000/v2.0 -> /tokens
Exception in thread "main" ClientResponseException{message=Not Found, status=404, status-code=NOT_FOUND}
	at org.openstack4j.core.transport.HttpExceptionHandler.mapException(HttpExceptionHandler.java:38)
	at org.openstack4j.core.transport.HttpExceptionHandler.mapException(HttpExceptionHandler.java:23)
	at org.openstack4j.openstack.internal.OSAuthenticator.authenticateV2(OSAuthenticator.java:125)
	at org.openstack4j.openstack.internal.OSAuthenticator.invoke(OSAuthenticator.java:52)
	at org.openstack4j.openstack.client.OSClientBuilder$ClientV2.authenticate(OSClientBuilder.java:117)
	at org.openstack4j.openstack.client.OSClientBuilder$ClientV2.authenticate(OSClientBuilder.java:79)

在调试过程中,执行如下命令,得到熟悉的响应(从OpenStack M版本开始):

> curl https://my-openstack-cloud:5000/
{
	"versions": {
		"values": [{
			"status": "stable",
			"updated": "2018-02-28T00:00:00Z",
			"media-types": [{
				"base": "application/json",
				"type": "application/vnd.openstack.identity-v3+json"
			}],
			"id": "v3.10",
			"links": [{
				"href": "https://my-openstack-cloud:5000/v3/",
				"rel": "self"
			}]
		}, {
			"status": "deprecated",
			"updated": "2016-08-04T00:00:00Z",
			"media-types": [{
				"base": "application/json",
				"type": "application/vnd.openstack.identity-v2.0+json"
			}],
			"id": "v2.0",
			"links": [{
				"href": "https://my-openstack-cloud:5000/v2.0/",
				"rel": "self"
			}, {
				"href": "https://docs.openstack.org/",
				"type": "text/html",
				"rel": "describedby"
			}]
		}]
	}
}

在确定OpenStack4j访问已有Cloud正常的情况下,怀疑是OpenStack的问题。

查看部署的OpenStack采用了OpenStack Q版本,恍然大悟。

通过OpenStack Q版本文档可知,对于OpenStack Queens及其之后版本:

  • 只有Keystone /v3有效
  • Keystone /v2.0的主要功能已经被移除
  • 仅保留Keystone /v2.0的ec2tokens API到OpenStack T版本

截图如下:

OpenStack4j访问OpenStack Q版本的注意事项

使用Keystone v3运行通过,代码如下:

OSClientV3 os = OSFactory
    .builderV3()
    .endpoint(cred.getCloudURI())
    .credentials(cred.getUsername(), cred.getPassword(), Identifier.byName(cred.getDomain()))
    .scopeToProject(Identifier.byName(cred.getProject()), Identifier.byName(cred.getDomain()))
    .withConfig(
        Config.newConfig()
            .withConnectionTimeout(1000 * 60)
            .withReadTimeout(1000 * 60 * 5))
    .authenticate();

参考链接:

    http://www.openstack4j.com/learn
    https://docs.openstack.org/keystone/latest/api_curl_examples.html
    https://docs.openstack.org/keystone/pike/api_curl_examples.html

相关文章:

  • 2022-12-23
  • 2021-11-08
  • 2022-12-23
  • 2021-12-27
  • 2021-12-03
  • 2022-01-18
  • 2021-08-30
  • 2022-02-16
猜你喜欢
  • 2021-10-28
  • 2021-11-17
  • 2022-12-23
  • 2021-11-20
  • 2021-08-15
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案