Skip to content

Commit

Permalink
change to decorated
Browse files Browse the repository at this point in the history
  • Loading branch information
Ubuntu committed Jun 2, 2022
1 parent e4db00c commit 8259894
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 10 deletions.
20 changes: 10 additions & 10 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1893,34 +1893,34 @@ def portchannel(db, ctx, namespace):
def add_portchannel(ctx, portchannel_name, min_links, fallback):
"""Add port channel"""

db = ctx.obj['db']
validated_db = ValidatedConfigDBConnector(db)

if is_portchannel_present_in_db(db, portchannel_name):
ctx.fail("{} already exists!".format(portchannel_name))

db = ValidatedConfigDBConnector()
db.connect()

fvs = {"admin_status": "up",
"mtu": "9100",
"lacp_key": "auto"}
fvs = {'admin_status': 'up',
'mtu': '9100',
'lacp_key': 'auto'}
if min_links != 0:
fvs["min_links"] = str(min_links)
if fallback != "false":
fvs["fallback"] = "true"
db.set_entry('PORTCHANNEL', portchannel_name, fvs)
validated_db.set_entry('PORTCHANNEL', portchannel_name, fvs)

@portchannel.command('del')
@click.argument('portchannel_name', metavar='<portchannel_name>', required=True)
@click.pass_context
def remove_portchannel(ctx, portchannel_name):
"""Remove port channel"""

db = ValidatedConfigDBConnector()
db.connect()
db = ctx.obj['db']
validated_db = ValidatedConfigDBConnector(db)

if len([(k, v) for k, v in db.get_table('PORTCHANNEL_MEMBER') if k == portchannel_name]) != 0:
click.echo("Error: Portchannel {} contains members. Remove members before deleting Portchannel!".format(portchannel_name))
else:
db.set_entry('PORTCHANNEL', portchannel_name, None)
validated_db.set_entry('PORTCHANNEL', portchannel_name, None)

@portchannel.group(cls=clicommon.AbbreviationGroup, name='member')
@click.pass_context
Expand Down
3 changes: 3 additions & 0 deletions config/validated_config_db_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

class ValidatedConfigDBConnector(ConfigDBConnector):

def __init__(self, db):
pass

def set_entry(self, table, key, value):
if value:
op = "add"
Expand Down

0 comments on commit 8259894

Please sign in to comment.