搜索

6.108.16. setupnetworks POST

download PDF

此方法用于更改主机网络接口的配置。

例如,如果您有一个具有三个网络接口的主机 eth0eth1eth2,并且您想要使用 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 请求。

表 6.338. 参数摘要
名称类型方向概述

async

布尔值

in

指明是否应异步执行该操作。

check_connectivity

布尔值

in

 

commit_on_success

布尔值

in

指定在完成设置并重新建立 {hypervisor-name} 和 Red Hat Virtualization Manager 之间的连接后,是否会在 {hypervisor-name} 和 Red Hat Virtualization Manager 中自动保存配置,且不会等待单独的 commitnetconfig 请求。

connectivity_timeout

整数

in

 

modified_bonds

HostNic[]

in

 

modified_labels

NetworkLabel[]

in

 

modified_network_attachments

NetworkAttachment[]

in

 

removed_bonds

HostNic[]

in

 

removed_labels

NetworkLabel[]

in

 

removed_network_attachments

NetworkAttachment[]

in

 

synchronized_network_attachments

NetworkAttachment[]

in

将同步的网络附加列表。

6.108.16.1. commit_on_success

指定在完成设置并重新建立 {hypervisor-name} 和 Red Hat Virtualization Manager 之间的连接后,是否会在 {hypervisor-name} 和 Red Hat Virtualization Manager 中自动保存配置,且不会等待单独的 commitnetconfig 请求。默认值为 false,这意味着配置不会自动保存。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.