我正在测试 vCloud Java SDK,但网络设置存在一些问题。
我已经实现了从模板创建 vApp,但问题是 vApp 获取了错误的网络接口。
我有两个接口命名(见图):
1.) 4PM-GR-test-Routed
2.) 4PM-GR-test-LAN-servers-arc-VLAN
当我通过模板创建 vApp 时
Vapp vapp = vdc.instantiateVappTemplate(instVappTemplParams);
如果我控制instVappTemplParams,则参数中都有两个网络,但最终创建的 vApp 有两个网络,均名为4PM-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);
}
}
}