Skip to content

Commit

Permalink
[dhcp_relay] Update CLI reference document and add a new API for ip a…
Browse files Browse the repository at this point in the history
…ddress type (sonic-net#1717)

#### What I did
Update CLI reference document following PR : sonic-net#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 sonic-net#8211 and this PR.
- Run DHCP CLI commands
  • Loading branch information
shlomibitton authored Aug 23, 2021
1 parent cd3ee78 commit 27502f0
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
20 changes: 15 additions & 5 deletions doc/Command-Reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <vlan_id> <dhcp_relay_destination_ip>
config vlan dhcp_relay add <vlan_id> <dhcp_relay_destination_ips>
```

- 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 <vlan-id> <dhcp_relay_destination_ip>
config vlan dhcp_relay del <vlan-id> <dhcp_relay_destination_ips>
```

- Example:
Expand All @@ -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)

Expand Down
12 changes: 12 additions & 0 deletions utilities_common/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import click
import json
import netaddr

from natsort import natsorted
from sonic_py_common import multi_asic
Expand Down Expand Up @@ -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):
'''
Expand Down

0 comments on commit 27502f0

Please sign in to comment.