-
Notifications
You must be signed in to change notification settings - Fork 252
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
31 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
Lists the virtual , similar to: | ||
az vm list --query [].id | ||
export SUBSCRIPTION_ID=$(az account show --query id --output tsv) | ||
export ACCESS_TOKEN=$(az account get-access-token --query accessToken --output tsv) | ||
cargo run --example vm_list | ||
*/ | ||
|
||
use azure_compute_mgmt::{operations::virtual_machines, Result}; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
let subscription_id = &get_subscription_id()?; | ||
let access_token = &get_access_token()?; | ||
let config = &azure_compute_mgmt::Configuration::new(access_token); | ||
let vms = virtual_machines::list_all(config, subscription_id, None).await?; | ||
println!("# of virtual machines {}", vms.value.len()); | ||
for vm in &vms.value { | ||
println!("{:?}", &vm.resource.id); | ||
} | ||
Ok(()) | ||
} | ||
|
||
fn get_subscription_id() -> Result<String> { | ||
Ok(std::env::var("SUBSCRIPTION_ID").map_err(|_| "SUBSCRIPTION_ID required")?) | ||
} | ||
|
||
fn get_access_token() -> Result<String> { | ||
Ok(std::env::var("ACCESS_TOKEN").map_err(|_| "ACCESS_TOKEN required")?) | ||
} |