list images python api call not listing the images present on the azure account.
How to list Azure images using python API calls? I want to use Azure python SDK/API calls to list all images that are available in my account. This is to implement the functionality of creating a virtual machine using custom images. I take the customer image name or id as the user input for creating a VM, and I want to use the Azure python API calls to validate if that image name/id is correct. Please let me know how I can achieve this using Python Azure API calls. I saw on the Azure Python SDK, a link where sample code for list all images is there but that link I believe is not working now. I tried the following code to list but is not responding and no error is also reported as well for the script images = compute_client.images.list_by_resource_group(resource_group) and images = compute_client.images.list()
Please help me out with the request. Thanks!
Thanks for the feedback, we’ll investigate asap.
I also want the Team's help in understanding that how can we implement the option to support the VM creation on Azure using the user passed image name as there are wide variety of options as mentioned below that are provided by Azure console while image selection so In the similar way how can we make sure to create VM using that image using Azure Python API calls.
During the process of VM Instance creation on Azure cloud, there are many options provided to select the image for the VM like under other items there are my image, shared image, community image, direct shared image then under marketplace there are options like All, recently created and private products and then under categories there are around 18 options like compute, migration, etc. etc.
My python script should have the ability to create the VM as per the user selected image using the Azure API calls. What is the kind of categorization is taken care of for the images we have in Azure like we have in other clouds like GCP accept an image name with the format "[
Please help me out with my queries. Thanks!
Hi @prmjh4 Sorry for the delay response. If you want to validate the image used in an existing VM, through python, you can run:
response = client.virtual_machines.get(resource_group_name, vm_name)
print(response.storage_profile.image_reference)
client.images.list() is for the custom images or so called my image, which you uploaded to Azure Portal though this method. To create a VM with an image in this type through python, see sample https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/compute/azure-mgmt-compute/generated_samples/virtual_machine_examples/virtual_machine_create_from_acustom_image.py.
shared image are your images stored on Azure Portal in another way, storing multiple images in a gallery, specified by parameters: Publisher, Offer and Sku. To use it ,see https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/compute/azure-mgmt-compute/generated_samples/virtual_machine_examples/virtual_machine_create_from_ageneralized_shared_image.py.
community image are images from community gallery, to create a community gallery: https://learn.microsoft.com/en-us/azure/virtual-machines/create-gallery?tabs=portal%2Cportaldirect%2Cportal2#create-a-community-gallery.
Under masterplace there are the images provided by Azure, use it by inputting its parameters: https://github.com/Azure/azure-sdk-for-python/blob/main/sdk/compute/azure-mgmt-compute/generated_samples/virtual_machine_examples/virtual_machine_create_linux_vm_with_automatic_by_platform_settings.py#L64
For your final question, I'm not pretty sure if there's something similar to image project, in Azure, images are specified whether by its defination(Publisher, Offer, Sku, Version) or its resource id.
Hope that answers your question. Please know that I'm not domain expert, for further queries on service side, it's better to seek help from service team https://github.com/Azure/azure-rest-api-specs.
Thank you for the detail explanation @ChenxiJiang333 I am going through the answer and update the issue once done. Thank you again for helping me out!
Hi @prmjh4. Thank you for opening this issue and giving us the opportunity to assist. To help our team better understand your issue and the details of your scenario please provide a response to the question asked above or the information requested above. This will help us more accurately address your issue.
Hi @prmjh4, we're sending this friendly reminder because we haven't heard back from you in 7 days. We need more information about this issue to help address it. Please be sure to give us your input. If we don't hear back from you within 14 days of this comment the issue will be automatically closed. Thank you!