|
27 | 27 | from utilities_common.intf_filter import parse_interface_in_filter
|
28 | 28 | from utilities_common import bgp_util
|
29 | 29 | import utilities_common.cli as clicommon
|
| 30 | +from utilities_common.helper import get_port_pbh_binding, get_port_acl_binding |
30 | 31 | from utilities_common.general import load_db_config, load_module_from_source
|
31 | 32 |
|
32 | 33 | from .utils import log
|
@@ -1802,14 +1803,15 @@ def synchronous_mode(sync_mode):
|
1802 | 1803 | @click.option('-n', '--namespace', help='Namespace name',
|
1803 | 1804 | required=True if multi_asic.is_multi_asic() else False, type=click.Choice(multi_asic.get_namespace_list()))
|
1804 | 1805 | @click.pass_context
|
1805 |
| -def portchannel(ctx, namespace): |
| 1806 | +@clicommon.pass_db |
| 1807 | +def portchannel(db, ctx, namespace): |
1806 | 1808 | # Set namespace to default_namespace if it is None.
|
1807 | 1809 | if namespace is None:
|
1808 | 1810 | namespace = DEFAULT_NAMESPACE
|
1809 | 1811 |
|
1810 | 1812 | config_db = ConfigDBConnector(use_unix_socket_path=True, namespace=str(namespace))
|
1811 | 1813 | config_db.connect()
|
1812 |
| - ctx.obj = {'db': config_db, 'namespace': str(namespace)} |
| 1814 | + ctx.obj = {'db': config_db, 'namespace': str(namespace), 'db_wrap': db} |
1813 | 1815 |
|
1814 | 1816 | @portchannel.command('add')
|
1815 | 1817 | @click.argument('portchannel_name', metavar='<portchannel_name>', required=True)
|
@@ -1939,6 +1941,22 @@ def add_portchannel_member(ctx, portchannel_name, port_name):
|
1939 | 1941 | if port_tpid != DEFAULT_TPID:
|
1940 | 1942 | ctx.fail("Port TPID of {}: {} is not at default 0x8100".format(port_name, port_tpid))
|
1941 | 1943 |
|
| 1944 | + # Don't allow a port to be a member of portchannel if already has ACL bindings |
| 1945 | + try: |
| 1946 | + acl_bindings = get_port_acl_binding(ctx.obj['db_wrap'], port_name, ctx.obj['namespace']) |
| 1947 | + if acl_bindings: |
| 1948 | + ctx.fail("Port {} is already bound to following ACL_TABLES: {}".format(port_name, acl_bindings)) |
| 1949 | + except Exception as e: |
| 1950 | + ctx.fail(str(e)) |
| 1951 | + |
| 1952 | + # Don't allow a port to be a member of portchannel if already has PBH bindings |
| 1953 | + try: |
| 1954 | + pbh_bindings = get_port_pbh_binding(ctx.obj['db_wrap'], port_name, DEFAULT_NAMESPACE) |
| 1955 | + if pbh_bindings: |
| 1956 | + ctx.fail("Port {} is already bound to following PBH_TABLES: {}".format(port_name, pbh_bindings)) |
| 1957 | + except Exception as e: |
| 1958 | + ctx.fail(str(e)) |
| 1959 | + |
1942 | 1960 | db.set_entry('PORTCHANNEL_MEMBER', (portchannel_name, port_name),
|
1943 | 1961 | {'NULL': 'NULL'})
|
1944 | 1962 |
|
|
0 commit comments