-
Notifications
You must be signed in to change notification settings - Fork 292
Add an example that lists the VM Images that run Linux without a publisher plan #921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,91 @@ | ||
/* | ||
Lists the VM images in specified location that do not have a publisher plan that must be | ||
agreed to before use. | ||
|
||
Note, for this example, if any image has a publisher plan, the all of the rest | ||
of the images in the offer are skipped. | ||
|
||
cargo run --package azure_mgmt_compute --example list_free_linux_images eastus | ||
*/ | ||
|
||
use azure_identity::AzureCliCredential; | ||
use azure_mgmt_compute::models::os_disk_image::OperatingSystem; | ||
use std::sync::Arc; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let location = std::env::args().nth(1).expect("please specify location"); | ||
|
||
let credential = Arc::new(AzureCliCredential {}); | ||
let subscription_id = AzureCliCredential::get_subscription()?; | ||
let client = azure_mgmt_compute::ClientBuilder::new(credential) | ||
.build() | ||
.virtual_machine_images_client(); | ||
|
||
let mut publishers = client | ||
.list_publishers(&location, &subscription_id) | ||
.into_future() | ||
.await? | ||
.into_iter() | ||
.map(|x| x.name) | ||
.collect::<Vec<_>>(); | ||
publishers.sort(); | ||
|
||
for publisher in publishers { | ||
let mut offers = client | ||
.list_offers(&location, &publisher, &subscription_id) | ||
.into_future() | ||
.await? | ||
.into_iter() | ||
.map(|x| x.name) | ||
.collect::<Vec<_>>(); | ||
offers.sort(); | ||
|
||
'offer: for offer in offers { | ||
let mut skus = client | ||
.list_skus(&location, &publisher, &offer, &subscription_id) | ||
.into_future() | ||
.await? | ||
.into_iter() | ||
.map(|x| x.name) | ||
.collect::<Vec<_>>(); | ||
skus.sort(); | ||
|
||
for sku in skus { | ||
let mut versions = client | ||
.list(&location, &publisher, &offer, &sku, &subscription_id) | ||
.into_future() | ||
.await? | ||
.into_iter() | ||
.map(|x| x.name) | ||
.collect::<Vec<_>>(); | ||
versions.sort(); | ||
|
||
for version in versions { | ||
let id = format!("{}:{}:{}:{}", publisher, offer, sku, version); | ||
eprintln!("checking {}", id); | ||
|
||
let vm = client | ||
.get(&location, &publisher, &offer, &sku, &version, &subscription_id) | ||
.into_future() | ||
.await?; | ||
|
||
if let Some(props) = vm.properties { | ||
if props.plan.is_some() { | ||
continue 'offer; | ||
} | ||
|
||
if let Some(os) = props.os_disk_image { | ||
if os.operating_system == OperatingSystem::Linux { | ||
println!("{}", id); | ||
break; | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
Ok(()) | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
then