虽然我没有找到直接使用 API 的好解决方案,但我确实想出了一个解决方案。我首先直接联系 Neutron 服务器创建网络,然后返回 ovirt sdk 将该网络引入我想要的数据中心/集群:
net_name = 'test_network'
data_center = 'Default'
net_dict = {'name': net_name} # add other parameters as desired
onps = conn.system_service().openstack_network_providers_service()
provider = onps.list()[0]
# get the URL of the provider, though in this case it might be "localhost" so swap that out for the host in the Connection url
url = "%s/v2.0/networks" % \
(provider.url.replace('localhost', conn.url.split('/')[2]),)
req = urllib2.Request(url)
req.add_header('Content-Type', 'application/json')
response = urllib2.urlopen(req, json.dumps({'network': net_dict}))
# now find that one
os_net_serv = onps.provider_service(provider.id).networks_service()
for os_net in os_net_serv.list():
if os_net.name == net_name:
net_serv = os_net_serv.network_service(os_net.id)
net_serv.import_(data_center=ovirtsdk4.types.DataCenter(name=data_center))
# now I can get it as an oVirt Network
net = conn.system_service().networks_service().list(
search='name=%s' % (net_name,))[0]