Search in sources :

Example 1 with ListPagedResponse

use of com.google.cloud.compute.v1.InstanceTemplatesClient.ListPagedResponse in project java-docs-samples by GoogleCloudPlatform.

the class ListInstanceTemplates method listInstanceTemplates.

// Get a list of InstanceTemplate objects available in a project.
public static ListPagedResponse listInstanceTemplates(String projectId) throws IOException {
    try (InstanceTemplatesClient instanceTemplatesClient = InstanceTemplatesClient.create()) {
        int count = 0;
        System.out.println("Listing instance templates...");
        ListPagedResponse templates = instanceTemplatesClient.list(projectId);
        for (InstanceTemplate instanceTemplate : templates.iterateAll()) {
            System.out.printf("%s. %s%n", ++count, instanceTemplate.getName());
        }
        return templates;
    }
}
Also used : ListPagedResponse(com.google.cloud.compute.v1.InstanceTemplatesClient.ListPagedResponse) InstanceTemplatesClient(com.google.cloud.compute.v1.InstanceTemplatesClient) InstanceTemplate(com.google.cloud.compute.v1.InstanceTemplate)

Aggregations

InstanceTemplate (com.google.cloud.compute.v1.InstanceTemplate)1 InstanceTemplatesClient (com.google.cloud.compute.v1.InstanceTemplatesClient)1 ListPagedResponse (com.google.cloud.compute.v1.InstanceTemplatesClient.ListPagedResponse)1