// TODO: Fix this!
String instanceName = "pl-" + UUID.randomUUID().toString();
Operation createServerOperation;
{
Instance create = new Instance();
create.setName(instanceName);
create.setZone(buildZoneUrl(projectId, ZONE_US_CENTRAL1_A));
{
NetworkInterface networkInterface = new NetworkInterface();
networkInterface.setNetwork(buildNetworkUrl(projectId, "default"));
AccessConfig networkAccessConfig = new AccessConfig();
networkAccessConfig.setType("ONE_TO_ONE_NAT");
networkInterface.setAccessConfigs(Lists.newArrayList(networkAccessConfig));
create.setNetworkInterfaces(Lists.newArrayList(networkInterface));
}
Metadata metadata = new Metadata();
metadata.setItems(Lists.<Items> newArrayList());
create.setMetadata(metadata);
if (request.tags != null) {
for (Tag tag : request.tags) {
Metadata.Items meta = new Metadata.Items();
meta.setKey(tag.getKey());
meta.setValue(tag.getValue());
metadata.getItems().add(meta);
}
}
if (request.sshPublicKey != null) {
Metadata.Items meta = new Metadata.Items();
meta.setKey("sshKeys");
meta.setValue(USER_NAME + ":" + OpenSshUtils.serialize(sshPublicKey));
metadata.getItems().add(meta);
}
create.setImage(foundImage.getSelfLink());
MachineType flavor = getClosestInstanceType(request);
if (flavor == null) {
throw new OpsException("Cannot determine machine type for request");
}
create.setMachineType(flavor.getSelfLink());
if (request.securityGroups != null) {
// TODO: Reimplement if needed
throw new UnsupportedOperationException();
}
// if (createdSecurityGroup != null) {
// ServerForCreate.SecurityGroup serverSecurityGroup = new ServerForCreate.SecurityGroup();
// serverSecurityGroup.setName(createdSecurityGroup.getName());
// create.getSecurityGroups().add(serverSecurityGroup);
// }
// create.setConfigDrive(cloudBehaviours.useConfigDrive());
log.info("Launching new server: " + instanceName);
try {
createServerOperation = compute.instances().insert(projectId, create).execute();
} catch (IOException e) {
throw new OpsException("Error launching new instance", e);
}
}
log.info("Waiting for server to be ready");
createServerOperation = waitComplete(createServerOperation, 10, TimeUnit.MINUTES);
Instance created;
InstanceState state = null;
while (true) {
created = findInstanceByName(instanceName);