Here are the examples of the java api class com.google.cloud.compute.AttachedDisk.PersistentDiskConfiguration taken from open source projects.
1. AttachedDiskTest#testConfigurationSetProjectId()
Project: gcloud-java
File: AttachedDiskTest.java
File: AttachedDiskTest.java
@Test public void testConfigurationSetProjectId() { PersistentDiskConfiguration persistentConfiguration = PersistentDiskConfiguration.of(DiskId.of("zone", "disk")); comparePersistentDiskConfiguration(PersistentDiskConfiguration.of(DiskId.of("project", "zone", "disk")), persistentConfiguration.setProjectId("project")); ScratchDiskConfiguration scratchDiskConfiguration = ScratchDiskConfiguration.of(DiskTypeId.of("zone", "diskType")); compareScratchDiskConfiguration(ScratchDiskConfiguration.of(DiskTypeId.of("project", "zone", "diskType")), scratchDiskConfiguration.setProjectId("project")); CreateDiskConfiguration createDiskConfiguration = CREATE_DISK_CONFIGURATION.toBuilder().diskType(DiskTypeId.of("zone", "diskType")).sourceImage(ImageId.of("image")).build(); compareCreateDiskConfiguration(CREATE_DISK_CONFIGURATION, createDiskConfiguration.setProjectId("project")); }
2. AttachedDiskTest#testConfigurationToBuilderIncomplete()
Project: gcloud-java
File: AttachedDiskTest.java
File: AttachedDiskTest.java
@Test public void testConfigurationToBuilderIncomplete() { PersistentDiskConfiguration persistentConfiguration = PersistentDiskConfiguration.of(DISK_ID); comparePersistentDiskConfiguration(persistentConfiguration, AttachedDisk.AttachedDiskConfiguration.<PersistentDiskConfiguration>fromPb(persistentConfiguration.toPb())); ScratchDiskConfiguration scratchDiskConfiguration = ScratchDiskConfiguration.of(DISK_TYPE_ID); compareScratchDiskConfiguration(scratchDiskConfiguration, AttachedDisk.AttachedDiskConfiguration.<ScratchDiskConfiguration>fromPb(scratchDiskConfiguration.toPb())); CreateDiskConfiguration createDiskConfiguration = CreateDiskConfiguration.of(IMAGE_ID); compareCreateDiskConfiguration(createDiskConfiguration, AttachedDisk.AttachedDiskConfiguration.<CreateDiskConfiguration>fromPb(createDiskConfiguration.toPb())); }
3. AttachedDiskTest#testSetProjectId()
Project: gcloud-java
File: AttachedDiskTest.java
File: AttachedDiskTest.java
@Test public void testSetProjectId() { PersistentDiskConfiguration persistentConfiguration = PersistentDiskConfiguration.of(DiskId.of("zone", "disk")); PersistentDiskConfiguration persistentConfigurationWithProject = PersistentDiskConfiguration.of(DiskId.of("project", "zone", "disk")); AttachedDisk attachedDisk = AttachedDisk.of(persistentConfiguration); compareAttachedDisk(AttachedDisk.of(persistentConfigurationWithProject), attachedDisk.setProjectId("project")); ScratchDiskConfiguration scratchDiskConfiguration = ScratchDiskConfiguration.of(DiskTypeId.of("zone", "diskType")); ScratchDiskConfiguration scratchDiskConfigurationWithProject = ScratchDiskConfiguration.of(DiskTypeId.of("project", "zone", "diskType")); compareAttachedDisk(AttachedDisk.of(scratchDiskConfigurationWithProject), AttachedDisk.of(scratchDiskConfiguration).setProjectId("project")); CreateDiskConfiguration createDiskConfiguration = CreateDiskConfiguration.of(ImageId.of("image")); CreateDiskConfiguration createDiskConfigurationWithProject = CreateDiskConfiguration.of(ImageId.of("project", "image")); compareAttachedDisk(AttachedDisk.of(createDiskConfigurationWithProject), AttachedDisk.of(createDiskConfiguration).setProjectId("project")); createDiskConfiguration = CREATE_DISK_CONFIGURATION.toBuilder().diskType(DiskTypeId.of("zone", "diskType")).sourceImage(ImageId.of("image")).build(); compareAttachedDisk(AttachedDisk.of(CREATE_DISK_CONFIGURATION), AttachedDisk.of(createDiskConfiguration).setProjectId("project")); }
4. 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"); } }
5. AttachedDiskTest#testConfigurationToAndFromPb()
Project: gcloud-java
File: AttachedDiskTest.java
File: AttachedDiskTest.java
@Test public void testConfigurationToAndFromPb() { PersistentDiskConfiguration persistentConfiguration = PersistentDiskConfiguration.of(DISK_ID); comparePersistentDiskConfiguration(persistentConfiguration, AttachedDisk.AttachedDiskConfiguration.<PersistentDiskConfiguration>fromPb(persistentConfiguration.toPb())); comparePersistentDiskConfiguration(PERSISTENT_DISK_CONFIGURATION, AttachedDisk.AttachedDiskConfiguration.<PersistentDiskConfiguration>fromPb(PERSISTENT_DISK_CONFIGURATION.toPb())); ScratchDiskConfiguration scratchDiskConfiguration = ScratchDiskConfiguration.of(DISK_TYPE_ID); compareScratchDiskConfiguration(scratchDiskConfiguration, AttachedDisk.AttachedDiskConfiguration.<ScratchDiskConfiguration>fromPb(scratchDiskConfiguration.toPb())); compareScratchDiskConfiguration(SCRATCH_DISK_CONFIGURATION, AttachedDisk.AttachedDiskConfiguration.<ScratchDiskConfiguration>fromPb(SCRATCH_DISK_CONFIGURATION.toPb())); CreateDiskConfiguration createDiskConfiguration = CreateDiskConfiguration.of(IMAGE_ID); compareCreateDiskConfiguration(createDiskConfiguration, AttachedDisk.AttachedDiskConfiguration.<CreateDiskConfiguration>fromPb(createDiskConfiguration.toPb())); compareCreateDiskConfiguration(CREATE_DISK_CONFIGURATION, AttachedDisk.AttachedDiskConfiguration.<CreateDiskConfiguration>fromPb(CREATE_DISK_CONFIGURATION.toPb())); }
6. AttachedDiskTest#testConfigurationOf()
Project: gcloud-java
File: AttachedDiskTest.java
File: AttachedDiskTest.java
@Test public void testConfigurationOf() { PersistentDiskConfiguration persistentConfiguration = PersistentDiskConfiguration.of(DISK_ID); assertEquals(DISK_ID, persistentConfiguration.sourceDisk()); assertEquals(Type.PERSISTENT, persistentConfiguration.type()); assertNull(persistentConfiguration.autoDelete()); assertNull(persistentConfiguration.boot()); assertNull(persistentConfiguration.interfaceType()); ScratchDiskConfiguration scratchDiskConfiguration = ScratchDiskConfiguration.of(DISK_TYPE_ID); assertEquals(DISK_TYPE_ID, scratchDiskConfiguration.diskType()); assertNull(scratchDiskConfiguration.interfaceType()); assertEquals(Type.SCRATCH, scratchDiskConfiguration.type()); assertTrue(scratchDiskConfiguration.autoDelete()); assertFalse(scratchDiskConfiguration.boot()); assertNull(scratchDiskConfiguration.interfaceType()); CreateDiskConfiguration createDiskConfiguration = CreateDiskConfiguration.of(IMAGE_ID); assertEquals(IMAGE_ID, createDiskConfiguration.sourceImage()); assertNull(createDiskConfiguration.diskType()); assertNull(createDiskConfiguration.diskName()); assertNull(createDiskConfiguration.diskSizeGb()); assertNull(createDiskConfiguration.interfaceType()); assertEquals(Type.PERSISTENT, createDiskConfiguration.type()); assertNull(createDiskConfiguration.autoDelete()); assertTrue(createDiskConfiguration.boot()); assertNull(createDiskConfiguration.interfaceType()); }
7. AttachedDiskTest#testConfigurationToBuilder()
Project: gcloud-java
File: AttachedDiskTest.java
File: AttachedDiskTest.java
@Test public void testConfigurationToBuilder() { comparePersistentDiskConfiguration(PERSISTENT_DISK_CONFIGURATION, PERSISTENT_DISK_CONFIGURATION.toBuilder().build()); compareScratchDiskConfiguration(SCRATCH_DISK_CONFIGURATION, SCRATCH_DISK_CONFIGURATION.toBuilder().build()); compareCreateDiskConfiguration(CREATE_DISK_CONFIGURATION, CREATE_DISK_CONFIGURATION.toBuilder().build()); PersistentDiskConfiguration persistentDiskConfiguration = PERSISTENT_DISK_CONFIGURATION.toBuilder().autoDelete(false).build(); assertFalse(persistentDiskConfiguration.autoDelete()); persistentDiskConfiguration = persistentDiskConfiguration.toBuilder().autoDelete(AUTO_DELETE).build(); assertEquals(PERSISTENT_DISK_CONFIGURATION, persistentDiskConfiguration); ScratchDiskConfiguration scratchDiskConfiguration = SCRATCH_DISK_CONFIGURATION.toBuilder().interfaceType(InterfaceType.SCSI).build(); assertEquals(InterfaceType.SCSI, scratchDiskConfiguration.interfaceType()); scratchDiskConfiguration = scratchDiskConfiguration.toBuilder().interfaceType(INTERFACE_TYPE).build(); assertEquals(SCRATCH_DISK_CONFIGURATION, scratchDiskConfiguration); CreateDiskConfiguration createDiskConfiguration = CREATE_DISK_CONFIGURATION.toBuilder().autoDelete(false).build(); assertFalse(createDiskConfiguration.autoDelete()); createDiskConfiguration = createDiskConfiguration.toBuilder().autoDelete(AUTO_DELETE).build(); assertEquals(CREATE_DISK_CONFIGURATION, createDiskConfiguration); }