/** * Returns an {@code ImageInfo} object given the image identity and an image configuration. Use * {@link DiskImageConfiguration} to create an image from an existing disk. Use {@link * StorageImageConfiguration} to create an image from a file stored in Google Cloud Storage. */ public static ImageInfo of(ImageId imageId, ImageConfiguration configuration) { return newBuilder(imageId, configuration).build(); }
/** * Creates an image for this disk given the image's name and description. * * @return a global operation if the image creation was successfully requested * @throws ComputeException upon failure */ public Operation createImage(String image, String description, OperationOption... options) { ImageInfo imageInfo = ImageInfo.newBuilder(ImageId.of(image), DiskImageConfiguration.of(getDiskId())) .setDescription(description) .build(); return compute.create(imageInfo, options); }
@Test public void testCreateImageWithDescription() { initializeExpectedDisk(4); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(GlobalOperationId.of("project", "op")) .build(); ImageId imageId = ImageId.of(IMAGE.getImage()); ImageInfo image = ImageInfo.newBuilder(imageId, DiskImageConfiguration.of(DISK_ID)) .setDescription("description") .build(); expect(compute.create(image)).andReturn(operation); replay(compute); initializeDisk(); assertSame(operation, disk.createImage(IMAGE.getImage(), "description")); }
@Test public void testCreateImageWithDescriptionAndOptions() { initializeExpectedDisk(4); expect(compute.getOptions()).andReturn(mockOptions); Operation operation = new Operation.Builder(serviceMockReturnsOptions) .setOperationId(GlobalOperationId.of("project", "op")) .build(); ImageId imageId = ImageId.of(IMAGE.getImage()); ImageInfo image = ImageInfo.newBuilder(imageId, DiskImageConfiguration.of(DISK_ID)) .setDescription("description") .build(); expect(compute.create(image, Compute.OperationOption.fields())).andReturn(operation); replay(compute); initializeDisk(); assertSame( operation, disk.createImage(IMAGE.getImage(), "description", Compute.OperationOption.fields())); }