-
Notifications
You must be signed in to change notification settings - Fork 664
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
[sonic-utilities] managementVRF cli support(l3mdev) #463
[sonic-utilities] managementVRF cli support(l3mdev) #463
Conversation
c69c660
to
fcdec1b
Compare
fcdec1b
to
c7917f1
Compare
This commit adds CLI support for management VRF using l3dev. mVRF can be enabled using config vrf add mgmt and deleted using config vrf del mgmt. Show commands for management VRF are added which displays the linux command output, will update show command display after concluding what would be the output for the show commands. Added cli to configure management interface(eth0), config interface ip eth0 add can be used to configure eth0 ip and config ip eth0 remove is used to remove eth0 ip. New cli config/show commands: config vrf add mgmt config vrf del mgmt config interface eth0 ip add ip/mask gatewayIP config interface eth0 ip remove ip/mask show mgmt-vrf show mgmt-vrf route show mgmt-vrf addresses show mgmt-vrf interfaces Signed-off-by: Harish Venkatraman <[email protected]>
c7917f1
to
afcfc4b
Compare
What relationship exists between managementVRF and VRF feature ? |
@a-barboza, these are two different features implemented separately. This CLI is being reviewed by the VRF work-group and checked for any commonalities. |
@prsunny Looks like there are quire a few commonalities (Eg: config vrf add, ...). So it is likely the patch will be redone. |
@jleveque : Resolved the conflict. Request you to kindly review and merge it. |
Is there a location where the table # of 5000 use for mgmt-vrf is mentioned ? I checked the mgmt-vrf HLD document but could not find a reference other than "1" in the example linux commands. |
@a-barboza : We shall update the document once if the PR is merged. Just waiting to see if there could be any changes in the CLI before merging based on any review comments. |
@a-barboza : Some of your questions from PR472 that are relevant for this PR are answered here.
|
@kannankvs: thanks for the replies. For answer 3 above: Will the HLD for management vrf be updated to state the following " As of now, eth0 alone will be part of mvrf; not front panel ports" ? |
@a-barboza : Yes, we will update it. |
config/main.py
Outdated
config_db.connect() | ||
entry = config_db.get_entry('MGMT_VRF_CONFIG', "vrf_global") | ||
if entry and entry['mgmtVrfEnabled'] == 'true' : | ||
click.echo("ManagementVRF is already Enabled.") |
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.
Can you fix the alignment here? Looks like tab spaces
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.
Done.
config/main.py
Outdated
click.echo("ManagementVRF is already Enabled.") | ||
return None | ||
config_db.mod_entry('MGMT_VRF_CONFIG',"vrf_global",{"mgmtVrfEnabled": "true"}) | ||
cmd="service ntp stop" |
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.
Can you add this to a function and give a comment why this has to be restarted? Also in future if another service is required to be restarted, it can be in one place. Currently I see this repeated
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.
Done. Moved it to a function and provided the required comments.
config/main.py
Outdated
|
||
@config.command('clear_mgmt') | ||
@click.pass_context | ||
def clear_mgmt(ctx): |
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.
What is the purpose of this? Is the backend code handling this? What if the user configures management VRF and then do a clear?
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.
clear_mgmt was earlier indented for easy deletion of configured values. Now that we have required "del/remove" functions, it is not required. It is removed now.
config/main.py
Outdated
|
||
for key in mgmtintf_key_list: | ||
# For loop runs for max 2 rows, once for IPv4 and once for IPv6. | ||
if ':' in ip_addr and ':' in key[1]: |
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.
Please use version from IPAddress to check for IPv4 and IPv6.
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.
Done. When mvrf was implemented in Feb2019, "ipaddress" module did not have the required path and hence it was unable to import. Now, the "ipaddress" module is available and it is already being used in main.py. It is now used in this function to check the version.
config/main.py
Outdated
@@ -991,6 +1108,12 @@ def remove(ctx, interface_name, ip_addr): | |||
if interface_name.startswith("Ethernet"): | |||
config_db.set_entry("INTERFACE", (interface_name, ip_addr), None) | |||
if_table = "INTERFACE" | |||
elif interface_name == 'eth0': | |||
config_db.set_entry("MGMT_INTERFACE", (interface_name, ip_addr), None) | |||
cmd="systemctl restart interfaces-config" |
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.
As mentioned above, this must be in a separate function to avoid duplication
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.
Done.
show/main.py
Outdated
|
||
|
||
@mgmt_vrf.command('addresses') | ||
def mgmt_vrf_addresses (): |
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.
This is confusing to show 'addresses' and 'address'. Can you paste both output. I think this can be removed and just use address
in L493
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.
Removed the confusing command. Like you said "show management_interface address" is good enough to display the configure address for eth0.
show/main.py
Outdated
cmd = "ntpq -p -n" | ||
run_command(cmd, display_cmd=verbose) | ||
ntpcmd = "ntpq -p -n" | ||
if ctx.invoked_subcommand is None: |
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.
As mentioned above, please use a function to check if mgmt vrf is enabled.
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.
Done.
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.
Not yet done, please address the earlier comment
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.
While resolving conflict, change got overwritten. Its resolved now. Apologies.
config/main.py
Outdated
"""VRF-related configuration tasks""" | ||
pass | ||
|
||
|
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.
Please remove extra line
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.
Done
@prsunny : Comments are addressed. Request you to review and merge. |
config/main.py
Outdated
click.echo("ManagementVRF is already Enabled.") | ||
return None | ||
config_db.mod_entry('MGMT_VRF_CONFIG',"vrf_global",{"mgmtVrfEnabled": "true"}) | ||
# To move eth0 to management VRF, interfaces-config service has be to be |
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.
Please move this comments to the below function. This is repeated below as well. Also please follow the multi-line comment format
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.
Actually the comments are slightly different for enable and disable conditions. That is why it was provided at this place. Now, the comments are moved inside the function and reworded to suit for both enable and disable conditions. By multi-line, we assume you meant the usage of """, which is also done now.
config/main.py
Outdated
return config_db.get_table('MGMT_INTERFACE').keys() | ||
|
||
|
||
def restart_interfaces_config_ntp_config(): |
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.
What is the difference between this and mvrf_restart_interfaces_config_ntp? Can we use the same?
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.
There is a difference. One is restarting the "ntp-config" service and the other is restarting "ntp" service. "ntp-config" service will regenerate the ntp.conf file, which is required when the IP address for eth0 is modified. Same is not required when VRF is enabled or disabled.
config/main.py
Outdated
# No need to capture the exception since the ip_addr is already validated earlier | ||
ip_input = ipaddress.ip_interface(ip_addr) | ||
current_ip = ip = ipaddress.ip_interface(key[1]) | ||
if (ip_input.version == 6) and (current_ip.version == 6): |
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.
if (ip_input.version == current_ip.version)
will cover both cases right?
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.
yes, it will cover. Changed.
show/main.py
Outdated
|
||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | ||
res = p.communicate() | ||
if p.returncode == 0 : |
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.
Extra space after 0
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.
Done.
show/main.py
Outdated
mvrf_dict = json.loads(p.stdout.read()) | ||
|
||
# if the mgmtVrfEnabled attribute is configured, check the value | ||
# and print Enabled or Disabled accordingly. |
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.
You may want to rephrase the comment here.
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.
Done.
show/main.py
Outdated
"""Show management VRF attributes""" | ||
|
||
if is_mgmt_vrf_enabled(ctx) is False: | ||
click.echo("\nKVSK:ManagementVRF : Disabled") |
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.
KVSK??
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.
Done.
show/main.py
Outdated
mgmt_ip_data = config_db.get_table('MGMT_INTERFACE') | ||
for key in natsorted(mgmt_ip_data.keys()): | ||
click.echo("Management IP address = {0}".format(key[1])) | ||
click.echo("Management NetWork Default Gateway = {0}".format(mgmt_ip_data[key]['gwaddr'])) |
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.
Network
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.
Done.
show/main.py
Outdated
cmd = "ntpq -p -n" | ||
run_command(cmd, display_cmd=verbose) | ||
ntpcmd = "ntpq -p -n" | ||
if ctx.invoked_subcommand is None: |
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.
Not yet done, please address the earlier comment
@prsunny : Addressed the new comments as well. |
Shall "MGMT_INTERFACE|eth0" be updated into the vrf "mgmt" in the CONFIG_DB when doing
|
Thats right Wenda |
This commit adds CLI support for management VRF using l3dev. mVRF can
be enabled using config vrf add mgmt and deleted using config vrf del mgmt.
Show commands for management VRF are added which displays the Linux command
output, will update show command display after concluding what would be the
output for the show commands.
Added cli to configure management interface(eth0), config interface ip eth0
add can be used to configure eth0 ip and config ip eth0 remove is used to
remove eth0 ip.
New cli config/show commands:
Signed-off-by: Harish Venkatraman [email protected]
- What I did
Added CLI support for management VRF
- How I did it
Added following new CLI commands to enable and disable management VRF using l3mdev and configure eth0 management interface ip address.
Modified show ntp command
- How to verify it
Configure management VRF using the above config command and use the show commands to display the output of mgmt-vrf interfaces, addresses, route and ntp.
- Previous command output (if the output of a command-line utility has changed)
- New command output (if the output of a command-line utility has changed)
-->
SAMPLE OUTPUTS OF SHOW COMMANDS
show mgmt-vrf
show mgmt-vrf routes
show management_interface address