我正在测试vCloud Java SDK,但我遇到了一些网络设置问题。
我已经实现了从模板创建vApp,但问题是vApp获取了错误的网络接口。
我有两个名为的接口(见图):
1。)4 PM-GR-test-Routed
2。)4 PM-GR-test-LAN-servers-arc-VLAN
当我使用
模板创建vApp时Vapp vapp = vdc.instantiateVappTemplate(instVappTemplParams);
如果我控制 instVappTemplParams ,参数中有两个网络,但最终创建的vApp有两个网络,名为 4 PM-GR-test-Routed
我使用下面的代码:
public static Vapp newvAppFromTemplate(ReferenceType vAppTemplateReference, Vdc vdc) throws VCloudException {
System.out.println("Instantiating " + vAppTemplateReference.getName() + " " + vAppTemplateReference.getHref());
System.out.println("-------------------------------");
// get the href of the OrgNetwork to which we can connect the vApp network
if (vdc.getAvailableNetworkRefs().size() == 0) {
System.out.println("No Networks in vdc to instantiate the vapp");
System.exit(0);
}
List<ReferenceType> networks = new ArrayList<ReferenceType>(vdc.getAvailableNetworkRefs());
// fill in the NetworkConfigSection
NetworkConfigSectionType networkConfigSection = new NetworkConfigSectionType();
MsgType networkInfo = new MsgType();
networkConfigSection.setInfo(networkInfo);
List<VAppNetworkConfigurationType> vAppNetworkConfigs = networkConfigSection.getNetworkConfig();
// specify the NetworkConfiguration for the vApp network
Iterator<ReferenceType> networkIterator = vdc.getAvailableNetworkRefs().iterator();
while(networkIterator.hasNext()){
ReferenceType networkReference = networkIterator.next();
System.out.println(networkReference.getName());
NetworkConfigurationType networkConfiguration = new NetworkConfigurationType();
networkConfiguration.setParentNetwork(networkReference);
networkConfiguration.setFenceMode(FenceModeValuesType.BRIDGED.value());
VAppNetworkConfigurationType vAppNetworkConfiguration = new VAppNetworkConfigurationType();
vAppNetworkConfiguration.setConfiguration(networkConfiguration);
vAppNetworkConfiguration.setNetworkName(networkReference.getName());
vAppNetworkConfigs.add(vAppNetworkConfiguration);
}
// fill in remaining InstantititonParams (name, Source)
InstantiationParamsType instantiationParams = new InstantiationParamsType();
List<JAXBElement<? extends SectionType>> sections = instantiationParams.getSection();
sections.add(new ObjectFactory().createNetworkConfigSection(networkConfigSection));
// create the request body (InstantiateVAppTemplateParams)
InstantiateVAppTemplateParamsType instVappTemplParams = new InstantiateVAppTemplateParamsType();
instVappTemplParams.setName("4pm-test-00004");
instVappTemplParams.setSource(vAppTemplateReference);
instVappTemplParams.setInstantiationParams(instantiationParams);
// make the request, and get an href to the vApp in return
Vapp vapp = vdc.instantiateVappTemplate(instVappTemplParams);
return vapp;
}
当我调用方法来设置filan IP-s时,我得到了两个与我之前说过的名字相同的网络。
设置ip-a的代码是:
public static void configureVMsIPAddressingMode(ReferenceType vappRef,Vdc vdc) throws VCloudException, TimeoutException {
System.out.println(" Configuring VM Ip Addressing Mode");
Vapp vapp = Vapp.getVappByReference(vcloudClient, vappRef);
List<VM> childVms = vapp.getChildrenVms();
for (VM childVm : childVms) {
NetworkConnectionSectionType networkConnectionSection = childVm.getNetworkConnectionSection();
List<NetworkConnectionType> networkConnections = networkConnectionSection.getNetworkConnection();
for (NetworkConnectionType networkConnection : networkConnections) {
String neteworkName = vdc.getAvailableNetworkRefs().iterator().next().getName();
networkConnection.setIpAddressAllocationMode(IpAddressAllocationModeType.MANUAL.value());
networkConnection.setNetwork(neteworkName);
System.out.println(neteworkName);
if(neteworkName.equals("4PM-GR-test-Routed")){
networkConnection.setIpAddress("192.168.135.4");
}else{
networkConnection.setIpAddress("10.30.1.4");
}
}
childVm.updateSection(networkConnectionSection).waitForTask(0);
for (String ip : VM.getVMByReference(vcloudClient,childVm.getReference()).getIpAddressesById().values()) {
System.out.println(" " + ip);
}
}
}
答案 0 :(得分:0)
我发现这是我的代码中的错误
这段代码给了我一个相同的名字
String neteworkName = vdc.getAvailableNetworkRefs().iterator().next().getName();
应该是
String neteworkName = networkConnection.getNetwork();