}
InstanceBase buildInstanceTemplate(MachineCreationRequest request, PlatformLayerKey parent) throws OpsException {
MachineProvider targetCloud = scheduler.pickCloud(request);
InstanceBase machine = targetCloud.buildInstanceTemplate(request);
machine.sshPublicKey = SshKeys.serialize(request.sshPublicKey);
machine.recipeId = request.recipeId;
if (request.publicPorts != null) {
if (machine.publicPorts == null) {
machine.publicPorts = Lists.newArrayList();
}
machine.publicPorts.addAll(request.publicPorts);
}
machine.getTags().addAll(request.tags);
if (parent != null) {
machine.getTags().add(Tag.buildParentTag(parent));
}
machine.cloud = targetCloud.getModel().getKey();
machine.hostPolicy = request.hostPolicy;
String id = request.hostname;
if (Strings.isNullOrEmpty(id)) {
id = UUID.randomUUID().toString();
}
machine.setKey(PlatformLayerKey.fromId(id));
return machine;
}