Java jclouds API 无法连接到 OpenStack 提供程序。
抛出异常并显示以下消息:java.util.NoSuchElementException:在目录 [] 中找不到 apiType 计算。
其他 API(python-novaclient、ruby-fog)工作得很好,所以问题看起来是特定于语言 (API) 的。
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());
}
}
非常感谢任何帮助或提示