vSphere+

 View Only
  • 1.  how get Vcenter topology info : Clusters, hosts via REST API ?

    Posted Dec 17, 2023 11:52 AM

     

    How get Vcenter topology info : Clusters, hosts via REST API ?

    I can get list of clusters and hosts via below REST API GET cmds:

    get https://{api_host}/api/vcenter/host

    get https://{api_host}/api/vcenter/cluster

    But in output is no info about relationship which hosts belong to which cluster.

    How can I achieve this please ?

     

    get https://{api_host}/api/vcenter/host

    Output:

        {
            "host""host-10100",
            "name""Host01",
            "connection_state""CONNECTED",
            "power_state""POWERED_ON"
        },
    ...
     

    get https://{api_host}/api/vcenter/cluster

    output :

        {
            "drs_enabled"true,
            "cluster""domain-c10090",
            "name""Cluster01",
            "ha_enabled"true
        },

     



  • 2.  RE: how get Vcenter topology info : Clusters, hosts via REST API ?

    Posted Dec 17, 2023 02:33 PM

    Try this:

    1. List Clusters: First, get the list of clusters using the /api/vcenter/cluster endpoint.

    2. List Hosts: Then, get the list of hosts using the /api/vcenter/host endpoint.

    3. Map Hosts to Clusters: Each host in the response from the /api/vcenter/host endpoint includes a cluster field that contains the cluster identifier (ID). You can map each host to its cluster by matching this cluster ID with the ID of clusters obtained from the /api/vcenter/cluster endpoint.

     

    Hope this help!



  • 3.  RE: how get Vcenter topology info : Clusters, hosts via REST API ?

    Posted Dec 17, 2023 05:01 PM

    hmm, reg. step 3. "Map Hosts to Clusters: Each host in the response from the /api/vcenter/host endpoint includes a cluster field that contains the cluster identifier (ID)" ...

    As I posted my example before, there is no such info about cluster

    GET  https://{api_host}/api/vcenter/host

    My Output: gathered from postman

    {
    "host": "host-10100",
    "name": "Host01",
    "connection_state": "CONNECTED",
    "power_state": "POWERED_ON"
    },

    ...

     



  • 4.  RE: how get Vcenter topology info : Clusters, hosts via REST API ?

    Posted Dec 18, 2023 08:56 AM

    I believe then that you should use the ESXi APIs instead of the vCenter ones:

    https://{api_host}/api/esx/settings/hosts/{host}/configuration?action=extract

    https://developer.vmware.com/apis/vsphere-automation/latest/esx/api/esx/settings/hosts/host/configurationactionextract/post/

    Otherwise, using PowerCLI will definitely make your life easier!



  • 5.  RE: how get Vcenter topology info : Clusters, hosts via REST API ?

    Posted Dec 18, 2023 12:21 PM

    Ouu, so we really don't have this option to check these basic info from Vcenter API ? 

    yes, I know about powercli... but I would like to implement it via pure API calls from python app. 



  • 6.  RE: how get Vcenter topology info : Clusters, hosts via REST API ?

    Posted Dec 18, 2023 02:14 PM

    I believe that once you are authenticated via API on the vCenter, you can extract from there the list of ESXi or Clusters, and then go on to query the hosts directly using the ESXi APIs, utilizing the authentication session already in use for the vCenter