在 ovrt python sdk 脚本中更新 VM 状态

Updating VM state in ovrt python sdk script

我正在尝试编写一个 python 脚本来查询 ovirt 中虚拟机的状态(我是 python 的新手!)

这是我正在使用的测试脚本!

APIURL="https://..."
APIUSER="...@..."
APIPASS="..."
CAFILE="path"
LOGFILENAME="/tmp/shutdown_vms_dc.log"


logging.basicConfig(level=logging.DEBUG,
                format='%(asctime)s %(levelname)s %(message)s',
                filename=LOGFILENAME,
                filemode='w')
if __name__ == "__main__":
    try:
        api = API(url=APIURL,
          username=APIUSER,
          password=APIPASS,
          ca_file=CAFILE)
        print 'Connected to RHEVM API  %s Successfully' % APIURL
    logging.info ( 'Successfully Connected to %s' % APIURL)

    vmsList = api.vms.list()
    while True:
        print '###############################################'
            for i in vmsList:
                    if i.name != 'HostedEngine':
                            print i.name + ': '  + i.status.state
        time.sleep(10)

except 作为 ex 的异常: logging.debug('Unexpected error: %s' % ex)

问题是状态没有得到更新,它总是在第一次运行时打印。我使用 ovirt 的 Web 界面关闭并启动虚拟机,但没有任何变化……我缺少什么???

非常感谢!!!

算了,我错了…… 线 vmList=api.vms.list() 为您留下与您何时拨打电话相关的静态数据。

因此,我通过调用以下命令在 for 循环中实现了我想要的: api.vms.get(i.name).status.state,其中i迭代第一个得到的vmList!成功了!