azure-sdk-for-python icon indicating copy to clipboard operation
azure-sdk-for-python copied to clipboard

list images python api call not listing the images present on the azure account.

Open prmjh4 opened this issue 1 year ago • 5 comments

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!

prmjh4 avatar Jan 03 '24 08:01 prmjh4

Thanks for the feedback, we’ll investigate asap.

xiangyan99 avatar Jan 03 '24 15:01 xiangyan99

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 "[]". The image project is optional and will default to the same project to which the instance will be provisioned. That will only work for custom images. GCP-provided images are in their own projects (I.e. Ubuntu images are in the ubuntu-os-cloud project). Similarly, what do we have in Azure?

Please help me out with my queries. Thanks!

prmjh4 avatar Jan 04 '24 07:01 prmjh4

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.

ChenxiJiang333 avatar Jan 08 '24 07:01 ChenxiJiang333

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!

prmjh4 avatar Jan 08 '24 09:01 prmjh4

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.

github-actions[bot] avatar Jan 11 '24 16:01 github-actions[bot]

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!

github-actions[bot] avatar Jan 18 '24 21:01 github-actions[bot]