Skip to content

Commit

Permalink
[config]: add the vid range check for creating vlan. (#634)
Browse files Browse the repository at this point in the history
Signed-off-by: wangshengjun <wangshengjun@asterfusion.com>
  • Loading branch information
wangshengjun authored and lguohan committed Nov 14, 2019
1 parent fe4446a commit 201132d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -835,11 +835,14 @@ def vlan(ctx, redis_unix_socket_path):
@click.argument('vid', metavar='<vid>', required=True, type=int)
@click.pass_context
def add_vlan(ctx, vid):
db = ctx.obj['db']
vlan = 'Vlan{}'.format(vid)
if len(db.get_entry('VLAN', vlan)) != 0:
ctx.fail("{} already exists".format(vlan))
db.set_entry('VLAN', vlan, {'vlanid': vid})
if vid >= 1 and vid <= 4094:
db = ctx.obj['db']
vlan = 'Vlan{}'.format(vid)
if len(db.get_entry('VLAN', vlan)) != 0:
ctx.fail("{} already exists".format(vlan))
db.set_entry('VLAN', vlan, {'vlanid': vid})
else :
ctx.fail("Invalid VLAN ID {} (1-4094)".format(vid))

@vlan.command('del')
@click.argument('vid', metavar='<vid>', required=True, type=int)
Expand Down

0 comments on commit 201132d

Please sign in to comment.