Skip navigation links

Package com.google.cloud.compute.deprecated

A client for Google Compute Engine – High-performance, scalable virtual machines.

See: Description

Package com.google.cloud.compute.deprecated Description

A client for Google Compute Engine – High-performance, scalable virtual machines.

Here's a simple usage example for using google-cloud from App/Compute Engine. This example shows how to create a snapshot from an existing disk. For the complete source code see CreateSnapshot.java.


 Compute compute = ComputeOptions.getDefaultInstance().getService();
 DiskId diskId = DiskId.of("us-central1-a", "disk-name");
 Disk disk = compute.getDisk(diskId, Compute.DiskOption.fields());
 if (disk != null) {
   String snapshotName = "disk-name-snapshot";
   Operation operation = disk.createSnapshot(snapshotName);
   operation = operation.waitFor();
   if (operation.getErrors() == null) {
     // use snapshot
     Snapshot snapshot = compute.getSnapshot(snapshotName);
   }
 }
 

This second example shows how to create a virtual machine instance. Complete source code can be found at CreateInstance.java.


 Compute compute = ComputeOptions.getDefaultInstance().getService();
 ImageId imageId = ImageId.of("debian-cloud", "debian-8-jessie-v20160329");
 NetworkId networkId = NetworkId.of("default");
 AttachedDisk attachedDisk = AttachedDisk.of(AttachedDisk.CreateDiskConfiguration.of(imageId));
 NetworkInterface networkInterface = NetworkInterface.of(networkId);
 InstanceId instanceId = InstanceId.of("us-central1-a", "instance-name");
 MachineTypeId machineTypeId = MachineTypeId.of("us-central1-a", "n1-standard-1");
 Operation operation =
     compute.create(InstanceInfo.of(instanceId, machineTypeId, attachedDisk, networkInterface));
 operation = operation.waitFor();
 if (operation.getErrors() == null) {
   // use instance
   Instance instance = compute.getInstance(instanceId);
 }
 
See Also:
Google Cloud Compute
Skip navigation links

Copyright © 2019 Google LLC. All rights reserved.