From 27502f0e2f58c742dfa508b260a59d45092114ae Mon Sep 17 00:00:00 2001 From: shlomibitton <60430976+shlomibitton@users.noreply.github.com> Date: Mon, 23 Aug 2021 13:26:15 +0300 Subject: [PATCH] [dhcp_relay] Update CLI reference document and add a new API for ip address type (#1717) #### What I did Update CLI reference document following PR : https://github.com/Azure/sonic-buildimage/pull/8211 Add a new API on utilities_common to get IP type. #### How I did it - Update doc/Command-Reference.md with new DHCP CLI. - Add ipaddress_type API to utilities_common/cli.py #### How to verify it - Build an image with PR https://github.com/Azure/sonic-buildimage/pull/8211 and this PR. - Run DHCP CLI commands --- doc/Command-Reference.md | 20 +++++++++++++++----- utilities_common/cli.py | 12 ++++++++++++ 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/doc/Command-Reference.md b/doc/Command-Reference.md index 35d7b28aef79..26b23ac31c91 100644 --- a/doc/Command-Reference.md +++ b/doc/Command-Reference.md @@ -2231,27 +2231,32 @@ This sub-section of commands is used to add or remove the DHCP Relay Destination **config vlan dhcp_relay add** -This command is used to add a DHCP Relay Destination IP address to the a VLAN. Note that more that one DHCP Relay Destination IP address can be added on a VLAN interface. +This command is used to add a DHCP Relay Destination IP address or multiple IP addresses to a VLAN. Note that more than one DHCP Relay Destination IP address can be added on a VLAN interface. - Usage: ``` - config vlan dhcp_relay add + config vlan dhcp_relay add ``` - Example: ``` admin@sonic:~$ sudo config vlan dhcp_relay add 1000 7.7.7.7 - Added DHCP relay destination address 7.7.7.7 to Vlan1000 + Added DHCP relay destination address ['7.7.7.7'] to Vlan1000 + Restarting DHCP relay service... + ``` + ``` + admin@sonic:~$ sudo config vlan dhcp_relay add 1000 7.7.7.7 1.1.1.1 + Added DHCP relay destination address ['7.7.7.7', '1.1.1.1'] to Vlan1000 Restarting DHCP relay service... ``` **config vlan dhcp_relay delete** -This command is used to delete a configured DHCP Relay Destination IP address from a VLAN interface. +This command is used to delete a configured DHCP Relay Destination IP address or multiple IP addresses from a VLAN interface. - Usage: ``` - config vlan dhcp_relay del + config vlan dhcp_relay del ``` - Example: @@ -2260,6 +2265,11 @@ This command is used to delete a configured DHCP Relay Destination IP address fr Removed DHCP relay destination address 7.7.7.7 from Vlan1000 Restarting DHCP relay service... ``` + ``` + admin@sonic:~$ sudo config vlan dhcp_relay del 1000 7.7.7.7 1.1.1.1 + Removed DHCP relay destination address ('7.7.7.7', '1.1.1.1') from Vlan1000 + Restarting DHCP relay service... + ``` Go Back To [Beginning of the document](#) or [Beginning of this section](#dhcp-relay) diff --git a/utilities_common/cli.py b/utilities_common/cli.py index 59aa36a7c054..9c0d0afe6771 100644 --- a/utilities_common/cli.py +++ b/utilities_common/cli.py @@ -7,6 +7,7 @@ import click import json +import netaddr from natsort import natsorted from sonic_py_common import multi_asic @@ -203,6 +204,17 @@ def is_ipaddress(val): return False return True +def ipaddress_type(val): + """ Return the IP address type """ + if not val: + return None + + try: + ip_version = netaddr.IPAddress(str(val)) + except netaddr.core.AddrFormatError: + return None + + return ip_version.version def is_ip_prefix_in_key(key): '''