I'm testing the vCloud Java SDK and I have some problems with the network settings.
I've achieved to create the vApp from a template, but the problem is that the vApp gets the wrong network interfaces.
I have two interfaces named (see the picture):
1.) 4PM-GR-test-Routed
2.) 4PM-GR-test-LAN-servers-arc-VLAN
I when I create the vApp via the template with
Vapp vapp = vdc.instantiateVappTemplate(instVappTemplParams);
if I control the instVappTemplParams there are both network in the params but the final created vApp has two networks both named 4PM-GR-test-Routed
I use the folowing code :
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;
}
And when I call the method to set the filan IP-s I got two networks with the same name as I said before.
The code for setting the ip-a is:
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);
}
}
}
I figured out that it was a bug in my code
this code was giving me always the same name
String neteworkName = vdc.getAvailableNetworkRefs().iterator().next().getName();
it should be
String neteworkName = networkConnection.getNetwork();