使用OpenStack的jclouds => java.util.NoSuchElementException:在目录[]中找不到apiType计算 [英] jclouds with OpenStack => java.util.NoSuchElementException: apiType compute not found in catalog []
问题描述
Java jclouds API无法连接到OpenStack提供程序.
Java jclouds API fails to connect to an OpenStack provider.
使用以下消息引发异常:java.util.NoSuchElementException:在目录[]中找不到apiType计算.
Exception is thrown with the following message: java.util.NoSuchElementException: apiType compute not found in catalog [].
其他API(python-novaclient,ruby-fog)可以正常工作,因此该问题看起来是特定于语言(API)的.
Other APIs (python-novaclient, ruby-fog) work just fine, so the problem looks language (API)-specific.
import static com.google.common.io.Closeables.closeQuietly;
import java.io.Closeable;
import java.util.Set;
import org.jclouds.ContextBuilder;
import org.jclouds.compute.ComputeService;
import org.jclouds.compute.ComputeServiceContext;
import org.jclouds.compute.domain.ComputeMetadata;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.NovaAsyncApi;
import org.jclouds.openstack.nova.v2_0.domain.Server;
import org.jclouds.openstack.nova.v2_0.features.ServerApi;
import org.jclouds.rest.RestContext;
import com.google.common.collect.ImmutableSet;
import com.google.inject.Module;
public class jcloudsOpenStack implements Closeable {
private ComputeService compute;
private RestContext nova;
public static void main(String[] args) {
jcloudsOpenStack jcloudOpenStack = new jcloudsOpenStack();
try {
jcloudOpenStack.init();
jcloudOpenStack.listServers();
jcloudOpenStack.close();
}
catch (Exception e) {
e.printStackTrace();
}
finally {
jcloudOpenStack.close();
}
}
private void init() {
Iterable modules = ImmutableSet. of(new SLF4JLoggingModule());
String provider = "openstack-nova";
String identity = "..."; // login name
String password = "..."; // password
ComputeServiceContext context = ContextBuilder.newBuilder(provider)
.endpoint("https://UltiCloud.com:5000/v2.0/")
.credentials(identity, password)
.modules(modules)
.buildView(ComputeServiceContext.class);
compute = context.getComputeService();
nova = context.unwrap();
}
private void listServers() {
Set<? extends ComputeMetadata> nodes = compute.listNodes();
System.out.println(nodes.size());
}
public void close() {
closeQuietly(compute.getContext());
}
}
非常感谢您的帮助或提示
Any help or a hint is greatly appreciated
推荐答案
最近几天我遇到了同样的问题,最后得到了解决. 您应该对凭据"功能的参数身份"使用用户名:租户名". 如果使用用户名"而不是租户名:用户名",则jclouds将仅查询令牌,而不是在查询令牌后查询端点列表,并且会引发异常.
I got the same problem in last few days, and finally i got this resolved. you should use"username:tenantname" for parameters 'identity' of 'credentials' function. if you use "username" instead of "tenantname:username", jclouds would query tokens only instead of querying endpoint-list after token-querying, and the exception been thrown.
看起来像这样:
ComputeServiceContext context = ContextBuilder.newBuilder(provider)
.endpoint("https://UltiCloud.com:5000/v2.0/")
.credentials("admin:admin", "123456")
.modules(modules)
.buildView(ComputeServiceContext.class);
不是这样的:
ComputeServiceContext context = ContextBuilder.newBuilder(provider)
.endpoint("https://UltiCloud.com:5000/v2.0/")
.credentials("admin", "123456")
.modules(modules)
.buildView(ComputeServiceContext.class);
希望这对你们有帮助
这篇关于使用OpenStack的jclouds => java.util.NoSuchElementException:在目录[]中找不到apiType计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!