how to assign network to vm using jclouds in openstack and How to list all networks in Openstack using Jclouds

断了今生、忘了曾经 提交于 2019-12-12 03:55:35

问题


Can someone help me understanding how to assign a specific network to a newly created VM using the JClouds API in OpenStack? I'm using following code to create the real server:

CreateServerOptions[] serverOptions = new CreateServerOptions[0];

ServerCreated serverCreated = serverApi.create(clonedVmName, imageId, FlavourId, serverOptions);

Also I'm using v1.0-quantum APIs to fetch all the networks as follows but it's not returning any. I'm not sure what's wrong with the following code:

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

      quantum = ContextBuilder.newBuilder(provider)
            .endpoint("http://10.37.53.229:5000/v2.0/")
            .credentials(identity, password)
            .modules(modules)
            .build();


      QuantumApi quanApi =  (QuantumApi)quantum.getApi();
      for(String zone : quanApi.getConfiguredZones())
      {
          System.out.println("Zone : "+ zone);
      }

      NetworkApi netApi = quanApi.getNetworkApiForZone("RegionOne");
      FluentIterable<? extends Network> nets = netApi.list();

      for(Network net : nets)
      {
          System.out.println(net.getName() +" Id : "+net.getId());
      }

回答1:


I use version 1.7.3 of JClouds and I build the options in the following way, giving network ids as parameters:

 CreateServerOptions options = CreateServerOptions.Builder
       .networks("00000000-0000-0000-0000-000000000000", "11111111-1111-1111-1111-111111111111")

As for listing networks here are good examples.



来源:https://stackoverflow.com/questions/19443692/how-to-assign-network-to-vm-using-jclouds-in-openstack-and-how-to-list-all-netwo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!