如何在Java中启动新的openstack实例?

时间:2017-07-10 13:53:40

标签: java openstack-nova jclouds

我试图通过引用下面的URL来在Java中启动新的开放堆栈实例。

https://help.dreamhost.com/hc/en-us/articles/216456877-How-to-launch-and-delete-OpenStack-instances-using-Java-and-Jclouds

以下是我的createInstance方法的样子: -

public void createInstance(String instanceName) {
    for (String region : regions) {
        ServerApi serverApi = novaApi.getServerApi(region);
        System.out.println("server api : " + serverApi.toString());
        String imageId = "7d246e9a-dd2a-4342-97f7-32accd0f9c35";
        String flavorId = "8041379d-7261-401d-90cf-e2d97184fe94";

        /*Launch an instance*/
        ServerCreated ser = serverApi.create(instanceName, imageId, flavorId);

        Server server = serverApi.get(ser.getId());
        while (server.getStatus().value().equals("ACTIVE") == false) {
            try {
                Thread.sleep(1000);
            } catch (InterruptedException ex) {
            }
            server = serverApi.get(ser.getId());
        }

        System.out.println(ser.getId());
    }
}

我收到HttpResponseException但能够获取图片ID,风味ID等。

  

exception:org.jclouds.http.HttpResponseException:command:POST http://192.168.1.224:8774/v2/e02b6387fa5a4b619bc2ba554661ea99/servers HTTP / 1.1失败,响应:HTTP / 1.1 400 Bad Request;内容:[{“badRequest”:{“message”:“找到多个可能的网络,使用网络ID更具体。”,“代码”:400}}]

1 个答案:

答案 0 :(得分:1)

您必须指定用于启动实例的flavor,image和networks。我看到你已经指定了味道和图像。 但是,您还必须指定要使用的网络。请查看以下链接中的答案

jcloud_create_instance_with_network