Exploring vSphere 6.5 API-Part 3: Esxi Host

In last 2 post of this series, we learn about digging out info about datacenter,cluster and virtual machines.

In this post we will learn about API options available for Esxi hosts.

If you have missed earlier posts of this series, you can read them from here:

1: Exploring vSphere 6.5 API-Datacenter & Cluster

2: Exploring vSphere 6.5 API-Virtual Machines

Let’s get started with fetching info about esxi hosts.

1: List all hosts present in a vCenter

Following query will list all esxi hosts that are present across all cluster/datacenter which are there in a vcenter.

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 7c639fb1e988b4c59dd77adef4c5d06c’ -X GET https://vcentersrv01.alex.local/rest/vcenter/host

Output
[code]
{“host”:”host-28″,”name”:”esxi01.alex.local”,”connection_state”:”CONNECTED”,”power_state”:”POWERED_ON”}

{“host”:”host-31″,”name”:”esxi02.alex.local”,”connection_state”:”CONNECTED”,”power_state”:”POWERED_ON”}

{“host”:”host-33″,”name”:”esxi03.alex.local”,”connection_state”:”CONNECTED”,”power_state”:”POWERED_ON”}

{“host”:”host-35″,”name”:”esxi04.alex.local”,”connection_state”:”CONNECTED”,”power_state”:”POWERED_ON”}

[/code]

 

2: List all host in a specific datacenter

You can limit search of esxi host to specific datacenter by using filter.datacenters option

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 7c639fb1e988b4c59dd77adef4c5d06c’ -X GET
https://vcentersrv01.alex.local/rest/vcenter/host?filter.datacenters=datacenter-2

3: List all hosts in a specific cluster

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 7c639fb1e988b4c59dd77adef4c5d06c’ -X GET https://vcentersrv01.alex.local/rest/vcenter/host?filter.clusters=domain-c7

output

[code]

{
“value”: [
{
“host”: “host-35”,
“name”: “esxi04.alex.local”,
“connection_state”: “CONNECTED”,
“power_state”: “POWERED_ON”
}
]
}

[/code]

4: Info about a particular host

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 7c639fb1e988b4c59dd77adef4c5d06c’ -X GET https://vcentersrv01.alex.local/rest/vcenter/host?filter.hosts=host-33

output

[code]

{
“value”: [
{
“host”: “host-33”,
“name”: “esxi03.alex.local”,
“connection_state”: “CONNECTED”,
“power_state”: “POWERED_ON”
}
]
}

[/code]

5: List all standalone host

If you have hosts that are not part of any cluster and are added as standalone host, you can list them by using filter.standalone=true

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 7c639fb1e988b4c59dd77adef4c5d06c’ -X GET https://vcentersrv01.alex.local/rest/vcenter/host?filter.standalone=true

6: List all hosts that are connected

The below query will filter out those hosts which are currently in disconnected state in vCenter

# curl -sik -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 7c639fb1e988b4c59dd77adef4c5d06c’ -X GET
https://vcentersrv01.alex.local/rest/vcenter/host?filter.connection_states=CONNECTED

7: Disconnect a host from the vCenter server.

POST https://vcentersrv01.alex.local/rest/vcenter/host/{host}/disconnect

Example:

# curl -sik -X GET -H ‘Accept: application/json’ -H ‘vmware-api-session-id: 7c639fb1e988b4c59dd77adef4c5d06c’ -X POST https://vcentersrv01.alex.local/rest/vcenter/host/host-28/disconnect

8: Connect to the host previously added to the vCenter server.

POST https://vcentersrv01.alex.local/rest/vcenter/host/{host}/connect

9: Remove a standalone host from the vCenter Server.

DELETE https://vcentersrv01.alex.local/rest/vcenter/host/{host}

I hope this post is informational to you. Feel free to share this on social media if it is worth sharing. Be sociable

One thought on “Exploring vSphere 6.5 API-Part 3: Esxi Host

  1. Pingback: vSphere 6.5 Link-O-Rama » Welcome to vSphere-land!

Leave a ReplyCancel reply