Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. public class ComputeExample {
  2. public static void main(String[] args) throws IOException, GeneralSecurityException {
  3. // Authentication is provided by the 'gcloud' tool when running locally
  4. // and by built-in service accounts when running on GAE, GCE, or GKE.
  5. GoogleCredential credential = GoogleCredential.getApplicationDefault();
  6.  
  7. // The createScopedRequired method returns true when running on GAE or a local developer
  8. // machine. In that case, the desired scopes must be passed in manually. When the code is
  9. // running in GCE, GKE or a Managed VM, the scopes are pulled from the GCE metadata server.
  10. // For more information, see
  11. // https://developers.google.com/identity/protocols/application-default-credentials
  12. if (credential.createScopedRequired()) {
  13. credential =
  14. credential.createScoped(
  15. Collections.singletonList("https://www.googleapis.com/auth/cloud-platform"));
  16. }
  17.  
  18. HttpTransport httpTransport = GoogleNetHttpTransport.newTrustedTransport();
  19. JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
  20. Compute computeService =
  21. new Compute.Builder(httpTransport, jsonFactory, credential)
  22. .setApplicationName("Google Cloud Platform Sample")
  23. .build();
  24.  
  25. // TODO: Change placeholders below to appropriate parameter values for the 'get' method:
  26.  
  27. // * Project ID for this request.
  28. String project = "";
  29.  
  30. // * The name of the zone for this request.
  31. String zone = "";
  32.  
  33. // * Name of the instance resource to return.
  34. String instance = "";
  35.  
  36. Compute.Instances.Get request = computeService.instances().get(project, zone, instance);
  37. Instance response = request.execute();
  38.  
  39. //I'm assuming there's a getStatus method here
  40. String status = response.getStatus();
  41. }
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement