-
Notifications
You must be signed in to change notification settings - Fork 710
Confirm portchannel and member ports exist before attempting delete operations #454
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from 6 commits
20272d7
5539480
448d9e2
d1b326e
2e153a8
b3a5e7b
33b0979
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -450,7 +450,13 @@ def add_portchannel(ctx, portchannel_name, min_links, fallback): | |
def remove_portchannel(ctx, portchannel_name): | ||
"""Remove port channel""" | ||
db = ctx.obj['db'] | ||
db.set_entry('PORTCHANNEL', portchannel_name, None) | ||
if len(db.get_entry('PORTCHANNEL', portchannel_name)) != 0: | ||
keys = [(k,v) for k,v in db.get_table('PORTCHANNEL_MEMBER') if k == portchannel_name] | ||
for k in keys: | ||
db.set_entry('PORTCHANNEL_MEMBER', k, None) | ||
db.set_entry('PORTCHANNEL', portchannel_name, None) | ||
else: | ||
ctx.fail("{} is not configured".format(portchannel_name)) | ||
|
||
@portchannel.group('member') | ||
@click.pass_context | ||
|
@@ -464,6 +470,28 @@ def portchannel_member(ctx): | |
def add_portchannel_member(ctx, portchannel_name, port_name): | ||
"""Add member to port channel""" | ||
db = ctx.obj['db'] | ||
port_channel = db.get_entry('PORTCHANNEL', portchannel_name) | ||
if get_interface_naming_mode() == "alias": | ||
port_name = interface_alias_to_name(port_name) | ||
if port_name is None: | ||
ctx.fail("'port_name' is None!") | ||
|
||
if len(port_channel) == 0: | ||
ctx.fail("{} doesn't exists".format(portchannel_name)) | ||
|
||
members = port_channel.get('members', []) | ||
if port_name in members: | ||
if get_interface_naming_mode() == "alias": | ||
port_name = interface_name_to_alias(port_name) | ||
if port_name is None: | ||
ctx.fail("'port_name' is None!") | ||
ctx.fail("{} is already a member of {}".format(port_name, portchannel_name)) | ||
else: | ||
ctx.fail("{} is already a member of {}".format(port_name, portchannel_name)) | ||
|
||
members.append(port_name) | ||
port_channel['members'] = members | ||
db.set_entry('PORTCHANNEL', portchannel_name, port_channel) | ||
db.set_entry('PORTCHANNEL_MEMBER', (portchannel_name, port_name), | ||
{'NULL': 'NULL'}) | ||
|
||
|
@@ -474,9 +502,32 @@ def add_portchannel_member(ctx, portchannel_name, port_name): | |
def del_portchannel_member(ctx, portchannel_name, port_name): | ||
"""Remove member from portchannel""" | ||
db = ctx.obj['db'] | ||
port_channel = db.get_entry('PORTCHANNEL', portchannel_name) | ||
if get_interface_naming_mode() == "alias": | ||
port_name = interface_alias_to_name(port_name) | ||
if port_name is None: | ||
ctx.fail("'port_name' is None!") | ||
|
||
if len(port_channel) == 0: | ||
ctx.fail("{} doesn't exists".format(portchannel_name)) | ||
|
||
members = port_channel.get('members', []) | ||
if port_name not in members: | ||
if get_interface_naming_mode() == "alias": | ||
port_name = interface_name_to_alias(port_name) | ||
if port_name is None: | ||
ctx.fail("'port_name' is None!") | ||
ctx.fail("{} is not a member of {}".format(port_name, portchannel_name)) | ||
else: | ||
ctx.fail("{} is not a member of {}".format(port_name, portchannel_name)) | ||
|
||
members.remove(port_name) | ||
if len(members) == 0: | ||
del port_channel['members'] | ||
else: | ||
port_channel['members'] = members | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we need the Thanks There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. addressed the review comments and updated the PR. Thanks. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. there're alternative ways of checking if the port-channel has members or not. please do not use this approach. we are trying to make the code DRY by not having duplicated information on two places; this attribute won't be supported in the future release |
||
db.set_entry('PORTCHANNEL', portchannel_name, port_channel) | ||
db.set_entry('PORTCHANNEL_MEMBER', (portchannel_name, port_name), None) | ||
db.set_entry('PORTCHANNEL_MEMBER', portchannel_name + '|' + port_name, None) | ||
|
||
|
||
# | ||
# 'mirror_session' group ('config mirror_session ...') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this line duplicate with line 475?
if it is 'alias' mode and the port_name is already in members, it will try to convert the name again?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review comments, I'll fix and run the test cases, will update the PR shortly