diff --git a/config/main.py b/config/main.py index b1bf599a83..3dd783bce8 100644 --- a/config/main.py +++ b/config/main.py @@ -4772,6 +4772,11 @@ def bind(ctx, interface_name, vrf_name): interface_addresses = get_interface_ipaddresses(config_db, interface_name) for ipaddress in interface_addresses: remove_router_interface_ip_address(config_db, interface_name, ipaddress) + if interface_type == "VLAN_SUB_INTERFACE": + subintf = config_db.get_entry(interface_type, alias) + if 'vrf_name' in subintf_entry: + subintf_entry.pop('vrf') + config_db.set_entry(table_name, interface_name, None) # When config_db del entry and then add entry with same key, the DEL will lost. if ctx.obj['namespace'] is DEFAULT_NAMESPACE: @@ -4783,6 +4788,10 @@ def bind(ctx, interface_name, vrf_name): while state_db.exists(state_db.STATE_DB, _hash): time.sleep(0.01) state_db.close(state_db.STATE_DB) + if interface_type == "VLAN_SUB_INTERFACE": + subintf['vrf_name'] = vrfname + config_db.set_entry(interface_type, alias, subintf) + else: config_db.set_entry(table_name, interface_name, {"vrf_name": vrf_name}) # @@ -6582,6 +6591,18 @@ def subintf_vlan_check(config_db, parent_intf, vlan): return True return False +def is_subintf_shortname(intf): + if VLAN_SUB_INTERFACE_SEPARATOR in intf: + if intf.startswith("Eth"): + if intf.startswith("Ethernet"): + return False + return True + elif intf.startswith("Po"): + if intf.startswith("PortChannel"): + return False + return True + return False + @subinterface.command('add') @click.argument('subinterface_name', metavar='', required=True) @click.argument('vid', metavar='', required=False, type=click.IntRange(1,4094)) @@ -6627,6 +6648,8 @@ def add_subinterface(ctx, subinterface_name, vid): subintf_dict = {} if vid is not None: subintf_dict.update({"vlan" : vid}) + elif is_subintf_shortname(subinterface_name): + ctx.fail("{} Encap vlan is mandatory for short name subinterfaces".format(subinterface_name)) if subintf_vlan_check(config_db, get_intf_longname(interface_alias), vid) is True: ctx.fail("Vlan {} encap already configured on other subinterface on {}".format(vid, interface_alias))