vmwarevspherevcentermaintenance-mode

VCenter Maintenance mode REST API is not working


I am trying to use the REST API /api/vcenter/host/maintenance/requests-v1 to move the ESX host to Maintenance mode. POST action was success. But host does not move to maintenance mode.

I have a vSphere v8.0 Trial version deployment where I am experimenting the Maintenance mode REST API. I have two ESX hosts and no cluster, no DRS, no HA in the setup.

I was able to move a host to maintenance mode from vSphere client web UI.

The host does not have any VMs running. Ready to be moved to maintenance mode.

I tried to use the REST API /api/vcenter/host/maintenance/requests-v1 from POSTMAN and the POST action was success and I am seeing the requests in the GET call to the above API.

But the host is not setting to maintenance mode in V-Sphere web client.

Am I missing any configurations/settings?

Any help would be really appreciated!


Solution

  • I found a work around with pyvmomi library. Using host.EnterMaintenanceMode(TIMEOUT) API.

    You need to have pyvmomi, requests libraries installed in your .venv. I disabled SSL verification for my testing.

    Posted a sample code to test this.

    import requests
    import pyVim    
    from pyVim import connect, task
    import ssl
    
    requests.packages.urllib3.disable_warnings()
    TIMEOUT =30
    context = ssl._create_unverified_context()
    
    my_cluster = connect.SmartConnect(host="{{vcenter_ip}}", port=443, user="{{user}}", pwd="{{pwd}}", sslContext=context)
    searcher = my_cluster.content.searchIndex
    host = searcher.FindByIp(ip="{{host-ip}}", vmSearch=False)
    task1 = host.EnterMaintenanceMode(TIMEOUT)
    task.WaitForTask(task1)
    print (host.name)
    connect.Disconnect(my_cluster)