Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ComputeExample {
- public static void main(String[] args) throws IOException, GeneralSecurityException {
- // Authentication is provided by the 'gcloud' tool when running locally
- // and by built-in service accounts when running on GAE, GCE, or GKE.
- GoogleCredential credential = GoogleCredential.getApplicationDefault();
- // The createScopedRequired method returns true when running on GAE or a local developer
- // machine. In that case, the desired scopes must be passed in manually. When the code is
- // running in GCE, GKE or a Managed VM, the scopes are pulled from the GCE metadata server.
- // For more information, see
- // https://developers.google.com/identity/protocols/application-default-credentials
- if (credential.createScopedRequired()) {
- credential =
- credential.createScoped(
- Collections.singletonList("https://www.googleapis.com/auth/cloud-platform"));
- }
- HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
- JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
- Compute computeService =
- new Compute.Builder(httpTransport, jsonFactory, credential)
- .setApplicationName("Google Cloud Platform Sample")
- .build();
- // TODO: Change placeholders below to appropriate parameter values for the 'get' method:
- // * Project ID for this request.
- String project = "";
- // * The name of the zone for this request.
- String zone = "";
- // * Name of the instance resource to return.
- String instance = "";
- Compute.Instances.Get request = computeService.instances().get(project, zone, instance);
- Instance response = request.execute();
- //I'm assuming there's a getStatus method here
- String status = response.getStatus();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement