[英]how to assign network to vm using jclouds in openstack and How to list all networks in Openstack using Jclouds
Can someone help me understanding how to assign a specific network to a newly created VM using the JClouds API in OpenStack? 有人可以帮助我了解如何使用OpenStack中的JClouds API将特定网络分配给新创建的VM吗? 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. 另外,我正在使用
v1.0-quantum
API来按如下方式获取所有网络,但不会返回任何网络。 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());
}
I use version 1.7.3 of JClouds and I build the options in the following way, giving network ids as parameters: 我使用JClouds的1.7.3版本,并以以下方式构建选项,将网络ID作为参数:
CreateServerOptions options = CreateServerOptions.Builder
.networks("00000000-0000-0000-0000-000000000000", "11111111-1111-1111-1111-111111111111")
As for listing networks here are good examples. 至于列表网络, 这是很好的例子。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.