// Get the region where the template is available
Datacenter datacenter = regionMap.get().get(Integer.valueOf(template.getImage().getLocation().getId()));
// Load the template
VirtualMachineTemplate virtualMachineTemplate = enterprise.getTemplateInRepository(datacenter,
Integer.valueOf(template.getImage().getId()));
// Get the zone where the template will be deployed
VirtualDatacenter vdc = cloudService.getVirtualDatacenter(Integer.valueOf(template.getHardware().getLocation()
.getId()));