// Get the zone where the template will be deployed
Integer locationId = Integer.valueOf(template.getHardware().getLocation().getId());
VirtualDatacenter vdc = cloudService.getVirtualDatacenter(locationId);
// Check if it already exists a group with the given name
Iterable<VirtualAppliance> existingGroups = vdc.listVirtualAppliances();
Optional<VirtualAppliance> vapp = tryFind(existingGroups, new Predicate<VirtualAppliance>() {
@Override
public boolean apply(VirtualAppliance input) {
return input.getName().equals(group);
}