@@ -608,6 +608,27 @@ def _change_hostname(hostname):
608
608
clicommon .run_command (r'sed -i "/\s{}$/d" /etc/hosts' .format (current_hostname ), display_cmd = True )
609
609
clicommon .run_command ('echo "127.0.0.1 {}" >> /etc/hosts' .format (hostname ), display_cmd = True )
610
610
611
+ def _clear_cbf ():
612
+ CBF_TABLE_NAMES = [
613
+ 'DSCP_TO_FC_MAP' ,
614
+ 'EXP_TO_FC_MAP' ]
615
+
616
+ namespace_list = [DEFAULT_NAMESPACE ]
617
+ if multi_asic .get_num_asics () > 1 :
618
+ namespace_list = multi_asic .get_namespaces_from_linux ()
619
+
620
+ for ns in namespace_list :
621
+ if ns is DEFAULT_NAMESPACE :
622
+ config_db = ConfigDBConnector ()
623
+ else :
624
+ config_db = ConfigDBConnector (
625
+ use_unix_socket_path = True , namespace = ns
626
+ )
627
+ config_db .connect ()
628
+ for cbf_table in CBF_TABLE_NAMES :
629
+ config_db .delete_table (cbf_table )
630
+
631
+
611
632
def _clear_qos ():
612
633
QOS_TABLE_NAMES = [
613
634
'TC_TO_PRIORITY_GROUP_MAP' ,
@@ -2061,6 +2082,83 @@ def start_default(verbose):
2061
2082
2062
2083
clicommon .run_command (cmd , display_cmd = verbose )
2063
2084
2085
+ #
2086
+ # 'cbf' group ('config cbf ...')
2087
+ #
2088
+ @config .group (cls = clicommon .AbbreviationGroup )
2089
+ @click .pass_context
2090
+ def cbf (ctx ):
2091
+ """CBF-related configuration tasks"""
2092
+ pass
2093
+
2094
+ @cbf .command ('clear' )
2095
+ def clear ():
2096
+ """Clear CBF configuration"""
2097
+ log .log_info ("'cbf clear' executing..." )
2098
+ _clear_cbf ()
2099
+
2100
+ @cbf .command ('reload' )
2101
+ @click .pass_context
2102
+ @click .option (
2103
+ '--json-data' , type = click .STRING ,
2104
+ help = "json string with additional data, valid with --dry-run option"
2105
+ )
2106
+ @click .option (
2107
+ '--dry_run' , type = click .STRING ,
2108
+ help = "Dry run, writes config to the given file"
2109
+ )
2110
+ def reload (ctx , dry_run , json_data ):
2111
+ """Reload CBF configuration"""
2112
+ log .log_info ("'cbf reload' executing..." )
2113
+ _clear_cbf ()
2114
+
2115
+ _ , hwsku_path = device_info .get_paths_to_platform_and_hwsku_dirs ()
2116
+ sonic_version_file = device_info .get_sonic_version_file ()
2117
+ from_db = "-d --write-to-db"
2118
+ if dry_run :
2119
+ from_db = "--additional-data \' {}\' " .format (json_data ) if json_data else ""
2120
+
2121
+ namespace_list = [DEFAULT_NAMESPACE ]
2122
+ if multi_asic .get_num_asics () > 1 :
2123
+ namespace_list = multi_asic .get_namespaces_from_linux ()
2124
+
2125
+ for ns in namespace_list :
2126
+ if ns is DEFAULT_NAMESPACE :
2127
+ asic_id_suffix = ""
2128
+ config_db = ConfigDBConnector ()
2129
+ else :
2130
+ asic_id = multi_asic .get_asic_id_from_name (ns )
2131
+ if asic_id is None :
2132
+ click .secho (
2133
+ "Command 'cbf reload' failed with invalid namespace '{}'" .
2134
+ format (ns ),
2135
+ fg = "yellow"
2136
+ )
2137
+ raise click .Abort ()
2138
+ asic_id_suffix = str (asic_id )
2139
+
2140
+ config_db = ConfigDBConnector (
2141
+ use_unix_socket_path = True , namespace = ns
2142
+ )
2143
+
2144
+ config_db .connect ()
2145
+
2146
+ cbf_template_file = os .path .join (hwsku_path , asic_id_suffix , "cbf.json.j2" )
2147
+ if os .path .isfile (cbf_template_file ):
2148
+ cmd_ns = "" if ns is DEFAULT_NAMESPACE else "-n {}" .format (ns )
2149
+ fname = "{}{}" .format (dry_run , asic_id_suffix ) if dry_run else "config-db"
2150
+ command = "{} {} {} -t {},{} -y {}" .format (
2151
+ SONIC_CFGGEN_PATH , cmd_ns , from_db ,
2152
+ cbf_template_file , fname , sonic_version_file
2153
+ )
2154
+
2155
+ # Apply the configuration
2156
+ clicommon .run_command (command , display_cmd = True )
2157
+ else :
2158
+ click .secho ("CBF definition template not found at {}" .format (
2159
+ cbf_template_file
2160
+ ), fg = "yellow" )
2161
+
2064
2162
#
2065
2163
# 'qos' group ('config qos ...')
2066
2164
#
0 commit comments