checkNotNull(template, "template was null");
checkNotNull(template.getOptions(), "template options was null");
checkArgument(template.getOptions().getClass().isAssignableFrom(GleSYSTemplateOptions.class),
"options class %s should have been assignable from GleSYSTemplateOptions", template.getOptions().getClass());
GleSYSTemplateOptions templateOptions = template.getOptions().as(GleSYSTemplateOptions.class);
CreateServerOptions createServerOptions = new CreateServerOptions();
createServerOptions.ip(templateOptions.getIp());
template.getOptions().userMetadata(ComputeServiceConstants.NODE_GROUP_KEY, group);
Map<String, String> md = metadataAndTagsAsCommaDelimitedValue(template.getOptions());
if (md.size() > 0) {
String description = Joiner.on('\n').withKeyValueSeparator("=").join(md);
// TODO: get glesys to stop stripping out equals and commas!
createServerOptions.description(base16().lowerCase().encode(description.getBytes(UTF_8)));
}
ServerSpec.Builder<?> builder = ServerSpec.builder();
builder.datacenter(template.getLocation().getId());
builder.templateName(template.getImage().getId());
builder.platform(template.getHardware().getHypervisor());
builder.memorySizeMB(template.getHardware().getRam());
builder.diskSizeGB(Math.round(template.getHardware().getVolumes().get(0).getSize()));
builder.cpuCores((int) template.getHardware().getProcessors().get(0).getCores());
builder.transferGB(templateOptions.getTransferGB());
ServerSpec spec = builder.build();
// use random root password unless one was provided via template options
String password = templateOptions.hasRootPassword() ? templateOptions.getRootPassword() : getRandomPassword();
logger.debug(">> creating new Server spec(%s) name(%s) options(%s)", spec, name, createServerOptions);
ServerDetails result = api.getServerApi().createWithHostnameAndRootPassword(spec, name, password,
createServerOptions);
logger.trace("<< server(%s)", result.getId());