使用ovirtsdk

时间:2016-08-04 09:43:47

标签: python-2.7

我正在尝试使用ovirtsdk创建ovirt机器。我必须提到配额。我只有配额ID。如何使用ovirtsdk创建VM?

1 个答案:

答案 0 :(得分:0)

这应该适用于Python SDK版本4:

import logging

import ovirtsdk4 as sdk
import ovirtsdk4.types as types

logging.basicConfig(level=logging.DEBUG, filename='example.log')

# This example will connect to the server and create a new virtual machine with specific quota:

# Create the connection to the server:
connection = sdk.Connection(
    url='https://engine40.example.com/ovirt-engine/api',
    username='admin@internal',
    password='123',
    ca_file='ca.pem',
    debug=True,
    log=logging.getLogger(),
)

# Get the reference to the "vms" service:
vms_service = connection.system_service().vms_service()

# Use the "add" method to create a new virtual machine:
vms_service.add(
    types.Vm(
        name='myvm',
        cluster=types.Cluster(
            name='mycluster',
        ),
        template=types.Template(
            name='Blank',
        ),
        quota=types.Quota(
            id='8ed65137-1260-4ac1-bd67-c399cca2d75d',
        ),
    ),
)

# Close the connection to the server:
connection.close()