A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cloud.google.com/compute/docs/api/using-libraries below:

Using client libraries | Compute Engine Documentation

Skip to main content Using client libraries

Stay organized with collections Save and categorize content based on your preferences.

This document demonstrates how to use Cloud Client Libraries for Compute Engine. It describes how to list, create, and delete virtual machine (VM) instances. It also describes how to check the status of a long-running operation. You can run code samples from your local machine or on a VM instance, provided that you have authorized the sample correctly.

For a full list of available client libraries, including other client libraries and third-party open source libraries, see Compute Engine Client Libraries.

Costs

In this document, you use the following billable components of Google Cloud:

To generate a cost estimate based on your projected usage, use the pricing calculator.

New Google Cloud users might be eligible for a

free trial

.

Before you begin

Before you begin, follow the installation and authentication setup steps on Compute Engine Client Libraries for the client library you want to use.

The examples in this document require you to provide information about the VM you want to create, like its location, machine type, and source image. For details on those values, see the following documents:

Creating an instance

The following example defines an instance that uses a specified name, machine type, network, source image, and disk. Then, it creates (inserts) the instance in a project and zone that you provide. In this example, the instance connects to the default network, which is created automatically for every project. You receive a message back when the API successfully creates the instance.

When you create a virtual machine (VM) instance, you must also attach a boot disk to the VM. The boot disk contains all of the necessary files required for starting a VM, including a public or custom OS image.

C# Go Java Node.js PHP Python Ruby Listing instances

The following examples list instances in a project, either in one zone or across all zones:

C#

You can also get a list of instances across all zones in your project:

Go

You can also get a list of instances across all zones in your project:

Java

You can also get a list of instances across all zones in your project:

Node.js

You can also get a list of instances across all zones in your project:

PHP

You can also get a list of instances across all zones in your project:

Python

You can also get a list of instances across all zones in your project:

Ruby

You can also get a list of instances across all zones in your project:

Deleting an instance

The following example deletes an instance based on the project, zone, and instance name that you provide. You receive a message back when the API successfully deletes the instance.

The delete operation is irreversible. When you only want to turn off an instance temporarily, consider stopping or suspending the instance instead.

If the autoDelete parameter is true for the instance, you also delete the boot disk when you delete the instance. This setting is set to true by default during instance creation, and you can adjust it when your use case calls for disks and instances to be deleted separately.

C# Go Java Node.js PHP Python Ruby Checking operation status

Requests to the Compute Engine API that modify resources such as instances immediately return a response acknowledging your request. The acknowledgement includes information about the status of the requested operation.

Depending on the nature of the operation, it can take some time to complete. The following example waits until an operation completes before continuing code execution:

C# Go Java Node.js PHP Python Ruby Handling default values

For some fields that you choose not to send in requests or don't receive in responses, the Compute Engine API assumes non-zero default values. Google specifies these default values in API reference field descriptions and in the comments of the protocol buffers that the client libraries are built on.

These protocol buffers are in protocol buffers v3 format and report a zero value for fields that aren't present, even when the Compute Engine API server uses a different default. Zero values for fields that aren't present are as follows: 0 for numbers, false for booleans, empty for strings.

In the protocol buffers that the Compute Engine Cloud Client Libraries are built on, all non-required fields are marked as proto3 optional. Consider a field named name marked as optional in a hypothetical protocol buffer message named MyRecord. For that field, do the following:

In general, check the API reference documentation to see how the server interprets an absent value or zero value for a field, as it varies by method.

For example, consider changing the prefix of the name of the usage report (reportNamePrefix) for your project. When the server receives an empty string value or doesn't receive the field at all, it uses a certain default value (usage_gce, as described in the reference for projects.setUsageExportBucket) to generate the report.

Although the server explicitly returns an empty string for reportNamePrefix, the reference for projects.get correctly indicates that the report is generated with the default value usage_gce for reportNamePrefix.

C#

Verify that the server used the default prefix value usage_gce:

Go

Verify that the server used the default prefix value usage_gce:

Java

Verify that the server used the default prefix value usage_gce:

Node.js

Verify that the server used the default prefix value usage_gce:

PHP

Verify that the server used the default prefix value usage_gce:

Python

Verify that the server used the default prefix value usage_gce:

Ruby

Verify that the server used the default prefix value usage_gce:

For more information on setting up usage exports, see Viewing usage reports.

Handling pagination

Some requests to the Compute Engine API return long lists of results, which the server provides to you as smaller "pages" of results with each call. When interacting with the API directly, you make multiple API requests to get responses for successive pages.

When you use Cloud Client Libraries, those requests simply return an iterator. You can then use the iterator to obtain all the individual results corresponding to your initial request. This process happens as though the results were returned in one long list. The client library silently issues any necessary API requests for additional pages to ensure your iterator automatically traverses the full set of results.

C#

You can also use the pages attribute of the returned object to have more granular control of iteration over paginated results from the API.

Go

You can also use the pages attribute of the returned object to have more granular control of iteration over paginated results from the API.

Java

You can also use the pages attribute of the returned object to have more granular control of iteration over paginated results from the API.

Node.js

You can also use the pages attribute of the returned object to have more granular control of iteration over paginated results from the API.

PHP

You can also use the pages attribute of the returned object to have more granular control of iteration over paginated results from the API.

Python

You can also use the pages attribute of the returned object to have more granular control of iteration over paginated results from the API.

Ruby

You can also use the pages attribute of the returned object to have more granular control of iteration over paginated results from the API.

Compute Engine in particular also offers aggregatedList methods like instances.aggregatedList. Pagination for those methods function similarly, but instead iterate over key-list pairs. For an example, see Listing instances.

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this tutorial, either delete the project that contains the resources, or keep the project and delete the individual resources.

When you're done experimenting, follow these cleanup instructions to avoid incurring charges for the virtual machine instance.

To delete a Compute Engine instance:

  1. In the Google Cloud console, go to the VM instances page.

    Go to VM instances

  2. Select the checkbox for the instance that you want to delete.
  3. To delete the instance, click more_vert More actions, click Delete, and then follow the instructions.
What's next Try it for yourself

If you're new to Google Cloud, create an account to evaluate how Compute Engine performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.

Try Compute Engine free

Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-08-07 UTC.

[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This document provides a guide on how to use Cloud Client Libraries to manage Compute Engine VM instances, including creating, listing, and deleting them."],["Code examples in C#, Go, Java, Node.js, PHP, Python, and Ruby are provided to demonstrate common VM operations like creating instances, listing instances in a zone or all zones, and deleting instances."],["The Compute Engine API allows setting a usage export bucket for detailed reports, and an empty `reportNamePrefix` will default to `usage_gce` across all language implementations."],["The Cloud Client Libraries offer iterators for automatic pagination when listing large numbers of results, but also allow for granular control by accessing individual pages."],["It's important to clean up resources, like deleting VM instances or the whole project, to avoid unnecessary billing charges."]]],[]]


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4