|
| 1 | +<!-- |
| 2 | +Copyright 2025 Google LLC |
| 3 | +
|
| 4 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +you may not use this file except in compliance with the License. |
| 6 | +You may obtain a copy of the License at |
| 7 | +
|
| 8 | + https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +
|
| 10 | +Unless required by applicable law or agreed to in writing, software |
| 11 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +See the License for the specific language governing permissions and |
| 14 | +limitations under the License. |
| 15 | +--> |
| 16 | + |
| 17 | +# Using the Compute Engine API |
| 18 | + |
| 19 | +The [Compute Engine] API allows you to create and run virtual machines (VMs) on |
| 20 | +Google Cloud. |
| 21 | + |
| 22 | +This guide shows you how to initialize the Compute Engine client library for |
| 23 | +Rust, and how to perform some basic operations using the library. |
| 24 | + |
| 25 | +## Pre-requisites |
| 26 | + |
| 27 | +The guide assumes you have an existing [Google Cloud project] with |
| 28 | +[billing enabled]. |
| 29 | + |
| 30 | +## Add the client library as a dependency |
| 31 | + |
| 32 | +Use `cargo` to add the necessary dependency: |
| 33 | + |
| 34 | +```toml |
| 35 | +cargo add google-cloud-compute-v1 |
| 36 | +``` |
| 37 | + |
| 38 | +## Create a virtual machine |
| 39 | + |
| 40 | +The client to create, and manipulate virtual machines is called `Instances`: |
| 41 | + |
| 42 | +```rust,ignore,noplayground |
| 43 | +{{#rustdoc_include ../samples/src/compute/quickstart.rs:client}} |
| 44 | +``` |
| 45 | + |
| 46 | +The client has several methods. For example `insert()` creates a new virtual |
| 47 | +machine: |
| 48 | + |
| 49 | +```rust,ignore,noplayground |
| 50 | +{{#rustdoc_include ../samples/src/compute/compute_instances_create.rs:all}} |
| 51 | +``` |
| 52 | + |
| 53 | +Note that this is a [long-running operation], you need to wait for its outcome, |
| 54 | +and verify if there are any errors. |
| 55 | + |
| 56 | +## Cleanup |
| 57 | + |
| 58 | +Delete the virtual machine using the console, or the `delete()` method: |
| 59 | + |
| 60 | +```rust,ignore,noplayground |
| 61 | +{{#rustdoc_include ../samples/src/compute/compute_instances_delete.rs:all}} |
| 62 | +``` |
| 63 | + |
| 64 | +## Next Steps |
| 65 | + |
| 66 | +- [Working with long-running operations](/working_with_long_running_operations.md) |
| 67 | +- [Configuring polling policies](/configuring_polling_policies.md) |
| 68 | +- [Compute Engine client libraries](https://cloud.google.com/compute/docs/api/libraries) |
| 69 | + |
| 70 | +[billing enabled]: https://cloud.google.com/billing/docs/how-to/verify-billing-enabled#confirm_billing_is_enabled_on_a_project |
| 71 | +[compute engine]: https://cloud.google.com/compute |
| 72 | +[google cloud project]: https://cloud.google.com/resource-manager/docs/creating-managing-projects |
| 73 | +[long-running operation]: /working_with_long_running_operations.md |
0 commit comments