diff --git a/config/main.py b/config/main.py index 3033145f..8edfeca4 100644 --- a/config/main.py +++ b/config/main.py @@ -5432,6 +5432,9 @@ def vrf(ctx): config_db.connect() ctx.obj = {} ctx.obj['config_db'] = config_db + state_db = SonicV2Connector(host='127.0.0.1') + state_db.connect(state_db.STATE_DB, False) + ctx.obj['state_db'] = state_db @vrf.command('add') @click.argument('vrf_name', metavar='', required=True) @@ -5439,6 +5442,8 @@ def vrf(ctx): def add_vrf(ctx, vrf_name): """Add vrf""" config_db = ValidatedConfigDBConnector(ctx.obj['config_db']) + state_db = ctx.obj['state_db'] + if not vrf_name.startswith("Vrf") and not (vrf_name == 'mgmt') and not (vrf_name == 'management'): ctx.fail("'vrf_name' must begin with 'Vrf' or named 'mgmt'/'management' in case of ManagementVRF.") if len(vrf_name) > 15: @@ -5449,6 +5454,12 @@ def add_vrf(ctx, vrf_name): vrf_add_management_vrf(config_db) else: try: + state_db.connect(state_db.STATE_DB, False) + _hash = '{}{}'.format('VRF_OBJECT_TABLE|', vrf_name) + while state_db.exists(state_db.STATE_DB, _hash): + log.log_info("Wait to remove {}!!!".format(vrf_name)) + time.sleep(0.01) + state_db.close(state_db.STATE_DB) config_db.set_entry('VRF', vrf_name, {"NULL": "NULL"}) except ValueError as e: ctx.fail("Invalid ConfigDB. Error: {}".format(e))