diff --git a/services/compute/mgmt/examples/vm_list.rs b/services/compute/mgmt/examples/vm_list.rs new file mode 100644 index 0000000000..20530ed9aa --- /dev/null +++ b/services/compute/mgmt/examples/vm_list.rs @@ -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 { + Ok(std::env::var("SUBSCRIPTION_ID").map_err(|_| "SUBSCRIPTION_ID required")?) +} + +fn get_access_token() -> Result { + Ok(std::env::var("ACCESS_TOKEN").map_err(|_| "ACCESS_TOKEN required")?) +}