VCenter维护模式REST API不起作用

huangapple go评论62阅读模式
英文:

VCenter Maintenance mode REST API is not working

问题

我正在尝试使用REST API /api/vcenter/host/maintenance/requests-v1 将ESX主机移至维护模式。POST操作成功。但主机未移至维护模式。

我有一个vSphere v8.0试用版部署,我正在尝试使用维护模式REST API。
我有两个ESX主机,没有集群,没有DRS,没有HA。

我能够从vSphere客户端Web UI将主机移至维护模式。

主机没有运行任何虚拟机。可以移至维护模式。

我尝试在POSTMAN中使用REST API /api/vcenter/host/maintenance/requests-v1,POST操作成功,并且在对上述API的GET调用中看到了请求。

但主机未在V-Sphere Web客户端中设置为维护模式。

我是否缺少任何配置/设置?

任何帮助将不胜感激!

英文:

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!

答案1

得分: 0

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)
英文:

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)

huangapple
  • 本文由 发表于 2023年4月20日 04:21:07
  • 转载请务必保留本文链接:https://go.coder-hub.com/76058525.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定