@@ -32,17 +32,37 @@ check_root_privileges() {
3232 fi
3333}
3434
35- # Function to check if the device is supported device with type spine routers and subtype UpstreamLC
36- check_spine_router () {
37- type= $( sonic-cfggen -d -v DEVICE_METADATA.localhost.type )
38- subtype= $( sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype )
39-
40- # only supported on UpstreamLC or UpperSpineRouter
41- if [[ ( " $type " == " SpineRouter " && " $subtype " == " UpstreamLC " ) || " $type " == " UpperSpineRouter " ]] ; then
42- return
35+ # Function to check if the device is a supported device type
36+ DEVICE_TYPE= " "
37+ DEVICE_SUBTYPE= " "
38+
39+ read_device_metadata () {
40+ if [[ -z " $DEVICE_TYPE " ]] ; then
41+ DEVICE_TYPE= $( sonic-cfggen -d -v DEVICE_METADATA.localhost.type )
42+ DEVICE_SUBTYPE= $( sonic-cfggen -d -v DEVICE_METADATA.localhost.subtype )
4343 fi
44+ }
4445
45- echo " Operation is only supported on Upstream SpineRouter." >&2
46+ declare -A prefix_type_devices
47+ prefix_type_devices=(
48+ [" ANCHOR_PREFIX" ]=" SpineRouter:UpstreamLC UpperSpineRouter"
49+ [" SUPPRESS_PREFIX" ]=" "
50+ )
51+
52+ validate_device_for_type () {
53+ local prefix_type=$1
54+ local allowed=" ${prefix_type_devices[$prefix_type]} "
55+ [[ -z " $allowed " ]] && return
56+ read_device_metadata
57+ local device_id=" $DEVICE_TYPE :$DEVICE_SUBTYPE "
58+ for entry in $allowed ; do
59+ if [[ " $entry " == * " :" * ]]; then
60+ [[ " $device_id " == " $entry " ]] && return
61+ else
62+ [[ " $DEVICE_TYPE " == " $entry " ]] && return
63+ fi
64+ done
65+ echo " Prefix type '$prefix_type ' is not supported on device type '$DEVICE_TYPE ' (subtype: '$DEVICE_SUBTYPE ')." >&2
4666 exit 1
4767}
4868
@@ -147,7 +167,7 @@ handle_prefix_list_single() {
147167}
148168
149169prefix_list_operations=(" add" " remove" " status" )
150- supported_prefix_types=(" ANCHOR_PREFIX" )
170+ supported_prefix_types=(" ANCHOR_PREFIX" " SUPPRESS_PREFIX " )
151171# Main script execution
152172if [[ " $1 " == " -h" || " $1 " == " --help" ]]; then
153173 display_help
156176if [ " $1 " != " status" ]; then
157177 check_root_privileges
158178fi
159- check_spine_router
160179skip_chassis_supervisor
161180
162181validate_operation $1 $2
182+ if [[ " $1 " == " add" || " $1 " == " remove" ]]; then
183+ validate_device_for_type " $2 "
184+ fi
163185
164186# Read SONiC immutable variables
165187[ -f /etc/sonic/sonic-environment ] && . /etc/sonic/sonic-environment
0 commit comments