forked from Azure/azure-sdk-for-rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
vm_list.rs
30 lines (25 loc) · 869 Bytes
/
vm_list.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
/*
Lists the virtual , similar to:
az vm list --query [].id
cargo run --package azure_mgmt_compute --example vm_list
*/
use azure_identity::AzureCliCredential;
use futures::stream::StreamExt;
use std::sync::Arc;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let credential = Arc::new(AzureCliCredential::new());
let subscription_id = AzureCliCredential::get_subscription().await?;
let client = azure_mgmt_compute::Client::builder(credential).build()?;
let mut count = 0;
let mut vms = client.virtual_machines_client().list_all(subscription_id).into_stream();
while let Some(vms) = vms.next().await {
let vms = vms?;
count += vms.value.len();
for vm in vms.value {
println!("{:?}", &vm.resource.id);
}
}
println!("# of virtual machines {count}");
Ok(())
}