Here are the examples of the java api class com.google.cloud.compute.ImageDiskConfiguration taken from open source projects.
1. ITComputeTest#testCreateGetAndDeleteImageDisk()
Project: gcloud-java
File: ITComputeTest.java
File: ITComputeTest.java
@Test public void testCreateGetAndDeleteImageDisk() throws InterruptedException, TimeoutException { String name = BASE_RESOURCE_NAME + "create-and-get-image-disk"; DiskId diskId = DiskId.of(ZONE, name); DiskInfo diskInfo = DiskInfo.of(diskId, ImageDiskConfiguration.of(IMAGE_ID)); Operation operation = compute.create(diskInfo); operation.waitFor(); // test get Disk remoteDisk = compute.getDisk(diskId); assertNotNull(remoteDisk); assertEquals(ZONE, remoteDisk.diskId().zone()); assertEquals(diskId.disk(), remoteDisk.diskId().disk()); assertEquals(DiskInfo.CreationStatus.READY, remoteDisk.creationStatus()); assertNotNull(remoteDisk.creationTimestamp()); assertNotNull(remoteDisk.generatedId()); assertTrue(remoteDisk.configuration() instanceof ImageDiskConfiguration); ImageDiskConfiguration remoteConfiguration = remoteDisk.configuration(); assertEquals(IMAGE_ID, remoteConfiguration.sourceImage()); assertNotNull(remoteConfiguration.sourceImageId()); assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.type()); assertNotNull(remoteConfiguration.sizeGb()); assertEquals("pd-standard", remoteConfiguration.diskType().type()); assertNull(remoteDisk.lastAttachTimestamp()); assertNull(remoteDisk.lastDetachTimestamp()); // test get with selected fields remoteDisk = compute.getDisk(diskId, Compute.DiskOption.fields()); assertNotNull(remoteDisk); assertEquals(ZONE, remoteDisk.diskId().zone()); assertEquals(diskId.disk(), remoteDisk.diskId().disk()); assertNull(remoteDisk.creationTimestamp()); assertNull(remoteDisk.generatedId()); assertTrue(remoteDisk.configuration() instanceof ImageDiskConfiguration); remoteConfiguration = remoteDisk.configuration(); assertEquals(IMAGE_ID, remoteConfiguration.sourceImage()); assertNull(remoteConfiguration.sourceImageId()); assertEquals(DiskConfiguration.Type.IMAGE, remoteConfiguration.type()); assertNull(remoteConfiguration.sizeGb()); assertEquals("pd-standard", remoteConfiguration.diskType().type()); assertNull(remoteDisk.lastAttachTimestamp()); assertNull(remoteDisk.lastDetachTimestamp()); operation = remoteDisk.delete(); operation.waitFor(); assertNull(compute.getDisk(diskId)); }
2. CreateAddressDiskAndInstance#main()
Project: gcloud-java
File: CreateAddressDiskAndInstance.java
File: CreateAddressDiskAndInstance.java
public static void main(String... args) throws InterruptedException, TimeoutException { // Create a service object // Credentials are inferred from the environment. Compute compute = ComputeOptions.defaultInstance().service(); // Create an external region address RegionAddressId addressId = RegionAddressId.of("us-central1", "test-address"); Operation operation = compute.create(AddressInfo.of(addressId)); // Wait for operation to complete operation = operation.waitFor(); if (operation.errors() == null) { System.out.println("Address " + addressId + " was successfully created"); } else { // inspect operation.errors() throw new RuntimeException("Address creation failed"); } // Create a persistent disk ImageId imageId = ImageId.of("debian-cloud", "debian-8-jessie-v20160329"); DiskId diskId = DiskId.of("us-central1-a", "test-disk"); ImageDiskConfiguration diskConfiguration = ImageDiskConfiguration.of(imageId); DiskInfo disk = DiskInfo.of(diskId, diskConfiguration); operation = compute.create(disk); // Wait for operation to complete operation = operation.waitFor(); if (operation.errors() == null) { System.out.println("Disk " + diskId + " was successfully created"); } else { // inspect operation.errors() throw new RuntimeException("Disk creation failed"); } // Create a virtual machine instance Address externalIp = compute.getAddress(addressId); InstanceId instanceId = InstanceId.of("us-central1-a", "test-instance"); NetworkId networkId = NetworkId.of("default"); PersistentDiskConfiguration attachConfiguration = PersistentDiskConfiguration.builder(diskId).boot(true).build(); AttachedDisk attachedDisk = AttachedDisk.of("dev0", attachConfiguration); NetworkInterface networkInterface = NetworkInterface.builder(networkId).accessConfigurations(AccessConfig.of(externalIp.address())).build(); MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1"); InstanceInfo instance = InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface); operation = compute.create(instance); // Wait for operation to complete operation = operation.waitFor(); if (operation.errors() == null) { System.out.println("Instance " + instanceId + " was successfully created"); } else { // inspect operation.errors() throw new RuntimeException("Instance creation failed"); } }