if (osVersion != null) {
builder.osVersionMatches(osVersion);
}
TemplateOptions options = service.templateOptions();
List<Statement> statements = Lists.newLinkedList();
if (adminAccess) {
statements.add(AdminAccess.standard());
}
if (recipes != null) {
for (String recipe : recipes) {
statements.add(recipeManager.createStatement(recipe, group));
}
}
if (ec2SecurityGroups != null) {
options.as(EC2TemplateOptions.class).securityGroups(ec2SecurityGroups);
}
if (ec2KeyPair != null) {
options.as(EC2TemplateOptions.class).keyPair(ec2KeyPair);
}
if (ec2NoKeyPair != null) {
options.as(EC2TemplateOptions.class).noKeyPair();
}
Set<? extends NodeMetadata> metadatas = null;
if (!statements.isEmpty()) {
options.runScript(new StatementList(statements));
}
try {
metadatas = service.createNodesInGroup(group, number, builder.options(options).build());
} catch (RunNodesException ex) {