public Map<?, ListenableFuture<Void>> execute(String group, int count, Template template, Set<NodeMetadata> goodNodes,
Map<NodeMetadata, Exception> badNodes, Multimap<NodeMetadata, CustomizationResponse> customizationResponses) {
Template mutableTemplate = template.clone();
NovaTemplateOptions templateOptions = NovaTemplateOptions.class.cast(mutableTemplate.getOptions());
assert template.getOptions().equals(templateOptions) : "options didn't clone properly";
String region = mutableTemplate.getLocation().getId();
if (templateOptions.shouldAutoAssignFloatingIp()) {
checkArgument(novaApi.getFloatingIPApi(region).isPresent(),
"Floating IPs are required by options, but the extension is not available! options: %s",
templateOptions);
}
boolean keyPairExtensionPresent = novaApi.getKeyPairApi(region).isPresent();
if (templateOptions.shouldGenerateKeyPair()) {
checkArgument(keyPairExtensionPresent,
"Key Pairs are required by options, but the extension is not available! options: %s", templateOptions);
KeyPair keyPair = keyPairCache.getUnchecked(RegionAndName.fromRegionAndName(region, namingConvention.create()
.sharedNameForGroup(group)));
keyPairCache.asMap().put(RegionAndName.fromRegionAndName(region, keyPair.getName()), keyPair);
templateOptions.keyPairName(keyPair.getName());
} else if (templateOptions.getKeyPairName() != null) {
checkArgument(keyPairExtensionPresent,
"Key Pairs are required by options, but the extension is not available! options: %s", templateOptions);
if (templateOptions.getLoginPrivateKey() != null) {
String pem = templateOptions.getLoginPrivateKey();
KeyPair keyPair = KeyPair.builder().name(templateOptions.getKeyPairName())
.fingerprint(fingerprintPrivateKey(pem)).privateKey(pem).build();
keyPairCache.asMap().put(RegionAndName.fromRegionAndName(region, keyPair.getName()), keyPair);
}
}
boolean securityGroupExtensionPresent = novaApi.getSecurityGroupApi(region).isPresent();
List<Integer> inboundPorts = Ints.asList(templateOptions.getInboundPorts());
if (!templateOptions.getGroups().isEmpty()) {
checkArgument(securityGroupExtensionPresent,
"Security groups are required by options, but the extension is not available! options: %s",
templateOptions);
} else if (securityGroupExtensionPresent) {
if (templateOptions.getGroups().isEmpty() && !inboundPorts.isEmpty()) {
String securityGroupName = namingConvention.create().sharedNameForGroup(group);
try {
securityGroupCache.get(new RegionSecurityGroupNameAndPorts(region, securityGroupName, inboundPorts));
} catch (ExecutionException e) {
throw Throwables.propagate(e.getCause());
}
templateOptions.securityGroups(securityGroupName);
}
}
templateOptions.userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group);
return super.execute(group, count, mutableTemplate, goodNodes, badNodes, customizationResponses);
}