use of org.jclouds.compute.domain.TemplateBuilder in project iobserve-analysis by research-iobserve.
the class AllocateActionScript method execute.
@Override
public void execute() throws RunNodesException {
final ResourceContainer container = this.action.getTargetResourceContainer();
final ResourceContainerCloud cloudContainer = this.getResourceContainerCloud(container);
final ComputeService client = this.getComputeServiceForContainer(cloudContainer);
final TemplateBuilder templateBuilder = client.templateBuilder();
final VMType instanceType = cloudContainer.getInstanceType();
templateBuilder.hardwareId(instanceType.getName());
templateBuilder.locationId(instanceType.getLocation());
// TODO maybe make this configurable
templateBuilder.osFamily(OsFamily.UBUNTU);
final Statement setupAdminInstructions = AdminAccess.standard();
// Necessary to set hostname to allow mapping for later events
final TemplateOptions options = Builder.runScript(setupAdminInstructions).runScript(AllocateActionScript.getChangeHostnameScript(cloudContainer)).runScript(this.getStartupScript());
templateBuilder.options(options);
final Template template = templateBuilder.build();
final String groupName = ModelHelper.getGroupName(cloudContainer);
final NodeMetadata node = Iterables.getOnlyElement(client.createNodesInGroup(groupName, 1, template));
AllocateActionScript.LOGGER.info(String.format("Allocated node for resource container '%s'. NodeID: %s, Hostname: %s, Adresses: %s", cloudContainer.getEntityName(), node.getId(), node.getHostname(), Iterables.concat(node.getPrivateAddresses(), node.getPublicAddresses())));
// TODO write resource container to original model to enable mapping
}
Aggregations