Skip to content

Commit 03ab53f

Browse files
committed
docs(compute/v1): initial user guide
1 parent b5f3708 commit 03ab53f

6 files changed

Lines changed: 102 additions & 5 deletions

File tree

guide/samples/src/compute.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ pub mod compute_instances_list_all;
2525
pub mod compute_instances_operation_check;
2626
pub mod compute_usage_report_get;
2727
pub mod compute_usage_report_set;
28+
pub mod quickstart;
2829

2930
pub async fn cleanup_stale_instances(client: &Instances, project_id: &str) -> anyhow::Result<()> {
3031
use google_cloud_wkt::Timestamp;

guide/samples/src/compute/compute_instances_create.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// [START compute_instances_create]
15+
// [START compute_instances_create] ANCHOR: all
1616
use google_cloud_compute_v1::client::Instances;
1717
use google_cloud_compute_v1::model::{
1818
AttachedDisk, AttachedDiskInitializeParams, Instance, NetworkInterface,
@@ -49,4 +49,4 @@ pub async fn sample(client: &Instances, project_id: &str, name: &str) -> anyhow:
4949

5050
Ok(())
5151
}
52-
// [END compute_instances_create]
52+
// [END compute_instances_create] ANCHOR_END: all

guide/samples/src/compute/compute_instances_delete.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15-
// [START compute_instances_delete]
15+
// [START compute_instances_delete] ANCHOR: all
1616
use google_cloud_compute_v1::client::Instances;
1717
use google_cloud_lro::Poller;
1818

@@ -32,4 +32,4 @@ pub async fn sample(client: &Instances, project_id: &str, name: &str) -> anyhow:
3232

3333
Ok(())
3434
}
35-
// [END compute_instances_delete]
35+
// [END compute_instances_delete] ANCHOR_END: all
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2025 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// https://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
pub async fn quickstart() -> anyhow::Result<()> {
16+
// [START rust_compute_instances_client] ANCHOR: client
17+
use google_cloud_compute_v1::client::Instances;
18+
let client = Instances::builder().build().await?;
19+
// [END rust_compute_instances_client] ANCHOR_END: client
20+
let _ = client;
21+
Ok(())
22+
}

guide/src/SUMMARY.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<!--
1+
<!--
22
Copyright 2025 Google LLC
33
44
Licensed under the Apache License, Version 2.0 (the "License");
@@ -27,6 +27,7 @@ limitations under the License.
2727
- [Speed up large object downloads](storage/striped_downloads.md)
2828
- [Use errors to terminate uploads](storage/terminate_uploads.md)
2929
- [How to write tests using the Storage client](storage/mocking.md)
30+
- [Using the Compute Engine API](compute.md)
3031
- [Update a resource using a field mask](update_resource.md)
3132
- [Configuring retry policies](configuring_retry_policies.md)
3233
- [Error handling](error_handling.md)

guide/src/compute.md

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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

Comments
 (0)