From 8d974001a9dcf51f38091011bc1fecd34ca895ab Mon Sep 17 00:00:00 2001 From: Joe LeVeque Date: Tue, 30 Apr 2019 16:58:57 -0700 Subject: [PATCH] [show] Call teamshow using sudo in 'show interfaces portchannel' (#524) * teamshow now also prints message and exits if not run as root --- scripts/teamshow | 7 +++++-- show/main.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/teamshow b/scripts/teamshow index 3c157f75f..3ea2691ed 100755 --- a/scripts/teamshow +++ b/scripts/teamshow @@ -19,6 +19,7 @@ """ import json +import os import re import swsssdk import subprocess @@ -127,6 +128,9 @@ class Teamshow(object): print tabulate(output, header) def main(): + if os.geteuid() != 0: + exit("This utility must be run as root") + try: team = Teamshow() team.get_portchannel_names() @@ -134,8 +138,7 @@ def main(): team.get_teamshow_result() team.display_summary() except Exception as e: - print e.message - sys.exit(1) + sys.exit(e.message) if __name__ == "__main__": main() diff --git a/show/main.py b/show/main.py index b853507b6..1a078ad13 100755 --- a/show/main.py +++ b/show/main.py @@ -617,7 +617,7 @@ def rif(interface, period, verbose): @click.option('--verbose', is_flag=True, help="Enable verbose output") def portchannel(verbose): """Show PortChannel information""" - cmd = "teamshow" + cmd = "sudo teamshow" run_command(cmd, display_cmd=verbose) #