dellemc.enterprise_sonic.sonic_dhcp_relay 模块 – 在 SONiC 上管理 DHCP 和 DHCPv6 中继配置

注意

此模块是 dellemc.enterprise_sonic 集合 (版本 2.5.1) 的一部分。

如果您使用的是 ansible 包,则可能已经安装了此集合。它不包含在 ansible-core 中。要检查是否已安装它,请运行 ansible-galaxy collection list

要安装它,请使用:ansible-galaxy collection install dellemc.enterprise_sonic

要在 playbook 中使用它,请指定:dellemc.enterprise_sonic.sonic_dhcp_relay

dellemc.enterprise_sonic 2.1.0 中的新增功能

概要

  • 此模块提供对运行 SONiC 的设备的第 3 层接口上的 DHCP 和 DHCPv6 中继参数的配置管理。

  • 需要提前在设备上创建第 3 层接口和 VRF 名称。

参数

参数

注释

config

列表 / 元素=字典

指定 DHCP 和 DHCPv6 中继配置。

ipv4

字典

要为 name 选项中提到的接口设置的 DHCP 中继配置。

circuit_id

字符串

指定 DHCP 中继 circuit-id 格式。

%h:%p - 主机名后跟接口名称,例如 sonic:Vlan100

%i - 物理接口的名称,例如 Eth1/2

%p - 接口的名称,例如 Vlan100

选项

  • "%h:%p"

  • "%i"

  • "%p"

布尔值

启用链路选择子选项。

选项

  • false

  • true

max_hop_count

整数

指定 DHCP 中继数据包的最大跳数。

范围是 1 到 16。

policy_action

字符串

指定处理 DHCP 中继选项的策略。

选项

  • "append"

  • "discard"

  • "replace"

server_addresses

列表 / 元素=字典

DHCP 服务器 IPv4 地址列表。

address

字符串

DHCP 服务器的 IPv4 地址。

source_interface

字符串

指定 DHCP 中继源接口。

vrf_name

字符串

指定 DHCP 服务器所在的 VRF 的名称。

此选项不用于 state *deleted*。

vrf_select

布尔值

启用 VRF 选择子选项。

选项

  • false

  • true

ipv6

字典

要为 name 选项中提到的接口设置的 DHCPv6 中继配置。

max_hop_count

整数

指定 DHCPv6 中继数据包的最大跳数。

范围是 1 到 16。

server_addresses

列表 / 元素=字典

DHCPv6 服务器 IPv6 地址列表。

address

字符串

DHCPv6 服务器的 IPv6 地址。

source_interface

字符串

指定 DHCPv6 中继源接口。

vrf_name

字符串

指定 DHCPv6 服务器所在的 VRF 的名称。

此选项仅与 state *merged* 一起使用。

vrf_select

布尔值

启用 VRF 选择子选项。

选项

  • false

  • true

name

字符串 / 必需

第 3 层接口的全名,即 Eth1/1。

state

字符串

模块完成后的配置状态。

merged - 将提供的 DHCP 和 DHCPv6 中继配置与设备上的配置合并。

deleted - 删除设备上的 DHCP 和 DHCPv6 中继配置。

replaced - 将指定接口的设备上的 DHCP 和 DHCPv6 中继配置替换为提供的配置。

overridden - 使用提供的配置覆盖所有设备上的 DHCP 和 DHCPv6 中继配置。

选项

  • "merged" ← (默认)

  • "deleted"

  • "replaced"

  • "overridden"

备注

注意

  • 针对戴尔科技公司提供的企业 SONiC 发行版进行了测试。

  • 支持 check_mode

示例

# Using deleted
#
# Before State:
# -------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 92.1.1.1 vrf VrfReg1
#  ip dhcp-relay max-hop-count 5
#  ip dhcp-relay vrf-select
#  ip dhcp-relay policy-action append
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 91::1 92::1
#  ipv6 dhcp-relay max-hop-count 5
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1 73.1.1.1
#  ip dhcp-relay source-interface Vlan100
#  ip dhcp-relay link-select
#  ip dhcp-relay circuit-id %h:%p
# !

  - name: Delete DHCP and DHCPv6 relay configurations
    dellemc.enterprise_sonic.sonic_dhcp_relay:
      config:
        - name: 'Eth1/1'
          ipv4:
            server_addresses:
              - address: '92.1.1.1'
            vrf_select: true
            max_hop_count: 5
          ipv6:
            server_addresses:
              - address: '91::1'
              - address: '92::1'
        - name: 'Eth1/2'
          ipv4:
            server_addresses:
              - address: '71.1.1.1'
              - address: '72.1.1.1'
            source_interface: 'Vlan100'
            link_select: true
            circuit_id: '%h:%p'
      state: deleted

# After State:
# ------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 vrf VrfReg1
#  ip dhcp-relay policy-action append
#  ipv6 address 81::1/24
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 73.1.1.1
# !


