}
@Override
public NodeAndInitialCredentials<Droplet> createNodeWithGroupEncodedIntoName(String group, final String name,
Template template) {
DigitalOceanTemplateOptions templateOptions = template.getOptions().as(DigitalOceanTemplateOptions.class);
CreateDropletOptions.Builder options = CreateDropletOptions.builder();
// Create a default keypair for the node so it has a known private key
Map<String, String> defaultKeys = keyGenerator.get();
logger.debug(">> creating default keypair for node...");
SshKey defaultKey = api.getKeyPairApi().create(name, defaultKeys.get("public"));
logger.debug(">> keypair created! %s", defaultKey);
options.addSshKeyId(defaultKey.getId());
// Check if there is a key to authorize in the portable options
if (!Strings.isNullOrEmpty(template.getOptions().getPublicKey())) {
logger.debug(">> creating user keypair for node...");
// The DigitalOcean API accepts multiple key pairs with the same name. It will be useful to identify all
// keypairs associated with the node when it comes to destroy it
SshKey key = api.getKeyPairApi().create(name, template.getOptions().getPublicKey());
logger.debug(">> keypair created! %s", key);
options.addSshKeyId(key.getId());
}
// DigitalOcean specific options
if (!templateOptions.getSshKeyIds().isEmpty()) {
options.addSshKeyIds(templateOptions.getSshKeyIds());
}
if (templateOptions.getPrivateNetworking() != null) {
options.privateNetworking(templateOptions.getPrivateNetworking());
}
if (templateOptions.getBackupsEnabled() != null) {
options.backupsEnabled(templateOptions.getBackupsEnabled());
}
// Find the location where the Droplet has to be created
final String locationId = template.getLocation().getId();
Region region = find(api.getRegionApi().list(), new Predicate<Region>() {