Integer.valueOf(template.getImage().getId()));
Integer overrideCores = options.getOverrideCores();
Integer overrideRam = options.getOverrideRam();
VirtualMachine vm = VirtualMachine.builder(context, template.getVirtualAppliance(), virtualMachineTemplate) //
.nameLabel(name) //
.cpu(overrideCores != null ? overrideCores : totalCores(template.getHardware())) //
.ram(overrideRam != null ? overrideRam : template.getHardware().getRam()) //
.password(options.getVncPassword()) // Can be null
.build();
vm.save();
// Once the virtual machine is created, override the default network
// settings if needed.
// If no public ip is available in the virtual datacenter, the virtual
// machine will be assigned by default an ip address in the default
// private VLAN for the virtual datacenter.
Optional<PublicIp> publicIp = tryFind(template.getVirtualDatacenter().listPurchasedPublicIps(),
IpPredicates.<PublicIp> notUsed());
if (publicIp.isPresent()) {
logger.debug(">> Found available public ip %s", publicIp.get().getIp());
vm.setNics(Lists.<Ip<?, ?>> newArrayList(publicIp.get()));
} else {
logger.debug(">> No available public ip found. Using a private ip");
}
// This is an async operation, but jclouds already waits until the node is
// RUNNING, so there is no need to block here
vm.deploy();
return new NodeAndInitialCredentials<VirtualMachine>(vm, vm.getId().toString(), null);
}