# Using deleted
#
# NOTE: Support is provided in the dhcp_relay resource module for deletion of all attributes for a
# given address family (IPv4 or IPv6) by using a "special" YAML sequence specifying a server address list
# containing a single "blank" IP address under the target address family. The following example shows
# a task using this syntax for deletion of all DHCP (IPv4) configurations for an interface, but the
# equivalent syntax is supported for DHCPv6 (IPv6) as well.
#
# Before State:
# -------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 92.1.1.1 vrf VrfReg1
#  ip dhcp-relay max-hop-count 5
#  ip dhcp-relay vrf-select
#  ip dhcp-relay policy-action append
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 91::1 92::1
#  ipv6 dhcp-relay max-hop-count 5
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1 73.1.1.1
#  ip dhcp-relay source-interface Vlan100
#  ip dhcp-relay link-select
#  ip dhcp-relay circuit-id %h:%p
# !

  - name: Delete all IPv4 DHCP relay configurations for interface Eth1/1
    dellemc.enterprise_sonic.sonic_dhcp_relay:
      config:
        - name: 'Eth1/1'
          ipv4:
            server_addresses:
              - address:
      state: deleted

# After State:
# ------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 91::1 92::1
#  ipv6 dhcp-relay max-hop-count 5
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1 73.1.1.1
#  ip dhcp-relay source-interface Vlan100
#  ip dhcp-relay link-select
#  ip dhcp-relay circuit-id %h:%p
# !


# Using deleted
#
# Before State:
# -------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 92.1.1.1 vrf VrfReg1
#  ip dhcp-relay max-hop-count 5
#  ip dhcp-relay vrf-select
#  ip dhcp-relay policy-action append
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 91::1 92::1
#  ipv6 dhcp-relay max-hop-count 5
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1 73.1.1.1
#  ip dhcp-relay source-interface Vlan100
#  ip dhcp-relay link-select
#  ip dhcp-relay circuit-id %h:%p
# !

  - name: Delete all DHCP and DHCPv6 relay configurations for interface Eth1/1
    dellemc.enterprise_sonic.sonic_dhcp_relay:
      config:
        - name: 'Eth1/1'
      state: deleted

# After State:
# ------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ipv6 address 81::1/24
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1 73.1.1.1
#  ip dhcp-relay source-interface Vlan100
#  ip dhcp-relay link-select
#  ip dhcp-relay circuit-id %h:%p
# !


# Using deleted
#
# Before State:
# -------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 92.1.1.1 vrf VrfReg1
#  ip dhcp-relay max-hop-count 5
#  ip dhcp-relay vrf-select
#  ip dhcp-relay policy-action append
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 91::1 92::1
#  ipv6 dhcp-relay max-hop-count 5
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1 73.1.1.1
#  ip dhcp-relay source-interface Vlan100
#  ip dhcp-relay link-select
#  ip dhcp-relay circuit-id %h:%p
# !

  - name: Delete all DHCP and DHCPv6 relay configurations
    dellemc.enterprise_sonic.sonic_dhcp_relay:
      config:
      state: deleted

# After State:
# ------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ipv6 address 81::1/24
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
# !


# Using merged
#
# Before State:
# -------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ipv6 address 81::1/24
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1
# !

  - name: Add DHCP and DHCPv6 relay configurations
    dellemc.enterprise_sonic.sonic_dhcp_relay:
      config:
        - name: 'Eth1/1'
          ipv4:
            server_addresses:
              - address: '91.1.1.1'
              - address: '92.1.1.1'
            vrf_name: 'VrfReg1'
            vrf_select: true
            max_hop_count: 5
            policy_action: 'append'
          ipv6:
            server_addresses:
              - address: '91::1'
              - address: '92::1'
            max_hop_count: 5
        - name: 'Eth1/2'
          ipv4:
            server_addresses:
              - address: '73.1.1.1'
            source_interface: 'Vlan100'
            link_select: true
            circuit_id: '%h:%p'
      state: merged

# After State:
# ------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 92.1.1.1 vrf VrfReg1
#  ip dhcp-relay max-hop-count 5
#  ip dhcp-relay vrf-select
#  ip dhcp-relay policy-action append
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 91::1 92::1
#  ipv6 dhcp-relay max-hop-count 5
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1 73.1.1.1
#  ip dhcp-relay source-interface Vlan100
#  ip dhcp-relay link-select
#  ip dhcp-relay circuit-id %h:%p
# !


