// if the vm contains a network connection and the vApp does not contain any configured
// network
if (vmHasNetworkConnectionConfigured(vm)) {
if (!vAppHasNetworkConfigured(vApp)) {
// add a new network connection section for the vm.
NetworkConnectionSection networkConnectionSection = NetworkConnectionSection.builder()
.info("Empty network configuration parameters").build();
// adding the network connection section to the instantiation params of the vapp.
vmInstantiationParams = InstantiationParams.builder().sections(ImmutableSet.of(networkConnectionSection))
.build();
}
// if the vm already contains a network connection section and if the vapp contains a
// configured network -> vm could be mapped to that network.
else {
Set<VAppNetworkConfiguration> vAppNetworkConfigurations = listVappNetworkConfigurations(vApp);
for (VAppNetworkConfiguration vAppNetworkConfiguration : vAppNetworkConfigurations) {
NetworkAssignment networkAssignment = NetworkAssignment.builder()
.innerNetwork(vAppNetworkConfiguration.getNetworkName())
.containerNetwork(vAppNetworkConfiguration.getNetworkName()).build();
networkAssignments.add(networkAssignment);
}
}
}
// if the vm does not contain any network connection sections and if the
// vapp contains a network configuration. we should add the vm to this
// vapp network
else {
if (vAppHasNetworkConfigured(vApp)) {
VAppNetworkConfiguration vAppNetworkConfiguration = getVAppNetworkConfig(vApp);
NetworkConnection networkConnection = NetworkConnection.builder()
.network(vAppNetworkConfiguration.getNetworkName())
.ipAddressAllocationMode(IpAddressAllocationMode.DHCP).build();
NetworkConnectionSection networkConnectionSection = NetworkConnectionSection.builder().info("networkInfo")
.primaryNetworkConnectionIndex(0).networkConnection(networkConnection).build();
// adding the network connection section to the instantiation params of the vapp.
vmInstantiationParams = InstantiationParams.builder().sections(ImmutableSet.of(networkConnectionSection))
.build();