Skip to content

Commit

Permalink
vm_list example
Browse files Browse the repository at this point in the history
  • Loading branch information
ctaggart committed Oct 15, 2020
1 parent 7fe6ad9 commit 563b786
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions services/compute/mgmt/examples/vm_list.rs
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")?)
}

0 comments on commit 563b786

Please sign in to comment.