Jclouds示例不在主机上工作(devstack)

时间:2015-11-01 11:39:36

标签: api jclouds keystone

我在Virtualbox上安装了Devstack,当我测试主页示例时,我想在我的主机上使用Jcloud进行应用程序开发

import com.google.common.collect.ImmutableSet;
import com.google.common.io.Closeables;
import com.google.inject.Module;
import org.jclouds.ContextBuilder;
import org.jclouds.logging.slf4j.config.SLF4JLoggingModule;
import org.jclouds.openstack.nova.v2_0.NovaApi;
import org.jclouds.openstack.nova.v2_0.domain.Server;
import org.jclouds.openstack.nova.v2_0.features.ServerApi;

import java.io.Closeable;
import java.io.IOException;
import java.util.Set;

public class JCloudsNova implements Closeable {
private final NovaApi novaApi;
private final Set<String> regions;

public static void main(String[] args) throws IOException {
    JCloudsNova jcloudsNova = new JCloudsNova();

    try {
        jcloudsNova.listServers();
        jcloudsNova.close();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        jcloudsNova.close();
    }
}

public JCloudsNova() {
    Iterable<Module> modules = ImmutableSet.<Module>of(new     SLF4JLoggingModule());

    String provider = "openstack-nova";
    String identity = "demo:demo"; // tenantName:userName
    String credential = "nova";

    novaApi = ContextBuilder.newBuilder(provider)
            .endpoint("http://127.0.0.0:5000/v2.0/")
            .credentials(identity, credential)
            .modules(modules)
            .buildApi(NovaApi.class);
    regions = novaApi.getConfiguredRegions();
}

private void listServers() {
    for (String region : regions) {
        ServerApi serverApi = novaApi.getServerApi(region);

        System.out.println("Servers in " + region);

        for (Server server : serverApi.listInDetail().concat()) {
            System.out.println("  " + server);
        }
    }
}

public void close() throws IOException {
    Closeables.close(novaApi, true);
}
}

我得到了这个输出:

