2016-12-06 35 views
0

我正在尋找一個REST API,使用它我們可以檢查作業的狀態。我正在ServiceNow中使用REST API調用來執行虛擬實例的提供。我能夠成功創建REST調用,並且從REST調用收到的響應指出STATUS:PENDING。Google雲狀態使用REST API進行檢查?

所以,我想檢查狀態是否已經從STATUS:PENDING更改爲STATUS:DONE/READY。我想用REST API調用來檢查這個,有沒有REST API調用來檢查這個。

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

上述鏈路被用於在谷歌API控制檯執行VM上的各種操作。

+1

你是問如何查詢你剛剛推出的一個實例的狀態?您可以使用compute.instances.get(請參閱https://cloud.google.com/compute/docs/reference/latest/instances/get)。 – jarmod

回答

0

您可以發送GET請求到https://www.googleapis.com/compute/v1/projects/project/zones/zone/instances/instance

這將返回一個Instance Resource,其中包含status屬性。

你可以找到更多關於CE REST API here的信息。

您還可以檢查出發送GET請求的Java的這個例子基於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(); 
    } 
}