简体   繁体   中英

Google Cloud Status Check using REST API?

I am looking for a REST API using which we can check the status of the Job. I am working in ServiceNow to do the Provision of the Virtual Instance using the REST API calls. I was able to create the REST calls successfully and the response received from the REST calls states that the STATUS:PENDING.

So, I want to check if the status has been changed from STATUS:PENDING to STATUS:DONE/READY. I want to check this using the REST API Call, is there any REST API call to check this.

https://developers.google.com/apis-explorer/?hl=en_US#p/compute/v1/

The above link is used in google API console to do Various Operations on VM.

You can send a GET request to https://www.googleapis.com/compute/v1/projects/project/zones/zone/instances/instance .

This will return an Instance Resource , which contains a status property.

You can find more info about the CE REST API here .

You can also check out this example in Java of sending a GET request based on this page

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(); 
   }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM