0

I'm trying to use the RHEV 4.1 API to get the host status of my hypervisor using python. RHEV 3.6 is working with my script. But if i use the following.

host = api.hosts.get(host_name)
host_state = host.status      //RHEV 3.6 this was host.state.status
print(host_state)

it gives the following

<ovirtsdk.xml.params.Status object at 0x3ce0f10>
dev-dbe101t                <ovirtsdk.xml.params.Status object at    0x3ce0f10>
dev-be101t-data1          None                   master
dev-be101t-data2          None

I can get the hostname and data-center name correctly. even this Status object is not iterable. According to the rhvm 3.6 and rhev 4.1 api difference.

In version 4 of the API this Status type has been removed and replaced by enum types. (my above code is working for rhev 3.6 and it gives the correct status of the host)

How can i retrieve the host status ? i found that the host.status type is a class and then i printed out all related class methods using dir(theobject) and found following useful methods. state,get_state, but it is giving none. but my api status is up

according to the api guide.

status is type of HostStatus ENUM

HOSTSTATUS ENUM contains a NAME called "up"

not sure how to get the host.status from the api. API returns this

<host>
<status>up</status>
</host>

4

1 回答 1

1

您在这里混合了两个 API。正如您正确编写的那样,oVirt 有两个版本的 API v3 和 v4。默认情况下 Python SDK v3 与 v3 API 一起使用,因此您应该将它与 oVirt 4.1/RHV 4.1 一起使用,与以前相同。

如果您使用 API v3 列出主机状态:

GET https://fqdn/ovirt-engine/api/v3/hosts

你会得到:

<status><state>up</state></status>

因此,您应该能够将statePython SDK v3 获取为:

host = api.hosts.get(host_name) host_state = host.status.state print(host_state)

在 APIv4 中,您将获得:

GET https://ondra.local:8443/ovirt-engine/api/v4/hosts

<status>up</status>

但这不相关,因为您仍然使用 Python SDK v3,它使用 APIv3。

于 2018-08-07T09:22:40.110 回答