[main] DEBUG o.j.rest.internal.InvokeHttpMethod - >> invoking   AuthenticationApi.authenticateWithTenantNameAndCredentials
[main] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Sending request 731849735: POST http://127.0.0.1:5000/v2.0/tokens HTTP/1.1
[main] DEBUG jclouds.wire - >> "Sensitive data in payload, use PROPERTY_LOGGER_WIRE_LOG_SENSITIVE_INFO override to enable logging this data."
[main] DEBUG jclouds.headers - >> POST http://127.0.0.1:5000/v2.0/tokens HTTP/1.1
[main] DEBUG jclouds.headers - >> Accept: application/json
[main] DEBUG jclouds.headers - >> Content-Type: application/json
[main] DEBUG jclouds.headers - >> Content-Length: 92
[main] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Receiving  response 731849735: HTTP/1.1 200 OK
[main] DEBUG jclouds.headers - << HTTP/1.1 200 OK
[main] DEBUG jclouds.headers - << Keep-Alive: timeout=5, max=100
[main] DEBUG jclouds.headers - << Server: Apache/2.4.7 (Ubuntu)
[main] DEBUG jclouds.headers - << Connection: Keep-Alive
[main] DEBUG jclouds.headers - << x-openstack-request-id: req-ee75199f-27ba-4d95-bc68-b5ddbd38235e
[main] DEBUG jclouds.headers - << Vary: X-Auth-Token
[main] DEBUG jclouds.headers - << Date: Sun, 01 Nov 2015 11:15:11 GMT
[main] DEBUG jclouds.headers - << Content-Type: application/json
[main] DEBUG jclouds.headers - << Content-Length: 5187
[main] DEBUG jclouds.wire - << "{"access": {"token": {"issued_at": "2015-11-01T11:15:11.741173", "expires": "2015-11-01T12:15:11Z", "id": "a907229e8fa94560a3d87ffd8bc959e7", "tenant": {"description": null, "enabled": true, "id": "b37cfd133b05457d82adc239cb762a6a", "name": "admin"}, "audit_ids": ["SWSlpB88SK6JFcfuAjqi_g"]}, "serviceCatalog": [{"endpoints": [{"adminURL": "http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a", "region": "RegionOne", "internalURL": "http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a", "id": "083ebebf2f284add866b15092e4b4918", "publicURL": "http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a"}], "endpoints_links": [], "type": "compute", "name": "nova"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8774/v2.1/b37cfd133b05457d82adc239cb762a6a", "region": "RegionOne", "internalURL": "http://10.0.2.15:8774/v2.1/b37cfd133b05457d82adc239cb762a6a", "id": "4fd099ac1b0542a8994281d86fc50e19", "publicURL": "http://10.0.2.15:8774/v2.1/b37cfd133b05457d82adc239cb762a6a"}], "endpoints_links": [], "type": "computev21", "name": "novav21"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8776/v2/b37cfd133b05457d82adc239cb762a6a", "region": "RegionOne", "internalURL": "http://10.0.2.15:8776/v2/b37cfd133b05457d82adc239cb762a6a", "id": "0b0499b8a437401bb96968d9f76ca7c7", "publicURL": "http://10.0.2.15:8776/v2/b37cfd133b05457d82adc239cb762a6a"}], "endpoints_links": [], "type": "volumev2", "name": "cinderv2"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8779/v1.0/b37cfd133b05457d82adc239cb762a6a", "region": "RegionOne", "internalURL": "http://10.0.2.15:8779/v1.0/b37cfd133b05457d82adc239cb762a6a", "id": "9dc6091b06e545bdaee41945d54a45ad", "publicURL": "http://10.0.2.15:8779/v1.0/b37cfd133b05457d82adc239cb762a6a"}], "endpoints_links": [], "type": "database", "name": "trove"}, {"endpoints": [{"adminURL": "http://10.0.2.15:9292", "region": "RegionOne", "internalURL": "http://10.0.2.15:9292", "id": "1c23e7d2ad234adaa9e8109472c28ac2", "publicURL": "http://10.0.2.15:9292"}], "endpoints_links": [], "type": "image", "name": "glance"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8386/v1.1/b37cfd133b05457d82adc239cb762a6a", "region": "RegionOne", "internalURL": "http://10.0.2.15:8386/v1.1/b37cfd133b05457d82adc239cb762a6a", "id": "2d3d2a5dff9b4799bc16e66409c66479", "publicURL": "http://10.0.2.15:8386/v1.1/b37cfd133b05457d82adc239cb762a6a"}], "endpoints_links": [], "type": "data_processing", "name": "sahara"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8000/v1", "region": "RegionOne", "internalURL": "http://10.0.2.15:8000/v1", "id": "0c9fa4ded5b14bb780a73f843baec0be", "publicURL": "http://10.0.2.15:8000/v1"}], "endpoints_links": [], "type": "cloudformation", "name": "heat-cfn"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8776/v1/b37cfd133b05457d82adc239cb762a6a", "region": "RegionOne", "internalURL": "http://10.0.2.15:8776/v1/b37cfd133b05457d82adc239cb762a6a", "id": "17f424ba438940b281c91287a8e2f247", "publicURL": "http://10.0.2.15:8776/v1/b37cfd133b05457d82adc239cb762a6a"}], "endpoints_links": [], "type": "volume", "name": "cinder"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8773/", "region": "RegionOne", "internalURL": "http://10.0.2.15:8773/", "id": "930d840f89eb4b978a1b6aa4c43550d6", "publicURL": "http://10.0.2.15:8773/"}], "endpoints_links": [], "type": "ec2", "name": "ec2"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8004/v1/b37cfd133b05457d82adc239cb762a6a", "region": "RegionOne", "internalURL": "http://10.0.2.15:8004/v1/b37cfd133b05457d82adc239cb762a6a", "id": "59524478bb014029832a84bbe55e7600", "publicURL": "http://10.0.2.15:8004/v1/b37cfd133b05457d82adc239cb762a6a"}], "endpoints_links": [], "type": "orchestration", "name": "heat"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8080", "region": "RegionOne", "internalURL": "http://10.0.2.15:8080/v1/AUTH_b37cfd133b05457d82adc239cb762a6a", "id": "5f4a0e402b0041a799207dc70f6abb01", "publicURL": "http://10.0.2.15:8080/v1/AUTH_b37cfd133b05457d82adc239cb762a6a"}], "endpoints_links": [], "type": "object-store", "name": "swift"}, {"endpoints": [{"adminURL": "http://10.0.2.15:8386/v1.1/b37cfd133b05457d82adc239cb762a6a", "region": "RegionOne", "internalURL": "http://10.0.2.15:8386/v1.1/b37cfd133b05457d82adc239cb762a6a", "id": "0d0183f6f94048bba68bbc540375debd", "publicURL": "http://10.0.2.15:8386/v1.1/b37cfd133b05457d82adc239cb762a6a"}], "endpoints_links": [], "type": "data-processing", "name": "sahara"}, {"endpoints": [{"adminURL": "http://10.0.2.15:35357/v2.0", "region": "RegionOne", "internalURL": "http://10.0.2.15:5000/v2.0", "id": "249b7361cf944d5b999666d3c89dff63", "publicURL": "http://10.0.2.15:5000/v2.0"}], "endpoints_links": [], "type": "identity", "name": "keystone"}, {"endpoints": [{"adminURL": "http://10.0.2.15:9696/", "region": "RegionOne", "internalURL": "http://10.0.2.15:9696/", "id": "59f12fcbf8044e688dd184914f1d4337", "publicURL": "http://10.0.2.15:9696/"}], "endpoints_links": [], "type": "network", "name": "neutron"}], "user": {"username": "admin", "roles_links": [], "id": "c2430e83e4814f058e7bf7ac783b04ec", "roles": [{"name": "admin"}], "name": "admin"}, "metadata": {"is_admin": 0, "roles": ["2d225038f03f4d1d928994c77728fbb6"]}}}"
[main] DEBUG o.j.o.k.v.s.RegionIdToURIFromAccessForTypeAndVersion - endpoints for apiType compute and version 2: {RegionOne=[Endpoint{id=083ebebf2f284add866b15092e4b4918, region=RegionOne, publicURL=http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a, internalURL=http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a, adminURL=http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a}]}
[main] DEBUG o.j.l.s.f.RegionIdsFromConfiguration - no jclouds.regions configured for provider openstack-nova
Servers in RegionOne
[main] DEBUG o.j.rest.internal.InvokeHttpMethod - >> invoking server:list
[main] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Sending request -1892986886: GET http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a/servers/detail HTTP/1.1
[main] DEBUG jclouds.headers - >> GET http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a/servers/detail HTTP/1.1
[main] DEBUG jclouds.headers - >> Accept: application/json
[main] DEBUG jclouds.headers - >> X-Auth-Token: a907229e8fa94560a3d87ffd8bc959e7
[main] DEBUG o.j.h.h.BackoffLimitedRetryHandler - Retry 1/5: delaying for 54 ms: server error: [method=org.jclouds.openstack.nova.v2_0.features.ServerApi.public abstract org.jclouds.collect.PagedIterable org.jclouds.openstack.nova.v2_0.features.ServerApi.listInDetail()[], request=GET http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a/servers/detail HTTP/1.1]
[main] DEBUG o.j.h.i.JavaUrlHttpCommandExecutorService - Sending request -1892986886: GET http://10.0.2.15:8774/v2/b37cfd133b05457d82adc239cb762a6a/servers/detail HTTP/1.1

请注意我使用intelijIdea作为IDE

2 个答案:

答案 0 :(得分:0)

问题可能与虚拟机的网络配置有关。 您的第一个请求将转至127.0.0.1:5000,并由Openstack Keystone服务正确处理。

keystone响应包括nova服务端点的地址 - 10.0.2.15:8774 - 这是用于列出服务器的API调用的位置。您的客户似乎无法连接到此IP。

检查虚拟机网络配置 - 确保网络模式允许主机操作系统连接到客户机操作系统。

答案 1 :(得分:0)

Virtualbox无法通过虚拟化扩展。您的devstack很可能无法在virtualbox下启动虚拟机。