|
14 | 14 | import ipaddress |
15 | 15 | from swsssdk import ConfigDBConnector, SonicV2Connector, SonicDBConfig |
16 | 16 | from minigraph import parse_device_desc_xml |
17 | | -from config_mgmt import configMgmt |
| 17 | +from config_mgmt import ConfigMgmt, ConfigMgmtDPB |
18 | 18 |
|
19 | 19 | import aaa |
20 | 20 | import mlnx |
@@ -208,17 +208,37 @@ def _validate_interface_mode(ctx, BREAKOUT_CFG_FILE, interface_name, target_brko |
208 | 208 | sys.exit(0) |
209 | 209 | return True |
210 | 210 |
|
211 | | -def load_configMgmt(verbose): |
| 211 | +def load_ConfigMgmt(verbose): |
212 | 212 | """ Load config for the commands which are capable of change in config DB. """ |
213 | 213 | try: |
214 | | - # TODO: set allowExtraTables to False, i.e we should have yang models for |
215 | | - # each table in Config. [TODO: Create Yang model for each Table] |
216 | | - # cm = configMgmt(debug=verbose, allowExtraTables=False) |
217 | | - cm = configMgmt(debug=verbose, allowExtraTables=True) |
| 214 | + cm = ConfigMgmtDPB(debug=verbose) |
218 | 215 | return cm |
219 | 216 | except Exception as e: |
220 | 217 | raise Exception("Failed to load the config. Error: {}".format(str(e))) |
221 | 218 |
|
| 219 | +""" |
| 220 | +Funtion to warn user about extra tables while Dynamic Port Breakout(DPB). |
| 221 | +confirm: re-confirm from user to proceed. |
| 222 | +Config Tables Without Yang model considered extra tables. |
| 223 | +cm = instance of config MGMT class. |
| 224 | +""" |
| 225 | +def breakout_warnUser_extraTables(cm, final_delPorts, confirm=True): |
| 226 | + |
| 227 | + try: |
| 228 | + # check if any extra tables exist |
| 229 | + eTables = cm.tablesWithOutYang() |
| 230 | + if len(eTables): |
| 231 | + # find relavent tables in extra tables, i.e. one which can have deleted |
| 232 | + # ports |
| 233 | + tables = cm.configWithKeys(configIn=eTables, keys=final_delPorts) |
| 234 | + click.secho("Below Config can not be verified, It may cause harm "\ |
| 235 | + "to the system\n {}".format(json.dumps(tables, indent=2))) |
| 236 | + click.confirm('Do you wish to Continue?', abort=True) |
| 237 | + except Exception as e: |
| 238 | + raise Exception("Failed in breakout_warnUser_extraTables. Error: {}".format(str(e))) |
| 239 | + |
| 240 | + return |
| 241 | + |
222 | 242 | def breakout_Ports(cm, delPorts=list(), addPorts=list(), portJson=dict(), \ |
223 | 243 | force=False, loadDefConfig=True, verbose=False): |
224 | 244 |
|
@@ -2060,11 +2080,14 @@ def breakout(ctx, interface_name, mode, verbose, force_remove_dependencies, load |
2060 | 2080 | # Start Interation with Dy Port BreakOut Config Mgmt |
2061 | 2081 | try: |
2062 | 2082 | """ Load config for the commands which are capable of change in config DB """ |
2063 | | - cm = load_configMgmt(verbose) |
| 2083 | + cm = load_ConfigMgmt(verbose) |
2064 | 2084 |
|
2065 | | - """ Delete all ports if forced else print dependencies using configMgmt API """ |
| 2085 | + """ Delete all ports if forced else print dependencies using ConfigMgmt API """ |
2066 | 2086 | final_delPorts = [intf for intf in del_intf_dict.keys()] |
2067 | | - """ Add ports with its attributes using configMgmt API """ |
| 2087 | + """ Warn user if tables without yang models exist and have final_delPorts """ |
| 2088 | + breakout_warnUser_extraTables(cm, final_delPorts, confirm=True) |
| 2089 | + # prompt |
| 2090 | + """ Add ports with its attributes using ConfigMgmt API """ |
2068 | 2091 | final_addPorts = [intf for intf in port_dict.keys()] |
2069 | 2092 | portJson = dict(); portJson['PORT'] = port_dict |
2070 | 2093 | # breakout_Ports will abort operation on failure, So no need to check return |
|
0 commit comments