AttachedDisk.of( "dev0", AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); InstanceInfo instanceInfo = InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE))
AttachedDisk.of( "dev0", AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); InstanceInfo instanceInfo = InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE))
AttachedDisk.of( "dev0", AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); AttachedDisk disk2 = AttachedDisk.of(
AttachedDisk.of( "dev0", AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); InstanceInfo instanceInfo = InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE))
AttachedDisk.of( "dev0", AttachedDisk.CreateDiskConfiguration.newBuilder(IMAGE_ID).setAutoDelete(true).build()); InstanceInfo instanceInfo = InstanceInfo.newBuilder(instanceId, MachineTypeId.of(ZONE, MACHINE_TYPE))
.setDiskType(DiskTypeId.of("zone", "diskType")) .setSourceImage(ImageId.of("image")) .build(); compareAttachedDisk( AttachedDisk.of(CREATE_DISK_CONFIGURATION),
@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() .setDiskType(DiskTypeId.of("zone", "diskType")) .setSourceImage(ImageId.of("image")) .build(); compareCreateDiskConfiguration( CREATE_DISK_CONFIGURATION, createDiskConfiguration.setProjectId("project")); }
@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().setAutoDelete(false).build(); assertFalse(persistentDiskConfiguration.autoDelete()); persistentDiskConfiguration = persistentDiskConfiguration.toBuilder().setAutoDelete(AUTO_DELETE).build(); assertEquals(PERSISTENT_DISK_CONFIGURATION, persistentDiskConfiguration); ScratchDiskConfiguration scratchDiskConfiguration = SCRATCH_DISK_CONFIGURATION.toBuilder().setInterfaceType(InterfaceType.SCSI).build(); assertEquals(InterfaceType.SCSI, scratchDiskConfiguration.getInterfaceType()); scratchDiskConfiguration = scratchDiskConfiguration.toBuilder().setInterfaceType(INTERFACE_TYPE).build(); assertEquals(SCRATCH_DISK_CONFIGURATION, scratchDiskConfiguration); CreateDiskConfiguration createDiskConfiguration = CREATE_DISK_CONFIGURATION.toBuilder().setAutoDelete(false).build(); assertFalse(createDiskConfiguration.autoDelete()); createDiskConfiguration = createDiskConfiguration.toBuilder().setAutoDelete(AUTO_DELETE).build(); assertEquals(CREATE_DISK_CONFIGURATION, createDiskConfiguration); }
@SuppressWarnings("unchecked") static CreateDiskConfiguration fromPb( com.google.api.services.compute.model.AttachedDisk diskPb) { AttachedDiskInitializeParams initializeParamsPb = diskPb.getInitializeParams(); Builder builder = newBuilder(ImageId.fromUrl(initializeParamsPb.getSourceImage())); if (initializeParamsPb.getDiskType() != null) { builder.setDiskType(DiskTypeId.fromUrl(initializeParamsPb.getDiskType())); } builder.setDiskName(initializeParamsPb.getDiskName()); builder.setDiskSizeGb(initializeParamsPb.getDiskSizeGb()); builder.setAutoDelete(diskPb.getAutoDelete()); if (initializeParamsPb.getDiskType() != null) { builder.setDiskType(DiskTypeId.fromUrl(initializeParamsPb.getDiskType())); } return builder.build(); } }
/** * Returns a {@code CreateDiskConfiguration} object given the source image that will be used to * create the disk. */ public static CreateDiskConfiguration of(ImageId sourceImage) { return newBuilder(sourceImage).build(); }
@Override CreateDiskConfiguration setProjectId(String projectId) { Builder builder = toBuilder(); if (builder.diskType != null) { builder.setDiskType(diskType.setProjectId(projectId)); } if (builder.sourceImage != null) { builder.setSourceImage(sourceImage.setProjectId(projectId)); } return builder.build(); }