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()
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()
Copy to ClipboardCopied!Toggle word wrapToggle overflow
如果 启动 请求成功,则输出文本的示例:
Started 'vm1'.
Started 'vm1'.
Copy to ClipboardCopied!Toggle word wrapToggle overflow