# Using replaced
#
# Before State:
# -------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 92.1.1.1 vrf VrfReg1
#  ip dhcp-relay max-hop-count 5
#  ip dhcp-relay vrf-select
#  ip dhcp-relay policy-action append
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 91::1 92::1
#  ipv6 dhcp-relay max-hop-count 5
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1 73.1.1.1
#  ip dhcp-relay source-interface Vlan100
#  ip dhcp-relay link-select
#  ip dhcp-relay circuit-id %h:%p
#  ipv6 address 61::1/24
#  ipv6 dhcp-relay 71::1 72::1
# !
# interface Eth1/3
#  mtu 9100
#  speed 400000
#  fec RS
#  shutdown
#  ip address 41.1.1.1/24
#  ip dhcp-relay 51.1.1.1 52.1.1.1
#  ip dhcp-relay circuit-id %h:%p
#  ipv6 address 41::1/24
#  ipv6 dhcp-relay 51::1 52::1
# !

  - name: Replace DHCP and DHCPv6 relay configurations of specified interfaces
    dellemc.enterprise_sonic.sonic_dhcp_relay:
      config:
        - name: 'Eth1/1'
          ipv4:
            server_addresses:
              - address: '91.1.1.1'
              - address: '93.1.1.1'
              - address: '95.1.1.1'
            vrf_name: 'VrfReg1'
            vrf_select: true
          ipv6:
            server_addresses:
              - address: '93::1'
              - address: '94::1'
            source_interface: 'Vlan100'
        - name: 'Eth1/2'
          ipv4:
            server_addresses:
              - address: '73.1.1.1'
            circuit_id: '%h:%p'
      state: replaced

# After State:
# ------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 93.1.1.1 95.1.1.1 vrf VrfReg1
#  ip dhcp-relay vrf-select
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 93::1 94::1
#  ipv6 dhcp-relay source-interface Vlan100
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 73.1.1.1
#  ip dhcp-relay circuit-id %h:%p
#  ipv6 address 61::1/24
# !
# interface Eth1/3
#  mtu 9100
#  speed 400000
#  fec RS
#  shutdown
#  ip address 41.1.1.1/24
#  ip dhcp-relay 51.1.1.1 52.1.1.1
#  ip dhcp-relay circuit-id %h:%p
#  ipv6 address 41::1/24
#  ipv6 dhcp-relay 51::1 52::1
# !


# Using overridden
#
# Before State:
# -------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 92.1.1.1 vrf VrfReg1
#  ip dhcp-relay max-hop-count 5
#  ip dhcp-relay vrf-select
#  ip dhcp-relay policy-action append
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 91::1 92::1
#  ipv6 dhcp-relay max-hop-count 5
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 71.1.1.1 72.1.1.1 73.1.1.1
#  ip dhcp-relay source-interface Vlan100
#  ip dhcp-relay link-select
#  ip dhcp-relay circuit-id %h:%p
#  ipv6 address 61::1/24
#  ipv6 dhcp-relay 71::1 72::1
# !
# interface Eth1/3
#  mtu 9100
#  speed 400000
#  fec RS
#  shutdown
#  ip address 41.1.1.1/24
#  ip dhcp-relay 51.1.1.1 52.1.1.1
#  ip dhcp-relay circuit-id %h:%p
#  ipv6 address 41::1/24
#  ipv6 dhcp-relay 51::1 52::1
# !

  - name: Override DHCP and DHCPv6 relay configurations
    dellemc.enterprise_sonic.sonic_dhcp_relay:
      config:
        - name: 'Eth1/1'
          ipv4:
            server_addresses:
              - address: '91.1.1.1'
              - address: '93.1.1.1'
              - address: '95.1.1.1'
            vrf_name: 'VrfReg1'
            vrf_select: true
          ipv6:
            server_addresses:
              - address: '93::1'
              - address: '94::1'
            source_interface: 'Vlan100'
        - name: 'Eth1/2'
          ipv4:
            server_addresses:
              - address: '73.1.1.1'
            circuit_id: '%h:%p'
      state: overridden

# After State:
# ------------
#
# sonic# show running-configuration interface
# !
# interface Eth1/1
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 81.1.1.1/24
#  ip dhcp-relay 91.1.1.1 93.1.1.1 95.1.1.1 vrf VrfReg1
#  ip dhcp-relay vrf-select
#  ipv6 address 81::1/24
#  ipv6 dhcp-relay 93::1 94::1
#  ipv6 dhcp-relay source-interface Vlan100
# !
# interface Eth1/2
#  mtu 9100
#  speed 400000
#  fec RS
#  no shutdown
#  ip address 61.1.1.1/24
#  ip dhcp-relay 73.1.1.1
#  ip dhcp-relay circuit-id %h:%p
#  ipv6 address 61::1/24
# !
# interface Eth1/3
#  mtu 9100
#  speed 400000
#  fec RS
#  shutdown
#  ip address 41.1.1.1/24
#  ipv6 address 41::1/24
# !

返回值

此处记录了常见的返回值 这里,以下是此模块独有的字段

描述

after

列表 / 元素=字符串

模块调用的结果配置。

返回:发生更改时

示例: ["The configuration returned will always be in the same format as the parameters above.\n"]

after(generated)

列表 / 元素=字符串

生成的配置模块调用。

返回:check_mode

示例: ["The configuration returned will always be in the same format as the parameters above.\n"]

before

列表 / 元素=字符串

模块调用之前的配置。

返回:始终返回

示例: ["The configuration returned will always be in the same format as the parameters above.\n"]

commands

列表 / 元素=字符串

推送到远程设备的命令集。

返回:始终返回

示例: ["command 1", "command 2", "command 3"]

作者

  • Arun Saravanan Balachandran (@ArunSaravananBalachandran)