【问题标题】:how to assign network to vm using jclouds in openstack and How to list all networks in Openstack using Jclouds如何在 openstack 中使用 jclouds 将网络分配给 vm 以及如何使用 Jclouds 在 Openstack 中列出所有网络
【发布时间】:2013-10-18 07:11:16
【问题描述】:

有人可以帮助我了解如何使用 OpenStack 中的 JClouds API 将特定网络分配给新创建的虚拟机吗?我正在使用以下代码来创建真正的服务器:

CreateServerOptions[] serverOptions = new CreateServerOptions[0];

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

我还使用v1.0-quantum API 来获取所有网络,如下所示,但它没有返回任何网络。我不确定以下代码有什么问题:

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());
      }

【问题讨论】:

标签: openstack jclouds openstack-neutron


【解决方案1】:

我使用 1.7.3 版的 JClouds,并按以下方式构建选项,将网络 ID 作为参数:

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

至于列出网络here 就是很好的例子。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-13
    • 1970-01-01
    • 2014-09-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多