-
Notifications
You must be signed in to change notification settings - Fork 650
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
Fix to get all port related attributes from config_db #362
Changes from 1 commit
78b6e69
19e49c1
26670e8
5035a05
91ca59e
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 |
---|---|---|
|
@@ -12,16 +12,50 @@ | |
from swsssdk import ConfigDBConnector | ||
from natsort import natsorted | ||
from minigraph import parse_device_desc_xml | ||
from portconfig import get_port_config | ||
|
||
import aaa | ||
import mlnx | ||
|
||
SONIC_CFGGEN_PATH = "sonic-cfggen" | ||
PLATFORM_ROOT_PATH = '/usr/share/sonic/device' | ||
SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' | ||
HWSKU_KEY = 'DEVICE_METADATA.localhost.hwsku' | ||
PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform' | ||
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. Why did you add definitions for 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. Joe, it is added as part of the initiall pull request. This is not necessary. Will remove the lines |
||
|
||
# | ||
# Helper functions | ||
# | ||
|
||
# Returns platform and HW SKU | ||
def get_platform_and_hwsku(): | ||
paavaanan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try: | ||
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], | ||
stdout=subprocess.PIPE, | ||
shell=False, | ||
stderr=subprocess.STDOUT) | ||
stdout = proc.communicate()[0] | ||
proc.wait() | ||
platform = stdout.rstrip('\n') | ||
|
||
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY], | ||
stdout=subprocess.PIPE, | ||
shell=False, | ||
stderr=subprocess.STDOUT) | ||
stdout = proc.communicate()[0] | ||
proc.wait() | ||
hwsku = stdout.rstrip('\n') | ||
except OSError, e: | ||
raise OSError("Cannot detect platform") | ||
|
||
return (platform, hwsku) | ||
|
||
|
||
# Get platform, hwsku and populate port_dict | ||
(platform, hwsku) = get_platform_and_hwsku() | ||
port_config = os.path.join("/usr/share/sonic/device", platform, hwsku, | ||
"port_config.ini") | ||
(port_dict, _) = get_port_config(platform, hwsku, port_config) | ||
paavaanan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
|
||
def run_command(command, display_cmd=False, ignore_error=False): | ||
"""Run bash command and print output to stdout | ||
|
@@ -43,12 +77,9 @@ def interface_alias_to_name(interface_alias): | |
"""Return default interface name if alias name is given as argument | ||
""" | ||
|
||
cmd = 'sonic-cfggen -d --var-json "PORT"' | ||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) | ||
|
||
port_dict = json.loads(p.stdout.read()) | ||
|
||
if interface_alias is not None: | ||
if not port_dict: | ||
click.echo("Invalid alias interface") | ||
for port_name in natsorted(port_dict.keys()): | ||
if interface_alias == port_dict[port_name]['alias']: | ||
return port_name | ||
|
@@ -61,12 +92,9 @@ def interface_name_to_alias(interface_name): | |
"""Return alias interface name if default name is given as argument | ||
""" | ||
|
||
cmd = 'sonic-cfggen -d --var-json "PORT"' | ||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) | ||
|
||
port_dict = json.loads(p.stdout.read()) | ||
|
||
if interface_name is not None: | ||
if not port_dict: | ||
click.echo("Invalid alias interface") | ||
for port_name in natsorted(port_dict.keys()): | ||
if interface_name == port_name: | ||
return port_dict[port_name]['alias'] | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,15 @@ | |
import sonic_platform | ||
from swsssdk import ConfigDBConnector | ||
from swsssdk import SonicV2Connector | ||
from portconfig import get_port_config | ||
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. Why add this import if you are not using it? 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. removed in new commit 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. ? This was not removed. 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 in new commit! |
||
|
||
import mlnx | ||
|
||
PLATFORM_ROOT_PATH = '/usr/share/sonic/device' | ||
SONIC_CFGGEN_PATH = '/usr/local/bin/sonic-cfggen' | ||
HWSKU_KEY = 'DEVICE_METADATA.localhost.hwsku' | ||
PLATFORM_KEY = 'DEVICE_METADATA.localhost.platform' | ||
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. Why add these four constants? They are not used anywhere in the file. 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. Other than SONIC_CFGGEN_PATH removed unused constants |
||
|
||
try: | ||
# noinspection PyPep8Naming | ||
import ConfigParser as configparser | ||
|
@@ -43,15 +49,43 @@ def read_config(self, filename): | |
except configparser.NoSectionError: | ||
pass | ||
|
||
# Returns platform and HW SKU | ||
def get_platform_and_hwsku(): | ||
paavaanan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
try: | ||
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-H', '-v', PLATFORM_KEY], | ||
stdout=subprocess.PIPE, | ||
shell=False, | ||
stderr=subprocess.STDOUT) | ||
stdout = proc.communicate()[0] | ||
proc.wait() | ||
platform = stdout.rstrip('\n') | ||
|
||
proc = subprocess.Popen([SONIC_CFGGEN_PATH, '-d', '-v', HWSKU_KEY], | ||
stdout=subprocess.PIPE, | ||
shell=False, | ||
stderr=subprocess.STDOUT) | ||
stdout = proc.communicate()[0] | ||
proc.wait() | ||
hwsku = stdout.rstrip('\n') | ||
except OSError, e: | ||
raise OSError("Cannot detect platform") | ||
|
||
return (platform, hwsku) | ||
|
||
|
||
class InterfaceAliasConverter(object): | ||
"""Class which handles conversion between interface name and alias""" | ||
|
||
def __init__(self): | ||
self.alias_max_length = 0 | ||
cmd = 'sonic-cfggen -d --var-json "PORT"' | ||
p = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE) | ||
self.port_dict = json.loads(p.stdout.read()) | ||
|
||
# Get platform and hwsku | ||
(platform, hwsku) = get_platform_and_hwsku() | ||
port_config = os.path.join("/usr/share/sonic/device", platform, hwsku, | ||
"port_config.ini") | ||
(self.port_dict, _) = get_port_config(platform, hwsku, port_config) | ||
paavaanan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if not self.port_dict: | ||
click.echo("Invalid alias interface") | ||
|
||
for port_name in self.port_dict.keys(): | ||
if self.alias_max_length < len( | ||
|
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.
Why add this import if you are not using it?
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 in the new commit