Search in sources :

Example 6 with DisksClient

use of com.google.cloud.compute.v1.DisksClient in project java-docs-samples by GoogleCloudPlatform.

the class InstancesAdvancedIT method createSnapshot.

private static Snapshot createSnapshot(Disk srcDisk) throws IOException, InterruptedException, ExecutionException, TimeoutException {
    try (SnapshotsClient snapshotsClient = SnapshotsClient.create();
        DisksClient disksClient = DisksClient.create()) {
        Snapshot snapshot = Snapshot.newBuilder().setName("test-snap-" + UUID.randomUUID()).build();
        OperationFuture<Operation, Operation> operation = disksClient.createSnapshotAsync(PROJECT_ID, ZONE, srcDisk.getName(), snapshot);
        operation.get(3, TimeUnit.MINUTES);
        return snapshotsClient.get(PROJECT_ID, snapshot.getName());
    }
}
Also used : Snapshot(com.google.cloud.compute.v1.Snapshot) SnapshotsClient(com.google.cloud.compute.v1.SnapshotsClient) Operation(com.google.cloud.compute.v1.Operation) DisksClient(com.google.cloud.compute.v1.DisksClient)

Example 7 with DisksClient

use of com.google.cloud.compute.v1.DisksClient in project java-docs-samples by GoogleCloudPlatform.

the class InstancesAdvancedIT method createSourceDisk.

private static Disk createSourceDisk() throws IOException, ExecutionException, InterruptedException, TimeoutException {
    try (DisksClient disksClient = DisksClient.create()) {
        Disk disk = Disk.newBuilder().setSourceImage(getActiveDebian().getSelfLink()).setName("test-disk-" + UUID.randomUUID()).build();
        OperationFuture<Operation, Operation> operation = disksClient.insertAsync(PROJECT_ID, ZONE, disk);
        // Wait for the operation to complete.
        operation.get(3, TimeUnit.MINUTES);
        return disksClient.get(PROJECT_ID, ZONE, disk.getName());
    }
}
Also used : Operation(com.google.cloud.compute.v1.Operation) Disk(com.google.cloud.compute.v1.Disk) DisksClient(com.google.cloud.compute.v1.DisksClient)

Aggregations

DisksClient (com.google.cloud.compute.v1.DisksClient)7 Operation (com.google.cloud.compute.v1.Operation)7 Disk (com.google.cloud.compute.v1.Disk)3 Snapshot (com.google.cloud.compute.v1.Snapshot)2 SnapshotsClient (com.google.cloud.compute.v1.SnapshotsClient)2 Image (com.google.cloud.compute.v1.Image)1 ImagesClient (com.google.cloud.compute.v1.ImagesClient)1 InsertImageRequest (com.google.cloud.compute.v1.InsertImageRequest)1 Instance (com.google.cloud.compute.v1.Instance)1 InstancesClient (com.google.cloud.compute.v1.InstancesClient)1