如何在openstack中使用jclouds将网络分配给vm,以及如何使用jclouds在openstack中列出所有网络 [英] how to assign network to vm using jclouds in openstack and How to list all networks in Openstack using Jclouds

查看:170
本文介绍了如何在openstack中使用jclouds将网络分配给vm,以及如何使用jclouds在openstack中列出所有网络的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

此外,我正在使用v1.0-quantum API来按如下方式获取所有网络,但不会返回任何网络.我不确定以下代码有什么问题:

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

推荐答案

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

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.

这篇关于如何在openstack中使用jclouds将网络分配给vm,以及如何使用jclouds在openstack中列出所有网络的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