6.108.16. setupnetworks POST
此方法用于更改主机网络接口的配置。
例如,如果您有一个具有三个网络接口的主机 eth0、eth1 和 eth2,并且您想要使用 eth0 和 eth 1 配置一个新绑定,并在上面放置 VLAN。使用一个简单的 shell 脚本和 curl 命令行 HTTP 客户端,可以按如下方式完成:
#!/bin/sh -ex
url="https://engine.example.com/ovirt-engine/api"
user="admin@internal"
password="..."
curl \
--verbose \
--cacert /etc/pki/ovirt-engine/ca.pem \
--user "${user}:${password}" \
--request POST \
--header "Version: 4" \
--header "Content-Type: application/xml" \
--header "Accept: application/xml" \
--data '
<action>
<modified_bonds>
<host_nic>
<name>bond0</name>
<bonding>
<options>
<option>
<name>mode</name>
<value>4</value>
</option>
<option>
<name>miimon</name>
<value>100</value>
</option>
</options>
<slaves>
<host_nic>
<name>eth1</name>
</host_nic>
<host_nic>
<name>eth2</name>
</host_nic>
</slaves>
</bonding>
</host_nic>
</modified_bonds>
<modified_network_attachments>
<network_attachment>
<network>
<name>myvlan</name>
</network>
<host_nic>
<name>bond0</name>
</host_nic>
<ip_address_assignments>
<ip_address_assignment>
<assignment_method>static</assignment_method>
<ip>
<address>192.168.122.10</address>
<netmask>255.255.255.0</netmask>
</ip>
</ip_address_assignment>
</ip_address_assignments>
<dns_resolver_configuration>
<name_servers>
<name_server>1.1.1.1</name_server>
<name_server>2.2.2.2</name_server>
</name_servers>
</dns_resolver_configuration>
</network_attachment>
</modified_network_attachments>
</action>
' \
"${url}/hosts/1ff7a191-2f3b-4eff-812b-9f91a30c3acc/setupnetworks"
这对 API 版本 4 有效。在以前的版本中,部分元素表示为 XML 属性而不是 XML 元素。特别是,选项和 ip 元素的表示如下:
<options name="mode" value="4"/>
<options name="miimon" value="100"/>
<ip address="192.168.122.10" netmask="255.255.255.0"/>
同样的操作也可使用 Python SDK 及以下代码完成:
# Find the service that manages the collection of hosts:
hosts_service = connection.system_service().hosts_service()
# Find the host:
host = hosts_service.list(search='name=myhost')[0]
# Find the service that manages the host:
host_service = hosts_service.host_service(host.id)
# Configure the network adding a bond with two slaves and attaching it to a
# network with an static IP address:
host_service.setup_networks(
modified_bonds=[
types.HostNic(
name='bond0',
bonding=types.Bonding(
options=[
types.Option(
name='mode',
value='4',
),
types.Option(
name='miimon',
value='100',
),
],
slaves=[
types.HostNic(
name='eth1',
),
types.HostNic(
name='eth2',
),
],
),
),
],
modified_network_attachments=[
types.NetworkAttachment(
network=types.Network(
name='myvlan',
),
host_nic=types.HostNic(
name='bond0',
),
ip_address_assignments=[
types.IpAddressAssignment(
assignment_method=types.BootProtocol.STATIC,
ip=types.Ip(
address='192.168.122.10',
netmask='255.255.255.0',
),
),
],
dns_resolver_configuration=types.DnsResolverConfiguration(
name_servers=[
'1.1.1.1',
'2.2.2.2',
],
),
),
],
)
# After modifying the network configuration it is very important to make it
# persistent:
host_service.commit_net_config()
为确保网络配置已保存到主机上,并且主机重启时会应用它,请记得调用 commitnetconfig。
由于 Red Hat Virtualization Manager 4.3,也可以在 setupnetworks 请求中指定 commit_on_success,在这种情况下,新配置会在完成设置并重新建立 {hypervisor-name} 和 Red Hat Virtualization Manager 之间的连接后自动保存在 {hypervisor-name} 和 Red Hat Virtualization Manager,且无需等待单独的 commitnetconfig 请求。
| 名称 | 类型 | 方向 | 概述 |
|---|---|---|---|
|
| in | 指明是否应异步执行该操作。 | |
|
| in | ||
|
| in | 指定在完成设置并重新建立 {hypervisor-name} 和 Red Hat Virtualization Manager 之间的连接后,是否会在 {hypervisor-name} 和 Red Hat Virtualization Manager 中自动保存配置,且不会等待单独的 commitnetconfig 请求。 | |
|
| in | ||
|
| in | ||
|
| in | ||
|
| in | ||
|
| in | ||
|
| in | ||
|
| in | ||
|
| in | 将同步的网络附加列表。 |
6.108.16.1. commit_on_success 复制链接链接已复制到粘贴板!
指定在完成设置并重新建立 {hypervisor-name} 和 Red Hat Virtualization Manager 之间的连接后,是否会在 {hypervisor-name} 和 Red Hat Virtualization Manager 中自动保存配置,且不会等待单独的 commitnetconfig 请求。默认值为 false,这意味着配置不会自动保存。