3.18. 启动虚拟机
您可以启动虚拟机。
例 3.16. 启动虚拟机
本示例使用 start
方法启动虚拟机。
V4
import time import ovirtsdk4 as sdk import ovirtsdk4.types as types connection = sdk.Connection( url='https://engine.example.com/ovirt-engine/api', username='admin@internal', password='password', ca_file='ca.pem', ) # Get the reference to the "vms" service: vms_service = connection.system_service().vms_service() # Find the virtual machine: vm = vms_service.list(search='name=vm1')[0] # Locate the service that manages the virtual machine, as that is where # the action methods are defined: vm_service = vms_service.vm_service(vm.id) # Call the "start" method of the service to start it: vm_service.start() # Wait until the virtual machine is up: while True: time.sleep(5) vm = vm_service.get() if vm.status == types.VmStatus.UP: break print("Started '%s'." % vm.name()) # Close the connection to the server: connection.close()
如果 启动
请求成功,则输出文本的示例:
Started 'vm1'.
UP
状态表示虚拟机正在运行。