vSphere

 View Only
  • 1.  How to get vm template list by VSphere rest api

    Posted Mar 14, 2024 10:08 AM

    Currently , we use rest api from WMware VSphere for our production.

    I want to get all vm templates by rest-api.


    But I only find /api/vcenter/vm-template/library-items/{template_library_item},
    So here are 2 questions?

    1.how to get vm-template list which are not under content library by rest api?
    2.how can I get all library items?



  • 2.  RE: How to get vm template list by VSphere rest api

    Broadcom Employee
    Posted May 29, 2024 11:51 AM

    Hello,

    thank you for the questions

    > 1.how to get vm-template list which are not under content library by rest api?

    The newer design REST API do not have this functionality. The vSphere Web Service (vim) API has capabilities to list VM templates. 

    You will need to do a bit of hacking and remixing to get the answer :-)

    This API can be called as a REST like API https://developer.broadcom.com/xapis/virtual-infrastructure-json-api/latest/

    Here you can find sample obtaining all VMs in Python https://github.com/vmware/pyvmomi-community-samples/blob/master/samples/vminfo_quick.py

    Here is how to use of Property Collector to list VMs using the VI/JSON API https://blogs.vmware.com/code/2023/12/28/read-vcenter-inventory-using-vi-json-api/

    You need to be looking for the vm.config.template property on the VMs and look for values equal to "true".

    > 2. how can I get all library items?

    Would this API do the trick for you POST https://{api_host}/api/content/library/item?action=find