use of com.google.cloud.compute.v1.ImagesClient in project java-docs-samples by GoogleCloudPlatform.
the class CreateInstancesAdvanced method createFromPublicImage.
// [END compute_instances_create_from_image]
// [END compute_instances_create_from_custom_image]
// [END compute_instances_create_from_image_plus_empty_disk]
// [END compute_instances_create_from_snapshot]
// [END compute_instances_create_from_image_plus_snapshot_disk]
// [END compute_instances_create_with_subnet]
// [START compute_instances_create_from_image]
/**
* Create a new VM instance with Debian 10 operating system.
*
* @param project project ID or project number of the Cloud project you want to use.
* @param zone name of the zone to create the instance in. For example: "us-west3-b"
* @param instanceName name of the new virtual machine (VM) instance.
* @return Instance object.
*/
public static Instance createFromPublicImage(String project, String zone, String instanceName) throws IOException, InterruptedException, ExecutionException, TimeoutException {
try (ImagesClient imagesClient = ImagesClient.create()) {
// List of public operating system (OS) images: https://cloud.google.com/compute/docs/images/os-details
Image image = imagesClient.getFromFamily("debian-cloud", "debian-10");
String diskType = String.format("zones/%s/diskTypes/pd-standard", zone);
Vector<AttachedDisk> disks = new Vector<>();
disks.add(diskFromImage(diskType, 10, true, image.getSelfLink()));
return createWithDisks(project, zone, instanceName, disks, "n1-standard-1", "global/networks/default", null);
}
}
use of com.google.cloud.compute.v1.ImagesClient in project java-docs-samples by GoogleCloudPlatform.
the class CreateInstancesAdvanced method createWithAdditionalDisk.
// [END compute_instances_create_from_custom_image]
// [START compute_instances_create_from_image_plus_empty_disk]
/**
* Create a new VM instance with Debian 10 operating system and a 11 GB additional empty disk.
*
* @param project project ID or project number of the Cloud project you want to use.
* @param zone name of the zone to create the instance in. For example: "us-west3-b"
* @param instanceName name of the new virtual machine (VM) instance.
* @return Instance object.
*/
public static Instance createWithAdditionalDisk(String project, String zone, String instanceName) throws IOException, InterruptedException, ExecutionException, TimeoutException {
try (ImagesClient imagesClient = ImagesClient.create()) {
// List of public operating system (OS) images: https://cloud.google.com/compute/docs/images/os-details
Image image = imagesClient.getFromFamily("debian-cloud", "debian-10");
String diskType = String.format("zones/%s/diskTypes/pd-standard", zone);
Vector<AttachedDisk> disks = new Vector<>();
disks.add(diskFromImage(diskType, 10, true, image.getSelfLink()));
disks.add(emptyDisk(diskType, 11));
return createWithDisks(project, zone, instanceName, disks, "n1-standard-1", "global/networks/default", null);
}
}
Aggregations