protected VApp instantiateVAppFromTemplate(String name, Template template) {
VCloudTemplateOptions vOptions = VCloudTemplateOptions.class.cast(template.getOptions());
URI templateId = URI.create(template.getImage().getId());
VAppTemplate vAppTemplate = vAppTemplates.getUnchecked(templateId);
if (vAppTemplate.getChildren().size() > 1)
throw new UnsupportedOperationException("we currently do not support multiple vms in a vAppTemplate "
+ vAppTemplate);
if (vAppTemplate.getNetworkSection().getNetworks().size() > 1)
throw new UnsupportedOperationException(
"we currently do not support multiple network connections in a vAppTemplate " + vAppTemplate);
Network networkToConnect = get(vAppTemplate.getNetworkSection().getNetworks(), 0);
NetworkConfig config = networkConfigurationForNetworkAndOptions.apply(networkToConnect, vOptions);
// note that in VCD 1.5, the network name after instantiation will be the same as the parent