3030from utilities_common .general import load_db_config
3131
3232from .utils import log
33+ from .yang_validation_service import YangValidationService
3334
3435from . import aaa
3536from . import chassis_modules
@@ -1753,10 +1754,6 @@ def portchannel(ctx, namespace):
17531754@click .pass_context
17541755def add_portchannel (ctx , portchannel_name , min_links , fallback ):
17551756 """Add port channel"""
1756- if is_portchannel_name_valid (portchannel_name ) != True :
1757- ctx .fail ("{} is invalid!, name should have prefix '{}' and suffix '{}'"
1758- .format (portchannel_name , CFG_PORTCHANNEL_PREFIX , CFG_PORTCHANNEL_NO ))
1759-
17601757 db = ctx .obj ['db' ]
17611758
17621759 if is_portchannel_present_in_db (db , portchannel_name ):
@@ -1769,17 +1766,18 @@ def add_portchannel(ctx, portchannel_name, min_links, fallback):
17691766 fvs ['min_links' ] = str (min_links )
17701767 if fallback != 'false' :
17711768 fvs ['fallback' ] = 'true'
1772- db .set_entry ('PORTCHANNEL' , portchannel_name , fvs )
1769+ yvs = YangValidationService ()
1770+ if not yvs .validate_set_entry ('PORTCHANNEL' , portchannel_name , fvs ):
1771+ ctx .fail ("Invalid configuration based on PortChannel YANG model" )
1772+ else :
1773+ db .set_entry ('PORTCHANNEL' , portchannel_name , fvs )
1774+
17731775
17741776@portchannel .command ('del' )
17751777@click .argument ('portchannel_name' , metavar = '<portchannel_name>' , required = True )
17761778@click .pass_context
17771779def remove_portchannel (ctx , portchannel_name ):
17781780 """Remove port channel"""
1779- if is_portchannel_name_valid (portchannel_name ) != True :
1780- ctx .fail ("{} is invalid!, name should have prefix '{}' and suffix '{}'"
1781- .format (portchannel_name , CFG_PORTCHANNEL_PREFIX , CFG_PORTCHANNEL_NO ))
1782-
17831781 db = ctx .obj ['db' ]
17841782
17851783 # Dont proceed if the port channel does not exist
@@ -1789,7 +1787,11 @@ def remove_portchannel(ctx, portchannel_name):
17891787 if len ([(k , v ) for k , v in db .get_table ('PORTCHANNEL_MEMBER' ) if k == portchannel_name ]) != 0 :
17901788 click .echo ("Error: Portchannel {} contains members. Remove members before deleting Portchannel!" .format (portchannel_name ))
17911789 else :
1792- db .set_entry ('PORTCHANNEL' , portchannel_name , None )
1790+ yvs = YangValidationService ()
1791+ if not yvs .validate_set_entry ('PORTCHANNEL' , portchannel_name , None ):
1792+ ctx .fail ("Invalid configuration based on PortChannel YANG model" )
1793+ else :
1794+ db .set_entry ('PORTCHANNEL' , portchannel_name , None )
17931795
17941796@portchannel .group (cls = clicommon .AbbreviationGroup , name = 'member' )
17951797@click .pass_context
0 commit comments