private JsonHelper jsonHelper;
@Override
public List<Resource> create(GccProvisionContextObject po, int index, List<Resource> resources) throws Exception {
Stack stack = stackRepository.findById(po.getStackId());
GccCredential gccCredential = (GccCredential) stack.getCredential();
GccTemplate gccTemplate = (GccTemplate) stack.getTemplate();
List<AttachedDisk> listOfDisks = new ArrayList<>();
listOfDisks.addAll(getBootDiskList(resources, gccCredential, gccTemplate));
listOfDisks.addAll(getAttachedDisks(resources, gccCredential, gccTemplate));
String name = String.format("%s-%s", stack.getName(), index);
Instance instance = new Instance();
instance.setMachineType(String.format("https://www.googleapis.com/compute/v1/projects/%s/zones/%s/machineTypes/%s",
po.getProjectId(), gccTemplate.getGccZone().getValue(), gccTemplate.getGccInstanceType().getValue()));
instance.setName(name);
instance.setCanIpForward(Boolean.TRUE);
instance.setNetworkInterfaces(getNetworkInterface(po.getProjectId(), stack.getName()));
instance.setDisks(listOfDisks);
Metadata metadata = new Metadata();
metadata.setItems(Lists.<Metadata.Items>newArrayList());
Metadata.Items sshMetaData = new Metadata.Items();
sshMetaData.setKey("sshKeys");
sshMetaData.setValue("ubuntu:" + gccCredential.getPublicKey());
Metadata.Items startupScript = new Metadata.Items();
startupScript.setKey("startup-script");
startupScript.setValue(po.getUserData());
metadata.getItems().add(sshMetaData);
metadata.getItems().add(startupScript);
instance.setMetadata(metadata);
Compute.Instances.Insert ins =
po.getCompute().instances().insert(gccCredential.getProjectId(), gccTemplate.getGccZone().getValue(), instance);
ins.setPrettyPrint(Boolean.TRUE);
ins.execute();
GccInstanceReadyPollerObject gccInstanceReady = new GccInstanceReadyPollerObject(po.getCompute(), stack, name);
gccInstanceReadyPollerObjectPollingService.pollWithTimeout(gccInstanceReadyCheckerStatus, gccInstanceReady, POLLING_INTERVAL, MAX_POLLING_ATTEMPTS);